When interrupt remapping is enabled with a split irqchip, KVM MSI routes carry the result of IOMMU interrupt remapping. Whenever the guest invalidates the interrupt remapping cache of an IOMMU, the IEC notifier kvm_update_msi_routes_all() rebuilds these routes. kvm_arch_add_msi_route_post() registers that notifier on the first MSI route update, and a static notify_list_inited flag blocks any further registration. With multiple vIOMMUs, only one IOMMU gets the notifier. Invalidations on the other IOMMUs leave KVM with stale MSI routes, so interrupts of devices behind those IOMMUs keep using the old remapping entries. Move the flag into X86IOMMUState, so the notifier is registered once on each IOMMU, when that IOMMU sees its first MSI route. Signed-off-by: Sairaj Kodilkar --- include/hw/i386/x86-iommu.h | 1 + target/i386/kvm/kvm.c | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h index eb575271e9d7..32cae9facfcd 100644 --- a/include/hw/i386/x86-iommu.h +++ b/include/hw/i386/x86-iommu.h @@ -65,6 +65,7 @@ struct X86IOMMUState { bool dt_supported; /* Whether vIOMMU supports DT */ bool dma_translation; /* Whether vIOMMU supports DMA translation */ QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ + bool notify_list_inited; /* Whether IEC notifier is initiated*/ }; bool x86_iommu_ir_supported(X86IOMMUState *s); diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 9bedf1fe680b..6714c51d406e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -6873,7 +6873,6 @@ void kvm_update_msi_routes_all(void *private, bool global, int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, int vector, PCIDevice *dev) { - static bool notify_list_inited = false; MSIRouteEntry *entry; X86IOMMUState *iommu = NULL; @@ -6892,16 +6891,14 @@ int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, trace_kvm_x86_add_msi_route(route->gsi); - if (!notify_list_inited) { + iommu = x86_iommu_device_get(dev); + if (iommu && !iommu->notify_list_inited) { /* For the first time we do add route, add ourselves into * IOMMU's IEC notify list if needed. */ - iommu = x86_iommu_device_get(dev); - if (iommu) { - x86_iommu_iec_register_notifier(iommu, - kvm_update_msi_routes_all, - NULL); - notify_list_inited = true; - } + x86_iommu_iec_register_notifier(iommu, + kvm_update_msi_routes_all, + NULL); + iommu->notify_list_inited = true; } return 0; } -- 2.34.1