All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow
@ 2020-11-19  6:29 ` Stanley Chu
  0 siblings, 0 replies; 8+ messages in thread
From: Stanley Chu @ 2020-11-19  6:29 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar, jejb
  Cc: beanhuo, asutoshd, cang, matthias.bgg, bvanassche,
	linux-mediatek, linux-arm-kernel, linux-kernel, kuohong.wang,
	peter.wang, chun-hung.wu, andy.teng, chaotian.jing, cc.chou,
	jiajie.hao, alice.chao, Stanley Chu

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 <stanley.chu@mediatek.com>
---
 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:
-- 
2.18.0


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

end of thread, other threads:[~2020-11-20  3:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19  6:29 [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow Stanley Chu
2020-11-19  6:29 ` Stanley Chu
2020-11-19  6:29 ` Stanley Chu
2020-11-19  7:14 ` Can Guo
2020-11-19  7:14   ` Can Guo
2020-11-20  3:30 ` Martin K. Petersen
2020-11-20  3:30   ` Martin K. Petersen
2020-11-20  3:30   ` Martin K. Petersen

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.