[PATCH v4 0/2] ufs: fix the abort path of device management commands in MCQ mode
From: Kiwoong Kim
Date: Mon Nov 02 2026 - 00:54:18 EST
This series fixes how a timed-out device management command (query, NOP)
is aborted in MCQ mode.
Patch 1 makes ufshcd_try_to_abort_task() skip the task management path
for device management commands and clear them with ufshcd_clear_cmd()
directly, as the single doorbell path in ufshcd_abort() already does.
Since the conversion to scsi_get_internal_cmd(), ufshcd_mcq_abort() sends
these commands to the QUERY TASK / ABORT TASK path, which is meant for
SCSI I/O commands.
Patch 2 makes ufshcd_mcq_sq_cleanup() wait for the OCS of a device
management command to be updated after SQ cleanup. UFSHCI does not
specify the order between the OCS update and the SQ_CUS update. Without
the wait, a late completion of the cleaned-up query can race with the
retry of that query, which leaves the host with two query contexts and
raises IS.UTPES.
Patch 2 depends on patch 1. Without patch 1, ufshcd_mcq_sq_cleanup() is
reached for a device management command only if the ABORT TASK TMF
succeeds.
Changes since v3:
- Split the v3 patch into two patches: the abort path fix and
the OCS poll after SQ cleanup (Bean Huo).
- Explain in patch 1 that the problem is only reachable since the
scsi_get_internal_cmd() conversion and add the corresponding Fixes tag,
per review.
- Add a Fixes tag to patch 2. (Bean Huo)
- Fix the step numbering of the timeline in the patch 2 commit message.
Link: https://lore.kernel.org/linux-scsi/20261030111045.982094-1-kwmad.kim@xxxxxxxxxxx/
Changes since v2:
- Use read_poll_timeout() for the OCS poll in ufshcd_mcq_sq_cleanup().
The open-coded loop did not re-read the OCS after the timeout, so it
could return a false -ETIMEDOUT if the OCS was updated while sleeping
in the last iteration (Sashiko).
Link: https://lore.kernel.org/linux-scsi/20261030093645.790159-1-kwmad.kim@xxxxxxxxxxx/
Changes since v1:
- Limit the OCS poll in ufshcd_mcq_sq_cleanup() to device management
commands. ufshcd_compl_one_cqe() copies the OCS from the CQE into the
UTRD only for them, so for SCSI commands the poll always ran for
MCQ_POLL_US and then failed with -ETIMEDOUT (Sashiko).
- Return -ETIMEDOUT only if OCS is still OCS_INVALID_COMMAND_STATUS
after the poll. OCS_ABORTED, which the host controller reports for
the cleaned-up request, is no longer treated as a cleanup failure
(Sashiko).
- Update the commit message to match.
Link: https://lore.kernel.org/linux-scsi/20261030083311.602909-1-kwmad.kim@xxxxxxxxxxx/
Kiwoong Kim (2):
ufs: core: skip ABORT TASK for device management commands
ufs: mcq: poll OCS after sq cleanup for device management commands
drivers/ufs/core/ufs-mcq.c | 21 +++++++++++++++++++++
drivers/ufs/core/ufshcd.c | 4 ++++
2 files changed, 25 insertions(+)
--
2.43.0