Skip to content

RFC intel_iommu: expose Shared Virtual Addressing to VMs

Liu Yi L kvm qemu-devel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest22 patches 0 repliesNew

Changelog from the cover letter

- RFC v3 -> v3.1:
a) Drop IOMMUContext, and rename DualStageIOMMUObject to HostIOMMUContext. HostIOMMUContext is per-vfio-container, it is exposed to vIOMMU via PCI layer. VFIO registers a PCIHostIOMMUFunc callback to PCI layer, vIOMMU could get HostIOMMUContext instance via it.
b) Check IOMMU uAPI version by VFIO_CHECK_EXTENSION
c) Add a check on VFIO_PASID_REQ availability via VFIO_GET_IOMMU_IHNFO
d) Reorder the series, put vSVA linux header file update in the beginning put the x-scalable-mode option mofification in the end of the series.
e) Dropped patch "[RFC v3 01/25] hw/pci: modify pci_setup_iommu() to set PCIIOMMUOps"
RFCv3: https://patchwork.kernel.org/cover/11356033/

- RFC v2 -> v3:
a) Introduce DualStageIOMMUObject to abstract the host IOMMU programming capability. e.g. request PASID from host, setup IOMMU nesting translation on host IOMMU. The pasid_alloc/bind_guest_page_table/iommu_cache_flush operations are moved to be DualStageIOMMUOps. Thus, DualStageIOMMUObject is an abstract layer which provides QEMU vIOMMU emulators with an explicit method to program host IOMMU.
b) Compared with RFC v2, the IOMMUContext has also been updated. It is modified to provide an abstract for vIOMMU emulators. It provides the method for pass-through modules (like VFIO) to communicate with host IOMMU. e.g. tell vIOMMU emulators about the IOMMU nesting capability on host side and report the host IOMMU DMA translation faults to vIOMMU emulators. RFC v2: https://www.spinics.net/lists/kvm/msg198556.html

- RFC v1 -> v2:
Introduce IOMMUContext to abstract the connection between VFIO and vIOMMU emulators, which is a replacement of the PCIPASIDOps in RFC v1. Modify x-scalable-mode to be string option instead of adding a new option as RFC v1 did. Refined the pasid cache management and addressed the TODOs mentioned in RFC v1.
RFC v1: https://patchwork.kernel.org/cover/11033657/

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/22scripts/update-linux-headers: Import iommu.hscripts/update-linux-headers.sh+1 -10 replies
2/22header file update VFIO/IOMMU vSVA APIslinux-headers/linux/iommu.h linux-headers/linux/vfio.h+499 -00 replies
3/22vfio: check VFIO_TYPE1_NESTING_IOMMU supporthw/vfio/common.c+12 -20 replies
4/22hw/iommu: introduce HostIOMMUContexthw/Makefile.objs hw/iommu/Makefile.objs hw/iommu/host_iommu_context.c +1 more+118 -00 replies
5/22hw/pci: add pci_device_setup_iommuhw/pci/pci.c include/hw/pci/pci.h+16 -00 replies
6/22vfio/pci: init HostIOMMUContext per-containerhw/vfio/common.c hw/vfio/pci.c include/hw/vfio/vfio-common.h+34 -00 replies
7/22vfio: get nesting iommu cap info from Kernelhw/iommu/host_iommu_context.c hw/vfio/common.c include/hw/iommu/host_iommu_context.h+108 -40 replies
8/22vfio/common: add pasid_alloc/free supporthw/vfio/common.c+46 -10 replies
9/22hw/pci: add pci_device_host_iommu_context()hw/pci/pci.c include/hw/pci/pci.h+9 -00 replies
10/22intel_iommu: add virtual command capability supporthw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h hw/i386/trace-events +1 more+209 -10 replies
11/22intel_iommu: process pasid cache invalidationhw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h hw/i386/trace-events+76 -50 replies
12/22intel_iommu: add PASID cache management infrastructurehw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h hw/i386/trace-events +1 more+433 -10 replies
13/22vfio: add bind stage-1 page table supporthw/iommu/host_iommu_context.c hw/vfio/common.c include/hw/iommu/host_iommu_context.h+92 -00 replies
14/22intel_iommu: bind/unbind guest page table to hosthw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h+115 -40 replies
15/22intel_iommu: replay guest pasid bindings to hosthw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h+173 -110 replies
16/22intel_iommu: replay pasid binds after context cache invalidationhw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h hw/i386/trace-events+73 -10 replies
17/22intel_iommu: do not pass down pasid bind for PASID #0hw/i386/intel_iommu.c+10 -00 replies
18/22vfio/common: add support for flush iommu stage-1 cachehw/iommu/host_iommu_context.c hw/vfio/common.c include/hw/iommu/host_iommu_context.h+48 -00 replies
19/22intel_iommu: process PASID-based iotlb invalidationhw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h+70 -00 replies
20/22intel_iommu: propagate PASID-based iotlb invalidation to hosthw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h+138 -00 replies
21/22intel_iommu: process PASID-based Device-TLB invalidationhw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h+19 -00 replies
22/22intel_iommu: modify x-scalable-mode to be string optionhw/i386/intel_iommu.c hw/i386/intel_iommu_internal.h include/hw/i386/intel_iommu.h+33 -20 replies

