mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Subject: [PATCH 2/4] blk-mq: fix q->mq_map access race
Date: Sun, 21 Jun 2015 22:52:29 +0900	[thread overview]
Message-ID: <1434894751-6877-3-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1434894751-6877-1-git-send-email-akinobu.mita@gmail.com>

CPU hotplug handling for blk-mq (blk_mq_queue_reinit) updates q->mq_map
by blk_mq_update_queue_map() for all request queues in all_q_list.
On the other hand, q->mq_map is released and set to NULL before
deleting the queue from all_q_list.

So if cpu hotplug event occurs in the window, invalid memory access
can happen.  Fix it by deleting the queue from all_q_list earlier
than destroyng q->mq_map.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
---
 block/blk-mq.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index ec94258..6487710 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2038,6 +2038,10 @@ void blk_mq_free_queue(struct request_queue *q)
 {
 	struct blk_mq_tag_set	*set = q->tag_set;
 
+	mutex_lock(&all_q_mutex);
+	list_del_init(&q->all_q_node);
+	mutex_unlock(&all_q_mutex);
+
 	blk_mq_del_queue_tag_set(q);
 
 	blk_mq_exit_hw_queues(q, set, set->nr_hw_queues);
@@ -2048,10 +2052,6 @@ void blk_mq_free_queue(struct request_queue *q)
 	kfree(q->mq_map);
 
 	q->mq_map = NULL;
-
-	mutex_lock(&all_q_mutex);
-	list_del_init(&q->all_q_node);
-	mutex_unlock(&all_q_mutex);
 }
 
 /* Basically redo blk_mq_init_queue with queue frozen */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/

  parent reply	other threads:[~2015-06-21 13:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-21 13:52 [PATCH 0/4] blk-mq: fix race conditions on cpu hotplug handling Akinobu Mita
2015-06-21 13:52 ` [PATCH 1/4] blk-mq: fix sysfs registration/unregistration race Akinobu Mita
2015-06-24  8:59   ` Ming Lei
2015-06-21 13:52 ` Akinobu Mita [this message]
2015-06-24  9:23   ` [PATCH 2/4] blk-mq: fix q->mq_map access race Ming Lei
2015-06-21 13:52 ` [PATCH 3/4] blk-mq: establish new mapping before cpu starts handling requests Akinobu Mita
2015-06-24  9:46   ` Ming Lei
2015-06-24 14:34     ` Akinobu Mita
2015-06-24 16:24       ` Ming Lei
2015-06-25  2:56         ` Akinobu Mita
2015-06-25  8:07           ` Ming Lei
2015-06-25 12:49             ` Akinobu Mita
2015-06-25 15:40               ` Ming Lei
2015-06-25 23:35                 ` Akinobu Mita
2015-06-26 17:14                   ` Akinobu Mita
2015-06-27 16:08                     ` Ming Lei
2015-06-29 14:25                       ` Akinobu Mita
2015-06-30  9:06                         ` Ming Lei
2015-06-21 13:52 ` [PATCH 4/4] blk-mq: fix mq_usage_counter race when switching to percpu mode Akinobu Mita
2015-06-24 12:35   ` Ming Lei
2015-06-29 14:31     ` Akinobu Mita

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=1434894751-6877-3-git-send-email-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    /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