Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sairaj Kodilkar <sarunkod@amd.com>
To: "Clément Mathieu--Drif" <clement.mathieu--drif@bull.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Alejandro Jimenez" <alejandro.j.jimenez@oracle.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Sairaj Kodilkar" <sarunkod@amd.com>,
	"Yi Liu" <yi.l.liu@intel.com>,
	kvm@vger.kernel.org, qemu-devel@nongnu.org
Cc: <Vasant.Hegde@amd.com>, <Suravee.Suthikulpanit@amd.com>
Subject: [PATCH 2/6] i386/kvm: x86_iommu: Introduce per-iommu notify_list_inited flag
Date: Mon, 30 Nov 2026 15:42:33 +0530	[thread overview]
Message-ID: <20261130101237.1416-3-sarunkod@amd.com> (raw)
In-Reply-To: <20261130101237.1416-1-sarunkod@amd.com>

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 <sarunkod@amd.com>
---
 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


  parent reply	other threads:[~2026-11-30 10:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:12 [PATCH 0/6] amd_iommu: Add support for multiple AMD vIOMMUs Sairaj Kodilkar
2026-11-30 10:12 ` [PATCH 1/6] hw/i386: Track the IOMMU to which IOAPIC is attached Sairaj Kodilkar
2026-11-30 10:12 ` Sairaj Kodilkar [this message]
2026-11-30 10:12 ` [PATCH 3/6] acpi-build: i386/pc: Track vIOMMUs in a list Sairaj Kodilkar
2026-11-30 10:12 ` [PATCH 4/6] amd_iommu: acpi-build: Add support for multiple AMD-IOMMUs Sairaj Kodilkar
2026-11-30 10:12 ` [PATCH 5/6] amd_iommu: Introduce AMDIVRSInfo for shared IVRS construction Sairaj Kodilkar
2026-11-30 10:12 ` [PATCH 6/6] x86-iommu: Allow multiple AMD vIOMMU devices Sairaj Kodilkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130101237.1416-3-sarunkod@amd.com \
    --to=sarunkod@amd.com \
    --cc=Suravee.Suthikulpanit@amd.com \
    --cc=Vasant.Hegde@amd.com \
    --cc=alejandro.j.jimenez@oracle.com \
    --cc=anisinha@redhat.com \
    --cc=clement.mathieu--drif@bull.com \
    --cc=imammedo@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=yi.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox