The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] dma-mapping: remove bogus test for pfn_valid from dma_map_resource
@ 2026-05-07  3:21 Jianpeng Chang
  2026-05-07 13:18 ` Robin Murphy
  0 siblings, 1 reply; 10+ messages in thread
From: Jianpeng Chang @ 2026-05-07  3:21 UTC (permalink / raw)
  To: m.szyprowski
  Cc: robin.murphy, leon, kbusch, jgg, iommu, linux-kernel, stable,
	Jianpeng Chang

dma_map_resource() uses pfn_valid() to ensure the range is not RAM.
However, pfn_valid() only checks for availability of the memory map for a
PFN but it does not ensure that the PFN is actually backed by RAM. On
ARM64 with SPARSEMEM (128MB section granularity), MMIO addresses that
share a section with RAM will falsely trigger the WARN_ON_ONCE.

This causes a WARNING on Raspberry Pi 4 during spi_bcm2835 probe because
the SPI FIFO register (0xfe204004) falls in the same sparsemem section as
the end of RAM (0xf8000000-0xfbffffff), both in section 31
(0xf8000000-0xffffffff).

The pfn_valid() check was originally removed by commit a9c38c5d267c
("dma-mapping: remove bogus test for pfn_valid from dma_map_resource")
but was accidentally re-introduced by commit f7326196a781
("dma-mapping: export new dma_*map_phys() interface") during the
refactoring of dma_map_resource() into a wrapper around dma_map_phys().

Drop the pfn_valid() test from dma_map_resource() again.

Fixes: f7326196a781 ("dma-mapping: export new dma_*map_phys() interface")
Signed-off-by: Jianpeng Chang <jianpeng.chang.cn@windriver.com>
---
Hi,

I found the WARNING in dma_map_resource() on Raspberry Pi 4 when using the
downstream kernel from https://github.com/raspberrypi/linux, which calls
dma_map_resource() in bcm2835-dma.c (mainline uses the physical address
directly instead).

Although mainline bcm2835-dma does not call dma_map_resource(), the bogus
pfn_valid() check can still affect any other driver that does, so it
should be removed again.

Thanks,
Jianpeng

 kernel/dma/mapping.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 23ed8eb9233e..e6b07f160d20 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -365,10 +365,6 @@ EXPORT_SYMBOL(dma_unmap_sg_attrs);
 dma_addr_t dma_map_resource(struct device *dev, phys_addr_t phys_addr,
 		size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
-	if (IS_ENABLED(CONFIG_DMA_API_DEBUG) &&
-	    WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr))))
-		return DMA_MAPPING_ERROR;
-
 	return dma_map_phys(dev, phys_addr, size, dir, attrs | DMA_ATTR_MMIO);
 }
 EXPORT_SYMBOL(dma_map_resource);
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-05-08 19:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07  3:21 [PATCH] dma-mapping: remove bogus test for pfn_valid from dma_map_resource Jianpeng Chang
2026-05-07 13:18 ` Robin Murphy
2026-05-08 10:01   ` Jianpeng Chang
2026-05-08 11:01     ` Robin Murphy
2026-05-08 11:31     ` Jason Gunthorpe
2026-05-08 12:16       ` Robin Murphy
2026-05-08 15:18         ` Jason Gunthorpe
2026-05-08 16:04           ` Robin Murphy
2026-05-08 17:36             ` Jason Gunthorpe
2026-05-08 19:11               ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox