diff options
| author | Kiwoong Kim <kwmad.kim@samsung.com> | 2026-11-06 13:12:47 +0900 |
|---|---|---|
| committer | Martin K. Petersen (Oracle) <mkp@kernel.org> | 2026-11-08 18:03:15 -0500 |
| commit | e510b597d8afca2e790e2b5429bc5e01e3386f65 (patch) | |
| tree | 0c03285a90c36814ea5d7e9135c5681d3d606778 /tools/perf/scripts/python | |
| parent | 30bdadc9aa3a684cd634c7fa49740b1151e7b2e5 (diff) | |
scsi: ufs: mcq: Poll OCS after sq cleanup for device management commands
Extend ufshcd_mcq_sq_cleanup() to poll the OCS field in the UTRD of a
device management command after a successful SQ_CUS poll. UFSHCI does not
specify the order between the OCS update and the SQ_CUS update, so OCS may
still be stale when cleanup returns. Without this poll, a late response to
a timed-out query can arrive while a retry is already in flight, leaving
the host controller with two query contexts and raising IS.UTPES.
Here is the timeline of an actual case I found with kernel 6.18:
1. The driver sent a query but the device didn't respond to it for a long
time.
[ 7384.156142] [4: kworker/u40:5:10671] exynos-ufs 38300000.ufs: ufshcd_mcq_sq_cleanup, hwq 0: cleanup return code (RTC) 0
[ 7384.156154] [4: kworker/u40:5:10671] exynos-ufs 38300000.ufs: ufshcd_query_flag: Sending flag query for idn 14 failed, err = -11
2. So after the query timed out, the driver did SQ cleanup. Then the host
controller updated the CQ tail and raised IS.CQES. Unfortunately,
complete() was called by the driver's ISR afterward.
3. The driver started to retry the query. In the meantime, it set OCS to
0xF. Then the driver didn't wait for completion due to the previous
complete() call, and just checked OCS.
[ 7384.156163] [4: kworker/u40:5:10671] exynos-ufs 38300000.ufs: ufshcd_query_flag: Sending flag query for idn 14 failed, err = 15
4. The driver retried the query again, but the device didn't return
anything, so the query also timed out.
[ 7385.660108] [3: kworker/u40:5:10671] exynos-ufs 38300000.ufs: ufshcd_query_flag: Sending flag query for idn 14 failed, err = -11
5. A few seconds later, the device returned the response of the first
query, but since the host controller was holding two query contexts and
couldn't handle it, it raised IS.UTPES.
The same problem exists in the current code. If the query times out, the
SCSI error handler calls ufshcd_abort() -> ufshcd_mcq_abort() ->
ufshcd_mcq_sq_cleanup(), the request is finished, and the retry reuses the
same reserved tag, struct scsi_cmnd and devman UCD. A late CQE for the
first query then maps to the same tag and completes the retry by calling
scsi_done() too early. The retry then returns the OCS of the first query
and, if that OCS is OCS_SUCCESS, its response as well. Hence
ufshcd_mcq_sq_cleanup() must not return until the CQE of the cleaned-up
request has been processed.
The poll is limited to device management commands because
ufshcd_compl_one_cqe() copies the OCS from the CQE into the UTRD only for
them. For SCSI commands, the OCS in the UTRD stays
OCS_INVALID_COMMAND_STATUS, so polling it would always time out.
The poll waits until OCS is no longer OCS_INVALID_COMMAND_STATUS or
MCQ_POLL_US elapses. -ETIMEDOUT is returned only if OCS is still
OCS_INVALID_COMMAND_STATUS after the poll. Any other value, such as
OCS_ABORTED reported by the host controller for the cleaned-up request,
means the cleanup has completed. The UFSHCI specification says "The host
controller shall free up any resources associated to the nexus, and shall
post a Completion Queue entry with OCS = ABORTED if clean up successful."
Each poll iteration reaps the CQ with ufshcd_mcq_poll_cqe_lock() before
reading the OCS, as ufshcd_clear_lu_cmds() does after ufshcd_clear_cmd().
This removes the dependency on interrupt delivery. Otherwise the OCS is
only updated once the interrupt handler processes the CQE, and a delayed or
lost interrupt would make the poll time out and escalate to a host reset
although the request has already been cleaned up.
The OCS is still read under hwq->cq_lock because the interrupt handler may
reap the CQE between the reap and the read. ufshcd_compl_one_cqe() updates
the OCS under that lock before it sets cmd->result and calls scsi_done().
Without the lock, cleanup could observe the new OCS and return while the
completion is still running. The abort could then finish the command and a
retry could reuse the same reserved request before the pending scsi_done()
call, which would then complete the retry prematurely.
Fixes: 8d7290348992 ("scsi: ufs: mcq: Add supporting functions for MCQ abort")
Signed-off-by: Kiwoong Kim <kwmad.kim@samsung.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Link: https://patch.msgid.link/a1af44cd90dca0dd8a9a06d09a254a4e7e0861b2.1793938245.git.kwmad.kim@samsung.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
