[PATCH 4/9] scsi: ufs: core: Fail PM commands fast when fatal recovery is scheduled
From: Stanley Jhu
Date: Thu Nov 12 2026 - 00:32:23 EST
Once a fatal error has scheduled the error handler during a PM
callback, the callback should fail fast and leave recovery to the
error handler. Two paths do not:
1. ufshcd_issue_dev_cmd() keeps sending device management commands to
the stopped controller, and each one waits for a full timeout. This
includes the NOP OUT retries in ufshcd_verify_dev_init() after the
controller has been stopped.
2. When START STOP UNIT times out, ufshcd_eh_timed_out() resets the
link inline and marks the host operational while the error handler
is still pending. System suspend can then succeed and hold
hba->host_sem across sleep, which blocks the error handler until
resume.
Fail device management commands with -EIO in that state, and let
START STOP UNIT, the only SCSI command a PM callback sends, take the
same deferred recovery path. __ufshcd_wl_suspend() then returns
-EBUSY, so system suspend is aborted and releases hba->host_sem for
the error handler, and runtime suspend is retried once recovery is
done. Also keep UFSHCD_STATE_EH_SCHEDULED_FATAL when
ufshcd_err_handler() stops early during shutdown so remaining shutdown
PM commands fail fast as well.
Fixes: 01d5e237b339 ("scsi: ufs: core: Handle PM commands timeout before SCSI EH")
Cc: stable@xxxxxxxxxxxxxxx # 7.3.x
Signed-off-by: Stanley Jhu <stanleyjhu@xxxxxxxxxx>
---
drivers/ufs/core/ufshcd.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 6d789f3badf1..5563d28ef92e 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -3395,6 +3395,11 @@ static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd,
struct request *rq = scsi_cmd_to_rq(cmd);
blk_status_t sts;
+ if (hba->pm_op_in_progress &&
+ hba->ufshcd_state == UFSHCD_STATE_EH_SCHEDULED_FATAL &&
+ !(ufshcd_eh_in_progress(hba) && ufshcd_is_hba_active(hba)))
+ return -EIO;
+
rq->timeout = msecs_to_jiffies(timeout);
sts = blk_execute_rq(rq, true);
if (sts != BLK_STS_OK)
@@ -7133,7 +7138,9 @@ static void ufshcd_err_handler(struct work_struct *work)
down(&hba->host_sem);
spin_lock_irqsave(&hba->host->host_lock, flags);
if (ufshcd_err_handling_should_stop(hba)) {
- if (hba->ufshcd_state != UFSHCD_STATE_ERROR)
+ if (!(hba->shutting_down &&
+ hba->ufshcd_state == UFSHCD_STATE_EH_SCHEDULED_FATAL) &&
+ hba->ufshcd_state != UFSHCD_STATE_ERROR)
hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
spin_unlock_irqrestore(&hba->host->host_lock, flags);
up(&hba->host_sem);
@@ -9701,6 +9708,7 @@ static void ufshcd_eh_pm_cmd_timed_out(struct ufs_hba *hba,
struct scsi_cmnd *scmd)
{
struct request *rq = scsi_cmd_to_rq(scmd);
+ bool is_scsi = ufshcd_is_scsi_cmd(scmd);
struct ufs_hw_queue *hwq;
if (!hba->mcq_enabled) {
@@ -9708,6 +9716,8 @@ static void ufshcd_eh_pm_cmd_timed_out(struct ufs_hba *hba,
return;
ufshcd_hba_stop(hba);
ufshcd_force_error_recovery(hba);
+ if (is_scsi)
+ ufshcd_release_scsi_cmd(hba, scmd);
set_host_byte(scmd, DID_TIME_OUT);
scsi_done(scmd);
return;
@@ -9730,6 +9740,8 @@ static void ufshcd_eh_pm_cmd_timed_out(struct ufs_hba *hba,
ufshcd_force_error_recovery(hba);
scoped_guard(spinlock_irqsave, &hwq->cq_lock) {
if (!test_bit(SCMD_STATE_COMPLETE, &scmd->state)) {
+ if (is_scsi)
+ ufshcd_release_scsi_cmd(hba, scmd);
set_host_byte(scmd, DID_TIME_OUT);
scsi_done(scmd);
}
@@ -9739,13 +9751,14 @@ static void ufshcd_eh_pm_cmd_timed_out(struct ufs_hba *hba,
static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
{
struct ufs_hba *hba = shost_priv(scmd->device->host);
+ bool is_scsi = ufshcd_is_scsi_cmd(scmd);
if (!hba->pm_op_in_progress) {
/* Activate the error handler in the SCSI core. */
return SCSI_EH_NOT_HANDLED;
}
- if (!ufshcd_is_scsi_cmd(scmd)) {
+ if (!is_scsi || hba->ufshcd_state == UFSHCD_STATE_EH_SCHEDULED_FATAL) {
ufshcd_eh_pm_cmd_timed_out(hba, scmd);
return SCSI_EH_DONE;
}
--
2.56.0.567.gdb80ae8cd5-goog