From: Stanley Jhu <stanleyjhu@google.com>
To: Bart Van Assche <bvanassche@acm.org>,
"Martin K . Petersen" <mkp@kernel.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Avri Altman <avri.altman@sandisk.com>
Cc: "James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
Peter Wang <peter.wang@mediatek.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-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Stanley Jhu <stanleyjhu@google.com>
Subject: [PATCH 0/2] scsi: ufs: core: Fix SCSI EH command ownership and remove force_compl
Date: Sun, 20 Sep 2026 22:33:17 +0800 [thread overview]
Message-ID: <20260920143319.3659543-1-stanleyjhu@google.com> (raw)
In ufshcd_host_reset_and_restore(), ufshcd_complete_requests(hba, true)
couples LLD resource release (ufshcd_release_scsi_cmd()) with command
completion (scsi_done()) right after ufshcd_hba_stop():
1. EH-owned SCSI commands (SCMD_STATE_COMPLETE set): skipping
scsi_done() in ufshcd_mcq_force_compl_one() also skips
ufshcd_release_scsi_cmd(), leaking DMA mappings and
clk_gating.active_reqs whenever ufshcd_abort() fails.
2. Non-EH SCSI commands (!SCMD_STATE_COMPLETE): calling scsi_done()
right after ufshcd_hba_stop() completes them before link recovery
finishes.
This series enforces a strict ownership boundary between LLD hardware
resources and SCSI command completion across SDB and MCQ error recovery:
- LLD resources (DMA mappings, crypto PRDT, clk_gating.active_reqs) are
tied to controller execution and are released whenever the hardware
stops executing a command, regardless of whether SCSI EH owns it.
- Command completion (scsi_done()) belongs exclusively to SCSI EH once
SCMD_STATE_COMPLETE is set. For commands where SCMD_STATE_COMPLETE is
not set, UFS cannot delegate completion to SCSI EH because UFS also
performs autonomous resets (ufshcd_err_handler() on UIC/controller
errors) outside of scsi_error_handler(). Since ufshcd_hba_stop()
(HCE = 0) wipes all in-flight hardware transfers while SCSI EH is
inactive, the driver itself requeues halted non-EH commands with
DID_REQUEUE after recovery finishes so they do not stall for the 30s
block timeout.
- Patch 1 tracks controller resource ownership with lrbp->in_flight and
halted non-EH commands with lrbp->pending_requeue, splits host-reset
cleanup into ufshcd_release_stopped_reqs() (at controller stop) and
ufshcd_requeue_non_eh_cmds() (after recovery finishes), and aligns
ownership across ufshcd_compl_one_cqe(), ufshcd_abort(), and
ufshcd_clear_lu_cmds().
- Patch 2 removes the unused force_compl parameter from
ufshcd_complete_requests() and ufshcd_mcq_compl_pending_transfer(),
along with the now-unreachable ufshcd_mcq_force_compl_one() and
ufshcd_mcq_compl_all_cqes_lock() helpers.
This supersedes the v2 series [3].
Link: https://lore.kernel.org/linux-scsi/eacb6c2a-9219-4e9b-8726-8d38b641f543@acm.org/ [1]
Link: https://lore.kernel.org/linux-scsi/1ddc5181-f547-465c-bfbe-dbf14a91493e@acm.org/ [2]
Link: https://lore.kernel.org/linux-scsi/20260918143809.3034592-1-stanleyjhu@google.com/ [3]
Link: https://lore.kernel.org/linux-scsi/20260920135014.3528082-1-stanleyjhu@google.com/ [4]
Tested:
Verified on QEMU ARM64 (SDB and MCQ) across probe, I/O, reset, and
unbind without UAF or leaks.
Stanley Jhu (2):
scsi: ufs: core: Release command resources instead of force-completing
scsi: ufs: core: Remove unused force_compl parameter and MCQ helper
drivers/ufs/core/ufs-mcq.c | 26 ----
drivers/ufs/core/ufshcd-priv.h | 2 -
drivers/ufs/core/ufshcd.c | 213 +++++++++++++++++++++++---------
include/ufs/ufshcd.h | 4 +
4 files changed, 157 insertions(+), 88 deletions(-)
--
2.51.0
next reply other threads:[~2026-09-20 14:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 14:33 Stanley Jhu [this message]
2026-09-20 14:33 ` [PATCH 1/2] scsi: ufs: core: Release command resources instead of force-completing Stanley Jhu
2026-09-21 0:41 ` Bart Van Assche
2026-09-21 4:37 ` Stanley Jhu
2026-09-20 14:33 ` [PATCH 2/2] scsi: ufs: core: Remove unused force_compl parameter and MCQ helper 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=20260920143319.3659543-1-stanleyjhu@google.com \
--to=stanleyjhu@google.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--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 \
/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®