]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvme: increment request genctr on completion
authorKeith Busch <kbusch@kernel.org>
Mon, 13 Dec 2021 17:08:47 +0000 (09:08 -0800)
committerChristoph Hellwig <hch@lst.de>
Thu, 23 Dec 2021 10:22:45 +0000 (11:22 +0100)
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.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h

index f82c098b1a61200b0a4e497996ee5a3954814e5e..44c375a1edbb961d813cb22826b27ef53aecf42c 100644 (file)
@@ -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;
index b334af8aa264285f508e1c06cb09ed59904e1499..a54096ba0552cea25a138bdb881633219d0d1608 100644 (file)
@@ -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;