Skip to contentSkip to conversation

nvme-pci: don't use dma_alloc_noncontiguous with 0 merge boundary

PATCH Applied Christoph Hellwig 5 participants 6 messages Dec 4, 2024 – Dec 5, 2024 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme-pci: don't use dma_alloc_noncontiguous with 0 merge boundary

Only call into nvme_alloc_host_mem_single which uses dma_alloc_noncontiguous when there is non-null dma merge boundary. Without this we'll call into dma_alloc_noncontiguous for device using dma-direct, which can work fine as long as the preferred size is below the MAX_ORDER of the page allocator, but blows up with a warning if it is too large.

Fixes 63a5c7a4b4c4 ("nvme-pci: use dma_alloc_noncontigous if possible")
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +2 -1
index 4c644bb7f069..778f124c2e21 100644
@@ -2172,6 +2172,7 @@ static int nvme_alloc_host_mem_multi(struct nvme_dev *dev, u64 preferred,
 
 static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
 {
+	unsigned long dma_merge_moundary = dma_get_merge_boundary(dev->dev);
 	u64 min_chunk = min_t(u64, preferred, PAGE_SIZE * MAX_ORDER_NR_PAGES);
 	u64 hmminds = max_t(u32, dev->ctrl.hmminds * 4096, PAGE_SIZE * 2);
 	u64 chunk_size;
@@ -2180,7 +2181,7 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
 	 * If there is an IOMMU that can merge pages, try a virtually
 	 * non-contiguous allocation for a single segment first.
 	 */
-	if (!(PAGE_SIZE & dma_get_merge_boundary(dev->dev))) {
+	if (dma_merge_moundary && (PAGE_SIZE & dma_merge_moundary) == 0) {
 		if (!nvme_alloc_host_mem_single(dev, preferred))
 			return 0;
 	}
Signature · 1 line
2.45.2
maintainer
#1 lore raw
Quoted 20 lines · Christoph Hellwig

Only call into nvme_alloc_host_mem_single which uses dma_alloc_noncontiguous when there is non-null dma merge boundary. Without this we'll call into dma_alloc_noncontiguous for device using dma-direct, which can work fine as long as the preferred size is below the MAX_ORDER of the page allocator, but blows up with a warning if it is too large.

Fixes 63a5c7a4b4c4 ("nvme-pci: use dma_alloc_noncontigous if possible")
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +0 -0
index 4c644bb7f069..778f124c2e21 100644

drivers/nvme/host/pci.c static int nvme_alloc_host_mem_multi(struct nvme_dev *dev, u64 preferred, · line 2175

Quoted 4 lines
drivers/nvme/host/pci.c +1 -0
@@ -2172,6 +2172,7 @@ static int nvme_alloc_host_mem_multi(struct nvme_dev *dev, u64 preferred,
 
 static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
 {
+	unsigned long dma_merge_moundary = dma_get_merge_boundary(dev->dev);

Fix looks fine, but s/moundary/boundary?

Signature · 1 line
Jens Axboe
author maintainer
#2 lore raw
Quoted 1 line · Jens Axboe

Fix looks fine, but s/moundary/boundary?

Yes :)

Tested-by on v1 1/1
#3 lore raw
In reply to Christoph Hellwig
Quoted 18 lines

-----Original Message-----
From: Christoph Hellwig <[email protected]>
Sent: Wednesday, December 4, 2024 6:13 AM
To: [email protected]; [email protected]
Cc: [email protected]; Leon Romanovsky <[email protected]>; Borah, Chaitanya Kumar <[email protected]>
Subject: [PATCH] nvme-pci: don't use dma_alloc_noncontiguous with 0 merge boundary

Only call into nvme_alloc_host_mem_single which uses dma_alloc_noncontiguous when there is non-null dma merge boundary. Without this we'll call into dma_alloc_noncontiguous for device using dma- direct, which can work fine as long as the preferred size is below the MAX_ORDER of the page allocator, but blows up with a warning if it is too large.

Quoted 4 lines
Fixes 63a5c7a4b4c4 ("nvme-pci: use dma_alloc_noncontigous if possible")
Quoted 33 lines
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c index renamed from drivers/nvme/host/pci.c +0 -0

4c644bb7f069..778f124c2e21 100644

drivers/nvme/host/pci.c +1 -0
@@ -2172,6 +2172,7 @@ static int nvme_alloc_host_mem_multi(struct
 nvme_dev *dev, u64 preferred,
 
 static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64
 preferred)  {
+	unsigned long dma_merge_moundary =
 dma_get_merge_boundary(dev->dev);
 	u64 min_chunk = min_t(u64, preferred, PAGE_SIZE *

MAX_ORDER_NR_PAGES);
u64 hmminds = max_t(u32, dev->ctrl.hmminds * 4096, PAGE_SIZE *
2);

drivers/nvme/host/pci.c +1 -1
 	u64 chunk_size;
@@ -2180,7 +2181,7 @@ static int nvme_alloc_host_mem(struct nvme_dev
 *dev, u64 min, u64 preferred)
 	 * If there is an IOMMU that can merge pages, try a virtually
 	 * non-contiguous allocation for a single segment first.
 	 */
-	if (!(PAGE_SIZE & dma_get_merge_boundary(dev->dev))) {
+	if (dma_merge_moundary && (PAGE_SIZE & dma_merge_moundary)
 == 0) {
 		if (!nvme_alloc_host_mem_single(dev, preferred))
drivers/nvme/host/pci.c +0 -1
 			return 0;
 	}
--

2.45.2

Reviewed-by on v1 1/1
#4 lore raw
In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

Only call into nvme_alloc_host_mem_single which uses dma_alloc_noncontiguous when there is non-null dma merge boundary. Without this we'll call into dma_alloc_noncontiguous for device using dma-direct, which can work fine as long as the preferred size is below the MAX_ORDER of the page allocator, but blows up with a warning if it is too large.

Quoted 8 lines
Fixes 63a5c7a4b4c4 ("nvme-pci: use dma_alloc_noncontigous if possible")
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Except moundary vs. boundary, everything looks good.

Thanks for the fix.

maintainer Applied
#5 lore raw
In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Only call into nvme_alloc_host_mem_single which uses dma_alloc_noncontiguous when there is non-null dma merge boundary. Without this we'll call into dma_alloc_noncontiguous for device using dma-direct, which can work fine as long as the preferred size is below the MAX_ORDER of the page allocator, but blows up with a warning if it is too large.

Thanks, applied to nvme-6.13 with the mentioned spelling fix.