[PATCH 1/2] iommu/amd: Skip device lookup when IRT caching is disabled
From: Guanghui Feng
Date: Fri Nov 13 2026 - 08:41:15 EST
The DMA alias invalidation path looks up the device before checking
irtcachedis_enabled. The lookup walks the PCI segment's device list,
but its result is unused when IRT caching is disabled.
Nested VM entry and exit can switch multiple interrupt routes between
guest and remapping modes, repeating this lookup for each IRTE update.
A reported nested virtualization workload scans 4334 device entries per
lookup, with median lookup latencies of 22-33 us despite IRT caching
being disabled.
Move the lookup after the early return. This removes the unnecessary
list walk without changing alias invalidation or completion handling
when IRT caching is enabled.
Fixes: 5aac28784dca ("iommu/amd: Invalidate IRT cache for DMA aliases")
Reported-by: Yifei Ge <geyifei@xxxxxxxxxxxxxxxxx>
Co-developed-by: hr567 <hr567@xxxxxxxxxxxxxxxxx>
Signed-off-by: hr567 <hr567@xxxxxxxxxxxxxxxxx>
Signed-off-by: Guanghui Feng <guanghuifeng@xxxxxxxxxxxxxxxxx>
---
drivers/iommu/amd/iommu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 0413dfc5cae5..8f5a38ae2e29 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3298,11 +3298,12 @@ static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid)
unsigned long flags;
struct iommu_cmd cmd;
struct pci_dev *pdev = NULL;
- struct iommu_dev_data *dev_data = search_dev_data(iommu, devid);
+ struct iommu_dev_data *dev_data;
if (iommu->irtcachedis_enabled)
return;
+ dev_data = search_dev_data(iommu, devid);
if (dev_data && dev_data->dev && dev_is_pci(dev_data->dev))
pdev = to_pci_dev(dev_data->dev);
--
2.43.7