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/8] x86-iommu: Introduce x86_iommu_device_get() for x86-iommu retrieval
Date: Wed, 14 Oct 2026 11:04:27 +0530 [thread overview]
Message-ID: <20261014053433.24564-3-sarunkod@amd.com> (raw)
In-Reply-To: <20261014053433.24564-1-sarunkod@amd.com>
kvm_arch_fixup_msi_route() and kvm_arch_add_msi_route_post() use
x86_iommu_get_default() whenever an IOMMU is present. This selects the
correct unit only when a single IOMMU is attached to the system bus.
The following patches allow an IOMMU to attach to a different bus and
isolate the subset of devices below it. Each IOMMU then serves only part
of the PCI topology, so interrupt remapping must determine the IOMMU that
actually serves a given device.
Add x86_iommu_device_get() to locate the IOMMU bus for a PCI device and
retrieve its X86IOMMUState through a new get_x86_iommu callback.
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
---
hw/i386/x86-iommu-stub.c | 5 +++++
hw/i386/x86-iommu.c | 16 ++++++++++++++++
include/hw/i386/x86-iommu.h | 6 ++++++
include/hw/pci/pci.h | 12 ++++++++++++
4 files changed, 39 insertions(+)
diff --git a/hw/i386/x86-iommu-stub.c b/hw/i386/x86-iommu-stub.c
index 781b5ff92227..b0383d2290b1 100644
--- a/hw/i386/x86-iommu-stub.c
+++ b/hw/i386/x86-iommu-stub.c
@@ -32,6 +32,11 @@ X86IOMMUState *x86_iommu_get_default(void)
return NULL;
}
+X86IOMMUState *x86_iommu_device_get(PCIDevice *dev)
+{
+ return NULL;
+}
+
bool x86_iommu_ir_supported(X86IOMMUState *s)
{
return false;
diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c
index a57445404ef8..601db5cfea09 100644
--- a/hw/i386/x86-iommu.c
+++ b/hw/i386/x86-iommu.c
@@ -26,6 +26,7 @@
#include "qemu/error-report.h"
#include "trace.h"
#include "system/kvm.h"
+#include "hw/pci/pci_bus.h"
void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
iec_notify_fn fn, void *data)
@@ -90,6 +91,21 @@ X86IOMMUState *x86_iommu_get_default(void)
return NULL;
}
+X86IOMMUState *x86_iommu_device_get(PCIDevice *dev)
+{
+ PCIBus *iommu_bus;
+ X86IOMMUState *iommu = NULL;
+
+ pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL);
+
+ if (iommu_bus && iommu_bus->iommu_ops->get_x86_iommu) {
+ iommu_bus->iommu_ops->get_x86_iommu(iommu_bus->iommu_opaque,
+ (void **)&iommu);
+ }
+
+ return iommu;
+}
+
static void x86_iommu_realize(DeviceState *dev, Error **errp)
{
X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h
index 0a1e1ba72571..eb575271e9d7 100644
--- a/include/hw/i386/x86-iommu.h
+++ b/include/hw/i386/x86-iommu.h
@@ -134,6 +134,12 @@ struct X86IOMMU_MSIMessage {
*/
X86IOMMUState *x86_iommu_get_default(void);
+/**
+ * x86_iommu_device_get - get IOMMU device for given PCI device
+ * @return: pointer to default IOMMU device
+ */
+X86IOMMUState *x86_iommu_device_get(PCIDevice *dev);
+
/**
* x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
* Cache) notifiers
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index f2448e941a0b..f3c4c3a4db56 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -698,6 +698,18 @@ typedef struct PCIIOMMUOps {
* Returns: the guest physical address of the MSI doorbell.
*/
uint64_t (*get_msi_direct_gpa)(PCIBus *bus, void *opaque, int devfn);
+
+ /**
+ * @get_x86_iommu: get parent x86-iommu for given hardware (AMD/Intel)
+ *
+ * Callback is required if IOMMU defines x86->int_remap()
+ *
+ * @opaque: the data passed to pci_setup_iommu()
+ *
+ * @x86_iommu: A pointer to store the x86-iommu object
+ */
+ int (*get_x86_iommu)(void *opaque, void **x86_iommu);
+
} PCIIOMMUOps;
bool pci_device_get_iommu_bus_devfn(PCIDevice *dev, PCIBus **piommu_bus,
--
2.34.1
next prev parent reply other threads:[~2026-10-14 5:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 5:34 [PATCH 0/8] amd_iommu: Allow IOMMU to attach on non system bus Sairaj Kodilkar
2026-10-14 5:34 ` [PATCH 1/8] amd_iommu: Assign ioapic_as only when interrupt remapping is supported Sairaj Kodilkar
2026-10-14 5:34 ` Sairaj Kodilkar [this message]
2026-10-14 5:34 ` [PATCH 3/8] amd_iommu: Add support for get_x86_iommu callback Sairaj Kodilkar
2026-10-14 5:34 ` [PATCH 4/8] intel_iommu: " Sairaj Kodilkar
2026-10-14 9:57 ` Clément MATHIEU--DRIF
2026-10-14 5:34 ` [PATCH 5/8] i386/kvm: Use x86_iommu_device_get() for per-device IOMMU lookup Sairaj Kodilkar
2026-10-14 5:34 ` [PATCH 6/8] amd_iommu: Introduce root bus Sairaj Kodilkar
2026-10-14 5:34 ` [PATCH 7/8] acpi-build: Create PCI topology using amd iommu " Sairaj Kodilkar
2026-10-14 5:34 ` [PATCH 8/8] amd_iommu: Allow IOMMU to attachment on non-system (pcie.0) bus 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=20261014053433.24564-3-sarunkod@amd.com \
--to=sarunkod@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=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--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