From: Alice Chao <alice.chao@mediatek.com>
To: Bean Huo <beanhuo@iokpp.de>, <stable@vger.kernel.org>
Cc: <linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<martin.petersen@oracle.com>,
<James.Bottomley@HansenPartnership.com>, <bvanassche@acm.org>,
<avri.altman@sandisk.com>, <alim.akhtar@samsung.com>,
<wsd_upstream@mediatek.com>, <linux-mediatek@lists.infradead.org>,
<peter.wang@mediatek.com>, <chun-hung.wu@mediatek.com>,
<cc.chou@mediatek.com>, <chaotian.jing@mediatek.com>,
<tun-yu.yu@mediatek.com>, <naomi.chu@mediatek.com>,
<ed.tsai@mediatek.com>
Subject: Re: [PATCH 6.18.y] scsi: ufs: core: Re-arm the device command completion before submitting
Date: Tue, 6 Oct 2026 17:55:03 +0800 [thread overview]
Message-ID: <ac1b17147198b189e606083e181db8802b72fac1.camel@mediatek.com> (raw)
In-Reply-To: <1912caf84d99bc2388960c907184f06689806ee6.camel@iokpp.de>
On Mon, 2026-10-05 at 13:54 +0200, Bean Huo wrote:
> The late CQE can come after the re-arm:
>
> timeout -> cleanup -> retry B -> re-arm -> send B -> A's CQE arrives,
> and then B
> is woken up early and fails, if B's own CQE in turn comes after C's
> re-arm, C
> fails the same way, and C may even read B's response as its own.
>
> Whether this stops depends on device latency against our retry path,
> not on the
> patch.
>
You are right. Re-arming only covers a late CQE that arrives while no
device command is in flight. The query retry wrappers resubmit right
away, so the next re-arm will usually happen before the previous CQE
lands, and the skew can cascade exactly as you describe. It is also
worse than an early wakeup: every device command shares the reserved
slot's response UPIU, so C can parse B's response as its own and
return a wrong value rather than an error.
> The root cause is that all device commands share hba->reserved_slot
> and the CQE
> carries only the tag. Since a successful SQ cleanup must post an
> ABORTED CQE,
> could the MCQ timeout path wait for and consume that CQE before
> returning -
> EAGAIN?
>
Agreed, that closes the window instead of narrowing it. In v2 the MCQ
timeout path will:
- after the SQ cleanup, wait (bounded) for the reserved slot's CQE -
the ABORTED one, or the regular one if the command completed
anyway - before returning;
- if no CQE shows up in time (e.g. cleanup failed, or
UFSHCD_QUIRK_MCQ_BROKEN_RTC), force a host reset and refuse device
commands outside the error handler until it has happened, so the
slot is not reused while that CQE can still arrive;
- keep reinit_completion() at submission time as a safety net.
> does this patch only covers a late CQE arriving while no device
> command is in
> flight. Did you test it with injected timeouts to see whether it
> recovers?
>
Yes, v1 only covers that case. And no, I have not tested it with
injected timeouts yet.
Before posting v2 I will run it with injected device command timeouts
in MCQ mode: periodic fake timeouts under a descriptor/attribute read
loop, with the values checked against known-good ones, and the case
where the CQE never arrives, to check that the host gets reset and
device commands recover. This will also show whether our controller
actually posts the ABORTED CQE after the SQ cleanup. I will run the
same injection on v1 and on the unpatched kernel for comparison and
put the results in the v2 changelog.
Thanks for the careful review.
Alice
prev parent reply other threads:[~2026-10-06 9:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 5:26 alice.chao
2026-09-16 1:52 ` Sasha Levin
2026-10-05 8:34 ` Alice Chao
2026-10-05 11:54 ` Bean Huo
2026-10-06 9:55 ` Alice Chao [this message]
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=ac1b17147198b189e606083e181db8802b72fac1.camel@mediatek.com \
--to=alice.chao@mediatek.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=beanhuo@iokpp.de \
--cc=bvanassche@acm.org \
--cc=cc.chou@mediatek.com \
--cc=chaotian.jing@mediatek.com \
--cc=chun-hung.wu@mediatek.com \
--cc=ed.tsai@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=naomi.chu@mediatek.com \
--cc=peter.wang@mediatek.com \
--cc=stable@vger.kernel.org \
--cc=tun-yu.yu@mediatek.com \
--cc=wsd_upstream@mediatek.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®