Re: [PATCH 0/2] iommu/amd: Optimize IRT cache invalidation for nested VM workloads

From: guanghuifeng@xxxxxxxxxxxxxxxxx

Date: Tue Dec 01 2026 - 21:31:27 EST


Hi Sairaj

Thanks a lot for running the tests and for the Tested-by.

Your numbers actually point at an important detail: the flush path
taking 172546 ns *including the COMPLETION_WAIT* means IRT caching
was ENABLED in this run (amd_iommu=irtcachedis not set). In that
configuration iommu_flush_irt_and_complete() still issues
INVALIDATE_INTERRUPT_TABLE + COMPLETION_WAIT, so the lookup is indeed
a tiny fraction -- and this patch deliberately keeps that behaviour
byte-for-byte identical, it only drops the redundant list walk.

The primary target of this patch is the *cache-disabled*
configuration (amd_iommu=irtcachedis). There, the function returns
early:

if (iommu->irtcachedis_enabled)
return;

so no command and no COMPLETION_WAIT are issued at all, and the
search_dev_data() walk becomes the *only* remaining cost of the
whole function. On the reported system the dev_data list has grown
to 4334 entries, making that walk 22-33 us of pure waste on every
nested VMRUN/#VMEXIT that toggles AVIC. This patch removes 100% of
it, not 0.2%.

So both measurements are correct and consistent -- they are two
points on the same O(N) curve:

- your setup: short list (~tens of entries) -> 373 ns
- reported setup: 4334 entries -> 22-33 us

The list is append-only (alloc_dev_data() only does llist_add(),
there is no llist_del()/kfree() in the driver, and dev_data is kept
across unplug on purpose), so its length grows monotonically with
SR-IOV VF churn and hotplug.

There is also a second win that applies to *your* configuration as
well: v2 removes the search_dev_data() call in
amd_ir_set_vcpu_affinity() too. That path is a use_vapic capability
check, not an invalidation, so it is unaffected by irtcachedis and
saves one O(N) walk on every AVIC vCPU affinity update regardless of
the cache setting.

Thanks again for the hardware validation -- it is much appreciated.

Best regards,
Guanghui Feng


在 2026/11/25 13:34, Sairaj Kodilkar 写道:
On 11/13/2026 3:20 PM, Guanghui Feng wrote:
This series optimizes the AMD IOMMU interrupt remapping table (IRT)
cache invalidation path for nested virtualization workloads.

When IOMMU AVIC is enabled, every nested VM entry/exit that switches
interrupt routes between guest and remapping modes calls into
iommu_flush_irt_and_complete(). A reported workload with 4334 device
entries shows median lookup latencies of 22-33 us per invocation due
to a linear search_dev_data() walk, even when IRT caching is disabled
and the lookup result is unused.

Patch 1 moves the device lookup after the irtcachedis_enabled early
return, eliminating the unnecessary walk when IRT caching is off.

Patch 2 caches the device data pointer (resolved at IRQ allocation
time) in struct amd_ir_data and threads it through all IRTE update
paths: guest-mode toggle, affinity change, IRQ enable/disable, and
IRTE free. The amd_irte_ops interface is extended to carry the
pointer, eliminating all search_dev_data() calls at runtime.

Both patches preserve DMA-alias invalidation, command ordering,
locking, and completion-wait semantics when IRT caching is enabled.

Guanghui Feng (2):
iommu/amd: Skip device lookup when IRT caching is disabled
iommu/amd: Reuse device data for IRTE cache invalidation

drivers/iommu/amd/amd_iommu_types.h | 10 ++--
drivers/iommu/amd/iommu.c | 73 ++++++++++++++++-------------
2 files changed, 48 insertions(+), 35 deletions(-)


Hi Guanghui,

Thanks for the patches. I ran a few tests to measure their impact.

Setup: 12 VMs, each with 32 vCPUs and one passthrough NVMe device. Each
VM runs a small nested (L2) guest that executes CPUID in a loop, which
toggles AVIC for every nested VMRUN/#VMEXIT.

At a 1:1 pCPU:vCPU ratio, averaged across the 12 VMs:

search_dev_data() lookup: 373.4 ns
iommu_flush_irt_and_complete(): 172546.1 ns (including the
COMPLETION_WAIT)

So the lookup is about 0.2% of the flush path. The completion wait is
the main bottleneck here, and the overall gain from this change is
minimal for this path.

The change is still valid, though. It removes a linear walk of the
dev_data list and the may help other places in the driver that call
search_dev_data().

Tested-by: Sairaj Kodilkar <sarunkod@xxxxxxx>

Thanks,
Sairaj