Skip to contentSkip to conversation

nvme-pci: allocate tagset on reset if necessary

PATCH In review Keith Busch 4 participants 4 messages Aug 26, 2024 – Aug 27, 2024 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-pci: allocate tagset on reset if necessary

From: Keith Busch <[email protected]>

If a drive is unable to create IO queues on the initial probe, a subsequent reset will need to allocate the tagset if IO queue creation is successful.

---
 drivers/nvme/host/pci.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nvme/host/pci.c +8 -3
index 6cd9395ba9ec3..8e280e13cf10d 100644
@@ -2508,9 +2508,14 @@ static unsigned int nvme_pci_nr_maps(struct nvme_dev *dev)
 
 static void nvme_pci_update_nr_queues(struct nvme_dev *dev)
 {
-	blk_mq_update_nr_hw_queues(&dev->tagset, dev->online_queues - 1);
-	/* free previously allocated queues that are no longer usable */
-	nvme_free_queues(dev, dev->online_queues);
+	if (!dev->ctrl.tagset) {
+		nvme_alloc_io_tag_set(&dev->ctrl, &dev->tagset, &nvme_mq_ops,
+				nvme_pci_nr_maps(dev), sizeof(struct nvme_iod));
+	} else {
+		blk_mq_update_nr_hw_queues(&dev->tagset, dev->online_queues - 1);
+		/* free previously allocated queues that are no longer usable */
+		nvme_free_queues(dev, dev->online_queues);
+	}
 }
 
 static int nvme_pci_enable(struct nvme_dev *dev)
Signature · 1 line
2.43.5
maintainer Reviewed-by on v1 1/1
#1 lore raw

drivers/nvme/host/pci.c static unsigned int nvme_pci_nr_maps(struct nvme_dev *dev) · line 2515

Quoted 5 lines · Keith Busch
drivers/nvme/host/pci.c +5 -0
+	if (!dev->ctrl.tagset) {
+		nvme_alloc_io_tag_set(&dev->ctrl, &dev->tagset, &nvme_mq_ops,
+				nvme_pci_nr_maps(dev), sizeof(struct nvme_iod));
+	} else {
+		blk_mq_update_nr_hw_queues(&dev->tagset, dev->online_queues - 1);

Overly long line here. Maybe just return early after the allocation above?

Otherwise looks good:

maintainer
#2 lore raw
Quoted 9 lines · Christoph Hellwig

drivers/nvme/host/pci.c static unsigned int nvme_pci_nr_maps(struct nvme_dev *dev) · line 2515

Quoted 5 lines · Keith Busch
drivers/nvme/host/pci.c +5 -0
+	if (!dev->ctrl.tagset) {
+		nvme_alloc_io_tag_set(&dev->ctrl, &dev->tagset, &nvme_mq_ops,
+				nvme_pci_nr_maps(dev), sizeof(struct nvme_iod));
+	} else {
+		blk_mq_update_nr_hw_queues(&dev->tagset, dev->online_queues - 1);

Overly long line here. Maybe just return early after the allocation above?

Done.

I think I should also add more details to the change log because this bug does cause a kernel crash. I think this is the first commit that removed tagset allocation from reset_work:

Fixes eac3ef262941f62 ("nvme-pci: split the initial probe from the rest path")
Quoted 1 line