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

* [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: Stanley Chu, alice.chao, bvanassche, andy.teng, cc.chou,
	chun-hung.wu, kuohong.wang, linux-kernel, jiajie.hao, cang,
	linux-mediatek, peter.wang, matthias.bgg, beanhuo, chaotian.jing,
	linux-arm-kernel, asutoshd

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
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* [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: Stanley Chu, alice.chao, bvanassche, andy.teng, cc.chou,
	chun-hung.wu, kuohong.wang, linux-kernel, jiajie.hao, cang,
	linux-mediatek, peter.wang, matthias.bgg, beanhuo, chaotian.jing,
	linux-arm-kernel, asutoshd

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
_______________________________________________
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] 8+ messages in thread

* Re: [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow
  2020-11-19  6:29 ` Stanley Chu
@ 2020-11-19  7:14   ` Can Guo
  -1 siblings, 0 replies; 8+ messages in thread
From: Can Guo @ 2020-11-19  7:14 UTC (permalink / raw)
  To: Stanley Chu
  Cc: linux-scsi, martin.petersen, avri.altman, alim.akhtar, jejb,
	beanhuo, asutoshd, 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

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

Reviewed-by: Can Guo <cang@codeaurora.org>

> ---
>  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:

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

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

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

Reviewed-by: Can Guo <cang@codeaurora.org>

> ---
>  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:

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow
  2020-11-19  6:29 ` Stanley Chu
  (?)
@ 2020-11-20  3:30   ` Martin K. Petersen
  -1 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2020-11-20  3:30 UTC (permalink / raw)
  To: Stanley Chu, jejb, alim.akhtar, avri.altman, linux-scsi
  Cc: Martin K . Petersen, bvanassche, cang, peter.wang, asutoshd,
	chun-hung.wu, alice.chao, matthias.bgg, chaotian.jing,
	linux-kernel, linux-mediatek, kuohong.wang, jiajie.hao,
	linux-arm-kernel, andy.teng, beanhuo, cc.chou

On Thu, 19 Nov 2020 14:29:16 +0800, 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.
> 
> [...]

Applied to 5.10/scsi-fixes, thanks!

[1/1] scsi: ufs: Fix race between shutdown and runtime resume flow
      https://git.kernel.org/mkp/scsi/c/e92643db5148

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow
@ 2020-11-20  3:30   ` Martin K. Petersen
  0 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2020-11-20  3:30 UTC (permalink / raw)
  To: Stanley Chu, jejb, alim.akhtar, avri.altman, linux-scsi
  Cc: linux-arm-kernel, bvanassche, Martin K . Petersen, andy.teng,
	beanhuo, chun-hung.wu, kuohong.wang, linux-kernel, jiajie.hao,
	cang, linux-mediatek, peter.wang, matthias.bgg, alice.chao,
	cc.chou, chaotian.jing, asutoshd

On Thu, 19 Nov 2020 14:29:16 +0800, 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.
> 
> [...]

Applied to 5.10/scsi-fixes, thanks!

[1/1] scsi: ufs: Fix race between shutdown and runtime resume flow
      https://git.kernel.org/mkp/scsi/c/e92643db5148

-- 
Martin K. Petersen	Oracle Linux Engineering

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH v1] scsi: ufs: Fix race between shutdown and runtime resume flow
@ 2020-11-20  3:30   ` Martin K. Petersen
  0 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2020-11-20  3:30 UTC (permalink / raw)
  To: Stanley Chu, jejb, alim.akhtar, avri.altman, linux-scsi
  Cc: linux-arm-kernel, bvanassche, Martin K . Petersen, andy.teng,
	beanhuo, chun-hung.wu, kuohong.wang, linux-kernel, jiajie.hao,
	cang, linux-mediatek, peter.wang, matthias.bgg, alice.chao,
	cc.chou, chaotian.jing, asutoshd

On Thu, 19 Nov 2020 14:29:16 +0800, 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.
> 
> [...]

Applied to 5.10/scsi-fixes, thanks!

[1/1] scsi: ufs: Fix race between shutdown and runtime resume flow
      https://git.kernel.org/mkp/scsi/c/e92643db5148

-- 
Martin K. Petersen	Oracle Linux Engineering

_______________________________________________
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] 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.