From f68d040c318f8022628d89e794b78326b352a9fe Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 16 Sep 2022 06:37:59 -0700 Subject: [PATCH] FROMLIST: scsi: ufs: Fix deadlocks between power management and error handler The following deadlocks have been observed on multiple test setups: * ufshcd_wl_suspend() is waiting for blk_execute_rq() to complete while it holds host_sem. * ufshcd_eh_host_reset_handler() invokes ufshcd_err_handler() and the latter function tries to obtain host_sem. This is a deadlock because blk_execute_rq() can't execute SCSI commands while the host is in the SHOST_RECOVERY state and because the error handler cannot make progress either. * ufshcd_wl_runtime_resume() is waiting for blk_execute_rq() to finish while it holds host_sem. * ufshcd_eh_host_reset_handler() invokes ufshcd_err_handler() and the latter function calls pm_runtime_resume(). This is a deadlock because of the same reason as the previous scenario. Fix both deadlocks by not obtaining host_sem from the power management code paths. Removing the host_sem locking from the power management code is safe because the ufshcd_err_handler() is already serialized against SCSI command execution. Cc: dh0421.hwang@samsung.com Cc: Asutosh Das Fixes: b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun") Signed-off-by: Bart Van Assche Bug: 240498410 Bug: 246990788 Bug: 247073231 Bug: 247081382 Bug: 247082093 Link: https://lore.kernel.org/linux-scsi/ Signed-off-by: Bart Van Assche Change-Id: Ifb9b429ba89ff6d8a133d96a172eaefc09d85955 --- 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 9ee325116902..fb62a8210075 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9337,16 +9337,13 @@ static int ufshcd_wl_suspend(struct device *dev) ktime_t start = ktime_get(); hba = shost_priv(sdev->host); - down(&hba->host_sem); if (pm_runtime_suspended(dev)) goto out; ret = __ufshcd_wl_suspend(hba, UFS_SYSTEM_PM); - if (ret) { + if (ret) dev_err(&sdev->sdev_gendev, "%s failed: %d\n", __func__, ret); - up(&hba->host_sem); - } out: if (!ret) @@ -9379,7 +9376,6 @@ out: hba->curr_dev_pwr_mode, hba->uic_link_state); if (!ret) hba->is_sys_suspended = false; - up(&hba->host_sem); return ret; } #endif