Reviews trailers per patch

3 of 22 patches have a Reviewed-by or Acked-by.

PatchCornelia HuckPeter Xu
1/22A-b
2/22
3/22
4/22
5/22
6/22
7/22
8/22
9/22
10/22R-b
11/22R-b
12/22
13/22
14/22
15/22
16/22
17/22
18/22
19/22
20/22
21/22
22/22

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC v3.1 00/22] intel_iommu: expose Shared Virtual Addressing to VMs

Shared Virtual Addressing (SVA), a.k.a, Shared Virtual Memory (SVM) on Intel platforms allows address space sharing between device DMA and applications. SVA can reduce programming complexity and enhance security.

This QEMU series is intended to expose SVA usage to VMs. i.e. Sharing guest application address space with passthru devices. This is called vSVA in this series. The whole vSVA enabling requires QEMU/VFIO/IOMMU changes. This version is 3.1 to address comments in RFCv3. It is based on the kernel which can be found in below github. This kernel has some internal tweak between VFIO and VT-d iommu driver, so it is not sent out to community review. But the interface between kernel and QEMU are latest. So I send out this version for review.
https://github.com/luxis1999/linux-vsva: vsva-linux-5.5-rc3-rfcv3.1

The high-level architecture for SVA virtualization is as below, the key design of vSVA support is to utilize the dual-stage IOMMU translation ( also known as IOMMU nesting translation) capability in host IOMMU.

    .-------------.  .---------------------------.
    |   vIOMMU    |  | Guest process CR3, FL only|
    |             |  '---------------------------'

.----------------/
| PASID Entry |--- PASID cache flush -
'-------------' |
| | V
| | CR3 in GPA
'-------------'
Guest

------| Shadow |--------------------------|--------
      v        v                          v
Host
    .-------------.  .----------------------.
    |   pIOMMU    |  | Bind FL for GVA-GPA  |
    |             |  '----------------------'
    .----------------/  |
    | PASID Entry |     V (Nested xlate)
    '----------------\.------------------------------.
    |             |   |SL for GPA-HPA, default domain|
    |             |   '------------------------------'
    '-------------'

Where:
- FL = First level/stage one page tables
- SL = Second level/stage two page tables

The complete vSVA kernel upstream patches are divided into three phases:
1. Common APIs and PCI device direct assignment
2. IOMMU-backed Mediated Device assignment
3. Page Request Services (PRS) support

This QEMU RFC patchset is aiming for the phase 1 and phase 2.

Related series:
[1] [PATCH V9 00/10] Nested Shared Virtual Address (SVA) VT-d support:

    https://lkml.org/lkml/2020/1/29/37
    [PATCH 0/3] IOMMU user API enhancement:
    https://lkml.org/lkml/2020/1/29/45

[2] [RFC v3 0/8] vfio: expose virtual Shared Virtual Addressing to VMs

    https://lkml.org/lkml/2020/1/29/255

There are roughly two parts:
1. Introduce HostIOMMUContext as abstract of host IOMMU. It provides explicit method for vIOMMU emulators to communicate with host IOMMU. e.g. propagate guest page table binding to host IOMMU to setup dual-stage DMA translation in host IOMMU and flush iommu iotlb.
2. Setup dual-stage IOMMU translation for Intel vIOMMU. Includes
- Check IOMMU uAPI version compatibility and VFIO Nesting capabilities which includes hardware compatibility (stage 1 format) and VFIO_PASID_REQ availability. This is preparation for setting up dual-stage DMA translation in host IOMMU.
- Propagate guest PASID allocation and free request to host.
- Propagate guest page table binding to host to setup dual-stage IOMMU DMA translation in host IOMMU.
- Propagate guest IOMMU cache invalidation to host to ensure iotlb correctness.

The complete QEMU set can be found in below link:
https://github.com/luxis1999/qemu.git: sva_qemu_rfcv3.1

Complete kernel can be found in:
https://github.com/luxis1999/linux-vsva.git: vsva-linux-5.5-rc3-rfcv3.1

Tests: basci functionality test, VM reboot/shutdown, full comapilation.
<more test would be done as this is RFC series>

