Skip to contentSkip to conversation

nvme-pci: limit max_hw_sectors based on the DMA max mapping size

PATCH New Christoph Hellwig 2 participants 2 messages Jul 3, 2019 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme-pci: limit max_hw_sectors based on the DMA max mapping size

When running a NVMe device that is attached to a addressing challenged PCIe root port that requires bounce buffering, our request sizes can easily overflow the swiotlb bounce buffer size. Limit the maximum I/O size to the limit exposed by the DMA mapping subsystem.

Signed-off-by Christoph Hellwig <hch at lst.de>
Reported-by Atish Patra <Atish.Patra at wdc.com>
Tested-by Atish Patra <Atish.Patra at wdc.com>
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index 49c1fc9907a6..a214c7b08763 100644
@@ -2497,7 +2497,8 @@ static void nvme_reset_work(struct work_struct *work)
 	 * Limit the max command size to prevent iod->sg allocations going
 	 * over a single page.
 	 */
-	dev->ctrl.max_hw_sectors = NVME_MAX_KB_SZ << 1;
+	dev->ctrl.max_hw_sectors = min_t(u32,
+		NVME_MAX_KB_SZ << 1, dma_max_mapping_size(dev->dev) >> 9);
 	dev->ctrl.max_segments = NVME_MAX_SEGS;
 
 	/*
Signature · 1 line
2.20.1
maintainer
#1 lore raw

PATCH 1/1 nvme-pci: limit max_hw_sectors based on the DMA max mapping size

Reviewed-by Sagi Grimberg <sagi at grimberg.me>