[PATCH v5 1/2] nvme-fabrics: do not leave a timed-out command's id resolvable

From: Yehyeong Lee

Date: Fri Dec 04 2026 - 08:54:09 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Yehyeong Lee <yhlee@xxxxxxxxxxxxxxxxxx>
---
drivers/nvme/host/fabrics.h | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
index caf5503d083329..07db19fc85a294 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);
}
--
2.43.0