nvme-pci: ensure we're polling a polled queue
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
@@ -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
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
@@ -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
Christoph Hellwig
maintainerRe: [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.
Re: [PATCH 2/3] nvme-pci: cap queue creation to used queues
In reply to Keith BuschQuoted 4 lines · Keith Busch
From: Keith Busch<[email protected]>
If the user reduces the special queue count at runtime and resets the controller,
Yes, I did see a crash on doing just that. Which is gone after this patch. And I guess you have reasons not to mark this for backport. So
PATCH 3/3 nvme-pci: do not try to add queue maps at runtime
In reply to Keith BuschFrom: 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
@@ -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
Christoph Hellwig
maintainerRe: [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.
Looks good: