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 3/6] acpi-build: i386/pc: Track vIOMMUs in a list
Date: Mon, 30 Nov 2026 15:42:34 +0530 [thread overview]
Message-ID: <20261130101237.1416-4-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 needs multiple vIOMMUs.
Replace the single pcms->iommu pointer with a list of vIOMMUs in
creation order, so that the following patches can iterate over it to
build the IVRS IVHD entries per IOMMU. Replace the
x86_iommu_get_default() with the first IOMMU in the list to create ACPI
tables.
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
---
hw/i386/acpi-build.c | 13 +++++++++----
hw/i386/pc.c | 31 +++++++++++++++++++++++--------
hw/i386/x86-iommu-stub.c | 5 -----
hw/i386/x86-iommu.c | 13 -------------
include/hw/i386/pc.h | 9 ++++++++-
include/hw/i386/x86-iommu.h | 7 +------
6 files changed, 41 insertions(+), 37 deletions(-)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a2a04de15ba1..0aa31af8de5f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1650,7 +1650,8 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,
/* Root complex IOAPIC uses one path only */
const size_t ioapic_scope_size = 6 /* device scope structure */ +
2 /* 1 path entry */;
- X86IOMMUState *iommu = x86_iommu_get_default();
+ PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+ X86IOMMUState *iommu = X86_IOMMU_DEVICE(QTAILQ_FIRST(&pcms->iommus)->dev);
IntelIOMMUState *intel_iommu = INTEL_IOMMU_DEVICE(iommu);
GArray *scope_blob = g_array_new(false, true, 1);
@@ -1883,9 +1884,11 @@ static void
build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
const char *oem_table_id)
{
- AMDVIState *s = AMD_IOMMU_DEVICE(x86_iommu_get_default());
+ PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+ PCIOMMUEntry *first = QTAILQ_FIRST(&pcms->iommus);
+ X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(first->dev);
+ AMDVIState *s = AMD_IOMMU_DEVICE(x86_iommu);
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 };
@@ -2050,7 +2053,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
{
PCMachineState *pcms = PC_MACHINE(machine);
X86MachineState *x86ms = X86_MACHINE(machine);
- DeviceState *iommu = pcms->iommu;
+ PCIOMMUEntry *iommu_entry = QTAILQ_FIRST(&pcms->iommus);
+ DeviceState *iommu = iommu_entry ? iommu_entry->dev : NULL;
GArray *table_offsets;
unsigned facs, dsdt, rsdt;
AcpiPmInfo pm;
@@ -2177,6 +2181,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
build_mcfg(tables_blob, tables->linker, &mcfg, x86ms->oem_id,
x86ms->oem_table_id);
}
+ /* All vIOMMUs have the same type, so the first one selects the table */
if (object_dynamic_cast(OBJECT(iommu), TYPE_AMD_IOMMU_DEVICE)) {
acpi_add_table(table_offsets, tables_blob);
build_amd_iommu(tables_blob, tables->linker, x86ms->oem_id,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f36fd02e9823..1b1101af0c79 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1318,6 +1318,27 @@ static void pc_sp_mem_plug(const HotplugHandler *hotplug_dev,
e820_add_entry(addr, size, E820_SOFT_RESERVED);
}
+static void pc_iommu_pre_plug(PCMachineState *pcms, DeviceState *dev,
+ Error **errp)
+{
+ PCIOMMUEntry *entry;
+
+ if (!QTAILQ_EMPTY(&pcms->iommus)) {
+ error_setg(errp, "QEMU does not support multiple vIOMMUs "
+ "for x86 yet.");
+ return;
+ }
+
+ if (object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) {
+ X86_IOMMU_DEVICE(dev)->index = pcms->nr_iommus;
+ }
+
+ entry = g_new0(PCIOMMUEntry, 1);
+ entry->dev = dev;
+ QTAILQ_INSERT_TAIL(&pcms->iommus, entry, next);
+ pcms->nr_iommus++;
+}
+
static void pc_machine_device_pre_plug_cb(const HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
@@ -1343,14 +1364,7 @@ static void pc_machine_device_pre_plug_cb(const HotplugHandler *hotplug_dev,
if (object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE) ||
object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
- PCMachineState *pcms = PC_MACHINE(hotplug_dev);
-
- if (pcms->iommu) {
- error_setg(errp, "QEMU does not support multiple vIOMMUs "
- "for x86 yet.");
- return;
- }
- pcms->iommu = dev;
+ pc_iommu_pre_plug(PC_MACHINE(hotplug_dev), dev, errp);
} else if (object_dynamic_cast(OBJECT(dev), TYPE_HV_BALLOON)) {
pc_hv_balloon_pre_plug(hotplug_dev, dev, errp);
}
@@ -1621,6 +1635,7 @@ static void pc_machine_initfn(Object *obj)
pcms->vmport = ON_OFF_AUTO_OFF;
#endif /* CONFIG_VMPORT */
pcms->max_ram_below_4g = 0; /* use default */
+ QTAILQ_INIT(&pcms->iommus);
pcms->smbios_entry_point_type = pcmc->default_smbios_ep_type;
pcms->south_bridge = pcmc->default_south_bridge;
diff --git a/hw/i386/x86-iommu-stub.c b/hw/i386/x86-iommu-stub.c
index b0383d2290b1..c32d8266bdf6 100644
--- a/hw/i386/x86-iommu-stub.c
+++ b/hw/i386/x86-iommu-stub.c
@@ -27,11 +27,6 @@ void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
{
}
-X86IOMMUState *x86_iommu_get_default(void)
-{
- return NULL;
-}
-
X86IOMMUState *x86_iommu_device_get(PCIDevice *dev)
{
return NULL;
diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c
index 601db5cfea09..160bdf9df93a 100644
--- a/hw/i386/x86-iommu.c
+++ b/hw/i386/x86-iommu.c
@@ -78,19 +78,6 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMessage *msg_out)
msg_out->data = msg.msi_data;
}
-X86IOMMUState *x86_iommu_get_default(void)
-{
- MachineState *ms = MACHINE(qdev_get_machine());
- PCMachineState *pcms =
- PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));
-
- if (pcms &&
- object_dynamic_cast(OBJECT(pcms->iommu), TYPE_X86_IOMMU_DEVICE)) {
- return X86_IOMMU_DEVICE(pcms->iommu);
- }
- return NULL;
-}
-
X86IOMMUState *x86_iommu_device_get(PCIDevice *dev)
{
PCIBus *iommu_bus;
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 844ae835784f..278a28e56d5a 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -16,6 +16,11 @@
#define MAX_IDE_BUS 2
+typedef struct PCIOMMUEntry {
+ DeviceState *dev;
+ QTAILQ_ENTRY(PCIOMMUEntry) next;
+} PCIOMMUEntry;
+
/**
* PCMachineState:
* @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
@@ -35,7 +40,9 @@ typedef struct PCMachineState {
I2CBus *smbus;
PFlashCFI01 *flash[2];
ISADevice *pcspk;
- DeviceState *iommu;
+ /* vIOMMUs in creation order; all of them have the same type */
+ QTAILQ_HEAD(, PCIOMMUEntry) iommus;
+ unsigned int nr_iommus;
BusState *idebus[MAX_IDE_BUS];
Object *alias_pcspk;
diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h
index 32cae9facfcd..05feff5c925c 100644
--- a/include/hw/i386/x86-iommu.h
+++ b/include/hw/i386/x86-iommu.h
@@ -66,6 +66,7 @@ struct X86IOMMUState {
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*/
+ unsigned int index; /* Instance number, set by the machine */
};
bool x86_iommu_ir_supported(X86IOMMUState *s);
@@ -129,12 +130,6 @@ struct X86IOMMU_MSIMessage {
};
};
-/**
- * x86_iommu_get_default - get default IOMMU device
- * @return: pointer to default IOMMU device
- */
-X86IOMMUState *x86_iommu_get_default(void);
-
/**
* x86_iommu_device_get - get IOMMU device for given PCI device
* @return: pointer to default IOMMU device
--
2.34.1
next prev parent reply other threads:[~2026-11-30 10:17 UTC|newest]
Thread overview: 13+ 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-12-01 7:32 ` Clément MATHIEU--DRIF
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 ` Sairaj Kodilkar [this message]
2026-12-01 7:32 ` [PATCH 3/6] acpi-build: i386/pc: Track vIOMMUs in a list Clément MATHIEU--DRIF
2026-12-01 9:01 ` 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
2026-12-01 7:32 ` Clément MATHIEU--DRIF
2026-12-01 9:03 ` Sairaj Kodilkar
2026-12-01 17:02 ` Clément MATHIEU--DRIF
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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.