All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] Three minor fixes w.r.t suspend/resume
@ 2021-04-26  2:24 Can Guo
  2021-04-26  2:24 ` [PATCH v1 1/3] scsi: ufs: Do not put UFS power into LPM if link is broken Can Guo
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Can Guo @ 2021-04-26  2:24 UTC (permalink / raw)
  To: asutoshd, ziqichen, nguyenb, hongwus, linux-scsi, kernel-team, cang

1st change can fix a possible OCP issue.
2nd and 3rd change can fix race conditions btw suspend/resume and other contexts.

Can Guo (3):
  scsi: ufs: Do not put UFS power into LPM if link is broken
  scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend
  scsi: ufs: Narrow down fast pass in system suspend path

 drivers/scsi/ufs/ufshcd.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


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

* [PATCH v1 1/3] scsi: ufs: Do not put UFS power into LPM if link is broken
  2021-04-26  2:24 [PATCH v1 0/3] Three minor fixes w.r.t suspend/resume Can Guo
@ 2021-04-26  2:24 ` Can Guo
  2021-04-26  2:24 ` [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend Can Guo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Can Guo @ 2021-04-26  2:24 UTC (permalink / raw)
  To: asutoshd, ziqichen, nguyenb, hongwus, linux-scsi, kernel-team, cang
  Cc: Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Stanley Chu, Bean Huo, Jaegeuk Kim,
	open list

During resume, if link is broken due to AH8 failure, make sure
ufshcd_resume() do not put UFS power back into LPM.

Fixes: 4db7a23605973 ("scsi: ufs: Fix concurrency of error handler and other error recovery paths")
Signed-off-by: Can Guo <cang@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index a8c5bd9..7ab6b12 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8666,7 +8666,7 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba *hba)
 	} else if (!ufshcd_is_ufs_dev_active(hba)) {
 		ufshcd_toggle_vreg(hba->dev, hba->vreg_info.vcc, false);
 		vcc_off = true;
-		if (!ufshcd_is_link_active(hba)) {
+		if (ufshcd_is_link_hibern8(hba) || ufshcd_is_link_off(hba)) {
 			ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq);
 			ufshcd_config_vreg_lpm(hba, hba->vreg_info.vccq2);
 		}
@@ -8688,7 +8688,7 @@ static int ufshcd_vreg_set_hpm(struct ufs_hba *hba)
 	    !hba->dev_info.is_lu_power_on_wp) {
 		ret = ufshcd_setup_vreg(hba, true);
 	} else if (!ufshcd_is_ufs_dev_active(hba)) {
-		if (!ret && !ufshcd_is_link_active(hba)) {
+		if (!ufshcd_is_link_active(hba)) {
 			ret = ufshcd_config_vreg_hpm(hba, hba->vreg_info.vccq);
 			if (ret)
 				goto vcc_disable;
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


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

* [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend
  2021-04-26  2:24 [PATCH v1 0/3] Three minor fixes w.r.t suspend/resume Can Guo
  2021-04-26  2:24 ` [PATCH v1 1/3] scsi: ufs: Do not put UFS power into LPM if link is broken Can Guo
@ 2021-04-26  2:24 ` Can Guo
  2021-04-26  2:24 ` [PATCH v1 3/3] scsi: ufs: Narrow down fast pass in system suspend path Can Guo
       [not found] ` <CGME20210426022700epcas2p298d2b9e6dd30781db9bf1e998f80eca1@epcms2p2>
  3 siblings, 0 replies; 6+ messages in thread
From: Can Guo @ 2021-04-26  2:24 UTC (permalink / raw)
  To: asutoshd, ziqichen, nguyenb, hongwus, linux-scsi, kernel-team, cang
  Cc: Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Stanley Chu, Bean Huo, Jaegeuk Kim,
	Chaotian Jing, open list

During ufs system suspend, leaving rpm_dev_flush_recheck_work running or
pending is risky, because concurrency may happen btw system suspend/resume
and runtime resume routine. Fix it by cancelling rpm_dev_flush_recheck_work
synchronously during system suspend.

Fixes: 1d53864c3617f5235f891ca0fbe9347c4cd35d46 ("scsi: ufs: Fix possible power drain during system suspend")
Signed-off-by: Can Guo <cang@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 7ab6b12..090b654 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -9058,11 +9058,12 @@ int ufshcd_system_suspend(struct ufs_hba *hba)
 	if (!hba->is_powered)
 		return 0;
 
+	cancel_delayed_work_sync(&hba->rpm_dev_flush_recheck_work);
+
 	if ((ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) ==
 	     hba->curr_dev_pwr_mode) &&
 	    (ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl) ==
-	     hba->uic_link_state) &&
-	     !hba->dev_info.b_rpm_dev_flush_capable)
+	     hba->uic_link_state))
 		goto out;
 
 	if (pm_runtime_suspended(hba->dev)) {
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


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

* [PATCH v1 3/3] scsi: ufs: Narrow down fast pass in system suspend path
  2021-04-26  2:24 [PATCH v1 0/3] Three minor fixes w.r.t suspend/resume Can Guo
  2021-04-26  2:24 ` [PATCH v1 1/3] scsi: ufs: Do not put UFS power into LPM if link is broken Can Guo
  2021-04-26  2:24 ` [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend Can Guo
@ 2021-04-26  2:24 ` Can Guo
       [not found] ` <CGME20210426022700epcas2p298d2b9e6dd30781db9bf1e998f80eca1@epcms2p2>
  3 siblings, 0 replies; 6+ messages in thread
From: Can Guo @ 2021-04-26  2:24 UTC (permalink / raw)
  To: asutoshd, ziqichen, nguyenb, hongwus, linux-scsi, kernel-team, cang
  Cc: Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Stanley Chu, Bean Huo, Jaegeuk Kim,
	Subhash Jadavani, Gilad Broner, open list

If spm_lvl is set to 0 or 1, when system suspend kicks start and hba is
runtime active, system suspend may just bail without doing anything (the
fast pass), leaving other contexts still running, e.g., clock gating and
clock scaling. When system resume kicks start, concurrency can happen btw
ufshcd_resume() and these contexts, leading to various stability issues.
Fix it by adding a check against hba's runtime status and allowing fast
pass only if hba is runtime suspended, otherwise let system suspend go
ahead call ufshcd_suspend(). This can guarantee that these contexts are
stopped by either runtime suspend or system suspend.

Fixes: 0b257734344aa ("scsi: ufs: optimize system suspend handling")
Signed-off-by: Can Guo <cang@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 090b654..1fd965f 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -9060,7 +9060,8 @@ int ufshcd_system_suspend(struct ufs_hba *hba)
 
 	cancel_delayed_work_sync(&hba->rpm_dev_flush_recheck_work);
 
-	if ((ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) ==
+	if (pm_runtime_suspended(hba->dev) &&
+	    (ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) ==
 	     hba->curr_dev_pwr_mode) &&
 	    (ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl) ==
 	     hba->uic_link_state))
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


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

* RE: [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend
       [not found] ` <CGME20210426022700epcas2p298d2b9e6dd30781db9bf1e998f80eca1@epcms2p2>
