Skip to contentSkip to conversation

ufs: core: Fix error handler host_sem issue

PATCH Applied [email protected] 3 participants 3 messages Oct 8, 2025 – Oct 22, 2025

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

PATCH v2 1/1 ufs: core: Fix error handler host_sem issue

From: Peter Wang <[email protected]>

Fix the issue where host_sem is not released due to a new return patch in commit f966e02ae521. Check pm_op_in_progress before acquiring hba->host_sem to prevent deadlocks and ensure proper resource management during error handling. Add comment for use ufshcd_rpm_get_noresume() to safely perform link recovery without interfering with ongoing PM operations.

Fixes f966e02ae521 ("scsi: ufs: core: Fix runtime suspend error deadlock")
---
 drivers/ufs/core/ufshcd.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/ufs/core/ufshcd.c +14 -8
index 8185a7791923..ff7a3d60b11d 100644
@@ -6670,6 +6670,20 @@ 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);
+		ufshcd_rpm_put(hba);
+		return;
+	}
+	ufshcd_rpm_put(hba);
+
 	down(&hba->host_sem);
 	spin_lock_irqsave(hba->host->host_lock, flags);
 	if (ufshcd_err_handling_should_stop(hba)) {
@@ -6681,14 +6695,6 @@ static void ufshcd_err_handler(struct work_struct *work)
 	}
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
-	ufshcd_rpm_get_noresume(hba);
-	if (hba->pm_op_in_progress) {
-		ufshcd_link_recovery(hba);
-		ufshcd_rpm_put(hba);
-		return;
-	}
-	ufshcd_rpm_put(hba);
-
 	ufshcd_err_handling_prepare(hba);
 
 	spin_lock_irqsave(hba->host->host_lock, flags);
Signature · 1 line
2.45.2
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 44 lines · On 10/7/25 11:55 PM, [email protected] wrote:

Fix the issue where host_sem is not released due to a new return patch in commit f966e02ae521. Check pm_op_in_progress before acquiring hba->host_sem to prevent deadlocks and ensure proper resource management during error handling. Add comment for use ufshcd_rpm_get_noresume() to safely perform link recovery without interfering with ongoing PM operations.

Fixes f966e02ae521 ("scsi: ufs: core: Fix runtime suspend error deadlock")
---
  drivers/ufs/core/ufshcd.c | 22 ++++++++++++++--------
  1 file changed, 14 insertions(+), 8 deletions(-)
drivers/ufs/core/ufshcd.c +14 -1
index 8185a7791923..ff7a3d60b11d 100644
@@ -6670,6 +6670,20 @@ 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);
+		ufshcd_rpm_put(hba);
+		return;
+	}
+	ufshcd_rpm_put(hba);
+
  	down(&hba->host_sem);
  	spin_lock_irqsave(hba->host->host_lock, flags);
  	if (ufshcd_err_handling_should_stop(hba)) {
@@ -6681,14 +6695,6 @@ static void ufshcd_err_handler(struct work_struct *work)
  	}
  	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
-	ufshcd_rpm_get_noresume(hba);

drivers/ufs/core/ufshcd.c static void ufshcd_err_handler(struct work_struct *work) · line 6700

Quoted 10 lines
drivers/ufs/core/ufshcd.c +0 -7
-	if (hba->pm_op_in_progress) {
-		ufshcd_link_recovery(hba);
-		ufshcd_rpm_put(hba);
-		return;
-	}
-	ufshcd_rpm_put(hba);
-
  	ufshcd_err_handling_prepare(hba);
 
  	spin_lock_irqsave(hba->host->host_lock, flags);

Thanks!

#2 lore raw
In reply to [email protected]

Peter,

Quoted 6 lines

Fix the issue where host_sem is not released due to a new return patch in commit f966e02ae521. Check pm_op_in_progress before acquiring hba->host_sem to prevent deadlocks and ensure proper resource management during error handling. Add comment for use ufshcd_rpm_get_noresume() to safely perform link recovery without interfering with ongoing PM operations.

Applied to 6.18/scsi-fixes, thanks!

Signature · 1 line
Martin K. Petersen