[PATCH 6/8] dma-mapping: fail early if physical address is mapped through platform callback
Leon Romanovsky
leon at kernel.org
Sun Jul 27 16:30:28 AEST 2025
On Fri, Jul 25, 2025 at 09:04:50PM +0100, Robin Murphy wrote:
> On 2025-06-25 2:19 pm, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro at nvidia.com>
> >
> > All platforms which implement map_page interface don't support physical
> > addresses without real struct page. Add condition to check it.
>
> As-is, the condition also needs to cover iommu-dma, because that also still
> doesn't support non-page-backed addresses. You can't just do a simple
> s/page/phys/ rename and hope it's OK because you happen to get away with it
> for coherent, 64-bit, trusted devices.
It needs to be follow up patch. Is this what you envision?
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index e1586eb52ab34..31214fde88124 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -167,6 +167,12 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
arch_dma_map_phys_direct(dev, phys + size))
addr = dma_direct_map_phys(dev, phys, size, dir, attrs);
else if (use_dma_iommu(dev))
+ if (IS_ENABLED(CONFIG_DMA_API_DEBUG) &&
+ !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
+ is_pfn_valid = pfn_valid(PHYS_PFN(phys));
+
+ if (unlikely(!is_pfn_valid))
+ return DMA_MAPPING_ERROR;
addr = iommu_dma_map_phys(dev, phys, size, dir, attrs);
else {
struct page *page = phys_to_page(phys);
~
~
~
Thanks
More information about the Linuxppc-dev
mailing list