Commit f10336b449 for qemu.org

commit f10336b449a14312fd4b35a278f91bcfe2ec2897
Author: Sairaj Kodilkar <sarunkod@amd.com>
Date:   Wed Oct 14 11:04:26 2026 +0530

    amd_iommu: Assign ioapic_as only when interrupt remapping is supported.

    When interrupt remapping is disabled (intremap=off), the IOAPIC should
    use the system address space instead of the IOMMU address space.
    Currently, the IOAPIC is unconditionally assigned to the IOMMU address
    space, which causes IOAPIC-triggered interrupts to be incorrectly
    translated by the IOMMU even when interrupt remapping is disabled.

    Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    Message-ID: <20261014053433.24564-2-sarunkod@amd.com>

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 56e7815412..817320c51c 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -2733,8 +2733,16 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion_overlap(&s->mr_sys, AMDVI_INT_ADDR_FIRST,
                                         &s->mr_ir, 1);

-    /* Pseudo address space under root PCI bus. */
-    x86ms->ioapic_as = amdvi_host_dma_iommu(bus, s, AMDVI_IOAPIC_SB_DEVID);
+    /**
+     * Pseudo address space under root PCI bus.
+     * The linux kernel disables the intremap when it cannot find IOAPIC under
+     * 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))) {
+        x86ms->ioapic_as = amdvi_host_dma_iommu(pcms->pcibus, s,
+                                                AMDVI_IOAPIC_SB_DEVID);
+    }

     if (kvm_enabled() && x86ms->apic_id_limit > 255 && !s->xtsup) {
         error_report("AMD IOMMU with x2APIC configuration requires xtsup=on");