From patchwork Tue May 28 08:12:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanley Chu X-Patchwork-Id: 10964097 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 459F692A for ; Tue, 28 May 2019 08:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 382A32237D for ; Tue, 28 May 2019 08:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BD8528644; Tue, 28 May 2019 08:12:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE5022237D for ; Tue, 28 May 2019 08:12:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbfE1IM1 (ORCPT ); Tue, 28 May 2019 04:12:27 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:17881 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726236AbfE1IM1 (ORCPT ); Tue, 28 May 2019 04:12:27 -0400 X-UUID: 166f0407fbc0412c9523ce831da75c28-20190528 X-UUID: 166f0407fbc0412c9523ce831da75c28-20190528 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 160705361; Tue, 28 May 2019 16:12:18 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 28 May 2019 16:12:10 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 28 May 2019 16:12:10 +0800 From: Stanley Chu To: , , , , CC: , , , , , , , , , , Stanley Chu Subject: [PATCH] scsi: ufs: Use pm_runtime_get_sync in shutdown flow Date: Tue, 28 May 2019 16:12:06 +0800 Message-ID: <1559031126-6587-1-git-send-email-stanley.chu@mediatek.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-MTK: N Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There might be a racing issue between UFS shutdown and runtime resume flow described as below, Thread #1: In UFS shutdown flow with ufshcd_shutdown() is running. Thread #2: In UFS runtime-resume flow which invokes ufshcd_runtime_resume() because UFS was in runtime-suspended state while an I/O request was issued. In this scenario, racing may happen and possibly lead to system hang if Thread #2 accesses UFS host's register map after host's resource, like power or clocks, are disabled by Thread #1. To avoid this racing, use PM public function pm_runtime_get_sync() in shutdown flow instead of internal function ufshcd_runtime_resume() for consolidated control of RPM status. One concern is that pm_runtime_get_sync() may be better paired with pm_runtime_put_sync(), however shutdown could be one-way path thus the pairing is not required. Signed-off-by: Stanley Chu Signed-off-by: Peter Wang --- drivers/scsi/ufs/ufshcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a208589426b1..cce7303f8653 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8095,11 +8095,8 @@ int ufshcd_shutdown(struct ufs_hba *hba) if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba)) goto out; - if (pm_runtime_suspended(hba->dev)) { - ret = ufshcd_runtime_resume(hba); - if (ret) - goto out; - } + if (pm_runtime_get_sync(hba->dev) < 0) + goto out; ret = ufshcd_suspend(hba, UFS_SHUTDOWN_PM); out: