All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: Use pm_runtime_get_sync in shutdown flow
@ 2019-05-28  8:12 ` Stanley Chu
  0 siblings, 0 replies; 2+ messages in thread
From: Stanley Chu @ 2019-05-28  8:12 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, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, Stanley Chu,
	linux-arm-kernel, beanhuo

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 <stanley.chu@mediatek.com>
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
---
 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:
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] scsi: ufs: Use pm_runtime_get_sync in shutdown flow
@ 2019-05-28  8:12 ` Stanley Chu
  0 siblings, 0 replies; 2+ messages in thread
From: Stanley Chu @ 2019-05-28  8:12 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, evgreen,
	linux-mediatek, peter.wang, matthias.bgg, Stanley Chu,
	linux-arm-kernel, beanhuo

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 <stanley.chu@mediatek.com>
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
---
 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:
-- 
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] 2+ messages in thread

end of thread, other threads:[~2019-05-28  8:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28  8:12 [PATCH] scsi: ufs: Use pm_runtime_get_sync in shutdown flow Stanley Chu
2019-05-28  8:12 ` Stanley Chu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.