Re: [PATCH v2] iommu/amd: Reuse device data for IRTE cache invalidation
From: Vasant Hegde
Date: Wed Dec 02 2026 - 04:41:43 EST
On 11/24/2026 5:45 PM, Guanghui Feng wrote:
> The DMA alias invalidation path in iommu_flush_irt_and_complete()
> performs a linear search_dev_data() walk on every IRTE update. Nested
> VM entry and exit can switch multiple interrupt routes between guest
> and remapping modes, repeating this lookup for each posted interrupt.
> A reported workload with 4334 device entries shows median lookup
> latencies of 22-33 us per invocation, even when IRT caching is
> disabled and the lookup result is unused.
>
> Save the allocation-time device data in struct amd_ir_data and thread
> it through all IRTE update paths:
>
> - iommu_flush_irt_and_complete() accepts a dev_data parameter. When
> IRT caching is disabled it returns immediately without any lookup.
> When dev_data is NULL (IOAPIC/HPET allocated before PCI enumeration)
> it falls back to search_dev_data() so DMA-alias invalidation still
> works if the device is later probed.
>
> - modify_irte_ga(), modify_irte() and free_irte() accept and forward
> dev_data.
>
> - The amd_irte_ops callbacks (activate, deactivate, set_affinity) are
> extended to carry dev_data so that amd_ir_update_irte() and the
> irq_remapping activate/deactivate domain callbacks pass the cached
> pointer.
>
> - amd_iommu_activate_guest_mode() and deactivate_guest_mode() pass
> ir_data->dev_data directly.
>
> - amd_ir_set_vcpu_affinity() reuses ir_data->dev_data for the vCPU
> affinity capability check. This path is only reachable through
> irq_bypass producers (VFIO-PCI, vhost-vDPA), where device probe
> always precedes IRQ allocation, so dev_data is guaranteed non-NULL.
>
> Device data is retained in the segment list across unplug and reused on
> reprobe, so the cached pointer remains valid throughout the IRQ
> lifetime. The PCI device is still resolved through dev_data->dev at
> flush time so that later device association is observed.
>
> DMA-alias invalidation, command ordering, locking and completion waits
> are preserved 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>
Applied. Thanks!
-Vasant