@ 2021-04-26  3:17   ` Daejun Park
  2021-04-26  3:33     ` Can Guo
  0 siblings, 1 reply; 6+ messages in thread
From: Daejun Park @ 2021-04-26  3:17 UTC (permalink / raw)
  To: asutoshd, ziqichen, nguyenb, hongwus, linux-scsi, kernel-team,
	cang, Daejun Park
  Cc: ALIM AKHTAR, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Stanley Chu, Bean Huo, Jaegeuk Kim,
	Chaotian Jing, open list

Hi Can Guo,

>diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>index 7ab6b12..090b654 100644
>--- a/drivers/scsi/ufs/ufshcd.c
>+++ b/drivers/scsi/ufs/ufshcd.c
>@@ -9058,11 +9058,12 @@ int ufshcd_system_suspend(struct ufs_hba *hba)
>         if (!hba->is_powered)
>                 return 0;
> 
>+        cancel_delayed_work_sync(&hba->rpm_dev_flush_recheck_work);
>+
>         if ((ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) ==
>              hba->curr_dev_pwr_mode) &&
>             (ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl) ==
>-             hba->uic_link_state) &&
>-             !hba->dev_info.b_rpm_dev_flush_capable)
I think it should not be removed.
It prevents power drain when runtime suspend and system suspend have same
power mode.

Thanks,
Daejun

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

* Re: [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend
  2021-04-26  3:17   ` [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend Daejun Park
@ 2021-04-26  3:33     ` Can Guo
  0 siblings, 0 replies; 6+ messages in thread
From: Can Guo @ 2021-04-26  3:33 UTC (permalink / raw)
  To: daejun7.park
  Cc: asutoshd, ziqichen, nguyenb, hongwus, linux-scsi, kernel-team,
	ALIM AKHTAR, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Stanley Chu, Bean Huo, Jaegeuk Kim,
	Chaotian Jing, open list

On 2021-04-26 11:17, Daejun Park wrote:
> Hi Can Guo,
> 
>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>> index 7ab6b12..090b654 100644
>> --- a/drivers/scsi/ufs/ufshcd.c
>> +++ b/drivers/scsi/ufs/ufshcd.c
>> @@ -9058,11 +9058,12 @@ int ufshcd_system_suspend(struct ufs_hba *hba)
>>         if (!hba->is_powered)
>>                 return 0;
>> 
>> +        cancel_delayed_work_sync(&hba->rpm_dev_flush_recheck_work);
>> +
>>         if ((ufs_get_pm_lvl_to_dev_pwr_mode(hba->spm_lvl) ==
>>              hba->curr_dev_pwr_mode) &&
>>             (ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl) ==
>> -             hba->uic_link_state) &&
>> -             !hba->dev_info.b_rpm_dev_flush_capable)
> I think it should not be removed.
> It prevents power drain when runtime suspend and system suspend have 
> same
> power mode.
> 

I will add it back in next ver.

Thanks,
Can Guo

> Thanks,
> Daejun

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

end of thread, other threads:[~2021-04-26  3:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26  2:24 [PATCH v1 0/3] Three minor fixes w.r.t suspend/resume Can Guo
2021-04-26  2:24 ` [PATCH v1 1/3] scsi: ufs: Do not put UFS power into LPM if link is broken Can Guo
2021-04-26  2:24 ` [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend Can Guo
2021-04-26  2:24 ` [PATCH v1 3/3] scsi: ufs: Narrow down fast pass in system suspend path Can Guo
     [not found] ` <CGME20210426022700epcas2p298d2b9e6dd30781db9bf1e998f80eca1@epcms2p2>
2021-04-26  3:17   ` [PATCH v1 2/3] scsi: ufs: Cancel rpm_dev_flush_recheck_work during system suspend Daejun Park
2021-04-26  3:33     ` Can Guo

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.