Skip to content

Commit 14ef496

Browse files
shroffniaxboe
authored andcommitted
block: fix nr_hw_queue update racing with disk addition/removal
The nr_hw_queue update could potentially race with disk addtion/removal while registering/unregistering hctx sysfs files. The __blk_mq_update_ nr_hw_queues() runs with q->tag_list_lock held and so to avoid it racing with disk addition/removal we should acquire q->tag_list_lock while registering/unregistering hctx sysfs files. With this patch, blk_mq_sysfs_register() (called during disk addition) and blk_mq_sysfs_unregister() (called during disk removal) now runs with q->tag_list_lock held so that it avoids racing with __blk_mq_update _nr_hw_queues(). Signed-off-by: Nilay Shroff <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent fe66286 commit 14ef496

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

block/blk-mq-sysfs.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,25 @@ int blk_mq_sysfs_register(struct gendisk *disk)
225225

226226
ret = kobject_add(q->mq_kobj, &disk_to_dev(disk)->kobj, "mq");
227227
if (ret < 0)
228-
goto out;
228+
return ret;
229229

230230
kobject_uevent(q->mq_kobj, KOBJ_ADD);
231231

232+
mutex_lock(&q->tag_set->tag_list_lock);
232233
queue_for_each_hw_ctx(q, hctx, i) {
233234
ret = blk_mq_register_hctx(hctx);
234235
if (ret)
235-
goto unreg;
236+
goto out_unreg;
236237
}
238+
mutex_unlock(&q->tag_set->tag_list_lock);
239+
return 0;
237240

238-
239-
out:
240-
return ret;
241-
242-
unreg:
241+
out_unreg:
243242
queue_for_each_hw_ctx(q, hctx, j) {
244243
if (j < i)
245244
blk_mq_unregister_hctx(hctx);
246245
}
246+
mutex_unlock(&q->tag_set->tag_list_lock);
247247

248248
kobject_uevent(q->mq_kobj, KOBJ_REMOVE);
249249
kobject_del(q->mq_kobj);
@@ -256,9 +256,10 @@ void blk_mq_sysfs_unregister(struct gendisk *disk)
256256
struct blk_mq_hw_ctx *hctx;
257257
unsigned long i;
258258

259-
259+
mutex_lock(&q->tag_set->tag_list_lock);
260260
queue_for_each_hw_ctx(q, hctx, i)
261261
blk_mq_unregister_hctx(hctx);
262+
mutex_unlock(&q->tag_set->tag_list_lock);
262263

263264
kobject_uevent(q->mq_kobj, KOBJ_REMOVE);
264265
kobject_del(q->mq_kobj);

0 commit comments

Comments
 (0)