Skip to contentSkip to conversation

scsi: ufs: move shutting_down back to ufshcd_shutdown

PATCH In review Jaegeuk Kim 2 participants 2 messages Feb 24, 2022 – Mar 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: move shutting_down back to ufshcd_shutdown

The commit b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun") moved hba->shutting_down from ufshcd_shutdown to ufshcd_wl_shutdown, which introduced regression as belows.

ufshcd_err_handler started; HBA state eh_non_fatal; powered 1; shutting down 1; saved_err = 4; saved_uic_err = 64; force_reset = 0
...
task:init state:D stack: 0 pid: 1 ppid: 0 flags:0x04000008

Call trace:
 __switch_to+0x25c/0x5e0
 __schedule+0x68c/0xaa8
 schedule+0x12c/0x24c
 schedule_timeout+0x98/0x138
 wait_for_common_io+0x13c/0x30c
 blk_execute_rq+0xb0/0x10c
 __scsi_execute+0x100/0x27c
 ufshcd_set_dev_pwr_mode+0x1c8/0x408
 __ufshcd_wl_suspend+0x564/0x688
 ufshcd_wl_shutdown+0xa8/0xc0
 device_shutdown+0x234/0x578
 kernel_restart+0x4c/0x140
 __arm64_sys_reboot+0x3a0/0x414
 el0_svc_common+0xd0/0x1e4
 el0_svc+0x28/0x88
 el0_sync_handler+0x8c/0xf0
 el0_sync+0x1c0/0x200

The init for reboot was stuck, since ufshcd_err_hanlder was skipped when shutting down WLUN. This patch allows to run the error handler and let disable it during final ufshcd_shutdown only.

Fixes b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun")
---
 drivers/scsi/ufs/ufshcd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/ufs/ufshcd.c +4 -4
index 460d2b440d2e..a37813b474d0 100644
@@ -9178,10 +9178,6 @@ static void ufshcd_wl_shutdown(struct device *dev)
 
 	hba = shost_priv(sdev->host);
 
-	down(&hba->host_sem);
-	hba->shutting_down = true;
-	up(&hba->host_sem);
-
 	/* Turn on everything while shutting down */
 	ufshcd_rpm_get_sync(hba);
 	scsi_device_quiesce(sdev);
@@ -9387,6 +9383,10 @@ EXPORT_SYMBOL(ufshcd_runtime_resume);
  */
 int ufshcd_shutdown(struct ufs_hba *hba)
 {
+	down(&hba->host_sem);
+	hba->shutting_down = true;
+	up(&hba->host_sem);
+
 	if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba))
 		goto out;
 
Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
#1 lore raw
Quoted 26 lines · Jaegeuk Kim

The commit b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun") moved hba->shutting_down from ufshcd_shutdown to ufshcd_wl_shutdown, which introduced regression as belows.

ufshcd_err_handler started; HBA state eh_non_fatal; powered 1; shutting down 1; saved_err = 4; saved_uic_err = 64; force_reset = 0
...
task:init state:D stack: 0 pid: 1 ppid: 0 flags:0x04000008

Call trace:
 __switch_to+0x25c/0x5e0
 __schedule+0x68c/0xaa8
 schedule+0x12c/0x24c
 schedule_timeout+0x98/0x138
 wait_for_common_io+0x13c/0x30c
 blk_execute_rq+0xb0/0x10c
 __scsi_execute+0x100/0x27c
 ufshcd_set_dev_pwr_mode+0x1c8/0x408
 __ufshcd_wl_suspend+0x564/0x688
 ufshcd_wl_shutdown+0xa8/0xc0
 device_shutdown+0x234/0x578
 kernel_restart+0x4c/0x140
 __arm64_sys_reboot+0x3a0/0x414
 el0_svc_common+0xd0/0x1e4
 el0_svc+0x28/0x88
 el0_sync_handler+0x8c/0xf0
 el0_sync+0x1c0/0x200
Quoted 3 lines

The init for reboot was stuck, since ufshcd_err_hanlder was skipped when shutting down WLUN. This patch allows to run the error handler and let disable it during final ufshcd_shutdown only.

I do not understand why it is stuck? If there was a non-fatal error, the request should complete anyway, or at least timeout.

Quoted 24 lines
Fixes b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun")
---
 drivers/scsi/ufs/ufshcd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/ufs/ufshcd.c +0 -4
index 460d2b440d2e..a37813b474d0 100644
@@ -9178,10 +9178,6 @@ static void ufshcd_wl_shutdown(struct device *dev)
 
 	hba = shost_priv(sdev->host);
 
-	down(&hba->host_sem);
-	hba->shutting_down = true;
-	up(&hba->host_sem);
-
 	/* Turn on everything while shutting down */
 	ufshcd_rpm_get_sync(hba);
 	scsi_device_quiesce(sdev);

drivers/scsi/ufs/ufshcd.c EXPORT_SYMBOL(ufshcd_runtime_resume); · line 9388

Quoted 6 lines
drivers/scsi/ufs/ufshcd.c +3 -0
@@ -9387,6 +9383,10 @@ EXPORT_SYMBOL(ufshcd_runtime_resume);
  */
 int ufshcd_shutdown(struct ufs_hba *hba)
 {
+	down(&hba->host_sem);
+	hba->shutting_down = true;
+	up(&hba->host_sem);

This does not seem right because the device is not accessible after __ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM), so shutting_down needs to be set before.

Quoted 4 lines
drivers/scsi/ufs/ufshcd.c +1 -0
+
 	if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba))
 		goto out;