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 0/6] amd_iommu: Add support for multiple AMD vIOMMUs
Date: Mon, 30 Nov 2026 15:42:31 +0530	[thread overview]
Message-ID: <20261130101237.1416-1-sarunkod@amd.com> (raw)

Overview
--------
This series lets a guest have more than one AMD vIOMMU. Each vIOMMU takes
care of the devices under its own PCIe root bus (pcie.0 or a pxb-pcie).
It builds on the root-bus series [1], which allows an AMD vIOMMU to sit
on a root bus other than pcie.0.

Motivation
----------
With the upcoming hardware-accelerated vIOMMU, each guest vIOMMU is tied
to one host IOMMU through that host IOMMU's VFMMIO region. Because of
this, VFIO devices that sit behind different host IOMMUs cannot share a
single guest vIOMMU. If a guest gets passthrough devices from more than
one host IOMMU, it needs one vIOMMU for each of them.

Solution
--------
1. Track all vIOMMUs in a list in the PC machine, in creation order.
2. Build one IVHD per AMD vIOMMU. Its device entries are the devices under
   that vIOMMU's root bus; a child bus served by another vIOMMU is skipped,
   so IVHDs never overlap.
3. Give each vIOMMU its own 16 KiB MMIO window starting at 0xfed80000,
   indexed by creation order. At most 8 vIOMMUs are allowed, so the windows
   stay below smram-open-high at 0xfeda0000.
4. Track the IOMMU that the IOAPIC is bound to, and register the KVM IEC
   notifier on every vIOMMU instead of only the first one.
5. Allow multiple AMD vIOMMUs in pc_iommu_pre_plug(). They cannot be mixed
   with Intel or virtio IOMMUs.

Every amd-iommu in a multi-vIOMMU configuration must use 'pci-id' to name
its AMDVI-PCI device, and each must be on a different root bus.

Command-line
------------
qemu-system-x86_64 \
-enable-kvm -m 10G -smp 8  \
-netdev user,id=USER0,hostfwd=tcp::3333-:22 \
-netdev user,id=USER1 \
-cpu EPYC-Genoa,x2apic=on,kvm-msi-ext-dest-id=on,+kvm-pv-unhalt,kvm-pv-tlb-flush,kvm-pv-ipi,kvm-pv-sched-yield  \
-machine q35,kernel_irqchip=split \
-global kvm-pit.lost_tick_policy=discard \
-nographic \
-kernel <vmlinuz> \
-initrd <initrd.img> \
-blockdev node-name=drive0,driver=qcow2,file.driver=file,file.filename=<IMG> \
-device virtio-blk-pci,num-queues=8,drive=drive0 \
-device pxb-pcie,id=pcie.1,bus=pcie.0,bus_nr=0x40 \
-device pcie-root-port,id=rp1.1,bus=pcie.1,chassis=1,slot=1 \
-device pcie-root-port,id=rp1.2,bus=pcie.1,chassis=2,slot=1 \
-device AMDVI-PCI,id=iommupci0,bus=rp1.1 \
-device amd-iommu,intremap=on,dma-remap=on,intremap=off,xtsup=off,pci-id=iommupci0 \
-device virtio-net-pci,id=vnet0,iommu_platform=on,disable-legacy=on,romfile=,netdev=USER0,bus=rp1.2 \
-device pxb-pcie,id=pcie.2,bus=pcie.0,bus_nr=0x50 \
-device pcie-root-port,id=rp2.1,bus=pcie.2,chassis=3,slot=1 \
-device pcie-root-port,id=rp2.2,bus=pcie.2,chassis=4,slot=1 \
-device AMDVI-PCI,id=iommupci1,bus=rp2.1 \
-device amd-iommu,intremap=on,dma-remap=on,intremap=off,xtsup=off,pci-id=iommupci1 \
-device virtio-net-pci,id=vnet1,iommu_platform=on,disable-legacy=on,romfile=,netdev=USER1,bus=rp2.2

Examples
--------
Example1, For below PCI configuration AMD IOMMU 1 will serve all the devices
under pxb-pci1 and AMD IOMMU 2 will serve all the devices under pxb-pci2.

pcie.0 -+- pxb-pci1 -+- pcie-root-port1.1 --- AMD IOMMU 1
        |            +- pcie-root-port2.1 --- Device1
        |            \- pcie-root-port3.1 --- Device2
        \- pxb-pci2 -+- pcie-root-port2.1 --- AMD IOMMU 2
                     +- pcie-root-port2.2 --- Device3
                     \- pcie-root-port2.3 --- Device4

Example2, For below PCI configuration, AMD IOMMU 3 will only serve Device5 and
Device6 and devices under pxb-pci buses will be served by IOMMUs of respective
buses.

pcie.0 -+- pxb-pci1 -+- pcie-root-port1.1 --- AMD IOMMU 1
        |            +- pcie-root-port2.1 --- Device1
        |            \- pcie-root-port3.1 --- Device2
        +- pxb-pci2 -+- pcie-root-port2.1 --- AMD IOMMU 2
        |            +- pcie-root-port2.2 --- Device3
        |            \- pcie-root-port2.3 --- Device4
        +--- AMD IOMMU 3
        +--- Device5
        \--- Device6

Example3, The below PCI configuration is invalid since both IOMMUs share same
root bus i.e. pxb-pci1.

[A] pcie.0 -+- pxb-pci1 -+- pcie-root-port1 --- AMD IOMMU 1
                         +- pcie-root-port2 --- AMD IOMMU 2
                         +- pcie-root-port3 --- Device2
                         \- pcie-root-port4 --- Device3

[B] amd-iommu devices with and without 'pci-id' mixed.
[C] More than 8 amd-iommu devices.
[D] amd-iommu mixed with intel-iommu or virtio-iommu.

---
Patches are based on top of 9cda597a1a39 and patch [1]

[1] https://lore.kernel.org/all/20261116134209.30331-1-sarunkod@amd.com/
---

Sairaj Kodilkar (6):
  hw/i386: Track the IOMMU to which IOAPIC is attached
  i386/kvm: x86_iommu: Introduce per-iommu notify_list_inited flag
  acpi-build: i386/pc: Track vIOMMUs in a list
  amd_iommu: acpi-build: Add support for multiple AMD-IOMMUs
  amd_iommu: Introduce AMDIVRSInfo for shared IVRS construction
  x86-iommu: Allow multiple AMD vIOMMU devices

 hw/i386/acpi-build.c        | 209 ++++++++++++++++++++----------------
 hw/i386/amd_iommu-stub.c    |  26 -----
 hw/i386/amd_iommu.c         |  76 ++++++++++---
 hw/i386/amd_iommu.h         |  15 ++-
 hw/i386/intel_iommu.c       |   1 +
 hw/i386/meson.build         |   3 +-
 hw/i386/pc.c                |  36 +++++--
 hw/i386/x86-iommu-stub.c    |   5 -
 hw/i386/x86-iommu.c         |  16 +--
 hw/intc/ioapic.c            |  18 ++--
 include/hw/i386/pc.h        |   9 +-
 include/hw/i386/x86-iommu.h |   8 +-
 include/hw/i386/x86.h       |   4 +
 target/i386/kvm/kvm.c       |  19 ++--
 14 files changed, 252 insertions(+), 193 deletions(-)
 delete mode 100644 hw/i386/amd_iommu-stub.c


-- 
2.34.1


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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:12 Sairaj Kodilkar [this message]
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 ` [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-1-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