* [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever
@ 2019-06-12 7:42 Stanley Chu
2019-06-12 11:10 ` Avri Altman
0 siblings, 1 reply; 3+ messages in thread
From: Stanley Chu @ 2019-06-12 7:42 UTC (permalink / raw)
To: linux-scsi, martin.petersen, avri.altman, alim.akhtar, pedrom.sousa
Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang,
peter.wang, evgreen, subhashj, linux-mediatek, ygardi,
matthias.bgg, stable, Stanley Chu, linux-arm-kernel, beanhuo
UFS runtime suspend can be triggered after pm_runtime_enable()
is invoked in ufshcd_pltfrm_init(). However if the first runtime
suspend is triggered before binding ufs_hba structure to ufs
device structure via platform_set_drvdata(), then UFS runtime
suspend will be no longer triggered in the future because its
dev->power.runtime_error was set in the first triggering and does
not have any chance to be cleared.
To be more clear, dev->power.runtime_error is set if hba is NULL
in ufshcd_runtime_suspend() which returns -EINVAL to rpm_callback()
where dev->power.runtime_error is set as -EINVAL. In this case, any
future rpm_suspend() for UFS device fails because
rpm_check_suspend_allowed() fails due to non-zero
dev->power.runtime_error.
To resolve this issue, make sure the first UFS runtime suspend
get valid "hba" in ufshcd_runtime_suspend(): Enable UFS runtime PM
only after hba is successfully bound to UFS device structure.
Fixes: e3ce73d (scsi: ufs: fix bugs related to null pointer access and array size)
Cc: stable@vger.kernel.org
Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
drivers/scsi/ufs/ufshcd-pltfrm.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index 8a74ec30c3d2..d7d521b394c3 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -430,24 +430,21 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
goto dealloc_host;
}
- pm_runtime_set_active(&pdev->dev);
- pm_runtime_enable(&pdev->dev);
-
ufshcd_init_lanes_per_dir(hba);
err = ufshcd_init(hba, mmio_base, irq);
if (err) {
dev_err(dev, "Initialization failed\n");
- goto out_disable_rpm;
+ goto dealloc_host;
}
platform_set_drvdata(pdev, hba);
+ pm_runtime_set_active(&pdev->dev);
+ pm_runtime_enable(&pdev->dev);
+
return 0;
-out_disable_rpm:
- pm_runtime_disable(&pdev->dev);
- pm_runtime_set_suspended(&pdev->dev);
dealloc_host:
ufshcd_dealloc_host(hba);
out:
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever
2019-06-12 7:42 [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever Stanley Chu
@ 2019-06-12 11:10 ` Avri Altman
2019-06-12 14:03 ` Stanley Chu
0 siblings, 1 reply; 3+ messages in thread
From: Avri Altman @ 2019-06-12 11:10 UTC (permalink / raw)
To: Stanley Chu, linux-scsi, martin.petersen, alim.akhtar, pedrom.sousa
Cc: marc.w.gonzalez, andy.teng, chun-hung.wu, kuohong.wang,
peter.wang, evgreen, subhashj, linux-mediatek, ygardi,
matthias.bgg, stable, linux-arm-kernel, beanhuo
Hi,
>
> UFS runtime suspend can be triggered after pm_runtime_enable()
> is invoked in ufshcd_pltfrm_init(). However if the first runtime
> suspend is triggered before binding ufs_hba structure to ufs
> device structure via platform_set_drvdata(), then UFS runtime
> suspend will be no longer triggered in the future because its
> dev->power.runtime_error was set in the first triggering and does
> not have any chance to be cleared.
>
> To be more clear, dev->power.runtime_error is set if hba is NULL
> in ufshcd_runtime_suspend() which returns -EINVAL to rpm_callback()
> where dev->power.runtime_error is set as -EINVAL. In this case, any
> future rpm_suspend() for UFS device fails because
> rpm_check_suspend_allowed() fails due to non-zero
> dev->power.runtime_error.
>
> To resolve this issue, make sure the first UFS runtime suspend
> get valid "hba" in ufshcd_runtime_suspend(): Enable UFS runtime PM
> only after hba is successfully bound to UFS device structure.
>
> Fixes: e3ce73d (scsi: ufs: fix bugs related to null pointer access and array size)
This code was inserted before platform_set_drvdata in
6269473 [SCSI] ufs: Add runtime PM support for UFS host controller driver.
Why do you point to e3ce73d?
Thanks,
Avri
> Cc: stable@vger.kernel.org
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
> drivers/scsi/ufs/ufshcd-pltfrm.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
> index 8a74ec30c3d2..d7d521b394c3 100644
> --- a/drivers/scsi/ufs/ufshcd-pltfrm.c
> +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
> @@ -430,24 +430,21 @@ int ufshcd_pltfrm_init(struct platform_device
> *pdev,
> goto dealloc_host;
> }
>
> - pm_runtime_set_active(&pdev->dev);
> - pm_runtime_enable(&pdev->dev);
> -
> ufshcd_init_lanes_per_dir(hba);
>
> err = ufshcd_init(hba, mmio_base, irq);
> if (err) {
> dev_err(dev, "Initialization failed\n");
> - goto out_disable_rpm;
> + goto dealloc_host;
> }
>
> platform_set_drvdata(pdev, hba);
>
> + pm_runtime_set_active(&pdev->dev);
> + pm_runtime_enable(&pdev->dev);
> +
> return 0;
>
> -out_disable_rpm:
> - pm_runtime_disable(&pdev->dev);
> - pm_runtime_set_suspended(&pdev->dev);
> dealloc_host:
> ufshcd_dealloc_host(hba);
> out:
> --
> 2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever
2019-06-12 11:10 ` Avri Altman
@ 2019-06-12 14:03 ` Stanley Chu
0 siblings, 0 replies; 3+ messages in thread
From: Stanley Chu @ 2019-06-12 14:03 UTC (permalink / raw)
To: Avri Altman
Cc: linux-scsi, martin.petersen, marc.w.gonzalez, andy.teng,
chun-hung.wu, kuohong.wang, peter.wang, evgreen, subhashj,
linux-mediatek, ygardi, alim.akhtar, matthias.bgg, stable,
stanley.chu, pedrom.sousa, linux-arm-kernel, beanhuo
Hi Avri,
On Wed, 2019-06-12 at 11:10 +0000, Avri Altman wrote:
> Hi,
>
> >
> > UFS runtime suspend can be triggered after pm_runtime_enable()
> > is invoked in ufshcd_pltfrm_init(). However if the first runtime
> > suspend is triggered before binding ufs_hba structure to ufs
> > device structure via platform_set_drvdata(), then UFS runtime
> > suspend will be no longer triggered in the future because its
> > dev->power.runtime_error was set in the first triggering and does
> > not have any chance to be cleared.
> >
> > To be more clear, dev->power.runtime_error is set if hba is NULL
> > in ufshcd_runtime_suspend() which returns -EINVAL to rpm_callback()
> > where dev->power.runtime_error is set as -EINVAL. In this case, any
> > future rpm_suspend() for UFS device fails because
> > rpm_check_suspend_allowed() fails due to non-zero
> > dev->power.runtime_error.
> >
> > To resolve this issue, make sure the first UFS runtime suspend
> > get valid "hba" in ufshcd_runtime_suspend(): Enable UFS runtime PM
> > only after hba is successfully bound to UFS device structure.
> >
> > Fixes: e3ce73d (scsi: ufs: fix bugs related to null pointer access and array size)
> This code was inserted before platform_set_drvdata in
> 6269473 [SCSI] ufs: Add runtime PM support for UFS host controller driver.
> Why do you point to e3ce73d?
e3ce73d (scsi: ufs: fix bugs related to null pointer access and array
size) changed the returned value from 0 to -EINVAL in case of NULL "hba"
in ufshcd_runtime_suspend().
But you are right, above patch may do the right thing, and the real root
cause is the incorrect timing of pm_runtime_enable().
I will fix commit message in next version.
>
> Thanks,
> Avri
Thanks.
Stanley
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-12 14:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 7:42 [PATCH v1] scsi: ufs: Avoid runtime suspend possibly being blocked forever Stanley Chu
2019-06-12 11:10 ` Avri Altman
2019-06-12 14:03 ` Stanley Chu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).