Skip to content

Commit 2565630

Browse files
Yu Kuaiaxboe
authored andcommitted
blk-cgroup: protect iterating blkgs with blkcg->lock in blkcg_print_stat()
blkcg_print_one_stat() will be called for each blkg: - access blkg->iostat, which is freed from rcu callback blkg_free_workfn(); - access policy data from pd_stat_fn(), which is freed from pd_free_fn(), while pd_free_fn() can be called by removing blkcg or deactivating policy; Take blkcg->lock while iterating so the blkgs stay online and both blkg->iostat and policy data for activated policies stay valid. Use irq-safe locking because blkcg->lock can be nested under q->queue_lock, which is used from IRQ completion paths. Prepare to convert protecting blkgs from request_queue with mutex. Signed-off-by: Yu Kuai <yukuai@fygo.io> Link: https://patch.msgid.link/05799877e720dcd300e2ddd4625e8e162959d7cc.1780621988.git.yukuai@fygo.io Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8a901e6 commit 2565630

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

block/blk-cgroup.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,13 +1191,10 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
11911191
else
11921192
css_rstat_flush(&blkcg->css);
11931193

1194-
rcu_read_lock();
1195-
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
1196-
spin_lock_irq(&blkg->q->queue_lock);
1194+
guard(spinlock_irq)(&blkcg->lock);
1195+
hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node)
11971196
blkcg_print_one_stat(blkg, sf);
1198-
spin_unlock_irq(&blkg->q->queue_lock);
1199-
}
1200-
rcu_read_unlock();
1197+
12011198
return 0;
12021199
}
12031200

0 commit comments

Comments
 (0)