Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1407404 > unrolled thread

[PATCH] blk-mq: clear q->mq_ops if init fail

Started byMing Lin <mlin@kernel.org>
First post2016-05-26 08:30 +0200
Last post2016-05-26 17:00 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] blk-mq: clear q->mq_ops if init fail Ming Lin <mlin@kernel.org> - 2016-05-26 08:30 +0200
    Re: [PATCH] blk-mq: clear q->mq_ops if init fail Christoph Hellwig <hch@lst.de> - 2016-05-26 09:10 +0200
    Re: [PATCH] blk-mq: clear q->mq_ops if init fail Jens Axboe <axboe@kernel.dk> - 2016-05-26 17:00 +0200

#1407404 — [PATCH] blk-mq: clear q->mq_ops if init fail

FromMing Lin <mlin@kernel.org>
Date2016-05-26 08:30 +0200
Subject[PATCH] blk-mq: clear q->mq_ops if init fail
Message-ID<rCWXT-2Qp-19@gated-at.bofh.it>
From: Ming Lin <ming.l@samsung.com>

blk_mq_init_queue() calls blk_mq_init_allocated_queue(), but q->mq_ops
was not cleared when blk_mq_init_allocated_queue() fails.
Then blk_cleanup_queue() calls blk_mq_free_queue() which will crash because:
- q->all_q_node is not added to all_q_list yet
- q->tag_set is NULL
- hctx was not setup yet or already freed

Fixed it by clearing q->mq_ops on error path.

Signed-off-by: Ming Lin <ming.l@samsung.com>
---
 block/blk-mq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 67bf8ed..86f08b1 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2054,7 +2054,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 
 	q->queue_ctx = alloc_percpu(struct blk_mq_ctx);
 	if (!q->queue_ctx)
-		return ERR_PTR(-ENOMEM);
+		goto err_exit;
 
 	q->queue_hw_ctx = kzalloc_node(nr_cpu_ids * sizeof(*(q->queue_hw_ctx)),
 						GFP_KERNEL, set->numa_node);
@@ -2118,6 +2118,8 @@ err_map:
 	kfree(q->queue_hw_ctx);
 err_percpu:
 	free_percpu(q->queue_ctx);
+err_exit:
+	q->mq_ops = NULL;
 	return ERR_PTR(-ENOMEM);
 }
 EXPORT_SYMBOL(blk_mq_init_allocated_queue);
-- 
1.9.1

[toc] | [next] | [standalone]


#1407412

FromChristoph Hellwig <hch@lst.de>
Date2016-05-26 09:10 +0200
Message-ID<rCXAC-3km-21@gated-at.bofh.it>
In reply to#1407404
On Wed, May 25, 2016 at 11:23:27PM -0700, Ming Lin wrote:
> From: Ming Lin <ming.l@samsung.com>
> 
> blk_mq_init_queue() calls blk_mq_init_allocated_queue(), but q->mq_ops
> was not cleared when blk_mq_init_allocated_queue() fails.
> Then blk_cleanup_queue() calls blk_mq_free_queue() which will crash because:
> - q->all_q_node is not added to all_q_list yet
> - q->tag_set is NULL
> - hctx was not setup yet or already freed
> 
> Fixed it by clearing q->mq_ops on error path.

Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

[toc] | [prev] | [next] | [standalone]


#1407592

FromJens Axboe <axboe@kernel.dk>
Date2016-05-26 17:00 +0200
Message-ID<rD4Vs-7H3-15@gated-at.bofh.it>
In reply to#1407404
On 05/26/2016 12:23 AM, Ming Lin wrote:
> From: Ming Lin <ming.l@samsung.com>
>
> blk_mq_init_queue() calls blk_mq_init_allocated_queue(), but q->mq_ops
> was not cleared when blk_mq_init_allocated_queue() fails.
> Then blk_cleanup_queue() calls blk_mq_free_queue() which will crash because:
> - q->all_q_node is not added to all_q_list yet
> - q->tag_set is NULL
> - hctx was not setup yet or already freed
>
> Fixed it by clearing q->mq_ops on error path.

Thanks Ming, applied for this series.

-- 
Jens Axboe

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web