All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] QEMU: CXL Type-2 device passthrough via vfio-pci
@ 2026-08-13 13:06 mhonap
  2026-08-13 13:06 ` [PATCH 01/10] linux-headers: Update vfio.h for CXL Type-2 passthrough mhonap
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: mhonap @ 2026-08-13 13:06 UTC (permalink / raw)
  To: alex, ankita, jic23, dave.jiang, alejandro.lucero-palau,
	smadhavan, pierrick.bouvier, mst, imammedo, anisinha, pbonzini,
	eric.auger, peter.maydell, richard.henderson, clg, cohuck
  Cc: kjaju, vsethi, zhiw, mhonap, qemu-devel, qemu-arm

From: Manish Honap <mhonap@nvidia.com>

This series adds QEMU support for passing a CXL Type-2 device (an
accelerator with host-managed device memory, e.g. a GPU) to a guest via
vfio-pci. The guest drives its own virtual endpoint HDM decoder and QEMU
maps the device memory at the guest physical address the guest commits,
while the host owns the host physical placement.

It is a full rewrite of the RFC v1 series [1] on clean upstream master,
reworked to address Jonathan's review.

Base: master (post pull-9p-20260725), commit 6333226c2a.


Kernel dependency
-----------------

Pairs with the kernel vfio-cxl series "vfio/cxl: CXL Type-2 device
passthrough" [2].
- The kernel exposes the device memory as an HPA-backed VFIO region, traps
  the HDM decoder block and runs its lock-on-commit FSM, handles the CXL
  DVSEC (including guest-triggered reset), and reports two things through
  VFIO:
  - A device flag (VFIO_DEVICE_FLAGS_CXL) and
  - The component-register geometry (VFIO_REGION_INFO_CAP_CXL_COMP_REGS).


Sample supported topology
-------------------------

Guest disk, network, and system-RAM lines are omitted:

  -machine virt,accel=kvm,gic-version=3,hmat=on,cxl=on,ras=on, \
           highmem-mmio-size=4T
  -object iommufd,id=iommufd0
  -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1
  -device cxl-rp,port=1,bus=cxl.1,id=rport0.1,chassis=4, \
          pref64-reserve=2G,mem-reserve=1G
  -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=256G
  -device arm-smmuv3,primary-bus=cxl.1,id=smmuv3.0,accel=on,ats=on, \
          ril=on,ssidsize=8,oas=48
  -device vfio-pci-nohotplug,host=<BDF>,bus=rport0.1,id=dev0, \
          iommufd=iommufd0
  -object acpi-generic-initiator,id=gi0,pci-dev=dev0,node=2
  ... (one acpi-generic-initiator per guest NUMA node the HDM memory backs)


Address model
-------------

The kernel fixes device memory to a host physical range before the guest
sees the device, and hardware presents a firmware-committed, locked
endpoint HDM decoder whose registers hold that host physical base.

QEMU never exposes Host physical base. It virtualizes the decoder base registers
in the trapped component-register read and returns the base of the device's
CFMWS window, a guest physical address, so the guest only ever sees a GPA.

QEMU maps the RAM-device region (backed by the fixed HPA) at that CFMWS base.

The kernel never learns the GPA and the guest never learns the HPA.

Because the decoder is already committed at boot, no guest commit write
triggers the mapping. QEMU maps once the guest enables memory decoding
(the Command register Memory-Space bit) and re-checks on any decoder
control write, so the region enters the guest address space and the IOAS
while the device is live.

When the guest clears Memory-Space, QEMU withdraws the mapping, matching the
kernel's revoke of the backing PTEs on the same write, so a guest access during
the disabled interval cannot fault a zapped mapping and stop the VM; the enable
path re-installs it.

This also helps to keep the guest-visible base as the CFMWS base by
construction, and the host physical placement stays with the kernel.

The RFC added the pxb-cxl _DSM because OS may treat PCI configuration as
reassignable and a BAR move would break the CXL.mem mapping. This change keeps
it narrower than the RFC v1 _DSM: it applies only to the host bridge that
carries the passed-through CXL device.


Reset
-----

There is no QEMU reset patch. A guest CXL reset is a DVSEC write that
lands in vfio config space and is handled entirely by the host kernel,
which stamps the outcome into DVSEC STATUS2. The kernel re-commits this
firmware-fixed decoder across the reset, and the guest reaches its memory
through the mapping QEMU already installed.


Reviewer feedback addressed
---------------------------

The RFC [1] thread has the full discussion.

Jonathan Cameron
  - The high-MMIO window and the cxl-fmws-base property are removed. The
    guest-visible base is the CFMWS base by construction, so it equals the
    decoder base and stays stable without a hack.
  - The guest programs its virtual (GPA) decoder and QEMU maps the memory at
    commit time.
  - The host owns the HPA, resolved before the guest sees the device.
  - The committed decoder is the fast path this series ships. The
    guest-programmed uncommitted case is delivered by cxl-core resolving the
    range at enumeration, not by a QEMU or vfio dynamic branch, so it is a
    later cxl-core item this series does not depend on.
  - FIRMWARE_COMMITTED is dropped; the cap is no longer exposed.
  - The one-endpoint, non-interleaved, no-switch topology is enforced at
    realize.
  - PCI/BAR configuration and CXL.mem stay independent.


Validation
----------

- Every patch passes scripts/checkpatch.pl --codespell --strict
  (patch 1 carries the expected imported-from-Linux warning)
- The series applies cleanly on the stated base.
- Ran couple of rounds of masoncl/review-prompts on this series before posting.


Pending items
-------------

Future enhancements for the multi-decoder, interleaved devices and switched
topologies.

Trapped CXL RAS registers are planned as a new VFIO region subtype that the same
region-by-subtype detection already handles, not as a change to the
component-register cap.

The bios-tables test refresh for the new _DSM is still to be added.


References
----------

[1] [RFC 0/9] QEMU: CXL Type-2 device passthrough via vfio-pci
https://lore.kernel.org/linux-cxl/20260427181235.3003865-1-mhonap@nvidia.com/

[2] [PATCH v4 00/27] vfio/pci: Add CXL Type-2 device passthrough support
https://lore.kernel.org/linux-cxl/20260813093631.2288172-1-mhonap@nvidia.com/


Manish Honap (10):
  linux-headers: Update vfio.h for CXL Type-2 passthrough
  hw/vfio/region: Add vfio_region_setup_with_ops()
  hw/vfio/pci: Detect a CXL Type-2 device and read its geometry
  hw/vfio/pci: Enforce the passthrough topology for a CXL device
  hw/vfio/pci: Back the CXL memory with a RAM-device region
  hw/vfio/pci: Bind a CXL device to its fixed memory window
  hw/vfio/pci: Map the CXL memory on the guest decoder commit
  docs/cxl: Document CXL Type-2 device passthrough
  hw/arm/smmu-common: Allow pxb-cxl as an SMMUv3 primary bus
  hw/pci-host: Emit a _DSM on pxb-cxl to preserve firmware PCI config

 docs/system/devices/cxl.rst               |  46 ++
 hw/acpi/Kconfig                           |   1 +
 hw/acpi/cxl-stub.c                        |   2 +-
 hw/acpi/cxl.c                             |   4 +-
 hw/acpi/pci.c                             |  40 ++
 hw/arm/smmu-common.c                      |  19 +-
 hw/i386/acpi-build.c                      |   2 +-
 hw/pci-bridge/pci_expander_bridge_stubs.c |   6 +
 hw/pci-host/gpex-acpi.c                   |  42 +-
 hw/vfio/pci.c                             | 742 ++++++++++++++++++++++
 hw/vfio/pci.h                             |  24 +
 hw/vfio/region.c                          |  27 +-
 hw/vfio/vfio-region.h                     |   3 +
 include/hw/acpi/cxl.h                     |   2 +-
 include/hw/acpi/pci.h                     |   1 +
 linux-headers/linux/vfio.h                |  22 +
 16 files changed, 927 insertions(+), 56 deletions(-)


base-commit: 055952c0aa91ea7a00d135b73f78fc0b13442d6c
-- 
2.25.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-08-13 17:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-13 13:06 [PATCH 00/10] QEMU: CXL Type-2 device passthrough via vfio-pci mhonap
2026-08-13 13:06 ` [PATCH 01/10] linux-headers: Update vfio.h for CXL Type-2 passthrough mhonap
2026-08-13 13:06 ` [PATCH 02/10] hw/vfio/region: Add vfio_region_setup_with_ops() mhonap
2026-08-13 13:06 ` [PATCH 03/10] hw/vfio/pci: Detect a CXL Type-2 device and read its geometry mhonap
2026-08-13 13:06 ` [PATCH 04/10] hw/vfio/pci: Enforce the passthrough topology for a CXL device mhonap
2026-08-13 13:06 ` [PATCH 05/10] hw/vfio/pci: Back the CXL memory with a RAM-device region mhonap
2026-08-13 13:06 ` [PATCH 06/10] hw/vfio/pci: Bind a CXL device to its fixed memory window mhonap
2026-08-13 13:06 ` [PATCH 07/10] hw/vfio/pci: Map the CXL memory on the guest decoder commit mhonap
2026-08-13 13:06 ` [PATCH 08/10] docs/cxl: Document CXL Type-2 device passthrough mhonap
2026-08-13 13:06 ` [PATCH 09/10] hw/arm/smmu-common: Allow pxb-cxl as an SMMUv3 primary bus mhonap
2026-08-13 13:06 ` [PATCH 10/10] hw/pci-host: Emit a _DSM on pxb-cxl to preserve firmware PCI config mhonap
2026-08-13 17:42 ` [PATCH 00/10] QEMU: CXL Type-2 device passthrough via vfio-pci Cédric Le Goater

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.