Commit c0f3fd2b authored by Jens Axboe's avatar Jens Axboe

blk-mq: fix deadlock in blk_mq_register_disk() error path

If we fail registering any of the hardware queues, we call
into blk_mq_unregister_disk() with the hotplug mutex already
held. Since blk_mq_unregister_disk() attempts to acquire the
same mutex, we end up in a less than happy place.
Reported-by: default avatarJinpu Wang <jinpu.wang@profitbricks.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 6d25ec14
...@@ -380,15 +380,13 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) ...@@ -380,15 +380,13 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
return ret; return ret;
} }
void blk_mq_unregister_disk(struct gendisk *disk) static void __blk_mq_unregister_disk(struct gendisk *disk)
{ {
struct request_queue *q = disk->queue; struct request_queue *q = disk->queue;
struct blk_mq_hw_ctx *hctx; struct blk_mq_hw_ctx *hctx;
struct blk_mq_ctx *ctx; struct blk_mq_ctx *ctx;
int i, j; int i, j;
blk_mq_disable_hotplug();
queue_for_each_hw_ctx(q, hctx, i) { queue_for_each_hw_ctx(q, hctx, i) {
blk_mq_unregister_hctx(hctx); blk_mq_unregister_hctx(hctx);
...@@ -405,6 +403,12 @@ void blk_mq_unregister_disk(struct gendisk *disk) ...@@ -405,6 +403,12 @@ void blk_mq_unregister_disk(struct gendisk *disk)
kobject_put(&disk_to_dev(disk)->kobj); kobject_put(&disk_to_dev(disk)->kobj);
q->mq_sysfs_init_done = false; q->mq_sysfs_init_done = false;
}
void blk_mq_unregister_disk(struct gendisk *disk)
{
blk_mq_disable_hotplug();
__blk_mq_unregister_disk(disk);
blk_mq_enable_hotplug(); blk_mq_enable_hotplug();
} }
...@@ -450,7 +454,7 @@ int blk_mq_register_disk(struct gendisk *disk) ...@@ -450,7 +454,7 @@ int blk_mq_register_disk(struct gendisk *disk)
} }
if (ret) if (ret)
blk_mq_unregister_disk(disk); __blk_mq_unregister_disk(disk);
else else
q->mq_sysfs_init_done = true; q->mq_sysfs_init_done = true;
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment