[PATCH 2/2] iommu/dma: Skip iova_to_phys() on unmap when unneeded
From: Joe Damato
Date: Fri Nov 06 2026 - 12:58:28 EST
iommu_dma_unmap_phys() looks up the physical address of every mapping
with iommu_iova_to_phys() before unmapping it.
This is unneeded for a coherent device that does not use a swiotlb.
Skipping this saves a page table walk.
iommu_dma_sync_single_for_cpu() already skips the walk for these
devices, so do the same in iommu_dma_unmap_phys().
Signed-off-by: Joe Damato <joe@xxxxxxx>
---
drivers/iommu/dma-iommu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index a25ee287a5ac..c4a5fac4f7cb 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1260,9 +1260,11 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
void iommu_dma_unmap_phys(struct device *dev, dma_addr_t dma_handle,
size_t size, enum dma_data_direction dir, unsigned long attrs)
{
+ unsigned long skip_phys;
phys_addr_t phys;
- if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) {
+ skip_phys = attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT);
+ if (skip_phys || dev_is_coherent_no_swiotlb(dev, size, dir)) {
__iommu_dma_unmap(dev, dma_handle, size);
return;
}
--
2.53.0-Meta