Changelog:
- RFC v3 -> v3.1:
a) Drop IOMMUContext, and rename DualStageIOMMUObject to HostIOMMUContext. HostIOMMUContext is per-vfio-container, it is exposed to vIOMMU via PCI layer. VFIO registers a PCIHostIOMMUFunc callback to PCI layer, vIOMMU could get HostIOMMUContext instance via it.
b) Check IOMMU uAPI version by VFIO_CHECK_EXTENSION
c) Add a check on VFIO_PASID_REQ availability via VFIO_GET_IOMMU_IHNFO
d) Reorder the series, put vSVA linux header file update in the beginning put the x-scalable-mode option mofification in the end of the series.
e) Dropped patch "[RFC v3 01/25] hw/pci: modify pci_setup_iommu() to set PCIIOMMUOps"
RFCv3: https://patchwork.kernel.org/cover/11356033/

- RFC v2 -> v3:
a) Introduce DualStageIOMMUObject to abstract the host IOMMU programming capability. e.g. request PASID from host, setup IOMMU nesting translation on host IOMMU. The pasid_alloc/bind_guest_page_table/iommu_cache_flush operations are moved to be DualStageIOMMUOps. Thus, DualStageIOMMUObject is an abstract layer which provides QEMU vIOMMU emulators with an explicit method to program host IOMMU.
b) Compared with RFC v2, the IOMMUContext has also been updated. It is modified to provide an abstract for vIOMMU emulators. It provides the method for pass-through modules (like VFIO) to communicate with host IOMMU. e.g. tell vIOMMU emulators about the IOMMU nesting capability on host side and report the host IOMMU DMA translation faults to vIOMMU emulators. RFC v2: https://www.spinics.net/lists/kvm/msg198556.html

- RFC v1 -> v2:
Introduce IOMMUContext to abstract the connection between VFIO and vIOMMU emulators, which is a replacement of the PCIPASIDOps in RFC v1. Modify x-scalable-mode to be string option instead of adding a new option as RFC v1 did. Refined the pasid cache management and addressed the TODOs mentioned in RFC v1.
RFC v1: https://patchwork.kernel.org/cover/11033657/

Eric Auger (1):
scripts/update-linux-headers: Import iommu.h

Liu Yi L (21):
header file update VFIO/IOMMU vSVA APIs
vfio: check VFIO_TYPE1_NESTING_IOMMU support hw/iommu: introduce HostIOMMUContext
hw/pci: add pci_device_setup_iommu
vfio/pci: init HostIOMMUContext per-container
vfio: get nesting iommu cap info from Kernel vfio/common: add pasid_alloc/free support
hw/pci: add pci_device_host_iommu_context()
intel_iommu: add virtual command capability support
intel_iommu: process pasid cache invalidation
intel_iommu: add PASID cache management infrastructure
vfio: add bind stage-1 page table support
intel_iommu: bind/unbind guest page table to host
intel_iommu: replay guest pasid bindings to host
intel_iommu: replay pasid binds after context cache invalidation
intel_iommu: do not pass down pasid bind for PASID #0 vfio/common: add support for flush iommu stage-1 cache
intel_iommu: process PASID-based iotlb invalidation
intel_iommu: propagate PASID-based iotlb invalidation to host
intel_iommu: process PASID-based Device-TLB invalidation
intel_iommu: modify x-scalable-mode to be string option

 hw/Makefile.objs                      |    1 +
 hw/i386/intel_iommu.c                 | 1176 ++++++++++++++++++++++++++++++++-
 hw/i386/intel_iommu_internal.h        |  119 ++++
 hw/i386/trace-events                  |    6 +
 hw/iommu/Makefile.objs                |    1 +
 hw/iommu/host_iommu_context.c         |   88 +++
 hw/pci/pci.c                          |   18 +
 hw/vfio/common.c                      |  236 ++++++-
 hw/vfio/pci.c                         |   21 +
 include/hw/i386/intel_iommu.h         |   41 +-
 include/hw/iommu/host_iommu_context.h |  106 +++
 include/hw/pci/pci.h                  |    7 +
 include/hw/vfio/vfio-common.h         |    2 +
 linux-headers/linux/iommu.h           |  372 +++++++++++
 linux-headers/linux/vfio.h            |  127 ++++
 scripts/update-linux-headers.sh       |    2 +-
 16 files changed, 2311 insertions(+), 12 deletions(-)
 create mode 100644 hw/iommu/Makefile.objs
 create mode 100644 hw/iommu/host_iommu_context.c
 create mode 100644 include/hw/iommu/host_iommu_context.h
 create mode 100644 linux-headers/linux/iommu.h
Signature · 1 line
2.7.4