Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755718AbbFUNxL (ORCPT ); Sun, 21 Jun 2015 09:53:11 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:35115 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755536AbbFUNw7 (ORCPT ); Sun, 21 Jun 2015 09:52:59 -0400 From: Akinobu Mita To: linux-kernel@vger.kernel.org, Jens Axboe Cc: Akinobu Mita Subject: [PATCH 2/4] blk-mq: fix q->mq_map access race Date: Sun, 21 Jun 2015 22:52:29 +0900 Message-Id: <1434894751-6877-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434894751-6877-1-git-send-email-akinobu.mita@gmail.com> References: <1434894751-6877-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1391 Lines: 47 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 Cc: Jens Axboe --- 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/