2020-12-24 17:22:40

by Bean Huo

[permalink] [raw]
Subject: [PATCH v2 3/3] scsi: ufs: Let resume callback return -EBUSY after ufshcd_shutdown

From: Bean Huo <[email protected]>

After ufshcd_shutdown(), both UFS device and UFS LINk are powered off,
return '0' will mislead the upper PM layer since the device has not been
successfully resumed yet. This will let pm_runtime_get_sync() caller
mistakenly believe the device/LINK has been resumed, which leads to
request processing timeout that was en-queued later.

To fix this, let ufshcd_system/runtimie_resume() return -EBUSY in case of
hba->is_powered == false.

Signed-off-by: Bean Huo <[email protected]>
---
drivers/scsi/ufs/ufshcd.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index e221add25a7e..e1bcac51c01f 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8950,14 +8950,16 @@ int ufshcd_system_resume(struct ufs_hba *hba)
return -EINVAL;
}

- if (!hba->is_powered || pm_runtime_suspended(hba->dev))
+ if (!hba->is_powered || pm_runtime_suspended(hba->dev)) {
/*
* Let the runtime resume take care of resuming
* if runtime suspended.
*/
+ ret = -EBUSY;
goto out;
- else
+ } else {
ret = ufshcd_resume(hba, UFS_SYSTEM_PM);
+ }
out:
trace_ufshcd_system_resume(dev_name(hba->dev), ret,
ktime_to_us(ktime_sub(ktime_get(), start)),
@@ -9026,10 +9028,12 @@ int ufshcd_runtime_resume(struct ufs_hba *hba)
if (!hba)
return -EINVAL;

- if (!hba->is_powered)
+ if (!hba->is_powered) {
+ ret = -EBUSY;
goto out;
- else
+ } else {
ret = ufshcd_resume(hba, UFS_RUNTIME_PM);
+ }
out:
trace_ufshcd_runtime_resume(dev_name(hba->dev), ret,
ktime_to_us(ktime_sub(ktime_get(), start)),
--
2.17.1


2021-01-04 19:29:46

by Bean Huo

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] scsi: ufs: Let resume callback return -EBUSY after ufshcd_shutdown

Hi Rafael

Would you please help to review this patch assoociated with PM resume
callback implementation?

Original code that ufshcd_system/runtime_resume returns '0' in case
resume failed due to the UFS device and UFS LINk are powered off(hba-
>is_powered == false).

In the patch 2/3 Add handling of the return value of
pm_runtime_get_sync() is to fix race exists between shudown path and
device access through sysfs node.



Thanks,
Bean


On Thu, 2020-12-24 at 18:20 +0100, Bean Huo wrote:
> From: Bean Huo <[email protected]>
>
> After ufshcd_shutdown(), both UFS device and UFS LINk are powered
> off,
> return '0' will mislead the upper PM layer since the device has not
> been
> successfully resumed yet. This will let pm_runtime_get_sync() caller
> mistakenly believe the device/LINK has been resumed, which leads to
> request processing timeout that was en-queued later.
>
> To fix this, let ufshcd_system/runtimie_resume() return -EBUSY in
> case of
> hba->is_powered == false.
>
> Signed-off-by: Bean Huo <[email protected]>
> ---
> drivers/scsi/ufs/ufshcd.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index e221add25a7e..e1bcac51c01f 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -8950,14 +8950,16 @@ int ufshcd_system_resume(struct ufs_hba *hba)
> return -EINVAL;
> }
>
> - if (!hba->is_powered || pm_runtime_suspended(hba->dev))
> + if (!hba->is_powered || pm_runtime_suspended(hba->dev)) {
> /*
> * Let the runtime resume take care of resuming
> * if runtime suspended.
> */
> + ret = -EBUSY;
> goto out;
> - else
> + } else {
> ret = ufshcd_resume(hba, UFS_SYSTEM_PM);
> + }
> out:
> trace_ufshcd_system_resume(dev_name(hba->dev), ret,
> ktime_to_us(ktime_sub(ktime_get(), start)),
> @@ -9026,10 +9028,12 @@ int ufshcd_runtime_resume(struct ufs_hba
> *hba)
> if (!hba)
> return -EINVAL;
>
> - if (!hba->is_powered)
> + if (!hba->is_powered) {
> + ret = -EBUSY;
> goto out;
> - else
> + } else {
> ret = ufshcd_resume(hba, UFS_RUNTIME_PM);
> + }
> out:
> trace_ufshcd_runtime_resume(dev_name(hba->dev), ret,
> ktime_to_us(ktime_sub(ktime_get(), start)),

2021-01-05 01:13:17

by Can Guo

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] scsi: ufs: Let resume callback return -EBUSY after ufshcd_shutdown

On 2020-12-25 01:20, Bean Huo wrote:
> From: Bean Huo <[email protected]>
>
> After ufshcd_shutdown(), both UFS device and UFS LINk are powered off,
> return '0' will mislead the upper PM layer since the device has not
> been
> successfully resumed yet. This will let pm_runtime_get_sync() caller
> mistakenly believe the device/LINK has been resumed, which leads to
> request processing timeout that was en-queued later.
>
> To fix this, let ufshcd_system/runtimie_resume() return -EBUSY in case
> of
> hba->is_powered == false.

This change won't work as you expect...

During/after shutdown, for UFS's case only,
pm_runtime_get_sync(hba->dev) will most likely return 0,
because it is already RUNTIME_ACTIVE, pm_runtime_get_sync()
will directly return 0... meaning your change won't even be
exercised.

Check Stanley's change -
https://lore.kernel.org/patchwork/patch/1341389/

Can Guo.

>
> Signed-off-by: Bean Huo <[email protected]>
> ---
> drivers/scsi/ufs/ufshcd.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index e221add25a7e..e1bcac51c01f 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -8950,14 +8950,16 @@ int ufshcd_system_resume(struct ufs_hba *hba)
> return -EINVAL;
> }
>
> - if (!hba->is_powered || pm_runtime_suspended(hba->dev))
> + if (!hba->is_powered || pm_runtime_suspended(hba->dev)) {
> /*
> * Let the runtime resume take care of resuming
> * if runtime suspended.
> */
> + ret = -EBUSY;
> goto out;
> - else
> + } else {
> ret = ufshcd_resume(hba, UFS_SYSTEM_PM);
> + }
> out:
> trace_ufshcd_system_resume(dev_name(hba->dev), ret,
> ktime_to_us(ktime_sub(ktime_get(), start)),
> @@ -9026,10 +9028,12 @@ int ufshcd_runtime_resume(struct ufs_hba *hba)
> if (!hba)
> return -EINVAL;
>
> - if (!hba->is_powered)
> + if (!hba->is_powered) {
> + ret = -EBUSY;
> goto out;
> - else
> + } else {
> ret = ufshcd_resume(hba, UFS_RUNTIME_PM);
> + }
> out:
> trace_ufshcd_runtime_resume(dev_name(hba->dev), ret,
> ktime_to_us(ktime_sub(ktime_get(), start)),