Skip to contentSkip to conversation

powerpc/pseries/iommu: Fix window size for direct mapping with pmem

PATCH Applied Leonardo Bras 3 participants 4 messages Apr 20, 2021 – Apr 21, 2021 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/pseries/iommu: Fix window size for direct mapping with pmem

As of today, if the DDW is big enough to fit (1 << MAX_PHYSMEM_BITS) it's possible to use direct DMA mapping even with pmem region.

But, if that happens, the window size (len) is set to (MAX_PHYSMEM_BITS - page_shift) instead of MAX_PHYSMEM_BITS, causing a pagesize times smaller DDW to be created, being insufficient for correct usage.

Fix this so the correct window size is used in this case.

Fixes bf6e2d562bbc4("powerpc/dma: Fallback to dma_ops when persistent memory present")
---
 arch/powerpc/platforms/pseries/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/iommu.c +1 -1
index 9fc5217f0c8e..836cbbe0ecc5 100644
@@ -1229,7 +1229,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
 	if (pmem_present) {
 		if (query.largest_available_block >=
 		    (1ULL << (MAX_PHYSMEM_BITS - page_shift)))
-			len = MAX_PHYSMEM_BITS - page_shift;
+			len = MAX_PHYSMEM_BITS;
 		else
 			dev_info(&dev->dev, "Skipping ibm,pmemory");
 	}
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Leonardo Bras

As of today, if the DDW is big enough to fit (1 << MAX_PHYSMEM_BITS) it's possible to use direct DMA mapping even with pmem region.

But, if that happens, the window size (len) is set to (MAX_PHYSMEM_BITS - page_shift) instead of MAX_PHYSMEM_BITS, causing a pagesize times smaller DDW to be created, being insufficient for correct usage.

Fix this so the correct window size is used in this case.

Good find indeed.

afaict this does not create a huge problem though as query.largest_available_block is always smaller than (MAX_PHYSMEM_BITS - page_shift) where it matters (phyp).

Quoted 20 lines
Fixes bf6e2d562bbc4("powerpc/dma: Fallback to dma_ops when persistent memory present")
---
  arch/powerpc/platforms/pseries/iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/iommu.c +1 -1
index 9fc5217f0c8e..836cbbe0ecc5 100644
@@ -1229,7 +1229,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
  	if (pmem_present) {
  		if (query.largest_available_block >=
  		    (1ULL << (MAX_PHYSMEM_BITS - page_shift)))
-			len = MAX_PHYSMEM_BITS - page_shift;
+			len = MAX_PHYSMEM_BITS;
  		else
  			dev_info(&dev->dev, "Skipping ibm,pmemory");
  	}
Signature · 1 line
Alexey
#2 lore raw
Quoted 12 lines · Alexey Kardashevskiy
Quoted 9 lines · Leonardo Bras

As of today, if the DDW is big enough to fit (1 << MAX_PHYSMEM_BITS) it's possible to use direct DMA mapping even with pmem region.

But, if that happens, the window size (len) is set to (MAX_PHYSMEM_BITS - page_shift) instead of MAX_PHYSMEM_BITS, causing a pagesize times smaller DDW to be created, being insufficient for correct usage.

Fix this so the correct window size is used in this case.

Quoted 9 lines

Good find indeed.

afaict this does not create a huge problem though as query.largest_available_block is always smaller than (MAX_PHYSMEM_BITS - page_shift) where it matters (phyp).

Thanks for reviewing!

Leonardo Bras

#3 lore raw
In reply to Leonardo Bras
Quoted 9 lines · Leonardo Bras

As of today, if the DDW is big enough to fit (1 << MAX_PHYSMEM_BITS) it's possible to use direct DMA mapping even with pmem region.

But, if that happens, the window size (len) is set to (MAX_PHYSMEM_BITS - page_shift) instead of MAX_PHYSMEM_BITS, causing a pagesize times smaller DDW to be created, being insufficient for correct usage.

[...]

Applied to powerpc/next.

[1/1] powerpc/pseries/iommu: Fix window size for direct mapping with pmem

      https://git.kernel.org/powerpc/c/a9d2f9bb225fd2a764aef57738ab6c7f38d782ae

cheers