blk-mq: fix error handling in __blk_mq_alloc_disk
PATCH 1/2 blk-mq: fix error handling in __blk_mq_alloc_disk
To fully clean up the queue if the disk allocation fails we need to call blk_mq_destroy_queue and not just blk_put_queue.
--- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq.c +1 -1
@@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata, disk =__alloc_disk_node (q, set->numa_node, lkclass);if (!disk) { -blk_put_queue (q); +blk_mq_destroy_queue (q);return ERR_PTR (-ENOMEM ); }set_bit (GD_OWNS_QUEUE , &disk->state);
Signature · 1 line
2.30.2
PATCH 2/2 block: call blk_mq_exit_queue from disk_release for never added disks
To undo the all initialization from blk_mq_init_allocated_queue in case of a probe failure where add_disk is never called we have to call blk_mq_exit_queue from put_disk.
This relies on the fact that drivers always call blk_mq_free_tag_set after calling put_disk in the probe error path if they have a gendisk at all.
We should be doing this in general, but can't do it for the normal teardown case (yet) as the tagset can be gone by the time the disk is released once it was added. I hope to sort this out properly eventually but for now this isolated hack will do it.
--- block/genhd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
block/genhd.c +15 -0
@@ -1138,6 +1138,18 @@ static void disk_release(struct device *dev)might_sleep ();WARN_ON_ONCE (disk_live (disk)); +/* +* To undo the all initialization from blk_mq_init_allocated_queue in +* case of a probe failure where add_disk is never called we have to +* call blk_mq_exit_queue here. We can't do this for the more common +* teardown case (yet) as the tagset can be gone by the time the disk +* is released once it was added. +*/ +if (queue_is_mq (disk->queue) && +test_bit (GD_OWNS_QUEUE , &disk->state) && + !test_bit (GD_ADDED , &disk->state)) +blk_mq_exit_queue (disk->queue); +blkcg_exit_queue (disk->queue);disk_release_events (disk);
@@ -1403,6 +1415,9 @@ EXPORT_SYMBOL(__blk_alloc_disk);* This decrements the refcount for the struct gendisk. When this reaches 0 * we'll have disk_release() called. * +* Note: for blk-mq disk put_disk must be called before freeing the tag_set +* when handling probe errors (that is before add_disk() is called). +* * Context: Any context, but the last reference must not be dropped from * atomic context. */
Signature · 1 line
2.30.2
Re: [PATCH 2/2] block: call blk_mq_exit_queue from disk_release for never added disks
Quoted 8 lines · Christoph Hellwig
To undo the all initialization from
blk_mq_init_allocated_queuein case of a probe failure whereadd_diskis never called we have to callblk_mq_exit_queuefromput_disk.This relies on the fact that drivers always call
blk_mq_free_tag_setafter callingput_diskin the probe error path if they have a gendisk at all.
Quoted 8 lines
We should be doing this in general, but can't do it for the normal teardown case (yet) as the tagset can be gone by the time the disk is released once it was added. I hope to sort this out properly eventually but for now this isolated hack will do it.
Fixes 6f8191fdf41d ("block: simplify disk shutdown")Signed-off-by Christoph Hellwig <[email protected]>---
Signature · 1 line
Ming
Quoted 14 lines · Christoph Hellwig
To fully clean up the queue if the disk allocation fails we need to call
blk_mq_destroy_queueand not justblk_put_queue.Fixes 6f8191fdf41d ("block: simplify disk shutdown")Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-mq.c +0
-0
block/blk-mq.c struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata, · line 3964
Quoted 6 lines
block/blk-mq.c +1
-1@@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata, disk =__alloc_disk_node (q, set->numa_node, lkclass);if (!disk) { -blk_put_queue (q); +blk_mq_destroy_queue (q);return ERR_PTR (-ENOMEM );
The same change is needed in case of blk_mq_init_allocated_queue() failure too.
Thanks,
Ming
Quoted 6 lines · Ming Lei
Quoted 6 lines
block/blk-mq.c +0
-0@@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
Quoted 7 lines
block/blk-mq.c struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata, · line 3964
Quoted 5 lines
block/blk-mq.c +1
-1disk =__alloc_disk_node (q, set->numa_node, lkclass);if (!disk) { -blk_put_queue (q); +blk_mq_destroy_queue (q);return ERR_PTR (-ENOMEM );The same change is needed in case of
blk_mq_init_allocated_queue()failure too.
I don't think so. blk_mq_init_allocated_queue only calls blk_mq_add_queue_tag_set at the very end, after any failure point, and the last failure point is blk_mq_realloc_hw_ctxs not mapping any queues. So what would we clean up when blk_mq_init_allocated_queue fails?
Ming Lei
Reviewed-byQuoted 15 lines · Christoph Hellwig
Quoted 6 lines · Ming Lei
Quoted 6 lines
block/blk-mq.c +0
-0@@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,Quoted 7 lines
block/blk-mq.c struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata, · line 3964
Quoted 5 lines
block/blk-mq.c +1
-1disk =__alloc_disk_node (q, set->numa_node, lkclass);if (!disk) { -blk_put_queue (q); +blk_mq_destroy_queue (q);return ERR_PTR (-ENOMEM );The same change is needed in case of
blk_mq_init_allocated_queue()failure too.
Quoted 5 lines
I don't think so.
blk_mq_init_allocated_queueonly callsblk_mq_add_queue_tag_setat the very end, after any failure point, and the last failure point isblk_mq_realloc_hw_ctxsnot mapping any queues. So what would we clean up whenblk_mq_init_allocated_queuefails?
OK, miss that, so looks fine:
Thanks,
Ming
Quoted 4 lines · Christoph Hellwig
To fully clean up the queue if the disk allocation fails we need to call
blk_mq_destroy_queueand not justblk_put_queue.
Applied, thanks!
[1/2] blk-mq: fix error handling in __blk_mq_alloc_disk
commit: 0a3e5cc7bbfcd571a2e53779ef7d7aa3c57d5432
[2/2] block: call blk_mq_exit_queue from disk_release for never added disks
commit: c5db2cfc6274692d821d33b59acb6ff615e350c1Best regards,
Signature · 1 line
Jens Axboe