From: Bart Van Assche <bvanassche@acm.org>
To: Peter Wang <peter.wang@mediatek.com>,
Stanley Jhu <stanleyjhu@google.com>
Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" <mkp@kernel.org>,
"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>,
"Bao D. Nguyen" <quic_nguyenb@quicinc.com>,
Can Guo <can.guo@oss.qualcomm.com>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ
Date: Wed, 23 Sep 2026 09:50:58 -0700 [thread overview]
Message-ID: <edb755c1-5d45-4b38-abc6-02450b53a242@acm.org> (raw)
In-Reply-To: <f116f82d28f7af4cfca76adf5cff6093fdf393a2.camel@mediatek.com>
On 9/22/26 11:09 PM, Peter Wang wrote:
> But whether the subsequent re-queue (DID_REQUEUE) violates, I
> haven't seen any prohibition?
While this is not written down explicitly anywhere as far as I
know, requeuing from inside the host error handler is not allowed
at all.
> Because currently the UFS error handler (ufshcd_err_handler)
> directly re-queues (By set DID_REQUEUE) the unfinish command,
> and err handler might be triggered in many places, for example,
> like UIC errors, directly resetting and re-queueing should be
> reasonable and can be handled quickly.
Have you noticed the following code in drivers/scsi/scsi_error.c?
scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
> If it cannot directly re-queue, then ufshcd_eh_host_reset_handler
> would need another similar function that does not handle re-queueing.
> But this looks unnecessary, direct re-queuing seems safe?
Requeuing from the .eh_host_reset_handler() is not safe at all. It may
trigger list corruption as follows:
1. The .eh_host_reset_handler() callback sets scmd->result to
DID_REQUEUE << 16 and calls scsi_done(scmd). This causes
blk_mq_requeue_request() to insert the SCSI command into
&q->requeue_list. The SCSI command stays there because the request
queue is not run immediately because the SCSI host is in the state
SHOST_RECOVERY.
2. The .eh_host_reset_handler() callback finishes and returns SUCCESS.
3. The SCSI EH thread in scsi_eh_host_reset() sees that the reset
succeeded and moves cmd to done_q.
4. The SCSI EH thread executes scsi_eh_flush_done_q(done_q).
5. scsi_eh_flush_done_q() invokes
scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY) for the same scmd
that is already present on the request queue requeue list.
6. scsi_queue_insert() calls __scsi_queue_insert(), which invokes
blk_mq_requeue_request() a second time. This causes list corruption.
Code that examines the corrupted requeue list will either crash or
trigger an infinite loop.
Bart.
next prev parent reply other threads:[~2026-09-23 16:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 12:23 [PATCH] scsi: ufs: core: Avoid unsafe MMIO reads in ufshcd_mcq_compl_all_cqes_lock() Stanley Jhu
2026-09-18 14:38 ` [PATCH v2 0/2] scsi: ufs: core: Fix unsafe MMIO reads and redundant CQ sweeps in MCQ reset Stanley Jhu
2026-09-18 14:38 ` [PATCH v2 1/2] scsi: ufs: core: Avoid unsafe MMIO reads in ufshcd_mcq_compl_all_cqes_lock() Stanley Jhu
2026-09-22 3:05 ` Peter Wang
2026-09-18 14:38 ` [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ Stanley Jhu
2026-09-18 16:06 ` Bart Van Assche
2026-09-20 13:49 ` Stanley Jhu
2026-09-21 17:13 ` Bart Van Assche
2026-09-22 7:37 ` Peter Wang
2026-09-22 16:30 ` Bart Van Assche
2026-09-23 6:09 ` Peter Wang
2026-09-23 11:18 ` Stanley Jhu
2026-09-23 17:02 ` Bart Van Assche
2026-09-23 16:50 ` Bart Van Assche [this message]
2026-09-22 7:36 ` Peter Wang
2026-09-18 22:15 ` [PATCH] scsi: ufs: core: Avoid unsafe MMIO reads in ufshcd_mcq_compl_all_cqes_lock() Bart Van Assche
2026-09-22 6:13 [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ Peter Wang (王信友)
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=edb755c1-5d45-4b38-abc6-02450b53a242@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=beanhuo@micron.com \
--cc=can.guo@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mani@kernel.org \
--cc=mkp@kernel.org \
--cc=peter.wang@mediatek.com \
--cc=quic_nguyenb@quicinc.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®