Skip to content

Commit 8b8ace0

Browse files
Ming Leiaxboe
authored andcommitted
block: fix q->blkg_list corruption during disk rebind
Multiple gendisk instances can allocated/added for single request queue in case of disk rebind. blkg may still stay in q->blkg_list when calling blkcg_init_disk() for rebind, then q->blkg_list becomes corrupted. Fix the list corruption issue by: - add blkg_init_queue() to initialize q->blkg_list & q->blkcg_mutex only - move calling blkg_init_queue() into blk_alloc_queue() The list corruption should be started since commit f1c006f ("blk-cgroup: synchronize pd_free_fn() from blkg_free_workfn() and blkcg_deactivate_policy()") which delays removing blkg from q->blkg_list into blkg_free_workfn(). Fixes: f1c006f ("blk-cgroup: synchronize pd_free_fn() from blkg_free_workfn() and blkcg_deactivate_policy()") Fixes: 1059699 ("block: move blkcg initialization/destroy into disk allocation/release handler") Cc: Yu Kuai <yukuai3@huawei.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Yu Kuai <yukuai3@huawei.com> Link: https://lore.kernel.org/r/20240407125910.4053377-1-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent beaa51b commit 8b8ace0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

block/blk-cgroup.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,16 +1409,19 @@ static int blkcg_css_online(struct cgroup_subsys_state *css)
14091409
return 0;
14101410
}
14111411

1412+
void blkg_init_queue(struct request_queue *q)
1413+
{
1414+
INIT_LIST_HEAD(&q->blkg_list);
1415+
mutex_init(&q->blkcg_mutex);
1416+
}
1417+
14121418
int blkcg_init_disk(struct gendisk *disk)
14131419
{
14141420
struct request_queue *q = disk->queue;
14151421
struct blkcg_gq *new_blkg, *blkg;
14161422
bool preloaded;
14171423
int ret;
14181424

1419-
INIT_LIST_HEAD(&q->blkg_list);
1420-
mutex_init(&q->blkcg_mutex);
1421-
14221425
new_blkg = blkg_alloc(&blkcg_root, disk, GFP_KERNEL);
14231426
if (!new_blkg)
14241427
return -ENOMEM;

block/blk-cgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ struct blkcg_policy {
189189
extern struct blkcg blkcg_root;
190190
extern bool blkcg_debug_stats;
191191

192+
void blkg_init_queue(struct request_queue *q);
192193
int blkcg_init_disk(struct gendisk *disk);
193194
void blkcg_exit_disk(struct gendisk *disk);
194195

@@ -482,6 +483,7 @@ struct blkcg {
482483
};
483484

484485
static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { return NULL; }
486+
static inline void blkg_init_queue(struct request_queue *q) { }
485487
static inline int blkcg_init_disk(struct gendisk *disk) { return 0; }
486488
static inline void blkcg_exit_disk(struct gendisk *disk) { }
487489
static inline int blkcg_policy_register(struct blkcg_policy *pol) { return 0; }

block/blk-core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
442442
init_waitqueue_head(&q->mq_freeze_wq);
443443
mutex_init(&q->mq_freeze_lock);
444444

445+
blkg_init_queue(q);
446+
445447
/*
446448
* Init percpu_ref in atomic mode so that it's faster to shutdown.
447449
* See blk_register_queue() for details.

0 commit comments

Comments
 (0)