* [PATCH 0/2] iommu/dma: Skip iova_to_phys() on unmap for coherent devices
@ 2026-11-06 17:57 Joe Damato
2026-11-06 17:57 ` [PATCH 1/2] iommu/dma: Add helper for coherent devs without swiotlb Joe Damato
2026-11-06 17:57 ` [PATCH 2/2] iommu/dma: Skip iova_to_phys() on unmap when unneeded Joe Damato
0 siblings, 2 replies; 3+ messages in thread
From: Joe Damato @ 2026-11-06 17:57 UTC (permalink / raw)
Cc: Joe Damato, iommu, Joerg Roedel (AMD),
linux-kernel, Robin Murphy, Will Deacon
Greetings:
iommu_dma_unmap_phys() calls iommu_iova_to_phys() on every unmap, which
walks the IOMMU page table. The physical address it returns is only used
for devices that are non-coherent or use a swiotlb.
For a coherent device that does not use swiotlb, the lookup is not
needed. iommu_dma_sync_single_for_cpu() and
iommu_dma_sync_single_for_device() already skip it for these devices, as
does __iommu_dma_iova_unlink() for the dma_iova_link() API.
Patch 1 factors the check out into a helper. Patch 2 uses the helper to
skip the lookup in iommu_dma_unmap_phys().
I split this into two patches because I thought it would make review and
bisect easier, but I can make them a single patch if needed.
One behavior change: for these devices the WARN_ON(!phys) in
iommu_dma_unmap_phys() is no longer reached, so unmapping an IOVA that
is not mapped no longer warns there. CONFIG_DMA_API_DEBUG still catches
this class of driver bug.
I tested on prod hosts serving TX heavy network traffic, which unmaps TX
buffers on completion.
Intel Xeon Gold 6138 (Skylake), VT-d:
- iova_to_phys() on unmap: 119-143 ns per TX packet (~0.5% of busy
CPU) before, 0 after
AMD EPYC 9334 (Genoa), AMD IOMMU:
- iova_to_phys() on unmap: ~10 ns per TX packet (~0.1% of busy CPU)
before, 0 after
So, the performance improvement is small, but measureable. The proposed
change removes redundant work in the unmap, though, making it match the map
path.
Thanks,
Joe
Joe Damato (2):
iommu/dma: Add helper for coherent devs without swiotlb
iommu/dma: Skip iova_to_phys() on unmap when unneeded
drivers/iommu/dma-iommu.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
base-commit: f66469d9905b39d2c260a15d7d6db450f4db67c1
--
2.53.0-Meta
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] iommu/dma: Add helper for coherent devs without swiotlb
2026-11-06 17:57 [PATCH 0/2] iommu/dma: Skip iova_to_phys() on unmap for coherent devices Joe Damato
@ 2026-11-06 17:57 ` Joe Damato
2026-11-06 17:57 ` [PATCH 2/2] iommu/dma: Skip iova_to_phys() on unmap when unneeded Joe Damato
1 sibling, 0 replies; 3+ messages in thread
From: Joe Damato @ 2026-11-06 17:57 UTC (permalink / raw)
To: Robin Murphy, Joerg Roedel (AMD), Will Deacon
Cc: Joe Damato, iommu, linux-kernel
Factor out some repeated logic which checks if a device is coherent and
if there is a swiotlb.
Replace repeated instances of this logic with a call to the helper
instead.
Signed-off-by: Joe Damato <joe@dama.to>
---
drivers/iommu/dma-iommu.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 78742aeba932..a25ee287a5ac 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -628,6 +628,12 @@ static bool dev_use_sg_swiotlb(struct device *dev, struct scatterlist *sg,
return false;
}
+static bool dev_is_coherent_no_swiotlb(struct device *dev, size_t size,
+ enum dma_data_direction dir)
+{
+ return dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir);
+}
+
/**
* iommu_dma_init_options - Initialize dma-iommu options
* @options: The options to be initialized
@@ -1103,7 +1109,7 @@ void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
{
phys_addr_t phys;
- if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir))
+ if (dev_is_coherent_no_swiotlb(dev, size, dir))
return;
phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
@@ -1120,7 +1126,7 @@ void iommu_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
{
phys_addr_t phys;
- if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir))
+ if (dev_is_coherent_no_swiotlb(dev, size, dir))
return;
phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
--
2.53.0-Meta
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] iommu/dma: Skip iova_to_phys() on unmap when unneeded
2026-11-06 17:57 [PATCH 0/2] iommu/dma: Skip iova_to_phys() on unmap for coherent devices Joe Damato
2026-11-06 17:57 ` [PATCH 1/2] iommu/dma: Add helper for coherent devs without swiotlb Joe Damato
@ 2026-11-06 17:57 ` Joe Damato
1 sibling, 0 replies; 3+ messages in thread
From: Joe Damato @ 2026-11-06 17:57 UTC (permalink / raw)
To: Robin Murphy, Joerg Roedel (AMD), Will Deacon
Cc: Joe Damato, iommu, linux-kernel
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@dama.to>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-06 17:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 17:57 [PATCH 0/2] iommu/dma: Skip iova_to_phys() on unmap for coherent devices Joe Damato
2026-11-06 17:57 ` [PATCH 1/2] iommu/dma: Add helper for coherent devs without swiotlb Joe Damato
2026-11-06 17:57 ` [PATCH 2/2] iommu/dma: Skip iova_to_phys() on unmap when unneeded Joe Damato
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®