Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1962675pxk; Mon, 14 Sep 2020 00:25:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/cLXvluaiz0SEnlfvpJoe8DO96Qo+oqGyctJSqz3NBTD7SUurmud6Gq4r+6oQmQaX6cCc X-Received: by 2002:a17:907:20d9:: with SMTP id qq25mr12720573ejb.382.1600068335225; Mon, 14 Sep 2020 00:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600068335; cv=none; d=google.com; s=arc-20160816; b=kTSt7bxmXaNWIjCstYF3ZB/ISDzeUTHlcS0KU0SBtgTsRPGP1TOyzKXBePJSgxAZDZ fJK1ZolV9XdIvSoeOOBCpDttv3tCC1KzAS8XhrEs1w53Br0Lbq1HB+5cn/jZUfo8gEMY W6LmdFApATSoEvue+GocpfsFKg6u6NWyMmxi6UYMwGlbg8tId5zIVaaMsYOhhF/d5BuM dywVaJqSDCY/lrUOSnd4BmhC7hw+IG9vZjxNRdPzTZsp5RX7K0TxTG2vmLOCZ6G1ZXzH z2hBFosgJPa2pBAr42Zs4MohotDTJx+BNSqwgD9U3JCRTVZmy6RFGsXB48idkR5bdmXD pDHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=fhL0FJeDACVIaqCqvMpFatNC1YuXNITN3RhYMlQx6Z4=; b=PXGVHvtl9haBfriqwbOwqry2Ht3fum7yWFQJHM+PTrg/O7PzzeKrDeBE7i59YaIlB5 fenBXWSCHH0FamrnmpXz3NOfbj4qc2u66fPdC471YQ+3MK4pHkAHyaEgp4ncb3nWNGE8 eeg3Qxm1G8XHtXOgGAEqswB3RKphLZYjWQbFGvjuoStAG8nHl6SFqRkXCT62VnBpMNXc bvAVnPE/k/fnRx7hoK1gjoWIq4wwt2M7PDmuL3f/elrD3yygGB3nTYmcC7lfUKmSqF8+ WCKSuoouitc6tjX1uAOzGOYh6E7UG3JCoLCRnXTzhfKJFLtndTwTfdToxPeKZXHdTwmu +T0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si6115145eja.581.2020.09.14.00.25.12; Mon, 14 Sep 2020 00:25:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726004AbgINHWH (ORCPT + 99 others); Mon, 14 Sep 2020 03:22:07 -0400 Received: from mail-m1271.qiye.163.com ([115.236.127.1]:26868 "EHLO mail-m1271.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725944AbgINHWG (ORCPT ); Mon, 14 Sep 2020 03:22:06 -0400 Received: from ubuntu.localdomain (unknown [157.0.31.125]) by mail-m1271.qiye.163.com (Hmail) with ESMTPA id C338D5822EA; Mon, 14 Sep 2020 15:21:54 +0800 (CST) From: Yang Yang To: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: onlyfever@icloud.com, yang.yang@vivo.com Subject: [PATCH] blk-mq: fix hang issue in blk_queue_enter() Date: Mon, 14 Sep 2020 00:19:03 -0700 Message-Id: <20200914071903.65704-1-yang.yang@vivo.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZSU1JSB1OSU9MT0gdVkpNS0tLTUNKSk9CQ0lVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NhQ6Exw5OT8qTxBDCB44Ng9J AQ9PCxpVSlVKTUtLS01DSkpOSE5JVTMWGhIXVQIaFRxVAhoVHDsNEg0UVRgUFkVZV1kSC1lBWUpO TFVLVUhKVUpJTllXWQgBWUFJQ05MNwY+ X-HM-Tid: 0a748b7dd9c798b6kuuuc338d5822ea Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a race between blk_queue_enter() and block layer's runtime suspend. CPU0 CPU1 --------------------------------- ------------------------------- blk_pre_runtime_suspend(q) { blk_queue_enter() { /* q->rpm_status=RPM_ACTIVE */ blk_set_pm_only(q) /* q->pm_only=1 */ blk_freeze_queue_start(q) blk_mq_unfreeze_queue(q) if (percpu_ref_tryget_live()) { /* pm=0 && q->pm_only=1 */ if (pm || !blk_queue_pm_only(q)) { } else { percpu_ref_put() } } wait_event(q->mq_freeze_wq, (!q->mq_freeze_depth && /* q->rpm_status=RPM_ACTIVE q->pm_only=1 */ (pm || (blk_pm_request_resume(q), !blk_queue_pm_only(q)))) || blk_queue_dying(q)) } spin_lock_irq(&q->queue_lock) q->rpm_status = RPM_SUSPENDING spin_unlock_irq(&q->queue_lock) } At this point blk_pm_request_resume() missed the chance to resume the queue, so blk_queue_enter() may wait here forever. The solution is to wake up the mq_freeze_wq after runtime suspend completed, make blk_pm_request_resume() reexamine the q->rpm_status flag. Signed-off-by: Yang Yang --- block/blk-pm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/blk-pm.c b/block/blk-pm.c index b85234d758f7..dec7d0aef606 100644 --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -132,6 +132,8 @@ void blk_post_runtime_suspend(struct request_queue *q, int err) if (err) blk_clear_pm_only(q); + else + wake_up_all(&q->mq_freeze_wq); } EXPORT_SYMBOL(blk_post_runtime_suspend); -- 2.17.1