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 1/6] hw/i386: Track the IOMMU to which IOAPIC is attached
Date: Mon, 30 Nov 2026 15:42:32 +0530 [thread overview]
Message-ID: <20261130101237.1416-2-sarunkod@amd.com> (raw)
In-Reply-To: <20261130101237.1416-1-sarunkod@amd.com>
Hardware accelerated vIOMMU on AMD requires one vIOMMU per host IOMMU
that backs assigned devices, so a guest can have multiple AMD vIOMMUs.
The IOAPIC sits outside the PCI hierarchy, so its IOMMU cannot be
looked up from a PCI bus. With multiple vIOMMUs, x86_iommu_get_default()
no longer identifies it, yet KVM MSI route fixup, IVRS construction and
the IEC notifier registration all need the IOMMU that remaps IOAPIC
interrupts.
Record it in the x86 machine state when the IOMMU is realized.
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
---
hw/i386/acpi-build.c | 4 +++-
hw/i386/amd_iommu.c | 4 +++-
hw/i386/intel_iommu.c | 1 +
hw/i386/pc.c | 1 +
hw/intc/ioapic.c | 18 +++++++++---------
include/hw/i386/x86.h | 4 ++++
target/i386/kvm/kvm.c | 4 ++--
7 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 84a8b14d83a6..a2a04de15ba1 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1885,6 +1885,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
{
AMDVIState *s = AMD_IOMMU_DEVICE(x86_iommu_get_default());
GArray *ivhd_blob = g_array_new(false, true, 1);
+ X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
+ X86MachineState *x86ms = X86_MACHINE(qdev_get_machine());
AcpiTable table = { .sig = "IVRS", .rev = 1, .oem_id = oem_id,
.oem_table_id = oem_table_id };
uint16_t iommu_devid = pci_get_bdf(&s->pci->dev);
@@ -1930,7 +1932,7 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
* Linux IOMMU driver checks for the special IVHD device (type IO-APIC).
* See Linux kernel commit 'c2ff5cf5294bcbd7fa50f7d860e90a66db7e5059'
*/
- if (x86_iommu_ir_supported(x86_iommu_get_default())) {
+ if (x86ms->ioapic_iommu == x86_iommu) {
build_append_int_noprefix(ivhd_blob,
(0x1ull << 56) | /* type IOAPIC */
(IOAPIC_SB_DEVID << 40) | /* IOAPIC devid */
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index be4b9b28ef60..031ecbdb3de5 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -2732,6 +2732,7 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)
MachineState *ms = MACHINE(qdev_get_machine());
PCMachineState *pcms = PC_MACHINE(ms);
X86MachineState *x86ms = X86_MACHINE(ms);
+ X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
PCIBus *iommu_bus;
if (s->pci_id) {
@@ -2796,9 +2797,10 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)
* AMD IOMMU IVRS, hence create a ioapic_as with root bus even though AMD
* IOMMU is not serving devices attached to root bus.
*/
- if (x86_iommu_ir_supported(X86_IOMMU_DEVICE(s))) {
+ if (!x86ms->ioapic_iommu && x86_iommu_ir_supported(X86_IOMMU_DEVICE(s))) {
x86ms->ioapic_as = amdvi_host_dma_iommu(pcms->pcibus, s,
AMDVI_IOAPIC_SB_DEVID);
+ x86ms->ioapic_iommu = x86_iommu;
}
if (kvm_enabled() && x86ms->apic_id_limit > 255 && !s->xtsup) {
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 01befad9a55b..5c1afeaa3940 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -5704,6 +5704,7 @@ static void vtd_realize(DeviceState *dev, Error **errp)
pci_setup_iommu(bus, &vtd_iommu_ops, dev);
/* Pseudo address space under root PCI bus. */
x86ms->ioapic_as = vtd_host_dma_iommu(bus, s, Q35_PSEUDO_DEVFN_IOAPIC);
+ x86ms->ioapic_iommu = X86_IOMMU_DEVICE(dev);
}
static void vtd_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4737eb471c14..f36fd02e9823 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -920,6 +920,7 @@ void pc_memory_init(PCMachineState *pcms,
/* Init default IOAPIC address space */
x86ms->ioapic_as = &address_space_memory;
+ x86ms->ioapic_iommu = NULL;
/* Init ACPI memory hotplug IO base address */
pcms->memhp_io_base = ACPI_MEMORY_HOTPLUG_BASE;
diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
index e171cf843247..2f0b4b3dcce4 100644
--- a/hw/intc/ioapic.c
+++ b/hw/intc/ioapic.c
@@ -439,15 +439,15 @@ static void ioapic_machine_done_notify(Notifier *notifier, void *data)
IOAPICCommonState *s = container_of(notifier, IOAPICCommonState,
machine_done);
X86MachineState *x86ms = X86_MACHINE(qdev_get_machine());
-
- if (accel_irqchip_is_split() && x86ms->ioapic_as != &address_space_memory) {
- X86IOMMUState *iommu = x86_iommu_get_default();
- if (iommu) {
- /* Register this IOAPIC with IOMMU IEC notifier, so that
- * when there are IR invalidates, we can be notified to
- * update kernel IR cache. */
- x86_iommu_iec_register_notifier(iommu, ioapic_iec_notifier, s);
- }
+ X86IOMMUState *iommu = x86ms->ioapic_iommu;
+
+ if (accel_irqchip_is_split() && iommu) {
+ /*
+ * Register this IOAPIC with IOMMU IEC notifier, so that
+ * when there are IR invalidates, we can be notified to
+ * update kernel IR cache.
+ */
+ x86_iommu_iec_register_notifier(iommu, ioapic_iec_notifier, s);
}
#endif
}
diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
index abb073ca47d3..43da8ced1933 100644
--- a/include/hw/i386/x86.h
+++ b/include/hw/i386/x86.h
@@ -26,6 +26,7 @@
#include "hw/isa/isa.h"
#include "qom/object.h"
#include "system/igvm-cfg.h"
+#include "hw/i386/x86-iommu.h"
struct X86MachineClass {
MachineClass parent;
@@ -85,6 +86,9 @@ struct X86MachineState {
*/
AddressSpace *ioapic_as;
+ /* IOMMU used by IOAPIC */
+ X86IOMMUState *ioapic_iommu;
+
/*
* Ratelimit enforced on detected bus locks in guest.
* The default value of the bus_lock_ratelimit is 0 per second,
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 76528f1123f4..9bedf1fe680b 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -6771,8 +6771,8 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
if (dev) {
iommu = x86_iommu_device_get(dev);
- } else if (x86ms->ioapic_as != &address_space_memory) {
- iommu = x86_iommu_get_default();
+ } else if (x86ms->ioapic_iommu) {
+ iommu = x86ms->ioapic_iommu;
}
if (iommu) {
--
2.34.1
next prev 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 ` Sairaj Kodilkar [this message]
2026-11-30 10:12 ` [PATCH 2/6] i386/kvm: x86_iommu: Introduce per-iommu notify_list_inited flag Sairaj Kodilkar
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-2-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