Skip to content

Commit 901932a

Browse files
Jiang Biaoaxboe
authored andcommitted
blkcg: init root blkcg_gq under lock
The initializing of q->root_blkg is currently outside of queue lock and rcu, so the blkg may be destroied before the initializing, which may cause dangling/null references. On the other side, the destroys of blkg are protected by queue lock or rcu. Put the initializing inside the queue lock and rcu to make it safer. Signed-off-by: Jiang Biao <jiang.biao2@zte.com.cn> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn> CC: Tejun Heo <tj@kernel.org> CC: Jens Axboe <axboe@kernel.dk> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bea5488 commit 901932a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

block/blk-cgroup.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,25 +1181,30 @@ int blkcg_init_queue(struct request_queue *q)
11811181
rcu_read_lock();
11821182
spin_lock_irq(q->queue_lock);
11831183
blkg = blkg_create(&blkcg_root, q, new_blkg);
1184+
if (IS_ERR(blkg))
1185+
goto err_unlock;
1186+
q->root_blkg = blkg;
1187+
q->root_rl.blkg = blkg;
11841188
spin_unlock_irq(q->queue_lock);
11851189
rcu_read_unlock();
11861190

11871191
if (preloaded)
11881192
radix_tree_preload_end();
11891193

1190-
if (IS_ERR(blkg))
1191-
return PTR_ERR(blkg);
1192-
1193-
q->root_blkg = blkg;
1194-
q->root_rl.blkg = blkg;
1195-
11961194
ret = blk_throtl_init(q);
11971195
if (ret) {
11981196
spin_lock_irq(q->queue_lock);
11991197
blkg_destroy_all(q);
12001198
spin_unlock_irq(q->queue_lock);
12011199
}
12021200
return ret;
1201+
1202+
err_unlock:
1203+
spin_unlock_irq(q->queue_lock);
1204+
rcu_read_unlock();
1205+
if (preloaded)
1206+
radix_tree_preload_end();
1207+
return PTR_ERR(blkg);
12031208
}
12041209

12051210
/**

0 commit comments

Comments
 (0)