From: Bart Van Assche <bvanassche@acm.org>
To: Stanley Jhu <stanleyjhu@google.com>,
linux-scsi@vger.kernel.org, "Martin K. Petersen" <mkp@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
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: Re: [PATCH 2/9] scsi: ufs: core: Defer link recovery on reserved PM command timeout
Date: Thu, 12 Nov 2026 07:19:32 -0800 [thread overview]
Message-ID: <59c577b6-4749-4edc-9dd9-a83f2a124adb@acm.org> (raw)
In-Reply-To: <20261112051542.1539779-3-stanleyjhu@google.com>
On 11/11/26 9:15 PM, Stanley Jhu wrote:
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index e9dcab35a4cd..6a5f5fa732d9 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -7147,7 +7147,7 @@ static void ufshcd_err_handler(struct work_struct *work)
> spin_unlock_irqrestore(&hba->host->host_lock, flags);
>
> /* Complete requests that have door-bell cleared by h/w */
> - if (!stop)
> + if (!stop && ufshcd_is_hba_active(hba))
> ufshcd_complete_requests(hba, false);
> spin_lock_irqsave(&hba->host->host_lock, flags);
> again:
> @@ -9689,6 +9689,50 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
> dev_err(hba->dev, "%s failed: %d\n", __func__, ret);
> }
>
> +/*
> + * Claim @scmd before stopping the HBA in case normal completion raced with
> + * scsi_timeout(), then complete @scmd so the PM caller releases
> + * hba->dev_cmd.lock and the reserved tag before error recovery runs.
> + */
> +static void ufshcd_eh_pm_cmd_timed_out(struct ufs_hba *hba,
> + struct scsi_cmnd *scmd)
> +{
> + struct request *rq = scsi_cmd_to_rq(scmd);
> + struct ufs_hw_queue *hwq;
> +
> + if (!hba->mcq_enabled) {
> + if (!ufshcd_clear_outstanding_reqs(hba, BIT(rq->tag)))
> + return;
> + ufshcd_hba_stop(hba);
> + ufshcd_force_error_recovery(hba);
> + set_host_byte(scmd, DID_TIME_OUT);
> + scsi_done(scmd);
> + return;
> + }
> +
> + hwq = ufshcd_mcq_req_to_hwq(hba, rq);
> + if (ufshcd_is_hba_active(hba))
> + ufshcd_mcq_poll_cqe_lock(hba, hwq);
> + scoped_guard(spinlock_irqsave, &hwq->cq_lock) {
> + if (test_bit(SCMD_STATE_COMPLETE, &scmd->state))
> + return;
> + }
> + spin_lock_irq(&hba->host->host_lock);
> + hba->force_reset = true;
> + if (hba->ufshcd_state != UFSHCD_STATE_ERROR)
> + hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_FATAL;
> + spin_unlock_irq(&hba->host->host_lock);
> + ufshcd_hba_stop(hba);
> + ufshcd_mcq_compl_all_cqes_lock(hba, hwq);
> + ufshcd_force_error_recovery(hba);
> + scoped_guard(spinlock_irqsave, &hwq->cq_lock) {
> + if (!test_bit(SCMD_STATE_COMPLETE, &scmd->state)) {
> + set_host_byte(scmd, DID_TIME_OUT);
> + scsi_done(scmd);
> + }
> + }
> +}
> +
> static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
> {
> struct ufs_hba *hba = shost_priv(scmd->device->host);
> @@ -9698,6 +9742,11 @@ static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
> return SCSI_EH_NOT_HANDLED;
> }
>
> + if (!ufshcd_is_scsi_cmd(scmd)) {
> + ufshcd_eh_pm_cmd_timed_out(hba, scmd);
> + return SCSI_EH_DONE;
> + }
> +
> /*
> * Handle the timeout directly to prevent a deadlock between
> * ufshcd_set_dev_pwr_mode() and ufshcd_err_handler().
I don't like the approach of this patch series. I think this series
changes much more code than what is necessary. There is a much simpler
way to fix the issue reported in the cover letter: instead of calling
ufshcd_link_recovery(hba) from ufshcd_eh_timed_out(), remove that call
from ufshcd_eh_timed_out() and instead call ufshcd_link_recovery(hba)
from ufshcd_set_dev_pwr_mode() if the SCSI error code returned by
ufshcd_execute_start_stop() indicates that the SCSI START STOP UNIT
command has timed out.
Thanks,
Bart.
next prev parent reply other threads:[~2026-11-12 15:19 UTC|newest]
Thread overview: 11+ 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 15:19 ` Bart Van Assche [this message]
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 ` [PATCH 4/9] scsi: ufs: core: Fail PM commands fast when fatal recovery is scheduled Stanley Jhu
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=59c577b6-4749-4edc-9dd9-a83f2a124adb@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=axboe@kernel.dk \
--cc=beanhuo@micron.com \
--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 \
--cc=stanleyjhu@google.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®