VFIO PCI Live Update (noiommu mode)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v6 Latest27 patches 20 repliesIn review
- v520 patches 24 repliesSuperseded
- v416 patches 8 repliesSuperseded
Changes in v6 from the cover letter
- Keep noiommu devices running across kexec and take them over without reset, instead of resetting them in freeze().
- Restrict preservation to bound noiommu cdev FDs.
- Add PCI helpers to serialize and restore struct pci_saved_state.
- Add unfreeze() and close races between freeze() and ioctl/config access. Refuse freeze() while SR-IOV is enabled, and refuse enabling SR-IOV on a frozen device.
- Protect incoming devices in the new kernel until they finish Live Update; reset unclaimed devices in finish() with a single pci_warn(). retrieve() and finish() look the device up under the device lock, so they never act on a device that vfio-pci is still probing.
- Fix vfio_pci_liveupdate_init() error handling to avoid a double unregister at module exit (reported by Sashiko on v5).
- Drop "vfio/pci: Export vfio_pci_dma_buf_move for vfio-pci module", "vfio: selftests: Expose iommu_modes to tests", and exports that were only needed by the v5 reset path.
- Update the VFIO PCI and PCI Live Update documentation.
- Selftests: add an iommufd noiommu mode, IOVA == PA mapping helpers, 2MB THP memfd helpers, an attach() driver op (igb, DSA), and a kexec test with DMA running across the Live Update.
Patches in v6 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/27 | vfio/pci: Factor out the reset logic in VFIO PCI device close pathdrivers/ | +53 | 0 replies | |
| 2/27 | vfio: Export various helpers from VFIOdrivers/ drivers/ drivers/ +1 more | +6 | 0 replies | |
| 3/27 | liveupdate: Export symbols needed by moduleskernel/ | +2 | 1 reply | |
| 4/27 | vfio/pci: Register a file handler with Live Update OrchestratorMAINTAINERS drivers/ drivers/ +4 more | +140 | 2 replies | |
| 5/27 | PCI: liveupdate: Add helpers to preserve struct pci_saved_stateDocumentation/ drivers/ drivers/ +3 more | +286 | 3 replies | |
| 6/27 | vfio: Add helpers to identify device files that can be preserveddrivers/ drivers/ drivers/ +1 more | +48 | 0 replies | |
| 7/27 | vfio/pci: Preserve vfio-pci device files across Live Updatedrivers/ drivers/ drivers/ +5 more | +434 | 7 replies | |
| 8/27 | vfio: Introduce vfio_find_device() helperdrivers/ include/ | +62 | 0 replies | |
| 9/27 | vfio: Refactor vfio_device_fops_cdev_open()drivers/ | +15 | 0 replies | |
| 10/27 | vfio: Add API to open cdev device for Live Update restoredrivers/ include/ | +43 | 0 replies | |
| 11/27 | vfio/pci: Retrieve preserved device files after Live Updatedrivers/ drivers/ drivers/ +1 more | +484 | 4 replies | |
| 12/27 | vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FDdrivers/ drivers/ drivers/ +1 more | +41 | 1 reply | |
| 13/27 | vfio/pci: Protect incoming preserved devices until they finish Live Updatedrivers/ drivers/ drivers/ +2 more | +91 | 0 replies | |
| 14/27 | vfio/pci: Take over preserved devices without resetting themdrivers/ drivers/ drivers/ | +141 | 0 replies | |
| 15/27 | docs: liveupdate: Add documentation for VFIO PCIDocumentation/ Documentation/ MAINTAINERS | +27 | 0 replies | |
| 16/27 | vfio: selftests: Build liveupdate library in VFIO selfteststools/ | +7 | 0 replies | |
| 17/27 | vfio: selftests: Add vfio_pci_liveupdate_uapi_testtools/ tools/ | +127 | 0 replies | |
| 18/27 | vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FDtools/ tools/ | +22 | 0 replies | |
| 19/27 | vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDEDtools/ | +7 | 0 replies | |
| 20/27 | vfio: selftests: Add iommufd noiommu modetools/ tools/ tools/ +1 more | +53 | 0 replies | |
| 21/27 | vfio: selftests: Add helpers to map DMA memory at IOVA == PA in noiommu modetools/ tools/ | +87 | 0 replies | |
| 22/27 | vfio: selftests: Add helpers for Live Update DMA memory and sysfs statetools/ tools/ tools/ +1 more | +77 | 0 replies | |
| 23/27 | vfio: selftests: Add an attach() driver optools/ tools/ tools/ +1 more | +105 | 0 replies | |
| 24/27 | vfio: selftests: Test preserving noiommu devices in vfio_pci_liveupdate_uapi_testtools/ | +102 | 0 replies | |
| 25/27 | vfio: selftests: Add vfio_pci_liveupdate_kexec_testtools/ tools/ | +106 | 0 replies | |
| 26/27 | vfio: selftests: Verify that opening VFIO device fails during Live Updatetools/ | +38 | 0 replies | |
| 27/27 | vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_testtools/ | +257 | 0 replies |
Reviews trailers per patch
3 of 27 patches have a Reviewed-by or Acked-by.
| Patch | Samiullah Khawaja | Pranjal Shrivastava | Bjorn Helgaas |
|---|---|---|---|
| 1/27 | |||
| 2/27 | |||
| 3/27 | R-b | R-b | |
| 4/27 | |||
| 5/27 | A-b | ||
| 6/27 | |||
| 7/27 | |||
| 8/27 | |||
| 9/27 | |||
| 10/27 | |||
| 11/27 | |||
| 12/27 | R-b | ||
| 13/27 | |||
| 14/27 | |||
| 15/27 | |||
| 16/27 | |||
| 17/27 | |||
| 18/27 | |||
| 19/27 | |||
| 20/27 | |||
| 21/27 | |||
| 22/27 | |||
| 23/27 | |||
| 24/27 | |||
| 25/27 | |||
| 26/27 | |||
| 27/27 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.
Cover letter [PATCH v6 00/27] VFIO PCI Live Update (noiommu mode)
This series adds a fully working Live Update support for vfio-pci devices in noiommu mode, using the Live Update Orchestrator (LUO) and Kexec HandOver (KHO).
This series can also be found on GitHub:
https://github.com/shvipin/linux/tree/vfio/liveupdate/v6
Unlike v5, which reset the device in freeze() and required userspace to re-initialize it after kexec, v6 keeps a preserved device running across the kexec: it is not reset, bus mastering and memory decode stay enabled, it stays in D0, and in-flight DMA continues into preserved memory (e.g. a LUO-preserved shmem memfd). In the new kernel, userspace retrieves the device FD from its LUO session and takes over the running device without resetting it on the first VFIO_DEVICE_BIND_IOMMUFD.
Preserving IOMMU-backed devices is refused with -EOPNOTSUPP until LUO can preserve IOMMU state; group/container FDs and unbound cdev FDs are refused with -ENOENT.
This series is built on top of PCI Live Update series version v10:
https://lore.kernel.org/linux-pci/[email protected]/
Design
======
- Preserve: only a bound noiommu vfio-pci cdev FD can be preserved (no VFs, Intel display devices, or zdev). The device is registered with PCI Live Update and its pre-open struct pci_saved_state is serialized into a versioned KHO buffer ("vfio-pci-v1").
- Freeze/unfreeze: freeze() requires interrupts to be disabled, the device to be in D0, and SR-IOV to be disabled (VFs are not preserved). It snapshots vconfig and pci_config_map, and masks physical INTx while leaving bus mastering enabled. If the kexec is aborted, unfreeze() restores INTx and the existing FD keeps working.
- Early protection in the new kernel: an incoming device is kept out of runtime D3, sibling dev_set resets are blocked, and opening it via its cdev or VFIO_GROUP_GET_DEVICE_FD fails with -EBUSY until the session is finished. If the new kernel is not in noiommu mode, bus mastering is cleared at registration.
- Retrieve and take-over: LIVEUPDATE_SESSION_RETRIEVE_FD validates the serialized state against the hardware and returns an unbound cdev FD. The first VFIO_DEVICE_BIND_IOMMUFD takes over the device without clearing bus mastering, resetting, or re-saving its state, restores the preserved vconfig, and keeps the original saved state so that normal reset/restore applies when the FD is closed.
- Unclaimed devices: if the session is finished or closed without taking over the device (not retrieved, retrieved but not bound, unbound, or driverless), the kernel logs one pci_warn(), resets the device, and restores its pre-Live-Update state.
- DMA memory ordering: a running device keeps DMAing until it is taken over or reset, so its DMA memory must stay pinned until then. LUO finishes files in LIFO order, so userspace must preserve the DMA memory (e.g. a memfd) in the same session and before the device. This is documented in Documentation/driver-api/vfio_pci_liveupdate.rst.
Testing
=======
- QEMU with an emulated igb device in noiommu mode, across real kexec reboots: vfio_pci_liveupdate_uapi_test and vfio_pci_liveupdate_kexec_test (opens fail with -EBUSY, memfd stays at the same physical addresses, pre-kexec DMA completes after take-over, and new DMA works without re-init).
- Physical Intel hosts with DSA (8086:0b25), across real kexec
reboots: vfio_pci_liveupdate_kexec_test with DMA started just before the kexec (opens fail with -EBUSY, memfd stays at the same physical addresses, pre-kexec DMA completes correctly after take-over, and new DMA works without re-init).
$ ./setup.sh 0000:6a:01.0 $ ./vfio_pci_liveupdate_kexec_test -s 1 0000:6a:01.0 $ kexec --reuse-cmdline -l -s /boot/vmlinuz $ kexec -e $ ./setup.sh 0000:6a:01.0 $ ./vfio_pci_liveupdate_kexec_test -s 2 0000:6a:01.0
AI disclosure
=============
New and reworked patches were developed with LLM assistance. Assisted-by is not needed now in linux kernel but I thought I should at least disclose this in cover letter.
v6:
- Keep noiommu devices running across kexec and take them over without reset, instead of resetting them in freeze().
- Restrict preservation to bound noiommu cdev FDs.
- Add PCI helpers to serialize and restore struct pci_saved_state.
- Add unfreeze() and close races between freeze() and ioctl/config access. Refuse freeze() while SR-IOV is enabled, and refuse enabling SR-IOV on a frozen device.
- Protect incoming devices in the new kernel until they finish Live Update; reset unclaimed devices in finish() with a single pci_warn(). retrieve() and finish() look the device up under the device lock, so they never act on a device that vfio-pci is still probing.
- Fix vfio_pci_liveupdate_init() error handling to avoid a double unregister at module exit (reported by Sashiko on v5).
- Drop "vfio/pci: Export vfio_pci_dma_buf_move for vfio-pci module", "vfio: selftests: Expose iommu_modes to tests", and exports that were only needed by the v5 reset path.
- Update the VFIO PCI and PCI Live Update documentation.
- Selftests: add an iommufd noiommu mode, IOVA == PA mapping helpers, 2MB THP memfd helpers, an attach() driver op (igb, DSA), and a kexec test with DMA running across the Live Update.
v5: https://lore.kernel.org/kvm/[email protected]/
v4: https://lore.kernel.org/kvm/[email protected]/
v3: https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/
v1: https://lore.kernel.org/kvm/[email protected]/
rfc: https://lore.kernel.org/kvm/[email protected]/
David Matlack (4):
vfio: Enforce preserved devices are retrieved via
LIVEUPDATE_SESSION_RETRIEVE_FD
docs: liveupdate: Add documentation for VFIO PCI
vfio: selftests: Add vfio_pci_liveupdate_uapi_test
vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED
Vipin Sharma (23):
vfio/pci: Factor out the reset logic in VFIO PCI device close path
vfio: Export various helpers from VFIO
liveupdate: Export symbols needed by modules
vfio/pci: Register a file handler with Live Update Orchestrator
PCI: liveupdate: Add helpers to preserve struct pci_saved_state
vfio: Add helpers to identify device files that can be preserved vfio/pci: Preserve vfio-pci device files across Live Update
vfio: Introduce vfio_find_device() helper
vfio: Refactor vfio_device_fops_cdev_open()
vfio: Add API to open cdev device for Live Update restore vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Protect incoming preserved devices until they finish Live
Update
vfio/pci: Take over preserved devices without resetting them
vfio: selftests: Build liveupdate library in VFIO selftests
vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD
vfio: selftests: Add iommufd noiommu mode
vfio: selftests: Add helpers to map DMA memory at IOVA == PA in
noiommu mode
vfio: selftests: Add helpers for Live Update DMA memory and sysfs
state
vfio: selftests: Add an attach() driver op
vfio: selftests: Test preserving noiommu devices in
vfio_pci_liveupdate_uapi_test
vfio: selftests: Add vfio_pci_liveupdate_kexec_test
vfio: selftests: Verify that opening VFIO device fails during Live
Update
vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test
Documentation/PCI/liveupdate.rst | 3 + Documentation/core-api/liveupdate.rst | 1 + .../driver-api/vfio_pci_liveupdate.rst | 25 + MAINTAINERS | 2 + drivers/pci/liveupdate.c | 223 ++++++ drivers/pci/pci.c | 5 - drivers/pci/pci.h | 6 + drivers/vfio/device_cdev.c | 87 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Kconfig | 11 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 14 +- drivers/vfio/pci/vfio_pci_config.c | 19 +- drivers/vfio/pci/vfio_pci_core.c | 348 ++++++-- drivers/vfio/pci/vfio_pci_intrs.c | 4 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 745 ++++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 177 +++++ drivers/vfio/vfio.h | 28 +- drivers/vfio/vfio_main.c | 85 +- include/linux/kho/abi/pci.h | 47 ++ include/linux/kho/abi/vfio_pci.h | 76 ++ include/linux/pci_liveupdate.h | 7 + include/linux/vfio.h | 19 + include/linux/vfio_pci_core.h | 11 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/vfio/Makefile | 23 +- .../selftests/vfio/lib/drivers/dsa/dsa.c | 35 +- .../selftests/vfio/lib/drivers/igb/igb.c | 39 +- .../selftests/vfio/lib/include/libvfio.h | 3 + .../vfio/lib/include/libvfio/iommu.h | 43 + .../vfio/lib/include/libvfio/sysfs.h | 1 + .../lib/include/libvfio/vfio_pci_device.h | 10 + .../lib/include/libvfio/vfio_pci_driver.h | 17 + tools/testing/selftests/vfio/lib/iommu.c | 70 +- tools/testing/selftests/vfio/lib/libvfio.c | 54 ++ tools/testing/selftests/vfio/lib/sysfs.c | 22 +- .../selftests/vfio/lib/vfio_pci_device.c | 56 +- .../selftests/vfio/lib/vfio_pci_driver.c | 22 +- .../vfio/vfio_pci_liveupdate_kexec_test.c | 388 +++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 227 ++++++ 40 files changed, 2826 insertions(+), 139 deletions(-) create mode 100644 Documentation/driver-api/vfio_pci_liveupdate.rst create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/vfio_pci.h create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c
base-commit: 312200e9211ede3f9a03cc17d094805e06e4674e
Signature · 1 line
2.56.0.317.g454f8302e1-goog