Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp492128imm; Wed, 15 Aug 2018 00:25:00 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyzrA+Jc32cKowr/bxQWb+61WXddKWktscr0l49CYpzKAF1RfbKAmmQyf1kUi5zx3PioANR X-Received: by 2002:a62:7f91:: with SMTP id a139-v6mr16658236pfd.99.1534317900550; Wed, 15 Aug 2018 00:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534317900; cv=none; d=google.com; s=arc-20160816; b=Zzb0ry0AgPYSg1OVeUkfE2xw79S8iWiMSofIrXJnYPO4oGesEVySySFnlteje7Kq11 GEA6306J2oBhKriWtdhdY4jCJ3NVodPOXn+yMW16NdO/bGO7d57Eav286x3o/Z9Cr180 SLs242flsHOxJOzxgkg0Mk1fLm/qklUg0txYaPl2dtFenZq9oIsZ5ds9aztsZxaM32u4 tBcSSNG9DLQo9h5cEDeRZBHH+9QUdF8Yv1wvf5YNNsFJLI2g8fK9ZRMrQYmt+q57hYKm 8cMOwQaRw40WgK/HHsmgWgW8ezmQC2XRqU7yfCp6yKcm9KvPu4ZH2rr1wTl11LHLBfwv DrnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=cqYwoarC8rcMzcKUzot61wudIilmxoi/tlYTKPCTjKI=; b=eTFkyLnd7s4ZmkLmXwz2nd8uQmxraF80/osUBAGgUTwxizq7olofnk4O0SWMeBbh3O uMCwG/o29cW6X1QSgfUcW0rhMy8dLAf//L+AEFM6nqvT7as6k97NorSyT/hH9bnfMXpb eCTe37ItFjg/BOPaxM2dN5Ptder6I4VViFFZKl6LGZoBWAsXYN3WeztGW1cQE65z/x49 go0Va0/iviDm5Q54AyJ+NUlPPVvhck67wdA8jjRG5YT317g0LRdoTeczq+P/mR5FY1Sa itU19NLeat6JdcdZHeX4pXs5UmJSD4h2kIlxzRKX+zrbdSIbAuMGeny3FLp29/WrSmvc 2eYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=CGvnQISR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j135-v6si26541124pfd.207.2018.08.15.00.24.44; Wed, 15 Aug 2018 00:25:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=CGvnQISR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728933AbeHOKO5 (ORCPT + 99 others); Wed, 15 Aug 2018 06:14:57 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:36672 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727872AbeHOKO4 (ORCPT ); Wed, 15 Aug 2018 06:14:56 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7F7Nqhv184685; Wed, 15 Aug 2018 07:23:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=cqYwoarC8rcMzcKUzot61wudIilmxoi/tlYTKPCTjKI=; b=CGvnQISRZw0Ehs3yrQNoljx29IDZrbqecyGaAR4BaMDy+N7LYJdFz6NlRbRh8Nznstbx YDHxg7Ohn2YYyLPI1MwrmQN91L7uF8mcxdEliFvoXfa82pzrSDJSQAveWUnZafVjXXFc eBIl2IqwY/I1bNjQnBnbaW1MWUnRj1Mpep8ISni9ZgcS6U0VJ5mQjBVJ1yXrF25EgPks OVqHFvbhyeXEbXYI6LpWGT3h8Yn9Fr+2nq+skAlpIVy+50DzBpITbM+Gr/ytBvAFPT8/ b7liJ1sk4g5u8Uln+U8c4huakhsrKHt7bMkKStF400jUD1JtYm6wodsF5Xu8PWntDkS5 Zg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2ksqrpbdqd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Aug 2018 07:23:52 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7F7NppH002666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Aug 2018 07:23:51 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7F7Npqu004117; Wed, 15 Aug 2018 07:23:51 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 15 Aug 2018 00:23:50 -0700 From: Jianchao Wang To: axboe@kernel.dk Cc: tom.leiming@gmail.com, bart.vanassche@wdc.com, keith.busch@linux.intel.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] blk-mq: sync the update nr_hw_queues with part_in_flight Date: Wed, 15 Aug 2018 15:25:15 +0800 Message-Id: <1534317915-5041-3-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534317915-5041-1-git-send-email-jianchao.w.wang@oracle.com> References: <1534317915-5041-1-git-send-email-jianchao.w.wang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8985 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808150081 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For blk-mq, part_in_flight/rw will invoke blk_mq_in_flight/rw to account the inflight requests. It will access the queue_hw_ctx and nr_hw_queues w/o any protection. When updating nr_hw_queues and blk_mq_in_flight/rw occur concurrently, panic comes up. To fix it, introduce mq_realloc_hw_ctxs into mark the updating nr_hw_queues process and use rcu to ensure the mq_realloc_hw_ctxs globally visible. Signed-off-by: Jianchao Wang --- block/blk-mq.c | 3 +++ block/genhd.c | 10 ++++++++-- include/linux/blkdev.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 89904cc..ff50afc 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2517,6 +2517,8 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, blk_mq_sysfs_unregister(q); + WRITE_ONCE(q->mq_realloc_hw_ctxs, true); + synchronize_rcu(); /* protect against switching io scheduler */ mutex_lock(&q->sysfs_lock); for (i = 0; i < set->nr_hw_queues; i++) { @@ -2564,6 +2566,7 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, } q->nr_hw_queues = i; mutex_unlock(&q->sysfs_lock); + WRITE_ONCE(q->mq_realloc_hw_ctxs, false); blk_mq_sysfs_register(q); } diff --git a/block/genhd.c b/block/genhd.c index 8cc719a3..f9e46aa 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -69,7 +69,10 @@ void part_in_flight(struct request_queue *q, struct hd_struct *part, unsigned int inflight[2]) { if (q->mq_ops) { - blk_mq_in_flight(q, part, inflight); + rcu_read_lock(); + if (!q->mq_realloc_hw_ctxs) + blk_mq_in_flight(q, part, inflight); + rcu_read_unlock(); return; } @@ -86,7 +89,10 @@ void part_in_flight_rw(struct request_queue *q, struct hd_struct *part, unsigned int inflight[2]) { if (q->mq_ops) { - blk_mq_in_flight_rw(q, part, inflight); + rcu_read_lock(); + if (!q->mq_realloc_hw_ctxs) + blk_mq_in_flight_rw(q, part, inflight); + rcu_read_unlock(); return; } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index ee930c4..5cb6662 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -662,6 +662,7 @@ struct request_queue { #endif bool mq_sysfs_init_done; + bool mq_realloc_hw_ctxs; size_t cmd_size; void *rq_alloc_data; -- 2.7.4