]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nvme-pci: limit max_hw_sectors based on the DMA max mapping size
authorChristoph Hellwig <hch@lst.de>
Wed, 3 Jul 2019 16:54:44 +0000 (09:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jul 2019 05:24:51 +0000 (07:24 +0200)
[ Upstream commit 7637de311bd2124b298a072852448b940d8a34b9 ]

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@lst.de>
Reported-by: Atish Patra <Atish.Patra@wdc.com>
Tested-by: Atish Patra <Atish.Patra@wdc.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/pci.c

index 245b6e2151c1bca4c3f4e5d0247ec76bb1e1c530..7fbcd72c438f6a1aa967c9f3fecd9ba10cb02fd2 100644 (file)
@@ -2521,7 +2521,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;
 
        /*