Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751448AbbFXJXx (ORCPT ); Wed, 24 Jun 2015 05:23:53 -0400 Received: from mail-ig0-f173.google.com ([209.85.213.173]:38438 "EHLO mail-ig0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750865AbbFXJXp (ORCPT ); Wed, 24 Jun 2015 05:23:45 -0400 MIME-Version: 1.0 In-Reply-To: <1434894751-6877-3-git-send-email-akinobu.mita@gmail.com> References: <1434894751-6877-1-git-send-email-akinobu.mita@gmail.com> <1434894751-6877-3-git-send-email-akinobu.mita@gmail.com> Date: Wed, 24 Jun 2015 17:23:44 +0800 Message-ID: Subject: Re: [PATCH 2/4] blk-mq: fix q->mq_map access race From: Ming Lei To: Akinobu Mita Cc: Linux Kernel Mailing List , Jens Axboe Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2138 Lines: 67 On Sun, Jun 21, 2015 at 9:52 PM, Akinobu Mita wrote: > 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. It should be better to free q->mq_map in blk_mq_release(), because now blk_cleanup_queue() can be run before del_gendisk(), such as loop and md. > > 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); As commented for patch 1, the above can be moved to blk_mq_unregister_disk() for fixing the issue of patch 1. > + > 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/ -- Ming Lei -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/