Skip to contentSkip to conversation

nvme-pci: ensure we're polling a polled queue

PATCH Superseded Keith Busch 3 participants 7 messages Feb 10 – Feb 12 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 nvme-pci: ensure we're polling a polled queue

From: Keith Busch <[email protected]>

A user can change the polled queue count at run time. There's a brief window during a reset where a hipri task may try to poll that queue before the block layer has updated the queue maps, which would race with the now irq driven queue, which can cause double completions.

---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index 80df992d1ae82..5a3e27305176f 100644
@@ -1496,7 +1496,8 @@ static int nvme_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob)
 	struct nvme_queue *nvmeq = hctx->driver_data;
 	bool found;
 
-	if (!nvme_cqe_pending(nvmeq))
+	if (!test_bit(NVMEQ_POLLED, &nvmeq->flags) ||
+	    !nvme_cqe_pending(nvmeq))
 		return 0;
 
 	spin_lock(&nvmeq->cq_poll_lock);
Signature · 1 line
2.47.3
#1 lore raw

PATCH 2/3 nvme-pci: cap queue creation to used queues

From: Keith Busch <[email protected]>

If the user reduces the special queue count at runtime and resets the controller, we need to reduce the number of queues and interrupts requested accordingly rather than start with the pre-allocated queue count.

---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index 5a3e27305176f..f6d5c242fb689 100644
@@ -2775,7 +2775,8 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
 	dev->nr_write_queues = write_queues;
 	dev->nr_poll_queues = poll_queues;
 
-	nr_io_queues = dev->nr_allocated_queues - 1;
+	nr_io_queues = min(nvme_max_io_queues(dev),
+			   dev->nr_allocated_queues - 1);
 	result = nvme_set_queue_count(&dev->ctrl, &nr_io_queues);
 	if (result < 0)
 		return result;
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 2/3] nvme-pci: cap queue creation to used queues

Quoted 6 lines · Keith Busch

From: Keith Busch <[email protected]>

If the user reduces the special queue count at runtime and resets the controller, we need to reduce the number of queues and interrupts requested accordingly rather than start with the pre-allocated queue count.

Maybe add a comment as the code isn't quite obvious?

Otherwise looks good.

#4 lore raw

PATCH 3/3 nvme-pci: do not try to add queue maps at runtime

In reply to Keith Busch

From: Keith Busch <[email protected]>

The block layer allocates the set's maps once. We can't add special purpose queues at runtime if they weren't allocated at initialization time.

---
 drivers/nvme/host/pci.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/nvme/host/pci.c +14 -0
index f6d5c242fb689..43d214d31a8cf 100644
@@ -2775,6 +2775,20 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
 	dev->nr_write_queues = write_queues;
 	dev->nr_poll_queues = poll_queues;
 
+	if (dev->ctrl.tagset) {
+		switch (dev->ctrl.tagset->nr_maps) {
+		case 1:
+			dev->nr_write_queues = 0;
+			dev->nr_poll_queues = 0;
+			break;
+		case 2:
+			dev->nr_poll_queues = 0;
+			break;
+		default:
+			break;
+		}
+	}
+
 	nr_io_queues = min(nvme_max_io_queues(dev),
 			   dev->nr_allocated_queues - 1);
 	result = nvme_set_queue_count(&dev->ctrl, &nr_io_queues);
Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH 3/3] nvme-pci: do not try to add queue maps at runtime

Quoted 5 lines · Keith Busch

From: Keith Busch <[email protected]>

The block layer allocates the set's maps once. We can't add special purpose queues at runtime if they weren't allocated at initialization time.

Same here, a comment in the code would be helpful.

drivers/nvme/host/pci.c static int nvme_setup_io_queues(struct nvme_dev *dev) · line 2786

Quoted 9 lines
drivers/nvme/host/pci.c +9 -0
+	if (dev->ctrl.tagset) {
+		switch (dev->ctrl.tagset->nr_maps) {
+		case 1:
+			dev->nr_write_queues = 0;
+			dev->nr_poll_queues = 0;
+			break;
+		case 2:
+			dev->nr_poll_queues = 0;
+			break;

Maybe use fallthrough or just two ifs to condense this a tiny bit?

Otherwise looks good.