From: Ming Lei <tom.leiming@gmail.com>
To: Jens Axboe <axboe@fb.com>, linux-kernel@vger.kernel.org
Cc: Ming Lei <tom.leiming@gmail.com>, Mike Snitzer <snitzer@redhat.com>
Subject: [RFC PATCH] blk-mq: fix failure case of blk_mq_init_allocated_queue
Date: Thu, 4 Jun 2015 22:39:01 +0800 [thread overview]
Message-ID: <1433428741-24931-1-git-send-email-tom.leiming@gmail.com> (raw)
Generally blk_cleanup_queue() is called for cleaning up
the request queue, just like what blk_mq_init_queue() does,
so blk_mq_init_allocated_queue() should return failue
simply in case blk_mq_init_hw_queues() fails, otherwise
double-free may be triggered.
Cc: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
Mike, DM may need to follow the rule, otherwise
the request queue can't be reused after failure is
returned from blk_mq_init_allocated_queue() since
both wrong queue type and memory leak can be caused .
Or do blk_mq_init_allocated_queue() need to recover
the queue to previous state in case of failure?
block/blk-mq.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 594eea0..d68b1a3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1732,11 +1732,8 @@ static int blk_mq_init_hw_queues(struct request_queue *q,
if (i == q->nr_hw_queues)
return 0;
- /*
- * Init failed
- */
- blk_mq_exit_hw_queues(q, set, i);
-
+ /* Let blk_cleanup_queue() handle the partial initialization */
+ q->nr_hw_queues = i;
return 1;
}
@@ -1920,6 +1917,10 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
}
EXPORT_SYMBOL(blk_mq_init_queue);
+/*
+ * In case of failure returned from this function,
+ * blk_cleanup_queue() has to be called for cleanup.
+ */
struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
struct request_queue *q)
{
@@ -2004,8 +2005,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
blk_mq_init_cpu_queues(q, set->nr_hw_queues);
+ /* blk_cleanup_queue() will handle the failure */
if (blk_mq_init_hw_queues(q, set))
- goto err_hctxs;
+ return ERR_PTR(-ENOMEM);
mutex_lock(&all_q_mutex);
list_add_tail(&q->all_q_node, &all_q_list);
--
1.9.1
reply other threads:[~2015-06-04 14:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433428741-24931-1-git-send-email-tom.leiming@gmail.com \
--to=tom.leiming@gmail.com \
--cc=axboe@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=snitzer@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome