From: Stanley Jhu <stanleyjhu@google.com>
To: linux-scsi@vger.kernel.org, "Martin K. Petersen" <mkp@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Bart Van Assche <bvanassche@acm.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Avri Altman <avri.altman@sandisk.com>,
Bean Huo <beanhuo@micron.com>,
Peter Wang <peter.wang@mediatek.com>,
Stanley Chu <stanley.chu@mediatek.com>,
Can Guo <quic_cang@quicinc.com>,
"Bao D. Nguyen" <quic_nguyenb@quicinc.com>,
Asutosh Das <quic_asutoshd@quicinc.com>,
Hongjie Fang <hongjiefang@asrmicro.com>,
Praveen Talari <praveen.talari@oss.qualcomm.com>,
HOYOUNG SEO <hy50.seo@samsung.com>,
Brian Kao <powenkao@google.com>, Jens Axboe <axboe@kernel.dk>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 4/9] scsi: ufs: core: Fail PM commands fast when fatal recovery is scheduled
Date: Thu, 12 Nov 2026 13:15:37 +0800 [thread overview]
Message-ID: <20261112051542.1539779-5-stanleyjhu@google.com> (raw)
In-Reply-To: <20261112051542.1539779-1-stanleyjhu@google.com>
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@vger.kernel.org # 7.3.x
Signed-off-by: Stanley Jhu <stanleyjhu@google.com>
---
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
next prev parent reply other threads:[~2026-11-12 5:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 5:15 [PATCH 0/9] scsi: ufs: core: Fix device management and PM recovery Stanley Jhu
2026-11-12 5:15 ` [PATCH 1/9] scsi: ufs: core: Do not poll unconfigured MCQ queues in the error handler Stanley Jhu
2026-11-12 5:15 ` [PATCH 2/9] scsi: ufs: core: Defer link recovery on reserved PM command timeout Stanley Jhu
2026-11-12 5:15 ` [PATCH 3/9] scsi: ufs: core: Wait for the reserved tag in ufshcd_get_dev_mgmt_cmd() Stanley Jhu
2026-11-12 5:15 ` Stanley Jhu [this message]
2026-11-12 5:15 ` [PATCH 5/9] scsi: ufs: core: Disable W-LUN runtime PM in ufshcd_err_handling_prepare() Stanley Jhu
2026-11-12 5:15 ` [PATCH 6/9] block: Keep RPM_ACTIVE in blk_pre_runtime_resume() when already active Stanley Jhu
2026-11-12 5:15 ` [PATCH 7/9] scsi: ufs: core: Unwind variant resume in EH when reset fails Stanley Jhu
2026-11-12 5:15 ` [PATCH 8/9] scsi: ufs: core: Wake suspended consumer queues after host reset Stanley Jhu
2026-11-12 5:15 ` [PATCH 9/9] scsi: ufs: core: Do not recover the link concurrently with a PM callback Stanley Jhu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112051542.1539779-5-stanleyjhu@google.com \
--to=stanleyjhu@google.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=axboe@kernel.dk \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=hongjiefang@asrmicro.com \
--cc=hy50.seo@samsung.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=peter.wang@mediatek.com \
--cc=powenkao@google.com \
--cc=praveen.talari@oss.qualcomm.com \
--cc=quic_asutoshd@quicinc.com \
--cc=quic_cang@quicinc.com \
--cc=quic_nguyenb@quicinc.com \
--cc=rafael.j.wysocki@intel.com \
--cc=stanley.chu@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®