Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp246077pxb; Wed, 18 Nov 2020 23:16:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxp7at7ZK0he3edkOSANYydIYJx2ZF8sdolb3SagwMKwAWftMNE694pDYVTh/QCTe/7CqdP X-Received: by 2002:a17:906:329a:: with SMTP id 26mr26349014ejw.227.1605770198497; Wed, 18 Nov 2020 23:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605770198; cv=none; d=google.com; s=arc-20160816; b=ZPvq0Kds0UkhyulbyGC3lX4yva0SPXqA/eiZk3hm5NBYdjHqOIv6H3iBj5IdOYUJzZ QHu38JTEXZ2ZPZDqZwIQcg+cg5bpDTxFbKfn9TZeCPOicwGNB+dKQ4MqBTWJSpqd3eNZ qPqPWGAdlA4VbaM5DiV8zfP2FOb1aMV3ZWfrIyHQD+e0pA3QE/mdz06/YwvByco6fUeh n9A+8q9TakFXOYQodh6FkkMgi7ULw4CPNfpqVT4whIrTayQC7PvfpHIIVLZIfTTaBd30 wBx5ffJczFdnsKnKi8nvDZswqJMj2P3MTKzai/3/pmEoYsnF/uzBnT0wyo6JKz15ThrE vBpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=XXv1sghWHsOtozF9TjpzQ8BZgyE+fxP4S3fS/+0JJH0=; b=04i2d0boZwz6RwEL3ZGtvbQAfJidYYyPGUS415nWcTtotaEbREbTSp2Hcjf5pX+rS7 G2ATTl1HHFOqca8OeVpPiS5dpZM9sPb5qk3gmUt2GZ5+6zYP4eCNCBG/bIp78IlRHTxQ w0AwI5vRIJf0lvX/fgVAE3BF/8edLcypzmBLqbX5Ak6MebGfpUC8iSG9Bdw3MI/+c3yB CNX2VGKuVfKMN4oQzqzqv+jZIFYagkqMsVAWsQOd4iWNfYqItD5yHZzUR+r0E+2vKyEF BcAARkxleUW94Pagt9edzEylTxLUqj8iJNGXhryMA9jW/SHXDUmgsrihGGq65MYT2PzW 4WQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=uSJY+ju1; 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 ga12si18658944ejc.14.2020.11.18.23.16.15; Wed, 18 Nov 2020 23:16:38 -0800 (PST) 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; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=uSJY+ju1; 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 S1726404AbgKSHOb (ORCPT + 99 others); Thu, 19 Nov 2020 02:14:31 -0500 Received: from z5.mailgun.us ([104.130.96.5]:64147 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726117AbgKSHOa (ORCPT ); Thu, 19 Nov 2020 02:14:30 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1605770070; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=XXv1sghWHsOtozF9TjpzQ8BZgyE+fxP4S3fS/+0JJH0=; b=uSJY+ju1YffieqGrAO5Emj7LomYfXpYOiJ55bWYl6kzyLxtvpBzm+vk2XuzMQQeL5vIu4G6z YtLocyQ6S0oEhJ+U+OW9c1tswqgVcFRD0RrhVclHOoNpEFTySHFhGBXqLFAAUDISsu6EjbPl 4xLg+1YEscnRlbM+R//0h5EfrAg= X-Mailgun-Sending-Ip: 104.130.96.5 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n08.prod.us-east-1.postgun.com with SMTP id 5fb61b51fa67d9becfd6996b (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 19 Nov 2020 07:14:25 GMT Sender: cang=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 39411C4346D; Thu, 19 Nov 2020 07:14:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id 25A96C4346B; Thu, 19 Nov 2020 07:14:20 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 19 Nov 2020 15:14:19 +0800 From: Can Guo To: Stanley Chu Cc: linux-scsi@vger.kernel.org, martin.petersen@oracle.com, avri.altman@wdc.com, alim.akhtar@samsung.com, jejb@linux.ibm.com, beanhuo@micron.com, asutoshd@codeaurora.org, matthias.bgg@gmail.com, bvanassche@acm.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kuohong.wang@mediatek.com, peter.wang@mediatek.com, chun-hung.wu@mediatek.com, andy.teng@mediatek.com, chaotian.jing@mediatek.com, cc.chou@mediatek.com, jiajie.hao@mediatek.com, alice.chao@mediatek.com Subject: Re: [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow In-Reply-To: <20201119062916.12931-1-stanley.chu@mediatek.com> References: <20201119062916.12931-1-stanley.chu@mediatek.com> Message-ID: <26585f80038d25fc6ee9dddf07e66b93@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-11-19 14:29, Stanley Chu wrote: > If UFS host device is in runtime-suspended state while > UFS shutdown callback is invoked, UFS device shall be > resumed for register accesses. Currently only UFS local > runtime resume function will be invoked to wake up the host. > This is not enough because if someone triggers runtime > resume from block layer, then race may happen between > shutdown and runtime resume flow, and finally lead to > unlocked register access. > > To fix this kind of issues, in ufshcd_shutdown(), use > pm_runtime_get_sync() instead of resuming UFS device by > ufshcd_runtime_resume() "internally" to let runtime PM > framework manage the whole resume flow. > > Fixes: 57d104c153d3 ("ufs: add UFS power management support") > Signed-off-by: Stanley Chu Reviewed-by: Can Guo > --- > drivers/scsi/ufs/ufshcd.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > index 80cbce414678..bb16cc04f106 100644 > --- a/drivers/scsi/ufs/ufshcd.c > +++ b/drivers/scsi/ufs/ufshcd.c > @@ -8941,11 +8941,7 @@ 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; > - } > + pm_runtime_get_sync(hba->dev); > > ret = ufshcd_suspend(hba, UFS_SHUTDOWN_PM); > out: