ufs: core: Fix an error handler crash
Subsystems (2)
Bart Van Assche
reviewerPATCH 1/1 ufs: core: Fix an error handler crash
The UFS error handler may be activated before SCSI scanning has started and hence before hba->ufs_device_wlun has been set. Check the hba->ufs_device_wlun pointer before using it.
--- drivers/ufs/core/ufshcd.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/ufs/core/ufshcd.c +14 -11
@@ -6698,19 +6698,22 @@ static void ufshcd_err_handler(struct work_struct *work) hba->saved_uic_err, hba->force_reset, ufshcd_is_link_broken(hba) ? "; link is broken" : ""); -/* -* Use ufshcd_rpm_get_noresume() here to safely perform link recovery -* even if an error occurs during runtime suspend or runtime resume. -* This avoids potential deadlocks that could happen if we tried to -* resume the device while a PM operation is already in progress. -*/ -ufshcd_rpm_get_noresume (hba); -if (hba->pm_op_in_progress) { -ufshcd_link_recovery (hba); +if (hba->ufs_device_wlun) { +/* +* Use ufshcd_rpm_get_noresume() here to safely perform link +* recovery even if an error occurs during runtime suspend or +* runtime resume. This avoids potential deadlocks that could +* happen if we tried to resume the device while a PM operation +* is already in progress. +*/ +ufshcd_rpm_get_noresume (hba); +if (hba->pm_op_in_progress) { +ufshcd_link_recovery (hba); +ufshcd_rpm_put (hba); +return ; + }ufshcd_rpm_put (hba); -return ; } -ufshcd_rpm_put (hba);down (&hba->host_sem);spin_lock_irqsave (hba->host->host_lock, flags);
Quoted 41 lines · Bart Van Assche
The UFS error handler may be activated before SCSI scanning has started and hence before
hba->ufs_device_wlunhas been set. Check thehba->ufs_device_wlunpointer before using it.Cc Peter Wang <[email protected]>Cc Nitin Rawat <[email protected]>Fixes e23ef4f22db3 ("scsi: ufs: core: Fix error handler host_sem issue")Fixes f966e02ae521 ("scsi: ufs: core: Fix runtime suspend error deadlock")Signed-off-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)drivers/ufs/core/ufshcd.c +11
-9@@ -6698,19 +6698,22 @@ static void ufshcd_err_handler(struct work_struct *work) hba->saved_uic_err, hba->force_reset, ufshcd_is_link_broken(hba) ? "; link is broken" : ""); -/* -* Use ufshcd_rpm_get_noresume() here to safely perform link recovery -* even if an error occurs during runtime suspend or runtime resume. -* This avoids potential deadlocks that could happen if we tried to -* resume the device while a PM operation is already in progress. -*/ -ufshcd_rpm_get_noresume (hba); -if (hba->pm_op_in_progress) { -ufshcd_link_recovery (hba); +if (hba->ufs_device_wlun) { +/* +* Use ufshcd_rpm_get_noresume() here to safely perform link +* recovery even if an error occurs during runtime suspend or +* runtime resume. This avoids potential deadlocks that could +* happen if we tried to resume the device while a PM operation +* is already in progress. +*/ +ufshcd_rpm_get_noresume (hba); +if (hba->pm_op_in_progress) { +ufshcd_link_recovery (hba);
drivers/ufs/core/ufshcd.c static void ufshcd_err_handler(struct work_struct *work) · line 6719
Quoted 10 lines
drivers/ufs/core/ufshcd.c +3
-2+ufshcd_rpm_put (hba); +return ; + }ufshcd_rpm_put (hba); -return ; } -ufshcd_rpm_put (hba);down (&hba->host_sem);spin_lock_irqsave (hba->host->host_lock, flags);
Hi Bart,
It seems you missed sending the below patch. Both patches are required to address the issue (hang and clock scaling errors), except for the UIC error, which still needs to be root-caused
Quoted 24 lines
drivers/ufs/core/ufshcd.c +4
-5@@ -1455,15 +1455,14 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba, u64 timeout_us)static void ufshcd_clock_scaling_unprepare (struct ufs_hba *hba,int err) {up_write (&hba->clk_scaling_lock); - +mutex_unlock (&hba->wb_mutex); +blk_mq_unquiesce_tagset (&hba->host->tag_set); +mutex_unlock (&hba->host->scan_mutex); +/* Enable Write Booster if current gear requires it else disable it */ if (ufshcd_enable_wb_if_scaling_up (hba) && !err)ufshcd_wb_toggle (hba, hba->pwr_info.gear_rx >= hba->clk_scaling.wb_gear); -mutex_unlock (&hba->wb_mutex); - -blk_mq_unquiesce_tagset (&hba->host->tag_set); -mutex_unlock (&hba->host->scan_mutex);ufshcd_release (hba);
Quoted 1 line
}
Thanks,
Nitin
Bart Van Assche
reviewerQuoted 1 line · Nitin Rawat
It seems you missed sending the below patch. Both patches are required to address the issue (hang and clock scaling errors), except for the UIC error, which still needs to be root-caused
My shell history tells me that I tried to send the fix for the clock scaling hang to the linux-scsi mailing list yesterday. Apparently the patch didn't reach the linux-scsi mailing list. Maybe this was caused by the hotel Wi-Fi. Anyway, thanks for having pointed this out. I have resent the fix for the clock scaling hang.
Bart.
Quoted 5 lines · Bart Van Assche
The UFS error handler may be activated before SCSI scanning has started and
hence beforehba->ufs_device_wlunhas been set. Check thehba->ufs_device_wlunpointer before using it.
Quoted 7 lines
Cc Peter Wang <[email protected]>Cc Nitin Rawat <[email protected]>Fixes e23ef4f22db3 ("scsi: ufs: core: Fix error handler host_semissue")
Fixes f966e02ae521 ("scsi: ufs: core: Fix runtime suspend errordeadlock")
Signed-off-by Bart Van Assche <[email protected]>
Thanks for fix this bug.
Quoted 9 lines · Bart Van Assche
The UFS error handler may be activated before SCSI scanning has started and hence before
hba->ufs_device_wlunhas been set. Check thehba->ufs_device_wlunpointer before using it.Cc Peter Wang <[email protected]>Cc Nitin Rawat <[email protected]>Fixes e23ef4f22db3 ("scsi: ufs: core: Fix error handler host_sem issue")Fixes f966e02ae521 ("scsi: ufs: core: Fix runtime suspend error deadlock")Signed-off-by Bart Van Assche <[email protected]>
Martin K. Petersen
AppliedBart,
Quoted 3 lines
The UFS error handler may be activated before SCSI scanning has started and hence before
hba->ufs_device_wlunhas been set. Check thehba->ufs_device_wlunpointer before using it.
Applied to 6.19/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen