blob: f0539dcded28f90399decfaa500ac7dee7fc99c5 [file] [log] [blame]
From 1e640c6de543ad3457b7df736d7583b446a76d0c Mon Sep 17 00:00:00 2001
From: Bijan Mottahedeh <>
Date: Wed, 26 Feb 2020 18:53:43 -0800
Subject: [PATCH] nvme-pci: Hold cq_poll_lock while completing CQEs
commit 9515743bfb39c61aaf3d4f3219a645c8d1fe9a0e upstream.
Completions need to consumed in the same order the controller submitted
them, otherwise future completion entries may overwrite ones we haven't
handled yet. Hold the nvme queue's poll lock while completing new CQEs to
prevent another thread from freeing command tags for reuse out-of-order.
Fixes: dabcefab45d3 ("nvme: provide optimized poll function for separate poll queues")
Signed-off-by: Bijan Mottahedeh <>
Reviewed-by: Sagi Grimberg <>
Reviewed-by: Jens Axboe <>
Signed-off-by: Keith Busch <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 18c0588c5cd8..27eabb53cd00 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1097,9 +1097,9 @@ static int nvme_poll(struct blk_mq_hw_ctx *hctx)
found = nvme_process_cq(nvmeq, &start, &end, -1);
+ nvme_complete_cqes(nvmeq, start, end);
- nvme_complete_cqes(nvmeq, start, end);
return found;