Skip to contentSkip to conversation

nvme: increment request genctr on completion

PATCH Applied Keith Busch 3 participants 3 messages Dec 13, 2021 – Dec 16, 2021 NVMe

lore
Share & tools
lore

Keith Busch

author maintainer
#0 lore raw

PATCH 1/1 nvme: increment request genctr on completion

The nvme request generation counter is intended to catch duplicate completions. Incrementing the counter on submission means duplicates can only be caught if the request tag is reallocated and dispatched prior to the driver observing the corrupted CQE. Incrementing on completion removes this window, making it possible to detect duplicate completions in consecutive entries.

---
 drivers/nvme/host/core.c | 2 --
 drivers/nvme/host/nvme.h | 4 ++++
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +0 -2
index f82c098b1a61..44c375a1edbb 100644
@@ -1037,8 +1037,6 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
 		return BLK_STS_IOERR;
 	}
 
-	if (!(ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
-		nvme_req(req)->genctr++;
 	cmd->common.command_id = nvme_cid(req);
 	trace_nvme_setup_cmd(req, cmd);
 	return ret;
drivers/nvme/host/nvme.h +4 -0
index b334af8aa264..a54096ba0552 100644
@@ -614,6 +614,10 @@ static inline bool nvme_try_complete_req(struct request *req, __le16 status,
 		union nvme_result result)
 {
 	struct nvme_request *rq = nvme_req(req);
+	struct nvme_ctrl *ctrl = rq->ctrl;
+
+	if (!(ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
+		rq->genctr++;
 
 	rq->status = le16_to_cpu(status) >> 1;
 	rq->result = result;
Signature · 1 line
2.25.4
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines

The nvme request generation counter is intended to catch duplicate completions. Incrementing the counter on submission means duplicates can only be caught if the request tag is reallocated and dispatched prior to the driver observing the corrupted CQE. Incrementing on completion removes this window, making it possible to detect duplicate completions in consecutive entries.

OK, It just occurred to me that blk_mq_tag_to_rq will still return the request after it was completed as tags->rqs[x] is not cleared when ending the request.

So this looks good.