From: sashiko-bot@kernel.org
To: "Yehyeong Lee" <yhlee@isslab.korea.ac.kr>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v5 1/2] nvme-fabrics: do not leave a timed-out command's id resolvable
Date: Fri, 04 Dec 2026 14:28:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-249971@kernel.org> (raw)
In-Reply-To: <20261204135345.2994739-2-yhlee@isslab.korea.ac.kr>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] nvme-fabrics: unsynchronized nr->genctr++ in
nvmf_retire_timed_out_command()
- [Low] nvme-fabrics: Fixes tag cites refactor 93ba75c90524 instead of
e4fdb2b167ed
--
commit d42cf469d2abf13e2a74d2e7aa0bac5c918cf7ba
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
> nvme-fabrics: do not leave a timed-out command's id resolvable
>
> nvmf_complete_timed_out_request() ends the request with
> blk_mq_complete_request() instead of nvme_try_complete_req(), which is the
> only place the host advances the generation counter that nvme_find_rq()
> checks a command id against. The id goes back to the tagset while the
> controller may still answer it, so a late response, R2T or C2HData for it
> resolves onto a request that is no longer in flight and completes it a
> second time.
>
> Stopping the queue first is no barrier: SHUT_RD does not discard what the
> socket has already received, and a queue that never reached
> NVME_TCP_Q_LIVE - the one carrying a connect or an in-band authentication
> command - is not stopped at all, so it keeps a working socket and a
> running io_work.
>
> Advance the generation where the host gives up, under the same quirk test
> nvme_try_complete_req() uses, and split it out as
> nvmf_retire_timed_out_command() for a transport that keeps using the queue
> after giving up and has to retire the id earlier than the completion.
> Advancing a monotonic counter twice is harmless, and a retry is a new
> dispatch through nvme_setup_cmd(), which recomputes the id from the
> current generation.
>
> Fixes: 93ba75c90524 ("nvme-fabrics: add a request timeout helper")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
[Severity: Low]
Should the Fixes tag cite commit e4fdb2b167ed ("nvme: increment request
genctr on completion") instead?
Commit 93ba75c90524 ("nvme-fabrics: add a request timeout helper") only
extracted the existing TCP and RDMA timeout completion code into
nvmf_complete_timed_out_request() without changing behavior. It was the
earlier commit that moved the genctr increment exclusively into
nvme_try_complete_req() while those timeout paths kept calling
blk_mq_complete_request() directly.
> diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
> index caf5503d08332..07db19fc85a29 100644
> --- a/drivers/nvme/host/fabrics.h
> +++ b/drivers/nvme/host/fabrics.h
> @@ -202,9 +202,18 @@ static inline char *nvmf_ctrl_subsysnqn(struct nvme_ctrl *ctrl)
> return ctrl->subsys->subnqn;
> }
>
> +static inline void nvmf_retire_timed_out_command(struct request *rq)
> +{
> + struct nvme_request *nr = nvme_req(rq);
> +
> + if (!(nr->ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
> + nr->genctr++;
> +}
> +
> static inline void nvmf_complete_timed_out_request(struct request *rq)
> {
> if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) {
> + nvmf_retire_timed_out_command(rq);
> nvme_req(rq)->status = NVME_SC_HOST_ABORTED_CMD;
> blk_mq_complete_request(rq);
> }
[Severity: Medium]
Can the unlocked nr->genctr++ in nvmf_retire_timed_out_command() race
with active RX, TX, or CQ paths on another CPU?
genctr is a plain u8 that was previously only updated on the serialized
completion path. When a connect or authentication command times out on
nvme-rdma before NVME_RDMA_Q_LIVE is set, nvme_rdma_stop_queue() is a
no-op and the CQ handler runs concurrently:
CPU0 (timeout work) CPU1 (RDMA CQ)
nvme_rdma_complete_timed_out()
nvme_rdma_stop_queue()
nvmf_complete_timed_out_request()
nvmf_retire_timed_out_command()
nr->genctr++ nvme_rdma_recv_done()
nvme_rdma_process_nvme_rsp()
nvme_find_rq()
reads nr->genctr <-- data race
...
nvme_try_complete_req()
rq->genctr++ <-- data race
This is a KCSAN data race against the plain reads in nvme_find_rq() and
the plain increment in nvme_try_complete_req(), and without atomic or
memory-ordered access a racing RX/CQ CPU on a weakly ordered architecture
is not guaranteed to observe the retired generation counter.
In commit "nvme-tcp: do not leave a timed-out request reachable from its
queue", nvme_tcp_complete_timed_out() also calls this helper before
stopping the queue or taking send_mutex/lock_sock(sk), which can race
with nvme_tcp_setup_h2c_data_pdu() and mismatch an H2CData command_id.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204135345.2994739-1-yhlee@isslab.korea.ac.kr?part=1
next prev parent reply other threads:[~2026-12-04 14:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:53 [PATCH v5 0/2] nvme-tcp: do not refer to a timed-out request after completing it Yehyeong Lee
2026-12-04 13:53 ` [PATCH v5 1/2] nvme-fabrics: do not leave a timed-out command's id resolvable Yehyeong Lee
2026-12-04 14:28 ` sashiko-bot [this message]
2026-12-04 13:53 ` [PATCH v5 2/2] nvme-tcp: do not leave a timed-out request reachable from its queue Yehyeong Lee
2026-12-04 15:06 ` sashiko-bot
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=sashiko-outbox-249971@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yhlee@isslab.korea.ac.kr \
/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