From: "Kiwoong Kim" <kwmad.kim@samsung.com>
To: "'Bart Van Assche'" <bvanassche@acm.org>,
<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<alim.akhtar@samsung.com>, <jejb@linux.ibm.com>,
<martin.petersen@oracle.com>, <kwangwon.min@samsung.com>,
<hy50.seo@samsung.com>, <cpgs@samsung.com>, <h10.kim@samsung.com>
Cc: <stable@vger.kernel.org>, <stanleyjhu@google.com>
Subject: RE: [PATCH v6 2/2] ufs: mcq: poll OCS after sq cleanup for device management commands
Date: Thu, 5 Nov 2026 14:59:04 +0900 [thread overview]
Message-ID: <003701dd6cea$c396cd10$4ac46730$@samsung.com> (raw)
In-Reply-To: <8939a53e-1b21-4dd9-b65c-cbe03b8b72ce@acm.org>
> > Here is the timeline of an actual case for this that happened with
> kernel 6.18.
> > [ ... ]
> > 2. So after the query was timed out, the driver did SQ cleanup.
> > Then the host updated CQ update and raised IS.CQES, > Unfortunately,
> complete() was called the driver's ISR afterward.
>
> This timeline describes code that no longer exists upstream. Since commit
> 08b12cda6c44 ("scsi: ufs: core: Switch to scsi_get_internal_cmd()"), the
> device management path no longer calls complete(). Please describe the
> race in terms of the current code:
Let me add it below the timeline described previously.
> 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 hba->dev_cmd.tag via
> devman_ucd_dma_addr and completes the retry too early. That is why cq_lock
> matters here. Please also keep lines in the patch description at 75
> columns or less.
>
> > +static enum utp_ocs ufshcd_mcq_read_ocs(struct ufs_hw_queue *hwq,
> > + struct ufshcd_lrb *lrbp)
> > +{
> > + guard(spinlock_irqsave)(&hwq->cq_lock);
> > + return READ_ONCE(lrbp->utr_descriptor_ptr->header.ocs);
> > +}
>
> READ_ONCE() is not necessary since the OCS is read with cq_lock held.
Got it.
>
> > + if (!err && blk_mq_is_reserved_rq(rq)) {
> > + enum utp_ocs ocs;
> > +
> > + err = read_poll_timeout(ufshcd_mcq_read_ocs, ocs,
> > + ocs != OCS_INVALID_COMMAND_STATUS, 20,
> > + MCQ_POLL_US, false, hwq, lrbp);
> > + if (err)
> > + dev_err(hba->dev, "%s: OCS not updated. hwq=%d, tag=%d
> err=%d\n",
> > + __func__, id, task_tag, err);
> > + }
> > +
> > if (ufshcd_mcq_sq_start(hba, hwq))
> > err = -ETIMEDOUT;
>
> The SQ is still stopped at this point, so this loop can stop fetching from
> the hardware queue for up to MCQ_POLL_US (500 ms). Please move the OCS
> poll after the ufshcd_mcq_sq_start() call.
I didn't get what you meant. The loop just reads updated OCS periodically
and from what I know, it's based on the assumption that when a task is cleaned up by setting SQRTCy.ICU to one
and it's successfully done, the host updates OCS, even if SQ is stopped.
If you feel I get your comment wrong, please let me know.
>
> This code also waits for the interrupt handler to process the CQE. Why not
> reap the CQE from this function? ufshcd_clear_lu_cmds() already does that
> by calling ufshcd_mcq_poll_cqe_lock(hba, hwq) after ufshcd_clear_cmd().
> Calling ufshcd_mcq_poll_cqe_lock() before reading the OCS would remove the
> dependency on interrupt delivery and match the existing code.
Because a successful SQ cleanup leads to OCS update,
which subsequently leads to raising IS.CQES when MCQ is enabled.
I understand your idea with ufshcd_clear_lu_cmds, then do you intend
Ignoring IS.CQES event in this case?
>
> Additionally, does the UFSHCI specification guarantee that the host
> controller posts a CQE (e.g. with OCS = ABORTED) for every command that
> has been cleaned up? If not, this patch turns cases that are harmless
> today into a host reset. Please cite the relevant section of the UFSHCI
> specification in the patch description or in a source code comment.
This is the sentence that I referred to:
"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."
> Thanks,
>
> Bart.
Thanks
Kiwoong Kim
BRs.
next prev parent reply other threads:[~2026-11-05 5:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261105004351epcas2p19e657481834dc8493d926f10cff77d03@epcas2p1.samsung.com>
2026-11-05 0:43 ` [PATCH v6 0/2] ufs: fix the abort path of device management commands in MCQ mode Kiwoong Kim
2026-11-05 0:43 ` [PATCH v6 1/2] ufs: core: skip ABORT TASK for device management commands Kiwoong Kim
2026-11-05 1:28 ` Bart Van Assche
2026-11-05 3:34 ` Kiwoong Kim
2026-11-05 3:36 ` Kiwoong Kim
2026-11-05 0:43 ` [PATCH v6 2/2] ufs: mcq: poll OCS after sq cleanup " Kiwoong Kim
2026-11-05 1:30 ` Bart Van Assche
2026-11-05 5:59 ` Kiwoong Kim [this message]
2026-11-05 17:53 ` Bart Van Assche
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='003701dd6cea$c396cd10$4ac46730$@samsung.com' \
--to=kwmad.kim@samsung.com \
--cc=alim.akhtar@samsung.com \
--cc=bvanassche@acm.org \
--cc=cpgs@samsung.com \
--cc=h10.kim@samsung.com \
--cc=hy50.seo@samsung.com \
--cc=jejb@linux.ibm.com \
--cc=kwangwon.min@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stable@vger.kernel.org \
--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