Skip to contentSkip to conversation

vfio/pci: Base Live Update support for VFIO

PATCH Superseded Vipin Sharma 4 participants 54 messages Jul 14 – Sep 5

Subsystems (8)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover vfio/pci: Base Live Update support for VFIO

Hello,

This series can be found on Github:

https://github.com/shvipin/linux vfio/liveupdate/v5

This series provides the base support to enable Live Update feature for VFIO PCI devices using the Live Update Orchestrator (LUO) and Kexec Handover (KHO).

Overview
--------

This series makes the following changes to support VFIO Live Update:

- Puts VFIO Live Update support behind the CONFIG_VFIO_PCI_LIVEUPDATE config option (which requires CONFIG_VFIO_DEVICE_CDEV).
- Preserves VFIO cdev device FDs across a kexec Live Update session via LUO/KHO.
- Enforces that incoming preserved devices can only be retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD post-kexec (preventing legacy group/cdev opens from accessing uninitialized state).
- Quiesces the device prior to kexec in freeze() by resetting hardware, disabling bus mastering, and marking the device frozen to reject post-freeze IO/MMIO.
- Includes VFIO selftests (uapi & kexec tests with continuous DMA checks) and kernel documentation.

VFIO PCI Live Update Roadmap
----------------------------

We are planning to add VFIO PCI Live Update support in phases. Since full support of this feature will come in phase, VFIO PCI Liveupdate is controlled by CONFIG_VFIO_PCI_LIVEUPDATE config option.

This series is phase 1 below:

1. PCIe function (non-VF) preserved across Live Update without changing BDF
2. PCIe function (non-VF) preserved across Live Update without resetting
3. PCIe function (non-VF) preserved across Live Update with continuous DMA (noiommu)
4. PCIe function (non-VF) preserved across Live Update with continuous DMA (iommufd)
5. PCIe VF preserved across Live Update with continuous DMA (iommufd)

Dependencies
------------

This series has following dependencies as shown in the diagram

    |---------------------------|
    |         VFIO v5           |  <--- Sent in this series.
    |---------------------------|
    |  Liveupdate Selftests[1]  |
    |---------------------------|
    |        PCI v7 [2]         |
    |---------------------------|

[1] https://lore.kernel.org/all/[email protected]/
These selftests changes are needed by other selftests also (iommu, kvm), so, I have sent them separately.

[2] https://lore.kernel.org/linux-pci/[email protected]/
This is the PCI v7, which adds the live update support in PCI core.

Github branch I have mentioned at the top has all of these dependencies.

Testing
-------

Tested using VFIO Live Update selftests in both QEMU and bare-metal environment (Intel DSA PCIe device).

  $ ./setup.sh 0000:00:04.0
  $ ./vfio_pci_liveupdate_kexec_test --stage 1 0000:6a:01.0
  $ kexec --reuse-cmdline -l -s /boot/vmlinuz
  $ kexec -e
  $ ./setup.sh 0000:00:04.0
  $ ./vfio_pci_liveupdate_kexec_test --stage 2 0000:6a:01.0

Kernel command line options used:
- liveupdate=on
- kho=on
- vfio_iommu_type1.allow_unsafe_interrupts=Y
- vfio_pci.enable_sriov=Y
- vfio_pci.disable_denylist=Y
- vfio.enable_unsafe_noiommu_mode=Y

Changelog
---------

v5:
- Addressed Sashiko feedback.
- Removed condition to disable CONFIG_VFIO_PCI_DMABUF.
- Expanded vfio_find_device() helper to safely discover a registered vfio_device by matching criteria. Internal Sashiko instance found data race.
- Updated selftests to latest changes in VFIO selftests.
- Rebased on top of PCI Live Update series v7.

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 (7):
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
vfio: selftests: Expose iommu_modes to tests
vfio: selftests: Verify that opening VFIO device fails during Live
Update
vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

Vipin Sharma (13):
vfio/pci: Factor out the reset logic in VFIO PCI device close path
vfio: Export various helpers from VFIO
vfio/pci: Export vfio_pci_dma_buf_move for vfio-pci module
liveupdate: Export symbols needed by modules
vfio/pci: Register a file handler with Live Update Orchestrator 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: selftests: Build liveupdate library in VFIO selftests
vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD
vfio: selftests: Add vfio_pci_liveupdate_kexec_test

 Documentation/core-api/liveupdate.rst         |   1 +
 .../driver-api/vfio_pci_liveupdate.rst        |  23 ++
 MAINTAINERS                                   |   2 +
 drivers/vfio/device_cdev.c                    |  67 +++-
 drivers/vfio/group.c                          |   9 +
 drivers/vfio/pci/Kconfig                      |  12 +
 drivers/vfio/pci/Makefile                     |   1 +
 drivers/vfio/pci/vfio_pci.c                   |  13 +-
 drivers/vfio/pci/vfio_pci_config.c            |   3 +
 drivers/vfio/pci/vfio_pci_core.c              | 119 +++---
 drivers/vfio/pci/vfio_pci_dmabuf.c            |   1 +
 drivers/vfio/pci/vfio_pci_liveupdate.c        | 340 ++++++++++++++++++
 drivers/vfio/pci/vfio_pci_priv.h              |  28 ++
 drivers/vfio/vfio.h                           |  18 +
 drivers/vfio/vfio_main.c                      |  67 +++-
 include/linux/kho/abi/vfio_pci.h              |  43 +++
 include/linux/vfio.h                          |  12 +
 include/linux/vfio_pci_core.h                 |   3 +
 kernel/liveupdate/luo_file.c                  |   2 +
 tools/testing/selftests/vfio/Makefile         |  23 +-
 .../vfio/lib/include/libvfio/iommu.h          |   2 +
 .../lib/include/libvfio/vfio_pci_device.h     |   3 +
 tools/testing/selftests/vfio/lib/iommu.c      |   4 +-
 .../selftests/vfio/lib/vfio_pci_device.c      |  25 +-
 .../vfio/vfio_pci_liveupdate_kexec_test.c     | 256 +++++++++++++
 .../vfio/vfio_pci_liveupdate_uapi_test.c      |  97 +++++
 26 files changed, 1097 insertions(+), 77 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: cbf37fff757e87376e80e11a8378393a8f25145f
prerequisite-patch-id: 85705fb54d3065efe1d87ab4b69e828a9f3404e7
prerequisite-patch-id: a33ae79b5fc0259bd013b430c18cc3d14a678599

Signature · 1 line
2.55.0.795.g602f6c329a-goog
#1 lore raw

PATCH v5 1/20 vfio/pci: Factor out the reset logic in VFIO PCI device close path

vfio_pci_core_disable() is a very long function doing multiple things like exiting runtime power management, setting device to D0 power, clearing bus master, clearing irqs, freeing eventfds, releasing device regions, unmapping PCI bars, and performing device/bus resets.

The upcoming VFIO Liveupdate feature will also need to utilize same reset logic.

Extract device reset code to a new helper function, vfio_pci_core_try_reset(), and update vfio_pci_core_disable() to use this new function.

No functional change intended.

---
 drivers/vfio/pci/vfio_pci_core.c | 100 ++++++++++++++++---------------
 1 file changed, 53 insertions(+), 47 deletions(-)
drivers/vfio/pci/vfio_pci_core.c +53 -47
index a28f1e99362c..3c8b990ee92f 100644
@@ -623,9 +623,60 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_enable);
 
-void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
+static void vfio_pci_core_try_reset(struct vfio_pci_core_device *vdev)
 {
+	struct pci_dev *pdev = vdev->pdev;
 	struct pci_dev *bridge;
+
+	vdev->needs_reset = true;
+
+	/*
+	 * If we have saved state, restore it.  If we can reset the device,
+	 * even better.  Resetting with current state seems better than
+	 * nothing, but saving and restoring current state without reset
+	 * is just busy work.
+	 */
+	if (pci_load_and_free_saved_state(pdev, &vdev->pci_saved_state)) {
+		pci_info(pdev, "%s: Couldn't reload saved state\n", __func__);
+
+		if (!vdev->reset_works)
+			return;
+
+		pci_save_state(pdev);
+	}
+
+	/*
+	 * Disable INTx and MSI, presumably to avoid spurious interrupts
+	 * during reset.  Stolen from pci_reset_function()
+	 */
+	pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
+
+	/*
+	 * Try to get the locks ourselves to prevent a deadlock. The
+	 * success of this is dependent on being able to lock the device,
+	 * which is not always possible.
+	 * We can not use the "try" reset interface here, which will
+	 * overwrite the previously restored configuration information.
+	 */
+	if (vdev->reset_works) {
+		bridge = pci_upstream_bridge(pdev);
+		if (bridge && !pci_dev_trylock(bridge))
+			goto out_restore_state;
+		if (pci_dev_trylock(pdev)) {
+			if (!__pci_reset_function_locked(pdev))
+				vdev->needs_reset = false;
+			pci_dev_unlock(pdev);
+		}
+		if (bridge)
+			pci_dev_unlock(bridge);
+	}
+
+out_restore_state:
+	pci_restore_state(pdev);
+}
+
+void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
+{
 	struct pci_dev *pdev = vdev->pdev;
 	struct vfio_pci_dummy_resource *dummy_res, *tmp;
 	struct vfio_pci_ioeventfd *ioeventfd, *ioeventfd_tmp;
@@ -700,54 +751,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 		kfree(dummy_res);
 	}
 
-	vdev->needs_reset = true;
-
 	vfio_pci_zdev_close_device(vdev);
 
-	/*
-	 * If we have saved state, restore it.  If we can reset the device,
-	 * even better.  Resetting with current state seems better than
-	 * nothing, but saving and restoring current state without reset
-	 * is just busy work.
-	 */
-	if (pci_load_and_free_saved_state(pdev, &vdev->pci_saved_state)) {
-		pci_info(pdev, "%s: Couldn't reload saved state\n", __func__);
-
-		if (!vdev->reset_works)
-			goto out;
-
-		pci_save_state(pdev);
-	}
-
-	/*
-	 * Disable INTx and MSI, presumably to avoid spurious interrupts
-	 * during reset.  Stolen from pci_reset_function()
-	 */
-	pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
-
-	/*
-	 * Try to get the locks ourselves to prevent a deadlock. The
-	 * success of this is dependent on being able to lock the device,
-	 * which is not always possible.
-	 * We can not use the "try" reset interface here, which will
-	 * overwrite the previously restored configuration information.
-	 */
-	if (vdev->reset_works) {
-		bridge = pci_upstream_bridge(pdev);
-		if (bridge && !pci_dev_trylock(bridge))
-			goto out_restore_state;
-		if (pci_dev_trylock(pdev)) {
-			if (!__pci_reset_function_locked(pdev))
-				vdev->needs_reset = false;
-			pci_dev_unlock(pdev);
-		}
-		if (bridge)
-			pci_dev_unlock(bridge);
-	}
-
-out_restore_state:
-	pci_restore_state(pdev);
-out:
+	vfio_pci_core_try_reset(vdev);
 	pci_disable_device(pdev);
 
 	vfio_pci_dev_set_try_reset(vdev->vdev.dev_set);
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#2 lore raw

PATCH v5 2/20 vfio: Export various helpers from VFIO

In reply to Vipin Sharma

The upcoming VFIO live update feature needs to access various helper functions for its logic which are not exported by default.

Export these functions and variable for other modules to use them. Remove static from their declaration and add them in include/linux/vfio.h and drivers/vfio/pci/vfio_pci_priv.h header files.

No functional change intended.

---
 drivers/vfio/pci/vfio_pci.c      | 2 +-
 drivers/vfio/pci/vfio_pci_core.c | 6 ++++--
 drivers/vfio/pci/vfio_pci_priv.h | 5 +++++
 drivers/vfio/vfio_main.c         | 3 ++-
 include/linux/vfio.h             | 1 +
 5 files changed, 13 insertions(+), 4 deletions(-)
drivers/vfio/pci/vfio_pci.c +1 -1
index 0c771064c0b8..1fb4b276afe7 100644
@@ -125,7 +125,7 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	return 0;
 }
 
-static const struct vfio_device_ops vfio_pci_ops = {
+const struct vfio_device_ops vfio_pci_ops = {
 	.name		= "vfio-pci",
 	.init		= vfio_pci_core_init_dev,
 	.release	= vfio_pci_core_release_dev,
drivers/vfio/pci/vfio_pci_core.c +4 -2
index 3c8b990ee92f..f31e59e5badb 100644
@@ -623,7 +623,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_enable);
 
-static void vfio_pci_core_try_reset(struct vfio_pci_core_device *vdev)
+void vfio_pci_core_try_reset(struct vfio_pci_core_device *vdev)
 {
 	struct pci_dev *pdev = vdev->pdev;
 	struct pci_dev *bridge;
@@ -674,6 +674,7 @@ static void vfio_pci_core_try_reset(struct vfio_pci_core_device *vdev)
 out_restore_state:
 	pci_restore_state(pdev);
 }
+EXPORT_SYMBOL_GPL(vfio_pci_core_try_reset);
 
 void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 {
@@ -1657,7 +1658,7 @@ ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *bu
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_write);
 
-static void vfio_pci_zap_bars(struct vfio_pci_core_device *vdev)
+void vfio_pci_zap_bars(struct vfio_pci_core_device *vdev)
 {
 	struct vfio_device *core_vdev = &vdev->vdev;
 	loff_t start = VFIO_PCI_INDEX_TO_OFFSET(VFIO_PCI_BAR0_REGION_INDEX);
@@ -1666,6 +1667,7 @@ static void vfio_pci_zap_bars(struct vfio_pci_core_device *vdev)
 
 	unmap_mapping_range(core_vdev->inode->i_mapping, start, len, true);
 }
+EXPORT_SYMBOL_GPL(vfio_pci_zap_bars);
 
 void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev)
 {
drivers/vfio/pci/vfio_pci_priv.h +5 -0
index fca9d0dfac90..85bc1666cb0e 100644
@@ -11,6 +11,8 @@
 /* Cap maximum number of ioeventfds per device (arbitrary) */
 #define VFIO_PCI_IOEVENTFD_MAX		1000
 
+extern const struct vfio_device_ops vfio_pci_ops;
+
 struct vfio_pci_ioeventfd {
 	struct list_head	next;
 	struct vfio_pci_core_device	*vdev;
@@ -73,6 +75,9 @@ u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev);
 void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev,
 					u16 cmd);
 
+void vfio_pci_zap_bars(struct vfio_pci_core_device *vdev);
+void vfio_pci_core_try_reset(struct vfio_pci_core_device *vdev);
+
 #ifdef CONFIG_VFIO_PCI_IGD
 bool vfio_pci_is_intel_display(struct pci_dev *pdev);
 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev);
drivers/vfio/vfio_main.c +2 -1
index 5e0422014523..2437af031169 100644
@@ -1467,7 +1467,7 @@ const struct file_operations vfio_device_fops = {
 #endif
 };
 
-static struct vfio_device *vfio_device_from_file(struct file *file)
+struct vfio_device *vfio_device_from_file(struct file *file)
 {
 	struct vfio_device_file *df = file->private_data;
 
@@ -1475,6 +1475,7 @@ static struct vfio_device *vfio_device_from_file(struct file *file)
 		return NULL;
 	return df->device;
 }
+EXPORT_SYMBOL_GPL(vfio_device_from_file);
 
 /**
  * vfio_file_is_valid - True if the file is valid vfio file
include/linux/vfio.h +1 -0
index 31b826efba00..cf0d941d0410 100644
@@ -378,6 +378,7 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devi
 bool vfio_file_is_valid(struct file *file);
 bool vfio_file_enforced_coherent(struct file *file);
 void vfio_file_set_kvm(struct file *file, struct kvm *kvm);
+struct vfio_device *vfio_device_from_file(struct file *file);
 
 #define VFIO_PIN_PAGES_MAX_ENTRIES	(PAGE_SIZE/sizeof(unsigned long))
 
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#3 lore raw

Re: [PATCH v5 02/20] vfio: Export various helpers from VFIO

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing EXPORT_SYMBOL_GPL for vfio_pci_ops, violating the stated intent to export the variable for…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing EXPORT_SYMBOL_GPL for vfio_pci_ops, violating the stated intent to export the variable for other modules. --

--- Patch [2]: [PATCH v5 02/20] vfio: Export various helpers from VFIO --- commit fcee4889ab47813a22592eb00c453edea425e0f0
Author: Vipin Sharma <[email protected]>

vfio: Export various helpers from VFIO

This commit makes several vfio helpers and the vfio_pci_ops variable globally visible by removing their static declarations and adding them to headers. The stated intent is to export these symbols for use by other modules, such as the upcoming live update feature.

drivers/vfio/pci/vfio_pci.c static int vfio_pci_open_device(struct vfio_device *core_vdev) · line 129

Quoted 11 lines
drivers/vfio/pci/vfio_pci.c +1 -1
index 0c771064c0b84..1fb4b276afe7c 100644
@@ -125,7 +125,7 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	return 0;
 }
 
-static const struct vfio_device_ops vfio_pci_ops = {
+const struct vfio_device_ops vfio_pci_ops = {
 	.name		= "vfio-pci",

[Severity: Low]
The commit message states the intent is to "Export these functions and variable for other modules to use them", but is there a missing EXPORT_SYMBOL_GPL(vfio_pci_ops) here?

The other helpers modified in this patch received an EXPORT_SYMBOL_GPL() tag, but vfio_pci_ops did not. Without it, external modules attempting to reference vfio_pci_ops will fail with unresolved symbol errors during the build.

Quoted 2 lines
drivers/vfio/pci/vfio_pci.c +0 -0
 	.init		= vfio_pci_core_init_dev,
 	.release	= vfio_pci_core_release_dev,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH v5 02/20] vfio: Export various helpers from VFIO

Quoted 32 lines · On Tue, Jul 14, 2026 at 03:30:51PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing EXPORT_SYMBOL_GPL for vfio_pci_ops, violating the stated intent to export the variable for other modules. --

--- Patch [2]: [PATCH v5 02/20] vfio: Export various helpers from VFIO --- commit fcee4889ab47813a22592eb00c453edea425e0f0
Author: Vipin Sharma <[email protected]>

vfio: Export various helpers from VFIO

This commit makes several vfio helpers and the vfio_pci_ops variable globally visible by removing their static declarations and adding them to headers. The stated intent is to export these symbols for use by other modules, such as the upcoming live update feature.

drivers/vfio/pci/vfio_pci.c static int vfio_pci_open_device(struct vfio_device *core_vdev) · line 129

Quoted 11 lines
drivers/vfio/pci/vfio_pci.c +1 -1
index 0c771064c0b84..1fb4b276afe7c 100644
@@ -125,7 +125,7 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev)
 	return 0;
 }
 
-static const struct vfio_device_ops vfio_pci_ops = {
+const struct vfio_device_ops vfio_pci_ops = {
 	.name		= "vfio-pci",

[Severity: Low]
The commit message states the intent is to "Export these functions and variable for other modules to use them", but is there a missing EXPORT_SYMBOL_GPL(vfio_pci_ops) here?

Quoted 4 lines

The other helpers modified in this patch received an EXPORT_SYMBOL_GPL() tag, but vfio_pci_ops did not. Without it, external modules attempting to reference vfio_pci_ops will fail with unresolved symbol errors during the build.

We don't need EXPORT_SYMBOL_GPL() because it is accessed in vfio_pci_liveupdate.c which is compiled in the same module vfio-pci.ko which has the definition.

I could have done better job in the commit message log to explain this. I will fix it in the next version.

Quoted 5 lines
Quoted 2 lines
drivers/vfio/pci/vfio_pci.c +0 -0
 	.init		= vfio_pci_core_init_dev,
 	.release	= vfio_pci_core_release_dev,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH v5 3/20 vfio/pci: Export vfio_pci_dma_buf_move for vfio-pci module

In reply to Vipin Sharma

VFIO Live update during freeze needs to reset the device before handing over to next kernel.

Export DMA revoke function which VFIO Live Update will call in its freeze before reset so that P2P DMA doesn't error out or cause some other issue.

---
 drivers/vfio/pci/vfio_pci_dmabuf.c | 1 +
 1 file changed, 1 insertion(+)
drivers/vfio/pci/vfio_pci_dmabuf.c +1 -0
index c16f460c01d6..2c05fb5a171a 100644
@@ -376,6 +376,7 @@ void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked)
 		fput(priv->dmabuf->file);
 	}
 }
+EXPORT_SYMBOL_GPL(vfio_pci_dma_buf_move);
 
 void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev)
 {
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#6 lore raw

PATCH v5 4/20 liveupdate: Export symbols needed by modules

In reply to Vipin Sharma

Export liveupdate_register_file_handler() and liveupdate_unregister_file_handler(). All of these will be used by vfio-pci in a subsequent commit, which can be built as a module.

---
 kernel/liveupdate/luo_file.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/liveupdate/luo_file.c +2 -0
index c39f96961a85..dd4e26ac34f0 100644
@@ -909,6 +909,7 @@ int liveupdate_register_file_handler(struct liveupdate_file_handler *fh)
 	up_write(&luo_register_rwlock);
 	return err;
 }
+EXPORT_SYMBOL_GPL(liveupdate_register_file_handler);
 
 /**
  * liveupdate_unregister_file_handler - Unregister a liveupdate file handler
@@ -926,3 +927,4 @@ void liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh)
 	luo_flb_unregister_all(fh);
 	list_del(&ACCESS_PRIVATE(fh, list));
 }
+EXPORT_SYMBOL_GPL(liveupdate_unregister_file_handler);
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#7 lore raw

PATCH v5 5/20 vfio/pci: Register a file handler with Live Update Orchestrator

In reply to Vipin Sharma

Register a live update file handler for vfio-pci device files. Add stub implementations of all required callbacks so that registration does not fail (i.e. to avoid breaking git-bisect). Register it with both live update framework and PCI subsystem.

This file handler will be extended in subsequent commits to enable a device bound to vfio-pci to run without interruption while the host is going through a kexec Live Update.

Put this support behind a new Kconfig VFIO_PCI_LIVEUPDATE that is marked experimental and default-disabled until more of the device preservation support has landed in the kernel.

---
 MAINTAINERS                            |  1 +
 drivers/vfio/pci/Kconfig               | 12 ++++
 drivers/vfio/pci/Makefile              |  1 +
 drivers/vfio/pci/vfio_pci.c            | 11 +++-
 drivers/vfio/pci/vfio_pci_liveupdate.c | 80 ++++++++++++++++++++++++++
 drivers/vfio/pci/vfio_pci_priv.h       | 14 +++++
 include/linux/kho/abi/vfio_pci.h       | 28 +++++++++
 7 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c
 create mode 100644 include/linux/kho/abi/vfio_pci.h
MAINTAINERS +1 -0
index 347c435ca404..77a35742de0a 100644
@@ -28329,6 +28329,7 @@ F:	Documentation/ABI/testing/debugfs-vfio
 F:	Documentation/ABI/testing/sysfs-devices-vfio-dev
 F:	Documentation/driver-api/vfio.rst
 F:	drivers/vfio/
+F:	include/linux/kho/abi/vfio_pci.h
 F:	include/linux/vfio.h
 F:	include/linux/vfio_pci_core.h
 F:	include/uapi/linux/vfio.h
drivers/vfio/pci/Kconfig +12 -0
index 296bf01e185e..c12d614fc6c4 100644
@@ -42,6 +42,18 @@ config VFIO_PCI_IGD
 	  and LPC bridge config space.
 
 	  To enable Intel IGD assignment through vfio-pci, say Y.
+
+config VFIO_PCI_LIVEUPDATE
+	bool "VFIO PCI support for Live Update (EXPERIMENTAL)"
+	depends on PCI_LIVEUPDATE
+	help
+	  Support for preserving devices bound to vfio-pci across a Live
+	  Update. This option should only be enabled by developers working on
+	  implementing this support. Once enough support has landed in the
+	  kernel, this option will no longer be marked EXPERIMENTAL.
+
+	  If you don't know what to do here, say N.
+
 endif
 
 config VFIO_PCI_ZDEV_KVM
drivers/vfio/pci/Makefile +1 -0
index 6138f1bf241d..bf296ab1c967 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o
 
 vfio-pci-y := vfio_pci.o
 vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o
+vfio-pci-$(CONFIG_VFIO_PCI_LIVEUPDATE) += vfio_pci_liveupdate.o
 obj-$(CONFIG_VFIO_PCI) += vfio-pci.o
 
 obj-$(CONFIG_MLX5_VFIO_PCI)           += mlx5/
drivers/vfio/pci/vfio_pci.c +10 -1
index 1fb4b276afe7..439d14d79d8f 100644
@@ -264,10 +264,14 @@ static int __init vfio_pci_init(void)
 
 	vfio_pci_core_set_params(nointxmask, is_disable_vga, disable_idle_d3);
 
+	ret = vfio_pci_liveupdate_init();
+	if (ret)
+		return ret;
+
 	/* Register and scan for devices */
 	ret = pci_register_driver(&vfio_pci_driver);
 	if (ret)
-		return ret;
+		goto err_liveupdate_cleanup;
 
 	vfio_pci_fill_ids();
 
@@ -275,12 +279,17 @@ static int __init vfio_pci_init(void)
 		pr_warn("device denylist disabled.\n");
 
 	return 0;
+
+err_liveupdate_cleanup:
+	vfio_pci_liveupdate_cleanup();
+	return ret;
 }
 module_init(vfio_pci_init);
 
 static void __exit vfio_pci_cleanup(void)
 {
 	pci_unregister_driver(&vfio_pci_driver);
+	vfio_pci_liveupdate_cleanup();
 }
 module_exit(vfio_pci_cleanup);
 
drivers/vfio/pci/vfio_pci_liveupdate.c new file +80 -0

80 lines not on this page · raw message

drivers/vfio/pci/vfio_pci_priv.h +14 -0
index 85bc1666cb0e..5d2ad128523d 100644
@@ -142,4 +142,18 @@ static inline void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev,
 }
 #endif
 
+#ifdef CONFIG_VFIO_PCI_LIVEUPDATE
+int __init vfio_pci_liveupdate_init(void);
+void vfio_pci_liveupdate_cleanup(void);
+#else
+static inline int vfio_pci_liveupdate_init(void)
+{
+	return 0;
+}
+
+static inline void vfio_pci_liveupdate_cleanup(void)
+{
+}
+#endif /* CONFIG_VFIO_PCI_LIVEUPDATE */
+
 #endif
include/linux/kho/abi/vfio_pci.h new file +28 -0
new file mode 100644
index 000000000000..67e8199eec59
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Copyright (c) 2026, Google LLC.
+ * Vipin Sharma <[email protected]>
+ * David Matlack <[email protected]>
+ */
+
+#ifndef _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H
+#define _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H
+
+/**
+ * DOC: VFIO PCI Live Update ABI
+ *
+ * VFIO uses the ABI defined below for preserving device files across a kexec
+ * reboot using LUO.
+ *
+ * Device metadata is serialized into memory which is then handed to the next
+ * kernel via KHO.
+ *
+ * This interface is a contract. Any modification to any of the serialization
+ * structs defined here constitutes a breaking change. Such changes require
+ * incrementing the version number in the VFIO_PCI_LUO_FH_COMPATIBLE string.
+ */
+
+#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1"
+
+#endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#8 lore raw

Re: [PATCH v5 05/20] vfio/pci: Register a file handler with Live Update Orchestrator

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The Kconfig option VFIO_PCI_LIVEUPDATE depends on a non-existent configuration symbol…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The Kconfig option VFIO_PCI_LIVEUPDATE depends on a non-existent configuration symbol PCI_LIVEUPDATE.
- [High] Calls to undeclared and undefined functions pci_liveupdate_register_flb() and pci_liveupdate_unregister_flb().
- [High] Masking -EOPNOTSUPP on FLB registration failure leads to a double unregistration of the file handler and potential kernel panic. --

--- Patch [5]: [PATCH v5 05/20] vfio/pci: Register a file handler with Live Update Orchestrator --- commit a3c1a8c69f4b2c27d2e063cca84eb003906e3bbf
Author: Vipin Sharma <[email protected]>

vfio/pci: Register a file handler with Live Update Orchestrator

This commit adds a live update file handler for vfio-pci device files with stub implementations. It registers the handler with the live update framework and PCI subsystem, gated behind a new VFIO_PCI_LIVEUPDATE option.

Quoted 4 lines
drivers/vfio/pci/Kconfig +0 -0
index 296bf01e185ec..c12d614fc6c4a 100644

[ ... ]

drivers/vfio/pci/Kconfig config VFIO_PCI_IGD · line 48

Quoted 8 lines
drivers/vfio/pci/Kconfig +4 -0
@@ -42,6 +42,18 @@ config VFIO_PCI_IGD
 	  and LPC bridge config space.
 
 	  To enable Intel IGD assignment through vfio-pci, say Y.
+
+config VFIO_PCI_LIVEUPDATE
+	bool "VFIO PCI support for Live Update (EXPERIMENTAL)"
+	depends on PCI_LIVEUPDATE

[Severity: High]
Does the PCI_LIVEUPDATE configuration symbol exist anywhere in the kernel tree? It appears this dependency cannot be met, preventing the new VFIO_PCI_LIVEUPDATE option from being selected.

Quoted 2 lines
drivers/vfio/pci/Kconfig +2 -0
+	help
+	  Support for preserving devices bound to vfio-pci across a Live

[ ... ]

Quoted 5 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +0 -0
new file mode 100644
index 0000000000000..803528c9f1b27

[ ... ]

drivers/vfio/pci/vfio_pci_liveupdate.c line 64

Quoted 9 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +9 -0
+int __init vfio_pci_liveupdate_init(void)
+{
+	int ret;
+
+	ret = liveupdate_register_file_handler(&vfio_pci_liveupdate_fh);
+	if (ret)
+		goto err_return;
+
+	ret = pci_liveupdate_register_flb(&vfio_pci_liveupdate_fh);

[Severity: High]
Are pci_liveupdate_register_flb() and pci_liveupdate_unregister_flb() declared in any header or defined in any source file? Building with this configuration enabled might result in implicit declaration compiler errors and fatal linker errors.

drivers/vfio/pci/vfio_pci_liveupdate.c line 73

Quoted 9 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +9 -0
+	if (ret)
+		goto err_unregister;
+
+	return 0;
+
+err_unregister:
+	liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh);
+err_return:
+	return (ret == -EOPNOTSUPP) ? 0 : ret;

[Severity: High]
If pci_liveupdate_register_flb() returns -EOPNOTSUPP, this error path unregisters the file handler but returns 0. Could this lead to a double unregistration when the module is unloaded and vfio_pci_liveupdate_cleanup() is called?

Calling liveupdate_unregister_file_handler() a second time on the already removed list node might cause list corruption and a kernel panic.

Quoted 7 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +7 -0
+}
+
+void vfio_pci_liveupdate_cleanup(void)
+{
+	pci_liveupdate_unregister_flb(&vfio_pci_liveupdate_fh);
+	liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#9 lore raw

Re: [PATCH v5 05/20] vfio/pci: Register a file handler with Live Update Orchestrator

Quoted 24 lines · On Tue, Jul 14, 2026 at 03:28:56PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The Kconfig option VFIO_PCI_LIVEUPDATE depends on a non-existent configuration symbol PCI_LIVEUPDATE.
- [High] Calls to undeclared and undefined functions pci_liveupdate_register_flb() and pci_liveupdate_unregister_flb().
- [High] Masking -EOPNOTSUPP on FLB registration failure leads to a double unregistration of the file handler and potential kernel panic. --

--- Patch [5]: [PATCH v5 05/20] vfio/pci: Register a file handler with Live Update Orchestrator --- commit a3c1a8c69f4b2c27d2e063cca84eb003906e3bbf
Author: Vipin Sharma <[email protected]>

vfio/pci: Register a file handler with Live Update Orchestrator

This commit adds a live update file handler for vfio-pci device files with stub implementations. It registers the handler with the live update framework and PCI subsystem, gated behind a new VFIO_PCI_LIVEUPDATE option.

Quoted 4 lines
drivers/vfio/pci/Kconfig +0 -0
index 296bf01e185ec..c12d614fc6c4a 100644

[ ... ]

Quoted 3 lines
drivers/vfio/pci/Kconfig +0 -0
@@ -42,6 +42,18 @@ config VFIO_PCI_IGD
 	  and LPC bridge config space.
 
Quoted 10 lines

drivers/vfio/pci/Kconfig config VFIO_PCI_IGD · line 48

Quoted 5 lines
drivers/vfio/pci/Kconfig +4 -0
 	  To enable Intel IGD assignment through vfio-pci, say Y.
+
+config VFIO_PCI_LIVEUPDATE
+	bool "VFIO PCI support for Live Update (EXPERIMENTAL)"
+	depends on PCI_LIVEUPDATE

[Severity: High]
Does the PCI_LIVEUPDATE configuration symbol exist anywhere in the kernel tree? It appears this dependency cannot be met, preventing the new VFIO_PCI_LIVEUPDATE option from being selected.

This series is built on top of an in-progress series as explained in the cover letter.
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 10 lines
Quoted 3 lines
drivers/vfio/pci/Kconfig +2 -0
+	help
+	  Support for preserving devices bound to vfio-pci across a Live

[ ... ]

Quoted 5 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +0 -0
new file mode 100644
index 0000000000000..803528c9f1b27

[ ... ]

Quoted 16 lines

drivers/vfio/pci/vfio_pci_liveupdate.c line 64

Quoted 9 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +9 -0
+int __init vfio_pci_liveupdate_init(void)
+{
+	int ret;
+
+	ret = liveupdate_register_file_handler(&vfio_pci_liveupdate_fh);
+	if (ret)
+		goto err_return;
+
+	ret = pci_liveupdate_register_flb(&vfio_pci_liveupdate_fh);

[Severity: High]
Are pci_liveupdate_register_flb() and pci_liveupdate_unregister_flb() declared in any header or defined in any source file? Building with this configuration enabled might result in implicit declaration compiler errors and fatal linker errors.

Available in the dependent series.

Quoted 16 lines

drivers/vfio/pci/vfio_pci_liveupdate.c line 73

Quoted 9 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +9 -0
+	if (ret)
+		goto err_unregister;
+
+	return 0;
+
+err_unregister:
+	liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh);
+err_return:
+	return (ret == -EOPNOTSUPP) ? 0 : ret;

[Severity: High]
If pci_liveupdate_register_flb() returns -EOPNOTSUPP, this error path unregisters the file handler but returns 0. Could this lead to a double unregistration when the module is unloaded and vfio_pci_liveupdate_cleanup() is called?

Quoted 3 lines

Calling liveupdate_unregister_file_handler() a second time on the already removed list node might cause list corruption and a kernel panic.

Yes, this is an issue. I will add the fix in next version. Separately, I will send a patch to make liveupdate_unregister_file_handler() idempotent.

Quoted 10 lines
Quoted 7 lines
drivers/vfio/pci/vfio_pci_liveupdate.c new file +7 -0
+}
+
+void vfio_pci_liveupdate_cleanup(void)
+{
+	pci_liveupdate_unregister_flb(&vfio_pci_liveupdate_fh);
+	liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#10 lore raw

PATCH v5 6/20 vfio/pci: Preserve vfio-pci device files across Live Update

In reply to Vipin Sharma

Implement the Live Update file handler callbacks to preserve a vfio-pci device across a Live Update. Subsequent commits will enable userspace to then retrieve this file after the Live Update.

State about each device is serialized into a new ABI struct, vfio_pci_core_device_ser. The contents of this struct are preserved across the Live Update to the next kernel using a combination of Kexec-Handover (KHO) to preserve the page(s) holding the struct, and the Live Update Orchestrator (LUO) to preserve the physical address of the struct.

For now, the only contents of struct vfio_pci_core_device_ser are the device's PCI segment number and BDF, ensuring the device can be uniquely identified after the Live Update.

Key design notes and constraints:

* Device state before kexec: Userspace is required to disable interrupts on the device and ensure it is in the D0 power state. This ensures the device does not send any interrupts until new handlers are set up by the next kernel.

* Device reset during freeze: The device is reset and its state is restored in the freeze() callback, ensuring the next kernel receives it in a consistent state. Eventually, this will be dropped so the device can be preserved in a running state, but that requires further work in VFIO and the core PCI layer.

* FD usability after freeze: Once the device is frozen, the VFIO device FD becomes unusable (i.e., ioctls and memory accesses will return errors) because the device may have already been reset. If the freeze operation fails, userspace must close the FD and reinitialize the device.

* Lifecycle: LUO holds a reference to this file while it is preserved. Therefore, VFIO is guaranteed that vfio_df_device_last_close() will not be called on this device until userspace has unpreserved the file via LUO.

---
 drivers/vfio/pci/Kconfig               |   2 +-
 drivers/vfio/pci/vfio_pci_config.c     |   3 +
 drivers/vfio/pci/vfio_pci_core.c       |  15 ++
 drivers/vfio/pci/vfio_pci_liveupdate.c | 198 ++++++++++++++++++++++++-
 drivers/vfio/pci/vfio_pci_priv.h       |   9 ++
 include/linux/kho/abi/vfio_pci.h       |  15 ++
 include/linux/vfio_pci_core.h          |   3 +
 7 files changed, 242 insertions(+), 3 deletions(-)
drivers/vfio/pci/Kconfig +1 -1
index c12d614fc6c4..d97c809599fa 100644
@@ -45,7 +45,7 @@ config VFIO_PCI_IGD
 
 config VFIO_PCI_LIVEUPDATE
 	bool "VFIO PCI support for Live Update (EXPERIMENTAL)"
-	depends on PCI_LIVEUPDATE
+	depends on PCI_LIVEUPDATE && VFIO_DEVICE_CDEV
 	help
 	  Support for preserving devices bound to vfio-pci across a Live
 	  Update. This option should only be enabled by developers working on
drivers/vfio/pci/vfio_pci_config.c +3 -0
index a10ed733f0e3..a51805515d30 100644
@@ -406,6 +406,9 @@ bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev)
 	struct pci_dev *pdev = vdev->pdev;
 	u16 cmd = le16_to_cpu(*(__le16 *)&vdev->vconfig[PCI_COMMAND]);
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return false;
+
 	/*
 	 * Memory region cannot be accessed if device power state is D3.
 	 *
drivers/vfio/pci/vfio_pci_core.c +15 -0
index f31e59e5badb..c312b0eaf7d0 100644
@@ -1087,6 +1087,9 @@ int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
 	struct pci_dev *pdev = vdev->pdev;
 	int i, ret;
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+
 	switch (info->index) {
 	case VFIO_PCI_CONFIG_REGION_INDEX:
 		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
@@ -1513,6 +1516,9 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 		container_of(core_vdev, struct vfio_pci_core_device, vdev);
 	void __user *uarg = (void __user *)arg;
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+
 	switch (cmd) {
 	case VFIO_DEVICE_GET_INFO:
 		return vfio_pci_ioctl_get_info(vdev, uarg);
@@ -1567,6 +1573,9 @@ int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
 	struct vfio_pci_core_device *vdev =
 		container_of(device, struct vfio_pci_core_device, vdev);
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+
 	switch (flags & VFIO_DEVICE_FEATURE_MASK) {
 	case VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY:
 		return vfio_pci_core_pm_entry(vdev, flags, arg, argsz);
@@ -1591,6 +1600,9 @@ static ssize_t vfio_pci_rw(struct vfio_pci_core_device *vdev, char __user *buf,
 	unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
 	int ret;
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+
 	if (index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
 		return -EINVAL;
 
@@ -1775,6 +1787,9 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
 	u64 phys_len, req_len, pgoff, req_start;
 	void __iomem *bar_io;
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+
 	index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
 
 	if (index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
drivers/vfio/pci/vfio_pci_liveupdate.c +196 -2

230 lines not on this page · raw message

drivers/vfio/pci/vfio_pci_priv.h +9 -0
index 5d2ad128523d..4b65753e8936 100644
@@ -145,6 +145,11 @@ static inline void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev,
 #ifdef CONFIG_VFIO_PCI_LIVEUPDATE
 int __init vfio_pci_liveupdate_init(void);
 void vfio_pci_liveupdate_cleanup(void);
+static inline bool vfio_pci_dev_is_frozen(struct vfio_pci_core_device *vdev)
+{
+	/* Written in VFIO PCI Liveupdate during freeze() event */
+	return smp_load_acquire(&vdev->liveupdate_frozen);
+}
 #else
 static inline int vfio_pci_liveupdate_init(void)
 {
@@ -154,6 +159,10 @@ static inline int vfio_pci_liveupdate_init(void)
 static inline void vfio_pci_liveupdate_cleanup(void)
 {
 }
+static inline bool vfio_pci_dev_is_frozen(struct vfio_pci_core_device *vdev)
+{
+	return false;
+}
 #endif /* CONFIG_VFIO_PCI_LIVEUPDATE */
 
 #endif
include/linux/kho/abi/vfio_pci.h +15 -0
index 67e8199eec59..229a13ac1e52 100644
@@ -9,6 +9,9 @@
 #ifndef _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H
 #define _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H
 
+#include <linux/compiler.h>
+#include <linux/types.h>
+
 /**
  * DOC: VFIO PCI Live Update ABI
  *
@@ -25,4 +28,16 @@
 
 #define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1"
 
+/**
+ * struct vfio_pci_core_device_ser - Serialized state of a single VFIO PCI
+ * device.
+ *
+ * @domain: The device's PCI domain number (segment).
+ * @bdf: The device's PCI bus, device, and function number.
+ */
+struct vfio_pci_core_device_ser {
+	u32 domain;
+	u16 bdf;
+} __packed;
+
 #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */
include/linux/vfio_pci_core.h +3 -0
index 5fc6ce4dd786..adc5d05456bd 100644
@@ -143,6 +143,9 @@ struct vfio_pci_core_device {
 	struct notifier_block	nb;
 	struct rw_semaphore	memory_lock;
 	struct list_head	dmabufs;
+#ifdef CONFIG_VFIO_PCI_LIVEUPDATE
+	bool			liveupdate_frozen;
+#endif
 };
 
 enum vfio_pci_io_width {
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#11 lore raw

Re: [PATCH v5 06/20] vfio/pci: Preserve vfio-pci device files across Live Update

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Lockless checks of `vfio_pci_dev_is_frozen()` in IOCTL and read/write handlers allow userspace to…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Lockless checks of vfio_pci_dev_is_frozen() in IOCTL and read/write handlers allow userspace to bypass the freeze state, breaking kexec handoff guarantees.
- [Medium] vdev->liveupdate_frozen is never cleared and unfreeze is unimplemented, permanently bricking the VFIO device if a kexec aborts. --

--- Patch [6]: [PATCH v5 06/20] vfio/pci: Preserve vfio-pci device files across Live Update --- commit 03e42ce3ade0f06aa286a1a8cacc4d3f5d2537c0
Author: Vipin Sharma <[email protected]>
vfio/pci: Preserve vfio-pci device files across Live Update

This commit implements the Live Update file handler callbacks to preserve a vfio-pci device across a Live Update. It serializes device state into vfio_pci_core_device_ser and resets the device during the freeze phase.

Quoted 4 lines
drivers/vfio/pci/vfio_pci_core.c +0 -0
index f31e59e5badb4..c312b0eaf7d00 100644

[ ... ]

drivers/vfio/pci/vfio_pci_core.c long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, · line 1521

Quoted 7 lines
drivers/vfio/pci/vfio_pci_core.c +3 -0
@@ -1513,6 +1516,9 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 		container_of(core_vdev, struct vfio_pci_core_device, vdev);
 	void __user *uarg = (void __user *)arg;
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+

[Severity: High]
Can a userspace thread race with the freeze operation here?

If a thread locklessly evaluates vfio_pci_dev_is_frozen() as false and then blocks waiting for vdev->igate or vdev->memory_lock, couldn't vfio_pci_liveupdate_freeze() concurrently acquire those locks, freeze the device, set liveupdate_frozen to true, and release the locks?

The ioctl thread would then wake up, acquire the lock, and modify the frozen device's state.

Quoted 4 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +0 -0
index 803528c9f1b27..e6eb7f6b53d7f 100644

[ ... ]

Quoted 3 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +2 -0
@@ -6,28 +6,221 @@
+static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args)
+{

[ ... ]

drivers/vfio/pci/vfio_pci_liveupdate.c

Quoted 9 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +9 -0
+	/*
+	 * Userspace cannot use the FD correctly now irrespective of liveupdate
+	 * freeze failing or succeeding. They will have to reinitialize the VFIO
+	 * device to continue using it as reset might have loaded default PCI
+	 * state. Disable ioctl, read, write and mmap access to the device.
+	 */
+	smp_store_release(&vdev->liveupdate_frozen, true);
+	return 0;
+}

[Severity: Medium]
Does this permanently brick the VFIO device if a kexec aborts?

The liveupdate_frozen flag is set to true here, but it looks like there is no corresponding clear on device close/open or kexec abort.

Because the unfreeze operation callback in vfio_pci_liveupdate_file_ops is unimplemented, the flag would remain set. Userspace attempting to recover by closing and reopening the FD would continue to receive -EIO until the driver is unbound.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#12 lore raw

Re: [PATCH v5 06/20] vfio/pci: Preserve vfio-pci device files across Live Update

Quoted 30 lines · On Tue, Jul 14, 2026 at 03:36:28PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Lockless checks of vfio_pci_dev_is_frozen() in IOCTL and read/write handlers allow userspace to bypass the freeze state, breaking kexec handoff guarantees.
- [Medium] vdev->liveupdate_frozen is never cleared and unfreeze is unimplemented, permanently bricking the VFIO device if a kexec aborts. --

--- Patch [6]: [PATCH v5 06/20] vfio/pci: Preserve vfio-pci device files across Live Update --- commit 03e42ce3ade0f06aa286a1a8cacc4d3f5d2537c0
Author: Vipin Sharma <[email protected]>
vfio/pci: Preserve vfio-pci device files across Live Update

This commit implements the Live Update file handler callbacks to preserve a vfio-pci device across a Live Update. It serializes device state into vfio_pci_core_device_ser and resets the device during the freeze phase.

Quoted 4 lines
drivers/vfio/pci/vfio_pci_core.c +0 -0
index f31e59e5badb4..c312b0eaf7d00 100644

[ ... ]

drivers/vfio/pci/vfio_pci_core.c long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, · line 1521

Quoted 7 lines
drivers/vfio/pci/vfio_pci_core.c +3 -0
@@ -1513,6 +1516,9 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 		container_of(core_vdev, struct vfio_pci_core_device, vdev);
 	void __user *uarg = (void __user *)arg;
 
+	if (vfio_pci_dev_is_frozen(vdev))
+		return -EIO;
+

[Severity: High]
Can a userspace thread race with the freeze operation here?

Quoted 8 lines

If a thread locklessly evaluates vfio_pci_dev_is_frozen() as false and then blocks waiting for vdev->igate or vdev->memory_lock, couldn't vfio_pci_liveupdate_freeze() concurrently acquire those locks, freeze the device, set liveupdate_frozen to true, and release the locks?

The ioctl thread would then wake up, acquire the lock, and modify the frozen device's state.

Userspace VM and hypervisor is expected to be stopped before initiating Live Update kexec. So, we should not see this issue. However, from correctness point of view this is a valid concern.

Considering, this is a temporary code where device is reset during kexec freeze, I am more inclined to leave it as it is. Future versions will add support for not freezing the device and let it continue DMA, we will remove the restrictions added here.

Quoted 22 lines
Quoted 4 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +0 -0
index 803528c9f1b27..e6eb7f6b53d7f 100644

[ ... ]

Quoted 3 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +2 -0
@@ -6,28 +6,221 @@
+static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args)
+{

[ ... ]

drivers/vfio/pci/vfio_pci_liveupdate.c

Quoted 9 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +9 -0
+	/*
+	 * Userspace cannot use the FD correctly now irrespective of liveupdate
+	 * freeze failing or succeeding. They will have to reinitialize the VFIO
+	 * device to continue using it as reset might have loaded default PCI
+	 * state. Disable ioctl, read, write and mmap access to the device.
+	 */
+	smp_store_release(&vdev->liveupdate_frozen, true);
+	return 0;
+}

[Severity: Medium]
Does this permanently brick the VFIO device if a kexec aborts?

Quoted 7 lines

The liveupdate_frozen flag is set to true here, but it looks like there is no corresponding clear on device close/open or kexec abort.

Because the unfreeze operation callback in vfio_pci_liveupdate_file_ops is unimplemented, the flag would remain set. Userspace attempting to recover by closing and reopening the FD would continue to receive -EIO until the driver is unbound.

Yes, this should be fixed. We should reset the state in unfreeze and when device FD is closed/opened. I will add the fix in next version.

Quoted 3 lines
Signature · 2 lines
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#13 lore raw

Re: [PATCH v5 06/20] vfio/pci: Preserve vfio-pci device files across Live Update

In reply to Vipin Sharma
Quoted 37 lines · Vipin Sharma
drivers/vfio/pci/vfio_pci_liveupdate.c +37 -0
+static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args)
+{
+	struct vfio_device *device = vfio_device_from_file(args->file);
+	struct vfio_pci_core_device *vdev;
+	struct pci_dev *pdev;
+
+	vdev = container_of(device, struct vfio_pci_core_device, vdev);
+	pdev = vdev->pdev;
+
+	guard(mutex)(&device->dev_set->lock);
+	guard(mutex)(&vdev->igate);
+	guard(rwsem_write)(&vdev->memory_lock);
+
+	/*
+	 * Userspace must disable interrupts on the device prior to freeze so
+	 * that the device does not send any interrupts until new interrupt
+	 * handlers have been established by the next kernel.
+	 */
+	if (vdev->irq_type != VFIO_PCI_NUM_IRQS) {
+		pci_err(pdev, "Freeze failed! Interrupts are still enabled.\n");
+		return -EINVAL;
+	}
+
+	if (pdev->current_state != PCI_D0) {
+		pci_err(pdev, "Freeze failed! Device not in D0 state.\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Reset is a temporary measure to provide kernel after kexec a clean
+	 * device while VFIO live update work is under development and not
+	 * fully supported. It will go away once continuous DMA support is
+	 * added to device preservation.
+	 */
+	vfio_pci_zap_bars(vdev);
+	vfio_pci_dma_buf_move(vdev, true);
+	vfio_pci_core_try_reset(vdev);

drivers/vfio/pci/vfio_pci_liveupdate.c line 224

Quoted 10 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +9 -0
+	pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
+	/*
+	 * Userspace cannot use the FD correctly now irrespective of liveupdate
+	 * freeze failing or succeeding. They will have to reinitialize the VFIO
+	 * device to continue using it as reset might have loaded default PCI
+	 * state. Disable ioctl, read, write and mmap access to the device.
+	 */
+	smp_store_release(&vdev->liveupdate_frozen, true);
+	return 0;
 }

I'm seeing the same lockdep splat the David found in v4.
https://lore.kernel.org/all/[email protected]/#t

======================================================
WARNING: possible circular locking dependency detected
7.2.0-dbg-DEV #3 Tainted: G S
------------------------------------------------------
kexec/13355 is trying to acquire lock:
ff3f086c95315d08 (&group->mutex){+.+.}-{4:4}, at: pci_dev_reset_iommu_prepare+0x6e/0x200

but task is already holding lock:
ff3f082de7f399a8 (&vdev->memory_lock){++++}-{4:4}, at: vfio_pci_liveupdate_freeze+0x58/0x100

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #5 (&vdev->memory_lock){++++}-{4:4}:

       down_read+0x3d/0x160
       vfio_pci_mmap_huge_fault+0xb9/0x150
       __do_fault+0x46/0x150
       do_pte_missing+0x21a/0x1000
       handle_mm_fault+0x7f8/0xb60
       do_user_addr_fault+0x476/0x6c0
       exc_page_fault+0x68/0xa0
       asm_exc_page_fault+0x26/0x30

-> #4 (&mm->mmap_lock){++++}-{4:4}:

       __might_fault+0x5e/0x80
       _copy_to_user+0x23/0x60
       perf_read+0x114/0x310
       vfs_read+0xe7/0x360
       ksys_read+0x73/0x100
       do_syscall_64+0x15f/0x4e0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #3 (&cpuctx_mutex){+.+.}-{4:4}:

       __mutex_lock+0x8c/0xd80
       perf_event_ctx_lock_nested+0x15a/0x210
       perf_event_enable+0x18/0xa0
       lockup_detector_online_cpu+0x22/0x30
       cpuhp_invoke_callback+0xfb/0x2c0
       cpuhp_thread_fun+0x164/0x1e0
       smpboot_thread_fn+0x17e/0x280
       kthread+0x10c/0x140
       ret_from_fork+0x16b/0x310
       ret_from_fork_asm+0x1a/0x30

-> #2 (cpuhp_state-up){+.+.}-{0:0}:

       cpuhp_thread_fun+0x95/0x1e0
       smpboot_thread_fn+0x17e/0x280
       kthread+0x10c/0x140
       ret_from_fork+0x16b/0x310
       ret_from_fork_asm+0x1a/0x30

-> #1 (cpu_hotplug_lock){++++}-{0:0}:

       cpus_read_lock+0x3b/0xd0
       __cpuhp_state_add_instance+0x19/0x40
       iova_domain_init_rcaches+0x1ef/0x230
       iommu_setup_dma_ops+0x18a/0x560
       iommu_device_register+0x188/0x220
       intel_iommu_init+0x35a/0x440
       pci_iommu_init+0x16/0x40
       do_one_initcall+0xf5/0x400
       do_initcall_level+0x82/0xa0
       do_initcalls+0x59/0xa0
       kernel_init_freeable+0x152/0x1d0
       kernel_init+0x1a/0x130
       ret_from_fork+0x16b/0x310
       ret_from_fork_asm+0x1a/0x30

-> #0 (&group->mutex){+.+.}-{4:4}:

       __lock_acquire+0x14c8/0x2750
       lock_acquire+0xd3/0x2c0
       __mutex_lock+0x8c/0xd80
       pci_dev_reset_iommu_prepare+0x6e/0x200
       pcie_flr+0x32/0xc0
       __pci_reset_function_locked+0x84/0x120
       vfio_pci_core_try_reset+0xa4/0x110
       vfio_pci_liveupdate_freeze+0x8a/0x100
       luo_file_freeze+0xd1/0x290
       luo_session_serialize+0xa6/0x240
       liveupdate_reboot+0x19/0x30
       kernel_kexec+0x39/0xb0
       __se_sys_reboot+0xfd/0x210
       do_syscall_64+0x15f/0x4e0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &group->mutex --> &mm->mmap_lock --> &vdev->memory_lock

 Possible unsafe locking scenario:
       CPU0                    CPU1
       ----                    ----
  lock(&vdev->memory_lock);
                               lock(&mm->mmap_lock);
                               lock(&vdev->memory_lock);

lock(&group->mutex);

*** DEADLOCK ***

9 locks held by kexec/13355:
#0: ffffffff85a81270 (system_transition_mutex){+.+.}-{4:4}, at: __se_sys_reboot+0xe4/0x210 #1: ffffffff85e1cfa8 (luo_session_serialize_rwsem){++++}-{4:4}, at: luo_session_serialize+0x30/0x240 #2: ffffffff85e1d140 (luo_session_global.outgoing.rwsem){+.+.}-{4:4}, at: luo_session_serialize+0x43/0x240 #3: ff3f082dee702108 (&session->mutex){+.+.}-{4:4}, at: luo_session_serialize+0x99/0x240 #4: ff3f082db51c2588 (&luo_file->mutex){+.+.}-{4:4}, at: luo_file_freeze+0x81/0x290
#5: ff3f082d8af761a8 (&new_dev_set->lock){+.+.}-{4:4}, at: vfio_pci_liveupdate_freeze+0x38/0x100 #6: ff3f082de7f39780 (&vdev->igate){+.+.}-{4:4}, at: vfio_pci_liveupdate_freeze+0x49/0x100 #7: ff3f082de7f399a8 (&vdev->memory_lock){++++}-{4:4}, at: vfio_pci_liveupdate_freeze+0x58/0x100 #8: ff3f086c908911f8 (&dev->mutex){....}-{4:4}, at: pci_dev_trylock+0x25/0x60

stack backtrace:
CPU: 132 UID: 0 PID: 13355 Comm: kexec Tainted: G S                  7.2.0-dbg-DEV #3 PREEMPTLAZY
Tainted: [S]=CPU_OUT_OF_SPEC
Hardware name: Google Izumi/izumi, BIOS 0.20260327.0-0 03/27/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0x54/0x70
 print_circular_bug+0x2e1/0x300
 check_noncircular+0xf9/0x120
 ? __bfs+0x129/0x200
 __lock_acquire+0x14c8/0x2750
 ? __lock_acquire+0x1223/0x2750
 ? check_noncircular+0xa5/0x120
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 lock_acquire+0xd3/0x2c0
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 ? lock_is_held_type+0x76/0x100
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 __mutex_lock+0x8c/0xd80
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 ? lockdep_hardirqs_on_prepare+0x152/0x220
 ? _raw_spin_unlock_irqrestore+0x35/0x50
 pci_dev_reset_iommu_prepare+0x6e/0x200
 pcie_flr+0x32/0xc0
 __pci_reset_function_locked+0x84/0x120
 vfio_pci_core_try_reset+0xa4/0x110
 vfio_pci_liveupdate_freeze+0x8a/0x100
 luo_file_freeze+0xd1/0x290
 luo_session_serialize+0xa6/0x240
 liveupdate_reboot+0x19/0x30
 kernel_kexec+0x39/0xb0
 __se_sys_reboot+0xfd/0x210
 ? check_object+0x1e8/0x390
 ? init_object+0x34/0x110
 ? lock_release+0xf0/0x330
 ? kmem_cache_free+0x1b5/0x520
 ? kmem_cache_free+0x1c9/0x520
 ? _raw_spin_unlock_irqrestore+0x35/0x50
 ? kmem_cache_free+0x1b5/0x520
 ? __x64_sys_close+0x3d/0x80
 ? entry_SYSCALL_64_after_hwframe+0x77/0x7f
 ? entry_SYSCALL_64_after_hwframe+0x77/0x7f
 do_syscall_64+0x15f/0x4e0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f04e7233313
Code: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 89 fa b8 a9 00 00 00 bf ad de e1 fe be 69 19 12 28 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 f7 d8 48 8b 0d eb fb 06 00 64 89 01 48
RSP: 002b:00007ffe7c91b688 EFLAGS: 00000246 ORIG_RAX: 00000000000000a9
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007f04e7233313
RDX: 0000000045584543 RSI: 0000000028121969 RDI: 00000000fee1dead
RBP: 00007ffe7c91b9b0 R08: 000000000000000a R09: 00007f04e72a4ff0
R10: 0000000000000011 R11: 0000000000000246 R12: 0000000000000001
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000002
 </TASK>
#14 lore raw

Re: [PATCH v5 06/20] vfio/pci: Preserve vfio-pci device files across Live Update

Quoted 33 lines · Josh Hilke
Quoted 32 lines · Vipin Sharma
drivers/vfio/pci/vfio_pci_liveupdate.c +32 -0
+static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args)
+{
+	struct vfio_device *device = vfio_device_from_file(args->file);
+	struct vfio_pci_core_device *vdev;
+	struct pci_dev *pdev;
+
+	vdev = container_of(device, struct vfio_pci_core_device, vdev);
+	pdev = vdev->pdev;
+
+	guard(mutex)(&device->dev_set->lock);
+	guard(mutex)(&vdev->igate);
+	guard(rwsem_write)(&vdev->memory_lock);
+
+	/*
+	 * Userspace must disable interrupts on the device prior to freeze so
+	 * that the device does not send any interrupts until new interrupt
+	 * handlers have been established by the next kernel.
+	 */
+	if (vdev->irq_type != VFIO_PCI_NUM_IRQS) {
+		pci_err(pdev, "Freeze failed! Interrupts are still enabled.\n");
+		return -EINVAL;
+	}
+
+	if (pdev->current_state != PCI_D0) {
+		pci_err(pdev, "Freeze failed! Device not in D0 state.\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Reset is a temporary measure to provide kernel after kexec a clean
+	 * device while VFIO live update work is under development and not
+	 * fully supported. It will go away once continuous DMA support is
Quoted 8 lines

drivers/vfio/pci/vfio_pci_liveupdate.c line 214

Quoted 5 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +5 -0
+	 * added to device preservation.
+	 */
+	vfio_pci_zap_bars(vdev);
+	vfio_pci_dma_buf_move(vdev, true);
+	vfio_pci_core_try_reset(vdev);

I'm seeing the same lockdep splat the David found in v4.
https://lore.kernel.org/all/[email protected]/#t

Thanks for reminding this.

Quoted 159 lines

======================================================
WARNING: possible circular locking dependency detected
7.2.0-dbg-DEV #3 Tainted: G S
------------------------------------------------------
kexec/13355 is trying to acquire lock:
ff3f086c95315d08 (&group->mutex){+.+.}-{4:4}, at: pci_dev_reset_iommu_prepare+0x6e/0x200

but task is already holding lock:
ff3f082de7f399a8 (&vdev->memory_lock){++++}-{4:4}, at: vfio_pci_liveupdate_freeze+0x58/0x100

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #5 (&vdev->memory_lock){++++}-{4:4}:

       down_read+0x3d/0x160
       vfio_pci_mmap_huge_fault+0xb9/0x150
       __do_fault+0x46/0x150
       do_pte_missing+0x21a/0x1000
       handle_mm_fault+0x7f8/0xb60
       do_user_addr_fault+0x476/0x6c0
       exc_page_fault+0x68/0xa0
       asm_exc_page_fault+0x26/0x30

-> #4 (&mm->mmap_lock){++++}-{4:4}:

       __might_fault+0x5e/0x80
       _copy_to_user+0x23/0x60
       perf_read+0x114/0x310
       vfs_read+0xe7/0x360
       ksys_read+0x73/0x100
       do_syscall_64+0x15f/0x4e0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #3 (&cpuctx_mutex){+.+.}-{4:4}:

       __mutex_lock+0x8c/0xd80
       perf_event_ctx_lock_nested+0x15a/0x210
       perf_event_enable+0x18/0xa0
       lockup_detector_online_cpu+0x22/0x30
       cpuhp_invoke_callback+0xfb/0x2c0
       cpuhp_thread_fun+0x164/0x1e0
       smpboot_thread_fn+0x17e/0x280
       kthread+0x10c/0x140
       ret_from_fork+0x16b/0x310
       ret_from_fork_asm+0x1a/0x30

-> #2 (cpuhp_state-up){+.+.}-{0:0}:

       cpuhp_thread_fun+0x95/0x1e0
       smpboot_thread_fn+0x17e/0x280
       kthread+0x10c/0x140
       ret_from_fork+0x16b/0x310
       ret_from_fork_asm+0x1a/0x30

-> #1 (cpu_hotplug_lock){++++}-{0:0}:

       cpus_read_lock+0x3b/0xd0
       __cpuhp_state_add_instance+0x19/0x40
       iova_domain_init_rcaches+0x1ef/0x230
       iommu_setup_dma_ops+0x18a/0x560
       iommu_device_register+0x188/0x220
       intel_iommu_init+0x35a/0x440
       pci_iommu_init+0x16/0x40
       do_one_initcall+0xf5/0x400
       do_initcall_level+0x82/0xa0
       do_initcalls+0x59/0xa0
       kernel_init_freeable+0x152/0x1d0
       kernel_init+0x1a/0x130
       ret_from_fork+0x16b/0x310
       ret_from_fork_asm+0x1a/0x30

-> #0 (&group->mutex){+.+.}-{4:4}:

       __lock_acquire+0x14c8/0x2750
       lock_acquire+0xd3/0x2c0
       __mutex_lock+0x8c/0xd80
       pci_dev_reset_iommu_prepare+0x6e/0x200
       pcie_flr+0x32/0xc0
       __pci_reset_function_locked+0x84/0x120
       vfio_pci_core_try_reset+0xa4/0x110
       vfio_pci_liveupdate_freeze+0x8a/0x100
       luo_file_freeze+0xd1/0x290
       luo_session_serialize+0xa6/0x240
       liveupdate_reboot+0x19/0x30
       kernel_kexec+0x39/0xb0
       __se_sys_reboot+0xfd/0x210
       do_syscall_64+0x15f/0x4e0
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  &group->mutex --> &mm->mmap_lock --> &vdev->memory_lock

 Possible unsafe locking scenario:
       CPU0                    CPU1
       ----                    ----
  lock(&vdev->memory_lock);
                               lock(&mm->mmap_lock);
                               lock(&vdev->memory_lock);

lock(&group->mutex);

*** DEADLOCK ***

9 locks held by kexec/13355:
#0: ffffffff85a81270 (system_transition_mutex){+.+.}-{4:4}, at: __se_sys_reboot+0xe4/0x210 #1: ffffffff85e1cfa8 (luo_session_serialize_rwsem){++++}-{4:4}, at: luo_session_serialize+0x30/0x240 #2: ffffffff85e1d140 (luo_session_global.outgoing.rwsem){+.+.}-{4:4}, at: luo_session_serialize+0x43/0x240 #3: ff3f082dee702108 (&session->mutex){+.+.}-{4:4}, at: luo_session_serialize+0x99/0x240 #4: ff3f082db51c2588 (&luo_file->mutex){+.+.}-{4:4}, at: luo_file_freeze+0x81/0x290
#5: ff3f082d8af761a8 (&new_dev_set->lock){+.+.}-{4:4}, at: vfio_pci_liveupdate_freeze+0x38/0x100 #6: ff3f082de7f39780 (&vdev->igate){+.+.}-{4:4}, at: vfio_pci_liveupdate_freeze+0x49/0x100 #7: ff3f082de7f399a8 (&vdev->memory_lock){++++}-{4:4}, at: vfio_pci_liveupdate_freeze+0x58/0x100 #8: ff3f086c908911f8 (&dev->mutex){....}-{4:4}, at: pci_dev_trylock+0x25/0x60

stack backtrace:
CPU: 132 UID: 0 PID: 13355 Comm: kexec Tainted: G S                  7.2.0-dbg-DEV #3 PREEMPTLAZY
Tainted: [S]=CPU_OUT_OF_SPEC
Hardware name: Google Izumi/izumi, BIOS 0.20260327.0-0 03/27/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0x54/0x70
 print_circular_bug+0x2e1/0x300
 check_noncircular+0xf9/0x120
 ? __bfs+0x129/0x200
 __lock_acquire+0x14c8/0x2750
 ? __lock_acquire+0x1223/0x2750
 ? check_noncircular+0xa5/0x120
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 lock_acquire+0xd3/0x2c0
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 ? lock_is_held_type+0x76/0x100
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 __mutex_lock+0x8c/0xd80
 ? pci_dev_reset_iommu_prepare+0x6e/0x200
 ? lockdep_hardirqs_on_prepare+0x152/0x220
 ? _raw_spin_unlock_irqrestore+0x35/0x50
 pci_dev_reset_iommu_prepare+0x6e/0x200
 pcie_flr+0x32/0xc0
 __pci_reset_function_locked+0x84/0x120
 vfio_pci_core_try_reset+0xa4/0x110
 vfio_pci_liveupdate_freeze+0x8a/0x100
 luo_file_freeze+0xd1/0x290
 luo_session_serialize+0xa6/0x240
 liveupdate_reboot+0x19/0x30
 kernel_kexec+0x39/0xb0
 __se_sys_reboot+0xfd/0x210
 ? check_object+0x1e8/0x390
 ? init_object+0x34/0x110
 ? lock_release+0xf0/0x330
 ? kmem_cache_free+0x1b5/0x520
 ? kmem_cache_free+0x1c9/0x520
 ? _raw_spin_unlock_irqrestore+0x35/0x50
 ? kmem_cache_free+0x1b5/0x520
 ? __x64_sys_close+0x3d/0x80
 ? entry_SYSCALL_64_after_hwframe+0x77/0x7f
 ? entry_SYSCALL_64_after_hwframe+0x77/0x7f
 do_syscall_64+0x15f/0x4e0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f04e7233313
Quoted 9 lines
Code: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 89 fa b8 a9 00 00 00 bf ad de e1 fe be 69 19 12 28 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 f7 d8 48 8b 0d eb fb 06 00 64 89 01 48
RSP: 002b:00007ffe7c91b688 EFLAGS: 00000246 ORIG_RAX: 00000000000000a9
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007f04e7233313
RDX: 0000000045584543 RSI: 0000000028121969 RDI: 00000000fee1dead
RBP: 00007ffe7c91b9b0 R08: 000000000000000a R09: 00007f04e72a4ff0
R10: 0000000000000011 R11: 0000000000000246 R12: 0000000000000001
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000002
 </TASK>

This lock chain is slightly different than what David reported in his email on v4.

Current dependency chain for v5:
-> #5 (&vdev->memory_lock){++++}-{4:4}:
-> #4 (&mm->mmap_lock){++++}-{4:4}:
-> #3 (&cpuctx_mutex){+.+.}-{4:4}: // Different
-> #2 (cpuhp_state-up){+.+.}-{0:0}: // Different
-> #1 (cpu_hotplug_lock){++++}-{0:0}:
-> #0 (&group->mutex){+.+.}-{4:4}:

David's dependency chain on v4:
-> #4 (&vdev->memory_lock){++++}-{4:4}:
-> #3 (&mm->mmap_lock){++++}-{4:4}:
-> #2 (&type->i_mutex_dir_key#4){++++}-{4:4}: // Different
-> #1 (cpu_hotplug_lock){++++}-{0:0}:
-> #0 (&group->mutex){+.+.}-{4:4}:

This seems like &group->mutex connects to cpu_hotplug_lock during boot, and cpu_hotplug_lock can connect to &mm->mmap_lock through any subsystems like Perf, VFS, etc.

One thing to note, VFIO has an existing ioctl VFIO_DEVICE_RESET which calls vfio_pci_ioctl_reset() and locks are taken in the same order in that function:

Lock vdev->memory_lock
-> pci_try_reset_function()

    -> pcie_flr()
       -> pci_dev_reset_iommu_prepare()
          -> Try to lock iommu_group->mutex

pci_dev_reset_iommu_prepare() is added in pcie_flr() in the commit f5b16b802174 ("PCI: Suspend iommu function prior to resetting a device"). So, this is relatively a new change and may have not been caught yet.

This is similar to what vfio_pci_liveupdate_freeze() is also doing regarding locks and reset.

I am not 100% this is an actual issue considering group->mutex to cpu_hotplug_lock dependency happens early in boot.

If this is an issue which must be fixed, I think we would have to makea flow like:
1. lock vdev->memory_lock
2. Disable memory in PCI_COMMAND.
3. Unlock vdev->memory_lock
4. Do PCI reset
5. Lock vdev->memory_lock and resume as old flow.

I wrote a test code (with assistance from GEMINI) to trigger lockdep warning in 7.2-rc1 kernel commit without any liveupdate patches and I can reproduce issue on a host having Intel DSA device (8086:0b25). This program mmaps a BAR of a VFIO device and reads it, after that it resets the device.

Expected: Program exits cleanly, without any lockdep warning.
Actual: Lockdep warning is printed similar to above.

--------------------------------------
/*
* vfio_cdev_lockdep_reproducer.c
*
* Standalone reproducer using modern VFIO cdev (/dev/vfio/devices/vfioX)
* and IOMMUFD (/dev/iommu) interfaces to trigger Lockdep circular locking
* dependency between &vdev->memory_lock and &group->mutex on ATS PCI devices. *
* Requirements:
* - Kernel booted with CONFIG_PROVE_LOCKING=y (Lockdep enabled)
* - An ATS-capable PCIe device bound to vfio-pci (e.g., Intel DSA / idxd)
*
* Build:
* gcc -Wall -static vfio_cdev_lockdep_reproducer.c -o vfio_cdev_lockdep_reproducer
*
* Usage:
* sudo ./vfio_cdev_lockdep_reproducer <pci_bdf>
* Example: sudo ./vfio_cdev_lockdep_reproducer 0000:6a:01.0
*/

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/vfio.h>
#include <linux/iommufd.h>

static int find_vfio_cdev_path(const char *bdf, char *cdev_path, size_t size)

{
	struct dirent *entry;
	char dir_path[256];
	DIR *dir;

	snprintf(dir_path, sizeof(dir_path),
		 "/sys/bus/pci/devices/%s/vfio-dev/", bdf);
	dir = opendir(dir_path);
	if (!dir) {
		fprintf(stderr, "[-] Failed to open %s (is %s bound?)\n",
			dir_path, bdf);
		return -1;
	}

	while ((entry = readdir(dir)) != NULL) {
		if (strncmp("vfio", entry->d_name, 4) == 0) {
			snprintf(cdev_path, size, "/dev/vfio/devices/%s",
				 entry->d_name);
			closedir(dir);
			return 0;
		}
	}

	closedir(dir);
	return -1;
}

static int setup_vfio_cdev(const char *bdf, int *out_iommufd,
int *out_device_fd)

{
	struct vfio_device_attach_iommufd_pt attach_args;
	struct vfio_device_bind_iommufd bind_args;
	struct iommu_ioas_alloc ioas_args;
	char cdev_path[4096];
	int iommufd;
	int device_fd;
	uint32_t ioas_id;
	int ret;

	ret = find_vfio_cdev_path(bdf, cdev_path, sizeof(cdev_path));
	if (ret < 0) {
		fprintf(stderr, "[-] Could not find cdev path for %s\n", bdf);
		return -1;
	}

	printf("[*] Found VFIO cdev node: %s\n", cdev_path);

	printf("[*] Opening /dev/iommu (IOMMUFD)...\n");
	iommufd = open("/dev/iommu", O_RDWR);
	if (iommufd < 0) {
		perror("open(/dev/iommu)");
		return -1;
	}

	memset(&ioas_args, 0, sizeof(ioas_args));
	ioas_args.size = sizeof(ioas_args);

	if (ioctl(iommufd, IOMMU_IOAS_ALLOC, &ioas_args) < 0) {
		perror("IOMMU_IOAS_ALLOC");
		close(iommufd);
		return -1;
	}
	ioas_id = ioas_args.out_ioas_id;
	printf("[+] Allocated IOMMUFD IOAS ID = %u\n", ioas_id);

	printf("[*] Opening VFIO cdev device %s...\n", cdev_path);
	device_fd = open(cdev_path, O_RDWR);
	if (device_fd < 0) {
		perror("open(cdev_path)");
		close(iommufd);
		return -1;
	}

	memset(&bind_args, 0, sizeof(bind_args));
	bind_args.argsz = sizeof(bind_args);
	bind_args.flags = 0;
	bind_args.iommufd = iommufd;

	if (ioctl(device_fd, VFIO_DEVICE_BIND_IOMMUFD, &bind_args) < 0) {
		perror("VFIO_DEVICE_BIND_IOMMUFD");
		close(device_fd);
		close(iommufd);
		return -1;
	}
	printf("[+] Bound VFIO device to IOMMUFD (devid = %u)\n",
	       bind_args.out_devid);

	memset(&attach_args, 0, sizeof(attach_args));
	attach_args.argsz = sizeof(attach_args);
	attach_args.flags = 0;
	attach_args.pt_id = ioas_id;

	if (ioctl(device_fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_args) < 0) {
		perror("VFIO_DEVICE_ATTACH_IOMMUFD_PT");
		close(device_fd);
		close(iommufd);
		return -1;
	}
	printf("[+] Attached VFIO device to IOAS ID %u\n", ioas_id);

	*out_iommufd = iommufd;
	*out_device_fd = device_fd;
	return 0;
}

static void exercise_bar_fault(int device_fd)

{
	struct vfio_region_info reg;
	volatile unsigned char dummy;
	bool bar_mmapped;
	void *map;
	int i;

	bar_mmapped = false;

	for (i = VFIO_PCI_BAR0_REGION_INDEX; i <= VFIO_PCI_BAR5_REGION_INDEX; i++) {
		memset(&reg, 0, sizeof(reg));
		reg.argsz = sizeof(reg);
		reg.index = i;

		if (ioctl(device_fd, VFIO_DEVICE_GET_REGION_INFO, &reg) < 0)
			continue;

		if (!(reg.flags & VFIO_REGION_INFO_FLAG_MMAP) || reg.size == 0)
			continue;

		printf("[*] Found BAR%d (0x%llx). mmap()ing...\n",
		       i, (unsigned long long)reg.size);

		map = mmap(NULL, reg.size, PROT_READ | PROT_WRITE,
			   MAP_SHARED, device_fd, reg.offset);
		if (map == MAP_FAILED)
			continue;

		printf("[*] Touching BAR%d to trigger fault...\n", i);
		dummy = *((volatile unsigned char *)map);
		(void)dummy;
		bar_mmapped = true;
		break;
	}

	if (!bar_mmapped) {
		printf("[!] No mmapable BAR found on this device.\n");
		printf("[!] For QEMU, try: -device nvme,serial=1,ats=on\n");
	}
}

int main(int argc, char **argv)

{
	const char *pci_bdf;
	int device_fd;
	int iommufd;
	int ret;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <pci_bdf>\n", argv[0]);
		fprintf(stderr, "Example: %s 0000:6a:01.0\n", argv[0]);
		return EXIT_FAILURE;
	}

	pci_bdf = argv[1];

	ret = setup_vfio_cdev(pci_bdf, &iommufd, &device_fd);
	if (ret < 0)
		return EXIT_FAILURE;

	/*
	 * Step 1: Exercise Page Fault path (mmap_lock -> memory_lock).
	 * Scan BAR0 to BAR5 and mmap the first region supporting mmap().
	 * Touching 1 byte causes page fault via vfio_pci_mmap_huge_fault(),
	 * taking down_read(&vdev->memory_lock).
	 */
	exercise_bar_fault(device_fd);

	/*
	 * Step 2: Trigger VFIO_DEVICE_RESET ioctl.
	 * Takes down_write(&vdev->memory_lock) -> pci_try_reset_function() ->
	 * pci_dev_reset_iommu_prepare(), taking guard(mutex)(&group->mutex).
	 *
	 * Lockdep detects the circular dependency and reports WARNING.
	 */
	printf("[*] Issuing VFIO_DEVICE_RESET ioctl under memory_lock...\n");
	if (ioctl(device_fd, VFIO_DEVICE_RESET) < 0) {
		perror("VFIO_DEVICE_RESET");
	} else {
		printf("[+] VFIO_DEVICE_RESET completed successfully.\n");
	}

	printf("[*] Check 'dmesg' for Lockdep circular dependency report!\n");

	close(device_fd);
	close(iommufd);
	return EXIT_SUCCESS;
}

--------------------------------------

#15 lore raw

PATCH v5 7/20 vfio: Introduce vfio_find_device() helper

In reply to Vipin Sharma

Introduce vfio_find_device() to discover a registered vfio_device from vfio_device_class matching user-provided criteria.

To ensure safe lifecycle handling, vfio_find_device() acquires a registration reference (device->refcount) via vfio_device_try_get_registration() rather than relying solely on device.kref taken in class_find_device(). Holding only kref allows vendor modules to unload while external callers hold device pointers, leading to a kernel panic on release. Callers must release the device via vfio_device_put_registration().

Additionally, move refcount_set() prior to vfio_device_add() in __vfio_register_dev() so device->refcount is initialized before the device is published to class lookups, avoiding registration data races.

On vfio_device_add() failure, the error path drops the initial registration reference and waits for completion to drain any reference taken by a concurrent lookup before returning the error to the driver.

---
 drivers/vfio/vfio_main.c | 64 +++++++++++++++++++++++++++++++++++++---
 include/linux/vfio.h     |  2 ++
 2 files changed, 62 insertions(+), 4 deletions(-)
drivers/vfio/vfio_main.c +60 -4
index 2437af031169..e91fd83dc58d 100644
@@ -13,6 +13,7 @@
 #include <linux/cdev.h>
 #include <linux/compat.h>
 #include <linux/device.h>
+#include <linux/device/class.h>
 #include <linux/fs.h>
 #include <linux/idr.h>
 #include <linux/iommu.h>
@@ -359,17 +360,20 @@ static int __vfio_register_dev(struct vfio_device *device,
 		goto err_out;
 	}
 
-	ret = vfio_device_add(device);
-	if (ret)
-		goto err_out;
-
 	/* Refcounting can't start until the driver calls register */
 	refcount_set(&device->refcount, 1);
 
+	ret = vfio_device_add(device);
+	if (ret)
+		goto err_add;
+
 	vfio_device_group_register(device);
 	vfio_device_debugfs_init(device);
 
 	return 0;
+err_add:
+	vfio_device_put_registration(device);
+	wait_for_completion(&device->comp);
 err_out:
 	vfio_device_remove_group(device);
 	return ret;
@@ -1797,6 +1801,58 @@ int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova, void *data,
 }
 EXPORT_SYMBOL(vfio_dma_rw);
 
+struct vfio_device_match_data {
+	const void *data;
+	device_match_t match;
+};
+
+static int vfio_device_match_fn(struct device *dev, const void *data)
+{
+	struct vfio_device *vdev = container_of(dev, struct vfio_device, device);
+	const struct vfio_device_match_data *mdata = data;
+
+	if (mdata->match(dev, mdata->data)) {
+		if (vfio_device_try_get_registration(vdev))
+			return 1;
+	}
+	return 0;
+}
+
+/**
+ * vfio_find_device - Find a registered VFIO device matching search criteria
+ * @data: Context data passed to the @match function
+ * @match: Device match callback function
+ *
+ * Finds a registered VFIO device in the vfio_device_class matching the search
+ * criteria specified by @match.
+ *
+ * On success, this function acquires a registration reference on the matched
+ * device via vfio_device_try_get_registration(). This pins the device and
+ * prevents its vendor driver module from unloading or unbinding while the
+ * reference is held.
+ *
+ * Return: Pointer to the matching vfio_device on success, or NULL if no
+ * matching device is found. The caller MUST release the acquired registration
+ * reference using vfio_device_put_registration() when finished with the device.
+ */
+struct vfio_device *vfio_find_device(const void *data, device_match_t match)
+{
+	struct vfio_device_match_data mdata = { .data = data, .match = match };
+	struct device *device;
+
+	device = class_find_device(&vfio_device_class, NULL, &mdata, vfio_device_match_fn);
+	if (!device)
+		return NULL;
+
+	/*
+	 * Drop standard kref reference. Caller holds reference from
+	 * vfio_device_try_get_registration().
+	 */
+	put_device(device);
+	return container_of(device, struct vfio_device, device);
+}
+EXPORT_SYMBOL_GPL(vfio_find_device);
+
 /*
  * Module/class support
  */
include/linux/vfio.h +2 -0
index cf0d941d0410..42c3a9ae3a85 100644
@@ -430,4 +430,6 @@ int vfio_virqfd_enable(void *opaque, int (*handler)(void *, void *),
 void vfio_virqfd_disable(struct virqfd **pvirqfd);
 void vfio_virqfd_flush_thread(struct virqfd **pvirqfd);
 
+struct vfio_device *vfio_find_device(const void *data, device_match_t match);
+
 #endif /* VFIO_H */
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#16 lore raw

PATCH v5 8/20 vfio: Refactor vfio_device_fops_cdev_open()

In reply to Vipin Sharma

Refactor vfio_device_fops_cdev_open() to use a static helper vfio_device_cdev_open(). This helper will be used in subsequent patches to support opening the device file during Live Update restore.

No functional change intended.

---
 drivers/vfio/device_cdev.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/vfio/device_cdev.c +15 -9
index 54abf312cf04..2231423fe56d 100644
@@ -16,14 +16,8 @@ void vfio_init_device_cdev(struct vfio_device *device)
 	device->cdev.owner = THIS_MODULE;
 }
 
-/*
- * device access via the fd opened by this function is blocked until
- * .open_device() is called successfully during BIND_IOMMUFD.
- */
-int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)
+static int vfio_device_cdev_open(struct vfio_device *device, struct file *file)
 {
-	struct vfio_device *device = container_of(inode->i_cdev,
-						  struct vfio_device, cdev);
 	struct vfio_device_file *df;
 	int ret;
 
@@ -37,14 +31,14 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)
 		goto err_put_registration;
 	}
 
-	filep->private_data = df;
+	file->private_data = df;
 
 	/*
 	 * Use the pseudo fs inode on the device to link all mmaps
 	 * to the same address space, allowing us to unmap all vmas
 	 * associated to this device using unmap_mapping_range().
 	 */
-	filep->f_mapping = device->inode->i_mapping;
+	file->f_mapping = device->inode->i_mapping;
 
 	return 0;
 
@@ -53,6 +47,18 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)
 	return ret;
 }
 
+/*
+ * device access via the fd opened by this function is blocked until
+ * .open_device() is called successfully during BIND_IOMMUFD.
+ */
+int vfio_device_fops_cdev_open(struct inode *inode, struct file *file)
+{
+	struct vfio_device *device = container_of(inode->i_cdev,
+						  struct vfio_device, cdev);
+
+	return vfio_device_cdev_open(device, file);
+}
+
 static void vfio_df_get_kvm_safe(struct vfio_device_file *df)
 {
 	spin_lock(&df->kvm_ref_lock);
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#17 lore raw

PATCH v5 9/20 vfio: Add API to open cdev device for Live Update restore

In reply to Vipin Sharma

During Live Update restore, VFIO PCI driver needs to recreate the device file context that was preserved before kexec and return it to the user.

Provide an API for VFIO Live Update to get VFIO device file. Use an anonymous inode when creating the file, since the retrieved device file is not opened through any particular cdev inode, and the cdev inode does not matter in practice.

---
 drivers/vfio/device_cdev.c | 39 ++++++++++++++++++++++++++++++++++++--
 include/linux/vfio.h       |  9 +++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)
drivers/vfio/device_cdev.c +37 -2
index 2231423fe56d..970932f22ecb 100644
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) 2023 Intel Corporation.
  */
+#include <linux/anon_inodes.h>
 #include <linux/vfio.h>
 #include <linux/iommufd.h>
 
@@ -16,9 +17,10 @@ void vfio_init_device_cdev(struct vfio_device *device)
 	device->cdev.owner = THIS_MODULE;
 }
 
-static int vfio_device_cdev_open(struct vfio_device *device, struct file *file)
+static int vfio_device_cdev_open(struct vfio_device *device, struct file **filep)
 {
 	struct vfio_device_file *df;
+	struct file *file = *filep;
 	int ret;
 
 	/* Paired with the put in vfio_device_fops_release() */
@@ -31,6 +33,24 @@ static int vfio_device_cdev_open(struct vfio_device *device, struct file *file)
 		goto err_put_registration;
 	}
 
+	/*
+	 * Simulate opening the character device using an anonymous inode. The
+	 * returned file has the same properties as a cdev file (e.g. operations
+	 * are blocked until BIND_IOMMUFD is called).
+	 */
+	if (!file) {
+		file = anon_inode_getfile_fmode("[vfio-device-liveupdate]",
+						&vfio_device_fops, NULL,
+						O_RDWR, FMODE_PREAD | FMODE_PWRITE);
+
+		if (IS_ERR(file)) {
+			ret = PTR_ERR(file);
+			goto err_free_device_file;
+		}
+
+		*filep = file;
+	}
+
 	file->private_data = df;
 
 	/*
@@ -42,11 +62,26 @@ static int vfio_device_cdev_open(struct vfio_device *device, struct file *file)
 
 	return 0;
 
+err_free_device_file:
+	kfree(df);
 err_put_registration:
 	vfio_device_put_registration(device);
 	return ret;
 }
 
+struct file *vfio_device_liveupdate_cdev_open(struct vfio_device *device)
+{
+	struct file *file = NULL;
+	int ret;
+
+	ret = vfio_device_cdev_open(device, &file);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return file;
+}
+EXPORT_SYMBOL_GPL(vfio_device_liveupdate_cdev_open);
+
 /*
  * device access via the fd opened by this function is blocked until
  * .open_device() is called successfully during BIND_IOMMUFD.
@@ -56,7 +91,7 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *file)
 	struct vfio_device *device = container_of(inode->i_cdev,
 						  struct vfio_device, cdev);
 
-	return vfio_device_cdev_open(device, file);
+	return vfio_device_cdev_open(device, &file);
 }
 
 static void vfio_df_get_kvm_safe(struct vfio_device_file *df)
include/linux/vfio.h +9 -0
index 42c3a9ae3a85..b896c64b11da 100644
@@ -430,6 +430,15 @@ int vfio_virqfd_enable(void *opaque, int (*handler)(void *, void *),
 void vfio_virqfd_disable(struct virqfd **pvirqfd);
 void vfio_virqfd_flush_thread(struct virqfd **pvirqfd);
 
+#if IS_ENABLED(CONFIG_VFIO_DEVICE_CDEV)
+struct file *vfio_device_liveupdate_cdev_open(struct vfio_device *device);
+#else
+static inline struct file *vfio_device_liveupdate_cdev_open(struct vfio_device *device)
+{
+	return ERR_PTR(-EOPNOTSUPP);
+}
+#endif /* IS_ENABLED(CONFIG_VFIO_DEVICE_CDEV) */
+
 struct vfio_device *vfio_find_device(const void *data, device_match_t match);
 
 #endif /* VFIO_H */
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#18 lore raw

PATCH v5 10/20 vfio/pci: Retrieve preserved device files after Live Update

In reply to Vipin Sharma

Enable userspace to retrieve preserved VFIO device files from VFIO after a Live Update by implementing the retrieve(), can_finish() and finish() file handler callbacks.

During retrieve, find the VFIO device using the BDF and domain information from the serialized state, and open it using the new vfio_device_liveupdate_cdev_open() API.

Disallow Live Update to finish if userspace hasn't opened the file successfully or any error occurred during retrieve.

---
 drivers/vfio/pci/vfio_pci_liveupdate.c | 64 +++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_liveupdate.c +62 -2
index e6eb7f6b53d7..4baac80d03f0 100644
@@ -39,7 +39,13 @@
  *    preserved, so there is no way for the file to be destroyed or the device
  *    to be unbound from the vfio-pci driver while it is preserved.
  *
- * Retrieving the file after kexec is not yet supported.
+ * After kexec, the preserved VFIO device file can be retrieved from the session
+ * just like any other preserved file::
+ *
+ *   ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg);
+ *   device_fd = arg.fd;
+ *   ...
+ *   ioctl(session_fd, LIVEUPDATE_SESSION_FINISH, ...);
  *
  * Restrictions
  * ============
@@ -93,6 +99,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/errno.h>
+#include <linux/file.h>
 #include <linux/kexec_handover.h>
 #include <linux/kho/abi/vfio_pci.h>
 #include <linux/liveupdate.h>
@@ -223,13 +230,65 @@ static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args)
 	return 0;
 }
 
+static int match_device(struct device *dev, const void *arg)
+{
+	struct vfio_device *device = container_of(dev, struct vfio_device, device);
+	const struct vfio_pci_core_device_ser *ser = arg;
+	struct pci_dev *pdev;
+
+	pdev = dev_is_pci(device->dev) ? to_pci_dev(device->dev) : NULL;
+	if (!pdev)
+		return false;
+
+	return ser->bdf == pci_dev_id(pdev) && ser->domain == pci_domain_nr(pdev->bus);
+}
+
 static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args)
 {
-	return -EOPNOTSUPP;
+	struct vfio_pci_core_device_ser *ser;
+	struct vfio_device *device;
+	struct file *file;
+	int ret = 0;
+
+	ser = phys_to_virt(args->serialized_data);
+
+	device = vfio_find_device(ser, match_device);
+	if (!device)
+		return -ENODEV;
+
+	file = vfio_device_liveupdate_cdev_open(device);
+	if (IS_ERR(file)) {
+		ret = PTR_ERR(file);
+		goto out;
+	}
+
+	args->file = file;
+out:
+	/* Drop the reference from vfio_find_device() */
+	vfio_device_put_registration(device);
+	return ret;
+
+}
+
+
+static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args *args)
+{
+	struct vfio_device *device;
+
+	if (args->retrieve_status <= 0)
+		return false;
+
+	device = vfio_device_from_file(args->file);
+	guard(mutex)(&device->dev_set->lock);
+	return vfio_device_cdev_opened(device);
 }
 
 static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args)
 {
+	struct vfio_device *device = vfio_device_from_file(args->file);
+
+	pci_liveupdate_finish(to_pci_dev(device->dev));
+	kho_restore_free(phys_to_virt(args->serialized_data));
 }
 
 static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = {
@@ -238,6 +297,7 @@ static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = {
 	.unpreserve = vfio_pci_liveupdate_unpreserve,
 	.freeze = vfio_pci_liveupdate_freeze,
 	.retrieve = vfio_pci_liveupdate_retrieve,
+	.can_finish = vfio_pci_liveupdate_can_finish,
 	.finish = vfio_pci_liveupdate_finish,
 	.owner = THIS_MODULE,
 };
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#19 lore raw

Re: [PATCH v5 10/20] vfio/pci: Retrieve preserved device files after Live Update

Quoted 16 lines · Vipin Sharma

static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) {

drivers/vfio/pci/vfio_pci_liveupdate.c +13 -1
-       return -EOPNOTSUPP;
+       struct vfio_pci_core_device_ser *ser;
+       struct vfio_device *device;
+       struct file *file;
+       int ret = 0;
+
+       ser = phys_to_virt(args->serialized_data);
+
+       device = vfio_find_device(ser, match_device);
+       if (!device)
+               return -ENODEV;
+
+       file = vfio_device_liveupdate_cdev_open(device);
+       if (IS_ERR(file)) {

drivers/vfio/pci/vfio_pci_liveupdate.c static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args) · line 270

Quoted 10 lines
drivers/vfio/pci/vfio_pci_liveupdate.c +10 -0
+               ret = PTR_ERR(file);
+               goto out;
+       }
+
+       args->file = file;
+out:
+       /* Drop the reference from vfio_find_device() */
+       vfio_device_put_registration(device);
+       return ret;
+

Remove extra newline after "return ret"

#20 lore raw

PATCH v5 11/20 vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Enforce that files for incoming (preserved by previous kernel) VFIO devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD rather than by opening the corresponding VFIO character device or via VFIO_GROUP_GET_DEVICE_FD.

Both of these methods would result in VFIO initializing the device without access to the preserved state of the device passed by the previous kernel.

---
 drivers/vfio/device_cdev.c             |  8 ++++++++
 drivers/vfio/group.c                   |  9 +++++++++
 drivers/vfio/pci/vfio_pci_liveupdate.c |  6 ++++++
 drivers/vfio/vfio.h                    | 18 ++++++++++++++++++
 4 files changed, 41 insertions(+)
drivers/vfio/device_cdev.c +8 -0
index 970932f22ecb..0050f0fe456b 100644
@@ -49,6 +49,14 @@ static int vfio_device_cdev_open(struct vfio_device *device, struct file **filep
 		}
 
 		*filep = file;
+	} else if (vfio_liveupdate_incoming_is_preserved(device)) {
+		/*
+		 * Since it is live update preserved device, it must be
+		 * retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD instead of
+		 * opening /dev/vfio/devices/vfioX.
+		 */
+		ret = -EBUSY;
+		goto err_free_device_file;
 	}
 
 	file->private_data = df;
drivers/vfio/group.c +9 -0
index b2299e5bc6df..62b4eaabc829 100644
@@ -316,6 +316,15 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
 	if (IS_ERR(device))
 		return PTR_ERR(device);
 
+	/*
+	 * This device was preserved across a Live Update. Accessing it via
+	 * VFIO_GROUP_GET_DEVICE_FD is not allowed.
+	 */
+	if (vfio_liveupdate_incoming_is_preserved(device)) {
+		vfio_device_put_registration(device);
+		return -EBUSY;
+	}
+
 	fd = FD_ADD(O_CLOEXEC, vfio_device_open_file(device));
 	if (fd < 0)
 		vfio_device_put_registration(device);
drivers/vfio/pci/vfio_pci_liveupdate.c +6 -0
index 4baac80d03f0..f0ea37d98696 100644
@@ -47,6 +47,12 @@
  *   ...
  *   ioctl(session_fd, LIVEUPDATE_SESSION_FINISH, ...);
  *
+ * .. note::
+ *    After kexec, if a device was preserved by the previous kernel, attempting
+ *    to open a new file for the device via its character device
+ *    (``/dev/vfio/devices/X``) or via ``VFIO_GROUP_GET_DEVICE_FD`` will fail
+ *    with ``-EBUSY``.
+ *
  * Restrictions
  * ============
  *
drivers/vfio/vfio.h +18 -0
index e4b72e79b7e3..496180950eb6 100644
@@ -11,6 +11,7 @@
 #include <linux/cdev.h>
 #include <linux/module.h>
 #include <linux/vfio.h>
+#include <linux/pci.h>
 
 struct iommufd_ctx;
 struct iommu_group;
@@ -461,4 +462,21 @@ static inline void vfio_device_debugfs_init(struct vfio_device *vdev) { }
 static inline void vfio_device_debugfs_exit(struct vfio_device *vdev) { }
 #endif /* CONFIG_VFIO_DEBUGFS */
 
+#ifdef CONFIG_VFIO_PCI_LIVEUPDATE
+static inline bool vfio_liveupdate_incoming_is_preserved(struct vfio_device *device)
+{
+	struct device *d = device->dev;
+
+	if (dev_is_pci(d))
+		return pci_liveupdate_is_incoming(to_pci_dev(d));
+
+	return false;
+}
+#else
+static inline bool vfio_liveupdate_incoming_is_preserved(struct vfio_device *device)
+{
+	return false;
+}
+#endif /* CONFIG_VFIO_PCI_LIVEUPDATE */
+
 #endif
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#21 lore raw

Re: [PATCH v5 11/20] vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The function `pci_liveupdate_is_incoming()` is called but is neither declared nor defined anywhere…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The function pci_liveupdate_is_incoming() is called but is neither declared nor defined anywhere in the kernel tree. --

--- Patch [11]: [PATCH v5 11/20] vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD --- commit 27d87a41631434a0adb6626f478ee97f35b6c917
Author: David Matlack <[email protected]>

vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD

This commit enforces that incoming VFIO devices preserved by a previous kernel are retrieved using LIVEUPDATE_SESSION_RETRIEVE_FD. It adds checks during device open and group device fd retrieval to return -EBUSY if an attempt is made to bypass the preserved state.

Quoted 4 lines
drivers/vfio/vfio.h +0 -0
index e4b72e79b7e3e..496180950eb6d 100644

[ ... ]

drivers/vfio/vfio.h static inline void vfio_device_debugfs_init(struct vfio_device *vdev) { } · line 471

Quoted 11 lines
drivers/vfio/vfio.h +7 -0
@@ -461,4 +462,21 @@ static inline void vfio_device_debugfs_init(struct vfio_device *vdev) { }
 static inline void vfio_device_debugfs_exit(struct vfio_device *vdev) { }
 #endif /* CONFIG_VFIO_DEBUGFS */
 
+#ifdef CONFIG_VFIO_PCI_LIVEUPDATE
+static inline bool vfio_liveupdate_incoming_is_preserved(struct vfio_device *device)
+{
+	struct device *d = device->dev;
+
+	if (dev_is_pci(d))
+		return pci_liveupdate_is_incoming(to_pci_dev(d));

[Severity: Low]
Does this code compile successfully when CONFIG_VFIO_PCI_LIVEUPDATE is enabled? It appears that pci_liveupdate_is_incoming is neither declared nor defined anywhere in the kernel tree.

Could a prerequisite patch adding this functionality to the PCI subsystem have been left out of this series?

Quoted 3 lines
drivers/vfio/vfio.h +3 -0
+
+	return false;
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#22 lore raw

Re: [PATCH v5 11/20] vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD

Quoted 39 lines · On Tue, Jul 14, 2026 at 03:28:44PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The function pci_liveupdate_is_incoming() is called but is neither declared nor defined anywhere in the kernel tree. --

--- Patch [11]: [PATCH v5 11/20] vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD --- commit 27d87a41631434a0adb6626f478ee97f35b6c917
Author: David Matlack <[email protected]>

vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD

This commit enforces that incoming VFIO devices preserved by a previous kernel are retrieved using LIVEUPDATE_SESSION_RETRIEVE_FD. It adds checks during device open and group device fd retrieval to return -EBUSY if an attempt is made to bypass the preserved state.

Quoted 4 lines
drivers/vfio/vfio.h +0 -0
index e4b72e79b7e3e..496180950eb6d 100644

[ ... ]

drivers/vfio/vfio.h static inline void vfio_device_debugfs_init(struct vfio_device *vdev) { } · line 471

Quoted 11 lines
drivers/vfio/vfio.h +7 -0
@@ -461,4 +462,21 @@ static inline void vfio_device_debugfs_init(struct vfio_device *vdev) { }
 static inline void vfio_device_debugfs_exit(struct vfio_device *vdev) { }
 #endif /* CONFIG_VFIO_DEBUGFS */
 
+#ifdef CONFIG_VFIO_PCI_LIVEUPDATE
+static inline bool vfio_liveupdate_incoming_is_preserved(struct vfio_device *device)
+{
+	struct device *d = device->dev;
+
+	if (dev_is_pci(d))
+		return pci_liveupdate_is_incoming(to_pci_dev(d));

[Severity: Low]
Does this code compile successfully when CONFIG_VFIO_PCI_LIVEUPDATE is enabled? It appears that pci_liveupdate_is_incoming is neither declared nor defined anywhere in the kernel tree.

Quoted 3 lines

Could a prerequisite patch adding this functionality to the PCI subsystem have been left out of this series?

This series is built on top of in-progress PCI Live Update series
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 8 lines
Quoted 3 lines
drivers/vfio/vfio.h +3 -0
+
+	return false;
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#23 lore raw

PATCH v5 12/20 docs: liveupdate: Add documentation for VFIO PCI

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Add documentation for preserving VFIO device files across a Live Update, generated from the kernel-doc comments in the code.

---
 Documentation/core-api/liveupdate.rst         |  1 +
 .../driver-api/vfio_pci_liveupdate.rst        | 23 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 3 files changed, 25 insertions(+)
 create mode 100644 Documentation/driver-api/vfio_pci_liveupdate.rst
Documentation/core-api/liveupdate.rst +1 -0
index 2bce2644eba2..20f1d2e20508 100644
@@ -38,6 +38,7 @@ The following types of file descriptors can be preserved
    :maxdepth: 1
 
    ../mm/memfd_preservation
+   ../driver-api/vfio_pci_liveupdate
 
 Public API
 ==========
Documentation/driver-api/vfio_pci_liveupdate.rst new file +23 -0
new file mode 100644
index 000000000000..1098b84e5ecd
@@ -0,0 +1,23 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+====================================
+VFIO PCI Device Preservation via LUO
+====================================
+
+.. kernel-doc:: drivers/vfio/pci/vfio_pci_liveupdate.c
+   :doc: VFIO PCI Preservation via LUO
+
+VFIO PCI Preservation ABI
+=========================
+
+.. kernel-doc:: include/linux/kho/abi/vfio_pci.h
+   :doc: VFIO PCI Live Update ABI
+
+.. kernel-doc:: include/linux/kho/abi/vfio_pci.h
+   :internal:
+
+See Also
+========
+
+- :doc:`/core-api/liveupdate`
+- :doc:`/core-api/kho/index`
MAINTAINERS +1 -0
index 77a35742de0a..43b3165d1c68 100644
@@ -28328,6 +28328,7 @@ T:	git https://github.com/awilliam/linux-vfio.git
 F:	Documentation/ABI/testing/debugfs-vfio
 F:	Documentation/ABI/testing/sysfs-devices-vfio-dev
 F:	Documentation/driver-api/vfio.rst
+F:	Documentation/driver-api/vfio_pci_liveupdate.rst
 F:	drivers/vfio/
 F:	include/linux/kho/abi/vfio_pci.h
 F:	include/linux/vfio.h
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#24 lore raw

PATCH v5 13/20 vfio: selftests: Build liveupdate library in VFIO selftests

In reply to Vipin Sharma

Import and build liveupdate selftest library in VFIO selftests.

It allows using liveupdate ioctls in VFIO selftests

---
 tools/testing/selftests/vfio/Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/testing/selftests/vfio/Makefile +7 -3
index e6e8cb52ab03..4c8a30f950c4 100644
@@ -21,6 +21,7 @@ TEST_FILES += scripts/setup.sh
 
 include ../lib.mk
 include lib/libvfio.mk
+include ../liveupdate/lib/libliveupdate.mk
 
 CFLAGS += -I$(top_srcdir)/tools/include
 CFLAGS += -MD
@@ -31,14 +32,17 @@ LDFLAGS += -pthread
 
 LDLIBS += -luuid
 
-$(TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBVFIO_O)
-	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBVFIO_O) $(LDLIBS) -o $@
+LIBS_O := $(LIBVFIO_O)
+LIBS_O += $(LIBLIVEUPDATE_O)
+
+$(TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBS_O)
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBS_O) $(LDLIBS) -o $@
 
 TEST_GEN_PROGS_O = $(patsubst %, %.o, $(TEST_GEN_PROGS))
 $(TEST_GEN_PROGS_O): $(OUTPUT)/%.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
-TEST_DEP_FILES = $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBVFIO_O))
+TEST_DEP_FILES = $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBS_O))
 -include $(TEST_DEP_FILES)
 
 EXTRA_CLEAN += $(TEST_GEN_PROGS_O) $(TEST_DEP_FILES)
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#25 lore raw

Re: [PATCH v5 13/20] vfio: selftests: Build liveupdate library in VFIO selftests

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The VFIO selftests Makefile includes a non-existent file `../liveupdate/lib/libliveupdate.mk`…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The VFIO selftests Makefile includes a non-existent file ../liveupdate/lib/libliveupdate.mk, which breaks the build. --

--- Patch [13]: [PATCH v5 13/20] vfio: selftests: Build liveupdate library in VFIO selftests --- commit 8a41a1e6305bdbe73648566ef65764a964e68dbb
Author: Vipin Sharma <[email protected]>

vfio: selftests: Build liveupdate library in VFIO selftests

This commit imports and builds the liveupdate selftest library within the VFIO selftests to allow using liveupdate ioctls.

tools/testing/selftests/vfio/Makefile TEST_FILES += scripts/setup.sh · line 24

Quoted 8 lines
tools/testing/selftests/vfio/Makefile +1 -0
@@ -21,6 +21,7 @@ TEST_FILES += scripts/setup.sh
 
 include ../lib.mk
 include lib/libvfio.mk
+include ../liveupdate/lib/libliveupdate.mk

[Severity: Low]
Does this file exist in the tree? Including this missing file causes a fatal build error when running make in the vfio selftests directory because ../liveupdate/lib/libliveupdate.mk cannot be found. Was the liveupdate library intended to be added in a prerequisite patch that was missed?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#26 lore raw

Re: [PATCH v5 13/20] vfio: selftests: Build liveupdate library in VFIO selftests

Quoted 18 lines · On Tue, Jul 14, 2026 at 03:20:31PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The VFIO selftests Makefile includes a non-existent file ../liveupdate/lib/libliveupdate.mk, which breaks the build. --

--- Patch [13]: [PATCH v5 13/20] vfio: selftests: Build liveupdate library in VFIO selftests --- commit 8a41a1e6305bdbe73648566ef65764a964e68dbb
Author: Vipin Sharma <[email protected]>

vfio: selftests: Build liveupdate library in VFIO selftests

This commit imports and builds the liveupdate selftest library within the VFIO selftests to allow using liveupdate ioctls.

Quoted 5 lines
tools/testing/selftests/vfio/Makefile +0 -0
@@ -21,6 +21,7 @@ TEST_FILES += scripts/setup.sh
 
Quoted 10 lines

tools/testing/selftests/vfio/Makefile TEST_FILES += scripts/setup.sh · line 24

Quoted 3 lines
tools/testing/selftests/vfio/Makefile +1 -0
 include ../lib.mk
 include lib/libvfio.mk
+include ../liveupdate/lib/libliveupdate.mk

[Severity: Low]
Does this file exist in the tree? Including this missing file causes a fatal build error when running make in the vfio selftests directory because ../liveupdate/lib/libliveupdate.mk cannot be found. Was the liveupdate library intended to be added in a prerequisite patch that was missed?

This is series is built on in-progress PCI Live Update series.
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 2 lines
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#27 lore raw

PATCH v5 14/20 vfio: selftests: Add vfio_pci_liveupdate_uapi_test

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Add a selftest to exercise preserving various VFIO files through /dev/liveupdate. Ensure that VFIO cdev device files can be preserved and everything else (group-based device files, group files, and container files) all fail.

---
 tools/testing/selftests/vfio/Makefile         |  1 +
 .../vfio/vfio_pci_liveupdate_uapi_test.c      | 97 +++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c
tools/testing/selftests/vfio/Makefile +1 -0
index 4c8a30f950c4..dc06fddcf855 100644
@@ -13,6 +13,7 @@ TEST_GEN_PROGS += vfio_pci_device_test
 TEST_GEN_PROGS += vfio_pci_device_init_perf_test
 TEST_GEN_PROGS += vfio_pci_driver_test
 TEST_GEN_PROGS += vfio_pci_sriov_uapi_test
+TEST_GEN_PROGS += vfio_pci_liveupdate_uapi_test
 
 TEST_FILES += scripts/cleanup.sh
 TEST_FILES += scripts/lib.sh
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.55.0.795.g602f6c329a-goog
#28 lore raw

Re: [PATCH v5 14/20] vfio: selftests: Add vfio_pci_liveupdate_uapi_test

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The selftest `vfio_pci_liveupdate_uapi_test.c` fails to compile and link due to missing headers…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The selftest vfio_pci_liveupdate_uapi_test.c fails to compile and link due to missing headers, libraries, and undefined functions. --

--- Patch [14]: [PATCH v5 14/20] vfio: selftests: Add vfio_pci_liveupdate_uapi_test --- commit 4ef2d85343eb23f4f743330b67aabe0e09e08f3d
Author: David Matlack <[email protected]>

vfio: selftests: Add vfio_pci_liveupdate_uapi_test

This commit adds a selftest to exercise preserving various VFIO files through /dev/liveupdate. It verifies that VFIO cdev device files can be preserved while group-based device files, group files, and container files fail.

tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c line 3

Quoted 9 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +3 -0
new file mode 100644
index 0000000000000..f81c8ab21db3f
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <libliveupdate.h>

[Severity: Low]
Does this header file exist in the tree? The build fails because <libliveupdate.h> cannot be found.

Additionally, is the Makefile missing an include for ../liveupdate/lib/libliveupdate.mk to ensure the dependencies are properly pulled in for the build?

Quoted 2 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +2 -0
+#include <libvfio.h>
+#include <kselftest_harness.h>

[ ... ]

tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c line 56

Quoted 5 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +5 -0
+TEST_F(vfio_pci_liveupdate_uapi_test, preserve_device)
+{
+	int ret;
+
+	ret = luo_session_preserve_fd(self->session_fd, self->device->fd, 0);

[Severity: Low]
Is this calling a kernel-space function from a user-space selftest?

Looking at the code, luo_session_preserve_fd() appears to be defined in kernel/liveupdate/luo_session.c. Since this is a user-space selftest, calling it here results in an undefined reference during compilation.

Should this be invoking an ioctl directly, or is there a user-space library wrapper intended to be used instead?

Quoted 4 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +4 -0
+
+	/* Preservation should only be supported for VFIO cdev files. */
+	ASSERT_EQ(ret, self->iommu->iommufd ? 0 : -ENOENT);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
#29 lore raw

Re: [PATCH v5 14/20] vfio: selftests: Add vfio_pci_liveupdate_uapi_test

Quoted 29 lines · On Tue, Jul 14, 2026 at 03:44:02PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The selftest vfio_pci_liveupdate_uapi_test.c fails to compile and link due to missing headers, libraries, and undefined functions. --

--- Patch [14]: [PATCH v5 14/20] vfio: selftests: Add vfio_pci_liveupdate_uapi_test --- commit 4ef2d85343eb23f4f743330b67aabe0e09e08f3d
Author: David Matlack <[email protected]>

vfio: selftests: Add vfio_pci_liveupdate_uapi_test

This commit adds a selftest to exercise preserving various VFIO files through /dev/liveupdate. It verifies that VFIO cdev device files can be preserved while group-based device files, group files, and container files fail.

tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c line 3

Quoted 9 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +3 -0
new file mode 100644
index 0000000000000..f81c8ab21db3f
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <libliveupdate.h>

[Severity: Low]
Does this header file exist in the tree? The build fails because <libliveupdate.h> cannot be found.

Quoted 3 lines

Additionally, is the Makefile missing an include for ../liveupdate/lib/libliveupdate.mk to ensure the dependencies are properly pulled in for the build?

This series is built on top of in-progress Live Update series.
https://lore.kernel.org/linux-pci/[email protected]/

Same for the other issue below.

Quoted 29 lines
Quoted 3 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +2 -0
+#include <libvfio.h>
+#include <kselftest_harness.h>

[ ... ]

tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c line 56

Quoted 5 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +5 -0
+TEST_F(vfio_pci_liveupdate_uapi_test, preserve_device)
+{
+	int ret;
+
+	ret = luo_session_preserve_fd(self->session_fd, self->device->fd, 0);

[Severity: Low]
Is this calling a kernel-space function from a user-space selftest?

Looking at the code, luo_session_preserve_fd() appears to be defined in kernel/liveupdate/luo_session.c. Since this is a user-space selftest, calling it here results in an undefined reference during compilation.

Should this be invoking an ioctl directly, or is there a user-space library wrapper intended to be used instead?

Quoted 4 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file +4 -0
+
+	/* Preservation should only be supported for VFIO cdev files. */
+	ASSERT_EQ(ret, self->iommu->iommufd ? 0 : -ENOENT);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
#30 lore raw

PATCH v5 15/20 vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD

In reply to Vipin Sharma

Use the given VFIO cdev FD to initialize vfio_pci_device in VFIO selftests. Add the assertion to make sure that passed cdev FD is not used with legacy VFIO APIs. If VFIO cdev FD is provided then do not open the device instead use the FD for any interaction with the device.

This API will allow writing selftests where VFIO device FD is preserved using liveupdate and retrieved later using liveupdate ioctl after kexec.

---
 .../lib/include/libvfio/vfio_pci_device.h     |  3 +++
 .../selftests/vfio/lib/vfio_pci_device.c      | 25 ++++++++++++++-----
 2 files changed, 22 insertions(+), 6 deletions(-)
tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +3 -0
index 3eabead717bb..66fc29662daa 100644
@@ -40,6 +40,9 @@ struct vfio_pci_device {
 
 struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iommu *iommu);
 void vfio_pci_device_free(struct vfio_pci_device *device);
+struct vfio_pci_device *__vfio_pci_device_init(const char *bdf,
+					       struct iommu *iommu,
+					       int device_fd);
 struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu);
 void vfio_pci_device_cleanup(struct vfio_pci_device *device);
 
tools/testing/selftests/vfio/lib/vfio_pci_device.c +19 -6
index 94dc5fcecbeb..a6e0e7c6e18e 100644
@@ -414,9 +414,13 @@ void vfio_pci_cdev_open(struct vfio_pci_device *device, const char *bdf)
 }
 
 static void vfio_pci_iommufd_setup(struct vfio_pci_device *device,
-				   const char *bdf, const char *vf_token)
+				   const char *bdf, int device_fd,
+				   const char *vf_token)
 {
-	vfio_pci_cdev_open(device, bdf);
+	if (device_fd >= 0)
+		device->fd = device_fd;
+	else
+		vfio_pci_cdev_open(device, bdf);
 	vfio_device_bind_iommufd(device->fd, device->iommu->iommufd, vf_token);
 	vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id);
 }
@@ -440,16 +444,20 @@ void vfio_pci_device_free(struct vfio_pci_device *device)
 	free(device);
 }
 
-struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu)
+struct vfio_pci_device *__vfio_pci_device_init(const char *bdf,
+					       struct iommu *iommu,
+					       int device_fd)
 {
 	struct vfio_pci_device *device;
 
 	device = vfio_pci_device_alloc(bdf, iommu);
 
-	if (iommu->mode->container_path)
+	if (iommu->mode->container_path) {
+		VFIO_ASSERT_EQ(device_fd, -1);
 		vfio_pci_container_setup(device, bdf, NULL);
-	else
-		vfio_pci_iommufd_setup(device, bdf, NULL);
+	} else {
+		vfio_pci_iommufd_setup(device, bdf, device_fd, NULL);
+	}
 
 	vfio_pci_device_setup(device);
 	vfio_pci_driver_probe(device);
@@ -457,6 +465,11 @@ struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iomm
 	return device;
 }
 
+struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu)
+{
+	return __vfio_pci_device_init(bdf, iommu, /*device_fd=*/-1);
+}
+
 void vfio_pci_device_cleanup(struct vfio_pci_device *device)
 {
 	int i;
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#31 lore raw

PATCH v5 16/20 vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Add Makefile support for TEST_GEN_PROGS_EXTENDED targets. These tests are not run by default.

TEST_GEN_PROGS_EXTENDED will be used for Live Update selftests in subsequent commits. These selftests must be run manually because they require the user/runner to perform additional actions, such as kexec, during the test.

---
 tools/testing/selftests/vfio/Makefile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/testing/selftests/vfio/Makefile +7 -5
index dc06fddcf855..591f1a52c310 100644
@@ -36,16 +36,18 @@ LDLIBS += -luuid
 LIBS_O := $(LIBVFIO_O)
 LIBS_O += $(LIBLIVEUPDATE_O)
 
-$(TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBS_O)
+$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBS_O)
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBS_O) $(LDLIBS) -o $@
 
-TEST_GEN_PROGS_O = $(patsubst %, %.o, $(TEST_GEN_PROGS))
-$(TEST_GEN_PROGS_O): $(OUTPUT)/%.o: %.c
+TESTS_O := $(patsubst %, %.o, $(TEST_GEN_PROGS))
+TESTS_O += $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED))
+
+$(TESTS_O): $(OUTPUT)/%.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
-TEST_DEP_FILES = $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBS_O))
+TEST_DEP_FILES = $(patsubst %.o, %.d, $(TESTS_O) $(LIBS_O))
 -include $(TEST_DEP_FILES)
 
-EXTRA_CLEAN += $(TEST_GEN_PROGS_O) $(TEST_DEP_FILES)
+EXTRA_CLEAN += $(TESTS_O) $(TEST_DEP_FILES)
 
 endif
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#32 lore raw

PATCH v5 17/20 vfio: selftests: Add vfio_pci_liveupdate_kexec_test

In reply to Vipin Sharma

Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented.

This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec.

To run this test manually:

 $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
 $ kexec ...   # NOTE: Exact method will be distro-dependent
 $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0

The second call to setup.sh is necessary because preserved devices are not bound to a driver after Live Update. Such devices must be manually bound by userspace after Live Update via driver_override.

This test is considered passing if all commands exit with 0.

---
 tools/testing/selftests/vfio/Makefile         |  4 +
 .../vfio/vfio_pci_liveupdate_kexec_test.c     | 89 +++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c
tools/testing/selftests/vfio/Makefile +4 -0
index 591f1a52c310..a2f0a459e1f4 100644
@@ -15,6 +15,10 @@ TEST_GEN_PROGS += vfio_pci_driver_test
 TEST_GEN_PROGS += vfio_pci_sriov_uapi_test
 TEST_GEN_PROGS += vfio_pci_liveupdate_uapi_test
 
+# This test must be run manually since it requires the user/automation to
+# perform a kexec during the test.
+TEST_GEN_PROGS_EXTENDED += vfio_pci_liveupdate_kexec_test
+
 TEST_FILES += scripts/cleanup.sh
 TEST_FILES += scripts/lib.sh
 TEST_FILES += scripts/run.sh
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.55.0.795.g602f6c329a-goog
#33 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing header and Makefile dependencies for liveupdate library. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing header and Makefile dependencies for liveupdate library.
--

--- Patch [17]: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test --- commit 5f1d9fcb84decd9a67e94d71a492e75ba0113c1b
Author: Vipin Sharma <[email protected]>

vfio: selftests: Add vfio_pci_liveupdate_kexec_test

This commit adds a new selftest to exercise preserving a vfio-pci device across a Live Update. The test verifies that the device file can be preserved before kexec and retrieved afterward.

tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c line 3

Quoted 9 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +3 -0
new file mode 100644
index 0000000000000..15b3e3af91d1e
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <libliveupdate.h>

[Severity: Low]
Does this header file exist in the tree? It looks like this could cause a build failure because libliveupdate.h cannot be found. The other liveupdate selftests appear to rely on luo_test_utils.h or direct ioctl calls instead of a libliveupdate library.

[ ... ]

Quoted 3 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +3 -0
+static void before_kexec(int luo_fd)
+{
+	struct vfio_pci_device *device;

[ ... ]

tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c line 32

Quoted 2 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +2 -0
+	printf("Preserving device in session\n");
+	ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN);

[Severity: Low]
Will this result in a linker error? It seems luo_session_preserve_fd is undefined without the accompanying library implementation. Should this test use direct ioctls or are there missing Makefile dependencies for a library?

[ ... ]

Quoted 3 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +3 -0
+static void after_kexec(int luo_fd, int state_session_fd)
+{
+	struct vfio_pci_device *device;

[ ... ]

tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c line 57

Quoted 2 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +2 -0
+	printf("Retrieving the device FD from LUO\n");
+	device_fd = luo_session_retrieve_fd(session_fd, DEVICE_TOKEN);

[Severity: Low]
Similarly here in after_kexec(), is luo_session_retrieve_fd implemented elsewhere in the test suite? It looks like this will also fail to link.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
#34 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

Quoted 14 lines · On Tue, Jul 14, 2026 at 03:35:26PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing header and Makefile dependencies for liveupdate library.
--

--- Patch [17]: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test --- commit 5f1d9fcb84decd9a67e94d71a492e75ba0113c1b
Author: Vipin Sharma <[email protected]>

vfio: selftests: Add vfio_pci_liveupdate_kexec_test

This commit adds a new selftest to exercise preserving a vfio-pci device across a Live Update. The test verifies that the device file can be preserved before kexec and retrieved afterward.

Quoted 16 lines

tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c line 3

Quoted 9 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +3 -0
new file mode 100644
index 0000000000000..15b3e3af91d1e
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <libliveupdate.h>

[Severity: Low]
Does this header file exist in the tree? It looks like this could cause a build failure because libliveupdate.h cannot be found. The other liveupdate selftests appear to rely on luo_test_utils.h or direct ioctl calls instead of a libliveupdate library.

This series is on top of in-progress PCI Live Update series.
https://lore.kernel.org/linux-pci/[email protected]/

Same for the below issues.

Quoted 33 lines

[ ... ]

Quoted 3 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +3 -0
+static void before_kexec(int luo_fd)
+{
+	struct vfio_pci_device *device;

[ ... ]

tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c line 32

Quoted 2 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +2 -0
+	printf("Preserving device in session\n");
+	ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN);

[Severity: Low]
Will this result in a linker error? It seems luo_session_preserve_fd is undefined without the accompanying library implementation. Should this test use direct ioctls or are there missing Makefile dependencies for a library?

[ ... ]

Quoted 3 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +3 -0
+static void after_kexec(int luo_fd, int state_session_fd)
+{
+	struct vfio_pci_device *device;

[ ... ]

tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c line 57

Quoted 2 lines
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +2 -0
+	printf("Retrieving the device FD from LUO\n");
+	device_fd = luo_session_retrieve_fd(session_fd, DEVICE_TOKEN);

[Severity: Low]
Similarly here in after_kexec(), is luo_session_retrieve_fd implemented elsewhere in the test suite? It looks like this will also fail to link.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
#35 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

In reply to Vipin Sharma
Quoted 6 lines · Vipin Sharma

Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented.

Quoted 7 lines

This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec.

To run this test manually:

  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
# ls /dev
autofs           disk       iommu         mem     rtc0      tty10 tty21  tty32  tty43  tty54  tty8    ttyS18  ttyS29   uinput  vcs6   vcsu4        virtio-ports
block            dma_heap   kmsg          mqueue  sg0       tty11 tty22  tty33  tty44  tty55  tty9    ttyS19  ttyS3    urandom vcsa   vcsu5        vport2p1
bsg              dri        kvm           net     shm       tty12 tty23  tty34  tty45  tty56  ttyS0   ttyS2   ttyS30   usbmon0 vcsa1  vcsu6        vsock
btrfs-control    fd         liveupdate    null    snapshot  tty13 tty24  tty35  tty46  tty57  ttyS1   ttyS20  ttyS31   usbmon1 vcsa2  vda          watchdog
bus              full       log           nvram   snd       tty14 tty25  tty36  tty47  tty58  ttyS10  ttyS21  ttyS4    usbmon2 vcsa3  vda1         watchdog0
cdrom            fuse       loop-control  port    sr0       tty15 tty26  tty37  tty48  tty59  ttyS11  ttyS22  ttyS5    userfaultfd vcsa4  vda2         zero
char             hidraw0    lp0           ppp     stderr    tty16 tty27  tty38  tty49  tty6   ttyS12  ttyS23  ttyS6    vcs vcsa5  vda3         zram0
console          hpet       lp1           ptmx    stdin     tty17 tty28  tty39  tty5   tty60  ttyS13  ttyS24  ttyS7    vcs1  vcsa6  vfio
core             hugepages  lp2           pts     stdout    tty18 tty29  tty4   tty50  tty61  ttyS14  ttyS25  ttyS8    vcs2  vcsu   vga_arbiter
cpu              hwrng      lp3           random  tty       tty19 tty3   tty40  tty51  tty62  ttyS15  ttyS26  ttyS9    vcs3  vcsu1  vhci
cpu_dma_latency  i2c-0      mapper        rfkill  tty0      tty2  tty30  tty41  tty52  tty63  ttyS16  ttyS27  udmabuf  vcs4  vcsu2  vhost-net
cuse             input      mcelog        rtc     tty1      tty20 tty31  tty42  tty53  tty7   ttyS17  ttyS28  uhid     vcs5  vcsu3  vhost-vsock
# tools/testing/selftests/vfio/scripts/setup.sh 0000:00:08.0

+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:08.0/driver_override
+ echo "0000:00:08.0" > /sys/bus/pci/drivers/vfio-pci/bind tools/testing/selftests/vfio/scripts/lib.sh: line 9: echo: write error: Invalid argument    <--- the error is here.

# lspci -vvv -s 0000:00:08.0

00:08.0 Unclassified device [00ff]: Red Hat, Inc. QEMU PCI Test Device
        Subsystem: Red Hat, Inc. QEMU Virtual Machine
        Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
        Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Region 0: Memory at fea1f000 (32-bit, non-prefetchable) [size=4K]
        Region 1: I/O ports at c000 [size=256]

Hi, Vipin

I worked with QEMU PCI Test Device. But the following error occur.

"tools/testing/selftests/vfio/scripts/lib.sh: line 9: echo: write error: Invalid argument"

Is this a known problem?

Thanks

Yanjun.Zhu

Quoted 131 lines
  $ kexec ...   # NOTE: Exact method will be distro-dependent
  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0

The second call to setup.sh is necessary because preserved devices are not bound to a driver after Live Update. Such devices must be manually bound by userspace after Live Update via driver_override.

This test is considered passing if all commands exit with 0.

---
  tools/testing/selftests/vfio/Makefile         |  4 +
  .../vfio/vfio_pci_liveupdate_kexec_test.c     | 89 +++++++++++++++++++
  2 files changed, 93 insertions(+)

create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c

tools/testing/selftests/vfio/Makefile +4 -0
index 591f1a52c310..a2f0a459e1f4 100644
@@ -15,6 +15,10 @@ TEST_GEN_PROGS += vfio_pci_driver_test
  TEST_GEN_PROGS += vfio_pci_sriov_uapi_test
  TEST_GEN_PROGS += vfio_pci_liveupdate_uapi_test
 
+# This test must be run manually since it requires the user/automation to
+# perform a kexec during the test.
+TEST_GEN_PROGS_EXTENDED += vfio_pci_liveupdate_kexec_test
+
  TEST_FILES += scripts/cleanup.sh
  TEST_FILES += scripts/lib.sh
  TEST_FILES += scripts/run.sh
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +89 -0
new file mode 100644
index 000000000000..15b3e3af91d1
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <libliveupdate.h>
+#include <libvfio.h>
+
+static const char *device_bdf;
+
+static char state_session[LIVEUPDATE_SESSION_NAME_LENGTH];
+static char device_session[LIVEUPDATE_SESSION_NAME_LENGTH];
+
+enum {
+	STATE_TOKEN,
+	DEVICE_TOKEN,
+};
+
+static void before_kexec(int luo_fd)
+{
+	struct vfio_pci_device *device;
+	struct iommu *iommu;
+	int session_fd;
+	int ret;
+
+	iommu = iommu_init("iommufd");
+	device = vfio_pci_device_init(device_bdf, iommu);
+
+	create_state_file(luo_fd, state_session, STATE_TOKEN, /*next_stage=*/2);
+
+	session_fd = luo_create_session(luo_fd, device_session);
+	VFIO_ASSERT_GE(session_fd, 0);
+
+	printf("Preserving device in session\n");
+	ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN);
+	VFIO_ASSERT_EQ(ret, 0);
+
+	close(luo_fd);
+	daemonize_and_wait();
+}
+
+static void after_kexec(int luo_fd, int state_session_fd)
+{
+	struct vfio_pci_device *device;
+	struct iommu *iommu;
+	int session_fd;
+	int device_fd;
+	int stage;
+
+	restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage);
+	VFIO_ASSERT_EQ(stage, 2);
+
+	session_fd = luo_retrieve_session(luo_fd, device_session);
+	VFIO_ASSERT_GE(session_fd, 0);
+
+	printf("Finishing the session before retrieving the device (should fail)\n");
+	VFIO_ASSERT_NE(luo_session_finish(session_fd), 0);
+
+	printf("Retrieving the device FD from LUO\n");
+	device_fd = luo_session_retrieve_fd(session_fd, DEVICE_TOKEN);
+	VFIO_ASSERT_GE(device_fd, 0);
+
+	printf("Finishing the session before binding to iommufd (should fail)\n");
+	VFIO_ASSERT_NE(luo_session_finish(session_fd), 0);
+
+	printf("Binding the device to an iommufd and setting it up\n");
+	iommu = iommu_init("iommufd");
+
+	/*
+	 * This will invoke various ioctls on device_fd such as
+	 * VFIO_DEVICE_GET_INFO. So this is a decent sanity test
+	 * that LUO actually handed us back a valid VFIO device
+	 * file and not something else.
+	 */
+	device = __vfio_pci_device_init(device_bdf, iommu, device_fd);
+
+	printf("Finishing the session\n");
+	VFIO_ASSERT_EQ(luo_session_finish(session_fd), 0);
+
+	vfio_pci_device_cleanup(device);
+	iommu_cleanup(iommu);
+}
+
+int main(int argc, char *argv[])
+{
+	device_bdf = vfio_selftests_get_bdf(&argc, argv);
+
+	sprintf(device_session, "device-%s", device_bdf);
+	sprintf(state_session, "state-%s", device_bdf);
+
+	return luo_test(argc, argv, state_session, before_kexec, after_kexec);
+}
Signature · 2 lines
Best Regards,
Yanjun.Zhu
#36 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

Quoted 67 lines · Zhu Yanjun
Quoted 6 lines · Vipin Sharma

Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented.

Quoted 7 lines

This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec.

To run this test manually:

  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
# ls /dev
autofs           disk       iommu         mem     rtc0      tty10 tty21 
tty32  tty43  tty54  tty8    ttyS18  ttyS29   uinput  vcs6   vcsu4       
virtio-ports
block            dma_heap   kmsg          mqueue  sg0       tty11 tty22 
tty33  tty44  tty55  tty9    ttyS19  ttyS3    urandom vcsa   vcsu5       
vport2p1
bsg              dri        kvm           net     shm       tty12 tty23 
tty34  tty45  tty56  ttyS0   ttyS2   ttyS30   usbmon0 vcsa1  vcsu6       
vsock
btrfs-control    fd         liveupdate    null    snapshot  tty13 tty24 
tty35  tty46  tty57  ttyS1   ttyS20  ttyS31   usbmon1 vcsa2  vda         
watchdog
bus              full       log           nvram   snd       tty14 tty25 
tty36  tty47  tty58  ttyS10  ttyS21  ttyS4    usbmon2 vcsa3  vda1       
 watchdog0
cdrom            fuse       loop-control  port    sr0       tty15 tty26 
tty37  tty48  tty59  ttyS11  ttyS22  ttyS5    userfaultfd vcsa4  vda2       
 zero
char             hidraw0    lp0           ppp     stderr    tty16 tty27 
tty38  tty49  tty6   ttyS12  ttyS23  ttyS6    vcs vcsa5  vda3         zram0
console          hpet       lp1           ptmx    stdin     tty17 tty28 
tty39  tty5   tty60  ttyS13  ttyS24  ttyS7    vcs1  vcsa6  vfio
core             hugepages  lp2           pts     stdout    tty18 tty29 
tty4   tty50  tty61  ttyS14  ttyS25  ttyS8    vcs2  vcsu   vga_arbiter
cpu              hwrng      lp3           random  tty       tty19 tty3 
 tty40  tty51  tty62  ttyS15  ttyS26  ttyS9    vcs3  vcsu1  vhci
cpu_dma_latency  i2c-0      mapper        rfkill  tty0      tty2  tty30 
tty41  tty52  tty63  ttyS16  ttyS27  udmabuf  vcs4  vcsu2  vhost-net
cuse             input      mcelog        rtc     tty1      tty20 tty31 
tty42  tty53  tty7   ttyS17  ttyS28  uhid     vcs5  vcsu3  vhost-vsock
# tools/testing/selftests/vfio/scripts/setup.sh 0000:00:08.0

+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:08.0/driver_override
+ echo "0000:00:08.0" > /sys/bus/pci/drivers/vfio-pci/bind tools/testing/selftests/vfio/scripts/lib.sh: line 9: echo: write error:
Invalid argument    <--- the error is here.

# lspci -vvv -s 0000:00:08.0

00:08.0 Unclassified device [00ff]: Red Hat, Inc. QEMU PCI Test Device
        Subsystem: Red Hat, Inc. QEMU Virtual Machine
        Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
        Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Region 0: Memory at fea1f000 (32-bit, non-prefetchable) [size=4K] Region 1: I/O ports at c000 [size=256]

Quoted 9 lines

Hi, Vipin

I worked with QEMU PCI Test Device. But the following error occur.

"tools/testing/selftests/vfio/scripts/lib.sh: line 9: echo: write error:
Invalid argument"

Is this a known problem?

Can you please check if you have passed iommu device in your QEMU command? This is what I pass to my QEMU command

-device intel-iommu,intremap=on,caching-mode=on,device-iotlb=on

Also, add the following to your guest kernel commandline

intel_iommu=on

This should fix the issue you are seeing.

Alternatively, you can also enable noiommu mode in VFIO by executing:

echo Y > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode

This should allow device to be bound to VFIO.

If none of the above approach works can you please share your QEMU command and your guest VM /proc/cmdline.

Thanks
Vipin

#37 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

In reply to Vipin Sharma
Quoted 11 lines · Vipin Sharma

Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented.

This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec.

To run this test manually:

Quoted 7 lines
  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
  $ kexec ...   # NOTE: Exact method will be distro-dependent
  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0

Hi, Vipin

Thanks a lot for your help. I followed your suggestion, vfio-pci setup can work.

The followings are the test result. In the step 3, after kexec, there are some fails. I am not sure if these are known problem or not.

1. Before kexec command

+ modprobe -v vfio-pci
+ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind
+ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
Preserving device in session
Preserving memfd of size 0x40100000 in session
# [STAGE 1] Forking persistent child to hold sessions...
# [STAGE 1] Child PID: 1236. Resources are pinned.
# [STAGE 1] You may now perform kexec reboot.
+ set +x

2. Run kexec command

3. After kexec command

+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind Checking open(/dev/vfio/devices/vfio0) fails  <--- I can confirm that the /dev/vfio/devices/vfio0 exists. But open this failed. Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (vfio_type1_iommu)      <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (vfio_type1v2_iommu).  <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (iommufd_compat_type1)  <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (iommufd_compat_type1v2). <--- fails
Retrieving memfd from LUO
Finishing the session before retrieving the device (should fail) Retrieving the device FD from LUO
Finishing the session before binding to iommufd (should fail) Binding the device to an iommufd and setting it up
Finishing the session

# lspci -vvv -s 0000:00:04.0
00:04.0 Unclassified device [00ff]: Red Hat, Inc. QEMU PCI Test Device
    Subsystem: Red Hat, Inc. QEMU Virtual Machine
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr-
Stepping- SERR- FastB2B- DisINTx+
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort-
<MAbort- >SERR- <PERR- INTx-
    IOMMU group: 16
    Region 0: Memory at fea23000 (32-bit, non-prefetchable) [size=4K]
    Region 1: I/O ports at c000 [size=256]
    Kernel driver in use: vfio-pci

Zhu Yanjun

Quoted 126 lines

The second call to setup.sh is necessary because preserved devices are not bound to a driver after Live Update. Such devices must be manually bound by userspace after Live Update via driver_override.

This test is considered passing if all commands exit with 0.

---
  tools/testing/selftests/vfio/Makefile         |  4 +
  .../vfio/vfio_pci_liveupdate_kexec_test.c     | 89 +++++++++++++++++++
  2 files changed, 93 insertions(+)

create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c

tools/testing/selftests/vfio/Makefile +4 -0
index 591f1a52c310..a2f0a459e1f4 100644
@@ -15,6 +15,10 @@ TEST_GEN_PROGS += vfio_pci_driver_test
  TEST_GEN_PROGS += vfio_pci_sriov_uapi_test
  TEST_GEN_PROGS += vfio_pci_liveupdate_uapi_test
 
+# This test must be run manually since it requires the user/automation to
+# perform a kexec during the test.
+TEST_GEN_PROGS_EXTENDED += vfio_pci_liveupdate_kexec_test
+
  TEST_FILES += scripts/cleanup.sh
  TEST_FILES += scripts/lib.sh
  TEST_FILES += scripts/run.sh
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file +89 -0
new file mode 100644
index 000000000000..15b3e3af91d1
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <libliveupdate.h>
+#include <libvfio.h>
+
+static const char *device_bdf;
+
+static char state_session[LIVEUPDATE_SESSION_NAME_LENGTH];
+static char device_session[LIVEUPDATE_SESSION_NAME_LENGTH];
+
+enum {
+	STATE_TOKEN,
+	DEVICE_TOKEN,
+};
+
+static void before_kexec(int luo_fd)
+{
+	struct vfio_pci_device *device;
+	struct iommu *iommu;
+	int session_fd;
+	int ret;
+
+	iommu = iommu_init("iommufd");
+	device = vfio_pci_device_init(device_bdf, iommu);
+
+	create_state_file(luo_fd, state_session, STATE_TOKEN, /*next_stage=*/2);
+
+	session_fd = luo_create_session(luo_fd, device_session);
+	VFIO_ASSERT_GE(session_fd, 0);
+
+	printf("Preserving device in session\n");
+	ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN);
+	VFIO_ASSERT_EQ(ret, 0);
+
+	close(luo_fd);
+	daemonize_and_wait();
+}
+
+static void after_kexec(int luo_fd, int state_session_fd)
+{
+	struct vfio_pci_device *device;
+	struct iommu *iommu;
+	int session_fd;
+	int device_fd;
+	int stage;
+
+	restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage);
+	VFIO_ASSERT_EQ(stage, 2);
+
+	session_fd = luo_retrieve_session(luo_fd, device_session);
+	VFIO_ASSERT_GE(session_fd, 0);
+
+	printf("Finishing the session before retrieving the device (should fail)\n");
+	VFIO_ASSERT_NE(luo_session_finish(session_fd), 0);
+
+	printf("Retrieving the device FD from LUO\n");
+	device_fd = luo_session_retrieve_fd(session_fd, DEVICE_TOKEN);
+	VFIO_ASSERT_GE(device_fd, 0);
+
+	printf("Finishing the session before binding to iommufd (should fail)\n");
+	VFIO_ASSERT_NE(luo_session_finish(session_fd), 0);
+
+	printf("Binding the device to an iommufd and setting it up\n");
+	iommu = iommu_init("iommufd");
+
+	/*
+	 * This will invoke various ioctls on device_fd such as
+	 * VFIO_DEVICE_GET_INFO. So this is a decent sanity test
+	 * that LUO actually handed us back a valid VFIO device
+	 * file and not something else.
+	 */
+	device = __vfio_pci_device_init(device_bdf, iommu, device_fd);
+
+	printf("Finishing the session\n");
+	VFIO_ASSERT_EQ(luo_session_finish(session_fd), 0);
+
+	vfio_pci_device_cleanup(device);
+	iommu_cleanup(iommu);
+}
+
+int main(int argc, char *argv[])
+{
+	device_bdf = vfio_selftests_get_bdf(&argc, argv);
+
+	sprintf(device_session, "device-%s", device_bdf);
+	sprintf(state_session, "state-%s", device_bdf);
+
+	return luo_test(argc, argv, state_session, before_kexec, after_kexec);
+}
#38 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

Quoted 16 lines · Yanjun.Zhu
Quoted 14 lines · Vipin Sharma

Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented.

This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec.

To run this test manually:

  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
Quoted 8 lines
Quoted 4 lines
  $ kexec ...   # NOTE: Exact method will be distro-dependent
  $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
  $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0

Hi, Vipin

Thanks a lot for your help. I followed your suggestion, vfio-pci setup can work.

I am glad your setup using virsh is working.

Quoted 19 lines

The followings are the test result. In the step 3, after kexec, there are some fails. I am not sure if these are known problem or not.

1. Before kexec command

+ modprobe -v vfio-pci
+ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind
+ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
Preserving device in session
Preserving memfd of size 0x40100000 in session
# [STAGE 1] Forking persistent child to hold sessions...
# [STAGE 1] Child PID: 1236. Resources are pinned.
# [STAGE 1] You may now perform kexec reboot.
+ set +x

Quoted 8 lines

2. Run kexec command

3. After kexec command

+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind Checking open(/dev/vfio/devices/vfio0) fails  <--- I can confirm that the /dev/vfio/devices/vfio0 exists. But open this failed.

This is correct output. Test is verifying that open should fail. If it didn't fail the ntest would have exited with an error. A preserved VFIO FD can only be retrived using Live Update session ioctls and not through usual VFIO dev path.

Quoted 8 lines

Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (vfio_type1_iommu)      <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (vfio_type1v2_iommu).  <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (iommufd_compat_type1)  <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (iommufd_compat_type1v2). <--- fails

These are all correct output. Test is verifying that userspace should not be able to get VFIO device FD only through Live Update session ioctls and nothing else.

Quoted 7 lines

Retrieving memfd from LUO
Finishing the session before retrieving the device (should fail) Retrieving the device FD from LUO
Finishing the session before binding to iommufd (should fail) Binding the device to an iommufd and setting it up Finishing the session

This is shows VFIO FD is successfully retrived by Live Update ioctl.

So, you saw expected output from successful test run. I will change the message getting printed to avoid confusion. I think current way of printing ".... fails" is confusing.

Thanks
Vipin

#39 lore raw

Re: [PATCH v5 17/20] vfio: selftests: Add vfio_pci_liveupdate_kexec_test

Quoted 76 lines · Vipin Sharma
Quoted 15 lines · Yanjun.Zhu
Quoted 14 lines · Vipin Sharma

Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented.

This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec.

To run this test manually:

   $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
   $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
Quoted 8 lines
Quoted 4 lines
   $ kexec ...   # NOTE: Exact method will be distro-dependent
   $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
   $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0

Hi, Vipin

Thanks a lot for your help. I followed your suggestion, vfio-pci setup can work.

I am glad your setup using virsh is working.

Quoted 18 lines

The followings are the test result. In the step 3, after kexec, there are some fails. I am not sure if these are known problem or not.

1. Before kexec command

+ modprobe -v vfio-pci
+ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind
+ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0
Preserving device in session
Preserving memfd of size 0x40100000 in session
# [STAGE 1] Forking persistent child to hold sessions...
# [STAGE 1] Child PID: 1236. Resources are pinned.
# [STAGE 1] You may now perform kexec reboot.
+ set +x

Quoted 8 lines

2. Run kexec command

3. After kexec command

+ echo "vfio-pci" > /sys/bus/pci/devices/0000:00:04.0/driver_override
+ echo "0000:00:04.0" > /sys/bus/pci/drivers/vfio-pci/bind Checking open(/dev/vfio/devices/vfio0) fails  <--- I can confirm that the /dev/vfio/devices/vfio0 exists. But open this failed.

This is correct output. Test is verifying that open should fail. If it didn't fail the ntest would have exited with an error. A preserved VFIO FD can only be retrived using Live Update session ioctls and not through usual VFIO dev path.

Quoted 8 lines

Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (vfio_type1_iommu)      <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (vfio_type1v2_iommu).  <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (iommufd_compat_type1)  <--- fails
Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, "0000:00:04.0") fails (iommufd_compat_type1v2). <--- fails

These are all correct output. Test is verifying that userspace should not be able to get VFIO device FD only through Live Update session ioctls and nothing else.

Quoted 7 lines

Retrieving memfd from LUO
Finishing the session before retrieving the device (should fail) Retrieving the device FD from LUO
Finishing the session before binding to iommufd (should fail) Binding the device to an iommufd and setting it up Finishing the session

Quoted 5 lines

This is shows VFIO FD is successfully retrived by Live Update ioctl.

So, you saw expected output from successful test run. I will change the message getting printed to avoid confusion. I think current way of printing ".... fails" is confusing.

Thanks a lot. I have made tests in KVM. I can get the same test results.

Reviewed-and-tested-by Zhu Yanjun <[email protected]>

Zhu Yanjun

Quoted 3 lines

Thanks
Vipin

Signature · 2 lines
Best Regards,
Yanjun.Zhu
#40 lore raw

PATCH v5 18/20 vfio: selftests: Expose iommu_modes to tests

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Expose the list of iommu_modes to enable tests that want to iterate through all possible iommu modes.

---
 tools/testing/selftests/vfio/lib/include/libvfio/iommu.h | 2 ++
 tools/testing/selftests/vfio/lib/iommu.c                 | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/vfio/lib/include/libvfio/iommu.h +2 -0
index e9a3386a4719..4b9cbe262159 100644
@@ -15,6 +15,8 @@ struct iommu_mode {
 	unsigned long iommu_type;
 };
 
+extern const struct iommu_mode iommu_modes[];
+extern const int nr_iommu_modes;
 extern const char *default_iommu_mode;
 
 struct dma_region {
tools/testing/selftests/vfio/lib/iommu.c +3 -1
index 035dac069d60..95a494f829d2 100644
@@ -23,7 +23,7 @@
 const char *default_iommu_mode = MODE_IOMMUFD;
 
 /* Reminder: Keep in sync with FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(). */
-static const struct iommu_mode iommu_modes[] = {
+const struct iommu_mode iommu_modes[] = {
 	{
 		.name = MODE_VFIO_TYPE1_IOMMU,
 		.container_path = "/dev/vfio/vfio",
@@ -49,6 +49,8 @@ static const struct iommu_mode iommu_modes[] = {
 	},
 };
 
+const int nr_iommu_modes = ARRAY_SIZE(iommu_modes);
+
 static const struct iommu_mode *lookup_iommu_mode(const char *iommu_mode)
 {
 	int i;
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#41 lore raw

PATCH v5 19/20 vfio: selftests: Verify that opening VFIO device fails during Live Update

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Verify that opening a VFIO device through its cdev file and via VFIO_GROUP_GET_DEVICE_FD both fail with -EBUSY if the device was preserved across a Live Update. When a device file is preserved across a Live Update, the file must be retrieved from /dev/liveupdate, not from VFIO directly.

---
 .../vfio/vfio_pci_liveupdate_kexec_test.c     | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c +38 -0
index 15b3e3af91d1..ec3fe8f19502 100644
@@ -36,6 +36,42 @@ static void before_kexec(int luo_fd)
 	daemonize_and_wait();
 }
 
+static void check_open_vfio_device_fails(void)
+{
+	const char *cdev_path = vfio_pci_get_cdev_path(device_bdf);
+	struct vfio_pci_device *device;
+	struct iommu *iommu;
+	int ret, i;
+
+	printf("Checking open(%s) fails\n", cdev_path);
+	ret = open(cdev_path, O_RDWR);
+	VFIO_ASSERT_EQ(ret, -1);
+	VFIO_ASSERT_EQ(errno, EBUSY);
+	free((void *)cdev_path);
+
+	for (i = 0; i < nr_iommu_modes; i++) {
+		if (!iommu_modes[i].container_path)
+			continue;
+
+		iommu = iommu_init(iommu_modes[i].name);
+
+		device = vfio_pci_device_alloc(device_bdf, iommu);
+		vfio_pci_group_setup(device, device_bdf);
+		vfio_container_set_iommu(device);
+
+		printf("Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, \"%s\") fails (%s)\n",
+		       device_bdf, iommu_modes[i].name);
+
+		ret = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, device->bdf);
+		VFIO_ASSERT_EQ(ret, -1);
+		VFIO_ASSERT_EQ(errno, EBUSY);
+
+		close(device->group_fd);
+		free(device);
+		iommu_cleanup(iommu);
+	}
+}
+
 static void after_kexec(int luo_fd, int state_session_fd)
 {
 	struct vfio_pci_device *device;
@@ -44,6 +80,8 @@ static void after_kexec(int luo_fd, int state_session_fd)
 	int device_fd;
 	int stage;
 
+	check_open_vfio_device_fails();
+
 	restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage);
 	VFIO_ASSERT_EQ(stage, 2);
 
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#42 lore raw

Re: [PATCH v5 19/20] vfio: selftests: Verify that opening VFIO device fails during Live Update

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] Test assertion failure due to IOMMU group already being claimed by preserved cdev - [Medium]…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Test assertion failure due to IOMMU group already being claimed by preserved cdev
- [Medium] Test assertion failure due to re-binding already bound preserved cdev
- [Low] Abstraction violation using free() instead of vfio_pci_device_free() --

--- Patch [19]: [PATCH v5 19/20] vfio: selftests: Verify that opening VFIO device fails during Live Update ---
Note: Due to recitation restrictions, this report uses a free-form summary
of the findings rather than quoting the original patch diff.

commit b5a56d527567933e2f5fd3077aed99e8404f21c3
Author: David Matlack <[email protected]>
Subject: vfio: selftests: Verify that opening VFIO device fails during Live Update

This patch verifies that opening a VFIO device through its cdev file and via VFIO_GROUP_GET_DEVICE_FD both fail with -EBUSY if the device was preserved across a Live Update.

[Severity: Medium]
In check_open_vfio_device_fails(), the test loops over legacy modes and calls vfio_pci_group_setup(). Since the device is already opened via cdev before kexec, the group's cdev_device_open_cnt is greater than zero.

Does this cause the group open attempt inside vfio_pci_group_setup() to fail with EBUSY? If so, it looks like this will trigger the VFIO_ASSERT_GE() assertion on the group_fd, which would abort the test before it can even reach the VFIO_GROUP_GET_DEVICE_FD ioctl it is intended to verify.

[Severity: Medium]
In after_kexec(), the test retrieves the preserved device_fd and attempts to initialize it with a newly created iommufd by calling __vfio_pci_device_init(), which then issues the VFIO_DEVICE_BIND_IOMMUFD ioctl.

Because the device_fd is preserved across the Live Update, doesn't it still retain its original binding state and reference to the original iommufd context? It appears this might cause the bind ioctl to return -EINVAL, triggering a fatal VFIO_ASSERT_EQ() in vfio_device_bind_iommufd() and crashing the test.

[Severity: Low]
In check_open_vfio_device_fails(), the code directly calls free(device) on the pointer returned by vfio_pci_device_alloc().

Would it be better to use vfio_pci_device_free() here instead? Even if it only wraps free() currently, using the library's abstraction might help prevent future memory leaks if internal allocations are added later.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
#43 lore raw

Re: [PATCH v5 19/20] vfio: selftests: Verify that opening VFIO device fails during Live Update

Quoted 23 lines · On Tue, Jul 14, 2026 at 03:42:07PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Test assertion failure due to IOMMU group already being claimed by preserved cdev
- [Medium] Test assertion failure due to re-binding already bound preserved cdev
- [Low] Abstraction violation using free() instead of vfio_pci_device_free() --

--- Patch [19]: [PATCH v5 19/20] vfio: selftests: Verify that opening VFIO device fails during Live Update ---
Note: Due to recitation restrictions, this report uses a free-form summary
of the findings rather than quoting the original patch diff.

commit b5a56d527567933e2f5fd3077aed99e8404f21c3
Author: David Matlack <[email protected]>
Subject: vfio: selftests: Verify that opening VFIO device fails during Live Update

This patch verifies that opening a VFIO device through its cdev file and via VFIO_GROUP_GET_DEVICE_FD both fail with -EBUSY if the device was preserved across a Live Update.

[Severity: Medium]
In check_open_vfio_device_fails(), the test loops over legacy modes and calls vfio_pci_group_setup(). Since the device is already opened via cdev before kexec, the group's cdev_device_open_cnt is greater than zero.

Quoted 5 lines

Does this cause the group open attempt inside vfio_pci_group_setup() to fail with EBUSY? If so, it looks like this will trigger the VFIO_ASSERT_GE() assertion on the group_fd, which would abort the test before it can even reach the VFIO_GROUP_GET_DEVICE_FD ioctl it is intended to verify.

Not an issue.

Kernel data structures are initialized after kexec. So, cdev_device_open_cnt will be 0 and vfio_pci_group_setup() will not fail.

Quoted 6 lines

[Severity: Medium]
In after_kexec(), the test retrieves the preserved device_fd and attempts to initialize it with a newly created iommufd by calling __vfio_pci_device_init(), which then issues the VFIO_DEVICE_BIND_IOMMUFD ioctl.

Quoted 6 lines

Because the device_fd is preserved across the Live Update, doesn't it still retain its original binding state and reference to the original iommufd context? It appears this might cause the bind ioctl to return -EINVAL, triggering a fatal VFIO_ASSERT_EQ() in vfio_device_bind_iommufd() and crashing the test.

Not an issue.

We do not have support for iommufd preservation yet it will not retain reference to the original iommufd context.

Quoted 7 lines

[Severity: Low]
In check_open_vfio_device_fails(), the code directly calls free(device) on the pointer returned by vfio_pci_device_alloc().

Would it be better to use vfio_pci_device_free() here instead? Even if it only wraps free() currently, using the library's abstraction might help prevent future memory leaks if internal allocations are added later.

It is not an issue right now. But I do agree we should use vfio_pci_device_free() for future proofing. I will change it.

Quoted 3 lines
Signature · 2 lines
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
#44 lore raw

PATCH v5 20/20 vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

In reply to Vipin Sharma

From: David Matlack <[email protected]>

Add a long-running DMA memcpy operation to vfio_pci_liveupdate_kexec_test so that the device attempts to perform DMAs continuously during the Live Update.

At this point iommufd preservation is not supported and bus mastering is not kept enabled on the device across the kexec, so most of these DMAs will be dropped. However this test ensures that the current device preservation support does not lead to system instability or crashes if the device is active. And once iommufd and bus mastering are preserved, this test can be relaxed to check that the DMA operations completed successfully.

---
 .../vfio/vfio_pci_liveupdate_kexec_test.c     | 129 ++++++++++++++++++
 1 file changed, 129 insertions(+)
tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c +129 -0
index ec3fe8f19502..51b2f24f352c 100644
@@ -1,8 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#include <linux/sizes.h>
+#include <sys/mman.h>
+
 #include <libliveupdate.h>
 #include <libvfio.h>
 
+#define MEMCPY_SIZE SZ_1G
+#define DRIVER_SIZE SZ_1M
+#define MEMFD_SIZE (MEMCPY_SIZE + DRIVER_SIZE)
+
+static struct dma_region memcpy_region;
 static const char *device_bdf;
 
 static char state_session[LIVEUPDATE_SESSION_NAME_LENGTH];
@@ -11,8 +19,89 @@ static char device_session[LIVEUPDATE_SESSION_NAME_LENGTH];
 enum {
 	STATE_TOKEN,
 	DEVICE_TOKEN,
+	MEMFD_TOKEN,
 };
 
+static void dma_memcpy_one(struct vfio_pci_device *device)
+{
+	void *src = memcpy_region.vaddr, *dst;
+	u64 size;
+
+	size = min_t(u64, memcpy_region.size / 2, device->driver.max_memcpy_size);
+	dst = src + size;
+
+	memset(src, 1, size);
+	memset(dst, 0, size);
+
+	printf("Kicking off 1 DMA memcpy operations of size 0x%lx...\n", size);
+	vfio_pci_driver_memcpy(device,
+			       to_iova(device, src),
+			       to_iova(device, dst),
+			       size);
+
+	VFIO_ASSERT_EQ(memcmp(src, dst, size), 0);
+}
+
+static void dma_memcpy_start(struct vfio_pci_device *device)
+{
+	void *src = memcpy_region.vaddr, *dst;
+	u64 count, size;
+
+	size = min_t(u64, memcpy_region.size / 2, device->driver.max_memcpy_size);
+	dst = src + size;
+
+	/*
+	 * Rough Math: If we assume the device will perform memcpy at a rate of
+	 * 30GB/s then 7200GB of transfers will run for about 4 minutes.
+	 */
+	count = (u64)7200 * SZ_1G / size;
+	count = min_t(u64, count, device->driver.max_memcpy_count);
+
+	memset(src, 1, size / 2);
+	memset(dst, 0, size / 2);
+
+	printf("Kicking off %lu DMA memcpy operations of size 0x%lx...\n", count, size);
+	vfio_pci_driver_memcpy_start(device,
+				     to_iova(device, src),
+				     to_iova(device, dst),
+				     size, count);
+}
+
+static void dma_memfd_map(struct vfio_pci_device *device, int fd)
+{
+	void *vaddr;
+
+	vaddr = mmap(NULL, MEMFD_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+	VFIO_ASSERT_NE(vaddr, MAP_FAILED);
+
+	memcpy_region.iova = SZ_4G;
+	memcpy_region.size = MEMCPY_SIZE;
+	memcpy_region.vaddr = vaddr;
+	iommu_map(device->iommu, &memcpy_region);
+
+	device->driver.region.iova = memcpy_region.iova + memcpy_region.size;
+	device->driver.region.size = DRIVER_SIZE;
+	device->driver.region.vaddr = vaddr + memcpy_region.size;
+	iommu_map(device->iommu, &device->driver.region);
+}
+
+static void dma_memfd_setup(struct vfio_pci_device *device, int session_fd)
+{
+	int fd, ret;
+
+	fd = memfd_create("dma-buffer", 0);
+	VFIO_ASSERT_GE(fd, 0);
+
+	ret = fallocate(fd, 0, 0, MEMFD_SIZE);
+	VFIO_ASSERT_EQ(ret, 0);
+
+	printf("Preserving memfd of size 0x%x in session\n", MEMFD_SIZE);
+	ret = luo_session_preserve_fd(session_fd, fd, MEMFD_TOKEN);
+	VFIO_ASSERT_EQ(ret, 0);
+
+	dma_memfd_map(device, fd);
+}
+
 static void before_kexec(int luo_fd)
 {
 	struct vfio_pci_device *device;
@@ -32,6 +121,27 @@ static void before_kexec(int luo_fd)
 	ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN);
 	VFIO_ASSERT_EQ(ret, 0);
 
+	dma_memfd_setup(device, session_fd);
+
+	/*
+	 * If the device has a selftests driver, kick off a long-running DMA
+	 * operation to exercise the device trying to DMA during a Live Update.
+	 * Since iommufd preservation is not supported yet, these DMAs should be
+	 * dropped. So this is just looking to verify that the system does not
+	 * fall over and crash as a result of a busy device being preserved.
+	 */
+	if (device->driver.ops) {
+		vfio_pci_driver_init(device);
+		dma_memcpy_start(device);
+
+		/*
+		 * Disable interrupts on the device or freeze() will fail.
+		 * Unfortunately there isn't a way to easily have a test for
+		 * that here since the check happens during shutdown.
+		 */
+		vfio_pci_msix_disable(device);
+	}
+
 	close(luo_fd);
 	daemonize_and_wait();
 }
@@ -78,6 +188,7 @@ static void after_kexec(int luo_fd, int state_session_fd)
 	struct iommu *iommu;
 	int session_fd;
 	int device_fd;
+	int memfd;
 	int stage;
 
 	check_open_vfio_device_fails();
@@ -88,6 +199,10 @@ static void after_kexec(int luo_fd, int state_session_fd)
 	session_fd = luo_retrieve_session(luo_fd, device_session);
 	VFIO_ASSERT_GE(session_fd, 0);
 
+	printf("Retrieving memfd from LUO\n");
+	memfd = luo_session_retrieve_fd(session_fd, MEMFD_TOKEN);
+	VFIO_ASSERT_GE(memfd, 0);
+
 	printf("Finishing the session before retrieving the device (should fail)\n");
 	VFIO_ASSERT_NE(luo_session_finish(session_fd), 0);
 
@@ -109,9 +224,23 @@ static void after_kexec(int luo_fd, int state_session_fd)
 	 */
 	device = __vfio_pci_device_init(device_bdf, iommu, device_fd);
 
+	dma_memfd_map(device, memfd);
+
 	printf("Finishing the session\n");
 	VFIO_ASSERT_EQ(luo_session_finish(session_fd), 0);
 
+	/*
+	 * Once iommufd preservation is supported and the device is kept fully
+	 * running across the Live Update, this should wait for the long-
+	 * running DMA memcpy operation kicked off in before_kexec() to
+	 * complete. But for now we expect the device to be reset so just
+	 * trigger a single memcpy to make sure it's still functional.
+	 */
+	if (device->driver.ops) {
+		vfio_pci_driver_init(device);
+		dma_memcpy_one(device);
+	}
+
 	vfio_pci_device_cleanup(device);
 	iommu_cleanup(iommu);
 }
Signature · 1 line
2.55.0.795.g602f6c329a-goog
#45 lore raw

Re: [PATCH v5 20/20] vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Partial initialization of DMA buffers in dma_memcpy_start(). --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Partial initialization of DMA buffers in dma_memcpy_start().
--

--- Patch [20]: [PATCH v5 20/20] vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test ---
Note: Due to system recitation restrictions, this report does not use the standard inline diff quoting format. The findings are instead summarized below without quoting the original patch code.

commit 123ec8cfeb386e8660107c771eabe7ddc5cba029
Author: David Matlack <[email protected]>

vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

This commit adds a long-running DMA memcpy operation to the VFIO PCI live update kexec test. It ensures that active device DMAs during a live update do not cause system instability, even though the DMAs are currently expected to be dropped.

[Severity: Medium]
In tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c, looking at the dma_memcpy_start() function, the buffer initialization seems incomplete.

The code calculates the transfer size and sets the destination pointer, but then calls memset() on the source and destination buffers using 'size / 2' instead of 'size'. Immediately after, vfio_pci_driver_memcpy_start() is kicked off using the full 'size'.

Does this code unintentionally leave the second half of the DMA buffers uninitialized? While the test does not currently verify the transferred data since iommufd preservation is unsupported, will this partial initialization cause false positives or negatives once the test is expanded to validate the completed DMA operations?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
#46 lore raw

Re: [PATCH v5 20/20] vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

Quoted 26 lines · On Tue, Jul 14, 2026 at 03:37:40PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Partial initialization of DMA buffers in dma_memcpy_start().
--

--- Patch [20]: [PATCH v5 20/20] vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test ---
Note: Due to system recitation restrictions, this report does not use the standard inline diff quoting format. The findings are instead summarized below without quoting the original patch code.

commit 123ec8cfeb386e8660107c771eabe7ddc5cba029
Author: David Matlack <[email protected]>

vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

This commit adds a long-running DMA memcpy operation to the VFIO PCI live update kexec test. It ensures that active device DMAs during a live update do not cause system instability, even though the DMAs are currently expected to be dropped.

[Severity: Medium]
In tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c, looking at the dma_memcpy_start() function, the buffer initialization seems incomplete.

The code calculates the transfer size and sets the destination pointer, but then calls memset() on the source and destination buffers using 'size / 2' instead of 'size'. Immediately after, vfio_pci_driver_memcpy_start() is kicked off using the full 'size'.

Quoted 6 lines

Does this code unintentionally leave the second half of the DMA buffers uninitialized? While the test does not currently verify the transferred data since iommufd preservation is unsupported, will this partial initialization cause false positives or negatives once the test is expanded to validate the completed DMA operations?

It is an issue, even though we are not verifying the copied data yet.

I will fix it in the next version.

Quoted 2 lines
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
#47 lore raw
In reply to Vipin Sharma
Quoted 66 lines · Vipin Sharma

Hello,

This series can be found on Github:

https://github.com/shvipin/linux vfio/liveupdate/v5

This series provides the base support to enable Live Update feature for VFIO PCI devices using the Live Update Orchestrator (LUO) and Kexec Handover (KHO).

Overview
--------

This series makes the following changes to support VFIO Live Update:

- Puts VFIO Live Update support behind the CONFIG_VFIO_PCI_LIVEUPDATE config option (which requires CONFIG_VFIO_DEVICE_CDEV).
- Preserves VFIO cdev device FDs across a kexec Live Update session via LUO/KHO.
- Enforces that incoming preserved devices can only be retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD post-kexec (preventing legacy group/cdev opens from accessing uninitialized state).
- Quiesces the device prior to kexec in freeze() by resetting hardware, disabling bus mastering, and marking the device frozen to reject post-freeze IO/MMIO.
- Includes VFIO selftests (uapi & kexec tests with continuous DMA checks) and kernel documentation.

VFIO PCI Live Update Roadmap
----------------------------

We are planning to add VFIO PCI Live Update support in phases. Since full support of this feature will come in phase, VFIO PCI Liveupdate is controlled by CONFIG_VFIO_PCI_LIVEUPDATE config option.

This series is phase 1 below:

1. PCIe function (non-VF) preserved across Live Update without changing BDF
2. PCIe function (non-VF) preserved across Live Update without resetting
3. PCIe function (non-VF) preserved across Live Update with continuous DMA (noiommu)
4. PCIe function (non-VF) preserved across Live Update with continuous DMA (iommufd)
5. PCIe VF preserved across Live Update with continuous DMA (iommufd)

Dependencies
------------

This series has following dependencies as shown in the diagram

     |---------------------------|
     |         VFIO v5           |  <--- Sent in this series.
     |---------------------------|
     |  Liveupdate Selftests[1]  |
     |---------------------------|
     |        PCI v7 [2]         |
     |---------------------------|

[1]https://lore.kernel.org/all/[email protected]/
These selftests changes are needed by other selftests also (iommu, kvm), so, I have sent them separately.

[2]https://lore.kernel.org/linux-pci/[email protected]/
This is the PCI v7, which adds the live update support in PCI core.

Quoted 7 lines

Github branch I have mentioned at the top has all of these dependencies.

Testing
-------

Tested using VFIO Live Update selftests in both QEMU and bare-metal environment (Intel DSA PCIe device).

I want to make tests VFIO Live Update selftests in QEMU. But how to select a PCIe device?

what device do the PCI ID 0000:00:04.0 and 0000:6a:01.0 mean in the following testcase?

Zhu Yanjun

Quoted 103 lines
   $ ./setup.sh 0000:00:04.0
   $ ./vfio_pci_liveupdate_kexec_test --stage 1 0000:6a:01.0
   $ kexec --reuse-cmdline -l -s /boot/vmlinuz
   $ kexec -e
   $ ./setup.sh 0000:00:04.0
   $ ./vfio_pci_liveupdate_kexec_test --stage 2 0000:6a:01.0

Kernel command line options used:
- liveupdate=on
- kho=on
- vfio_iommu_type1.allow_unsafe_interrupts=Y
- vfio_pci.enable_sriov=Y
- vfio_pci.disable_denylist=Y
- vfio.enable_unsafe_noiommu_mode=Y

Changelog
---------

v5:
- Addressed Sashiko feedback.
- Removed condition to disable CONFIG_VFIO_PCI_DMABUF.
- Expanded vfio_find_device() helper to safely discover a registered vfio_device by matching criteria. Internal Sashiko instance found data race.
- Updated selftests to latest changes in VFIO selftests.
- Rebased on top of PCI Live Update series v7.

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 (7):
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
vfio: selftests: Expose iommu_modes to tests
vfio: selftests: Verify that opening VFIO device fails during Live
Update
vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

Vipin Sharma (13):
vfio/pci: Factor out the reset logic in VFIO PCI device close path
vfio: Export various helpers from VFIO
vfio/pci: Export vfio_pci_dma_buf_move for vfio-pci module
liveupdate: Export symbols needed by modules
vfio/pci: Register a file handler with Live Update Orchestrator 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: selftests: Build liveupdate library in VFIO selftests
vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD
vfio: selftests: Add vfio_pci_liveupdate_kexec_test

  Documentation/core-api/liveupdate.rst         |   1 +
  .../driver-api/vfio_pci_liveupdate.rst        |  23 ++
  MAINTAINERS                                   |   2 +
  drivers/vfio/device_cdev.c                    |  67 +++-
  drivers/vfio/group.c                          |   9 +
  drivers/vfio/pci/Kconfig                      |  12 +
  drivers/vfio/pci/Makefile                     |   1 +
  drivers/vfio/pci/vfio_pci.c                   |  13 +-
  drivers/vfio/pci/vfio_pci_config.c            |   3 +
  drivers/vfio/pci/vfio_pci_core.c              | 119 +++---
  drivers/vfio/pci/vfio_pci_dmabuf.c            |   1 +
  drivers/vfio/pci/vfio_pci_liveupdate.c        | 340 ++++++++++++++++++
  drivers/vfio/pci/vfio_pci_priv.h              |  28 ++
  drivers/vfio/vfio.h                           |  18 +
  drivers/vfio/vfio_main.c                      |  67 +++-
  include/linux/kho/abi/vfio_pci.h              |  43 +++
  include/linux/vfio.h                          |  12 +
  include/linux/vfio_pci_core.h                 |   3 +
  kernel/liveupdate/luo_file.c                  |   2 +
  tools/testing/selftests/vfio/Makefile         |  23 +-
  .../vfio/lib/include/libvfio/iommu.h          |   2 +
  .../lib/include/libvfio/vfio_pci_device.h     |   3 +
  tools/testing/selftests/vfio/lib/iommu.c      |   4 +-
  .../selftests/vfio/lib/vfio_pci_device.c      |  25 +-
  .../vfio/vfio_pci_liveupdate_kexec_test.c     | 256 +++++++++++++
  .../vfio/vfio_pci_liveupdate_uapi_test.c      |  97 +++++
  26 files changed, 1097 insertions(+), 77 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: cbf37fff757e87376e80e11a8378393a8f25145f
prerequisite-patch-id: 85705fb54d3065efe1d87ab4b69e828a9f3404e7
prerequisite-patch-id: a33ae79b5fc0259bd013b430c18cc3d14a678599

#48 lore raw
Quoted 74 lines · Yanjun.Zhu
Quoted 71 lines · Vipin Sharma

Hello,

This series can be found on Github:

https://github.com/shvipin/linux vfio/liveupdate/v5

This series provides the base support to enable Live Update feature for VFIO PCI devices using the Live Update Orchestrator (LUO) and Kexec Handover (KHO).

Overview
--------

This series makes the following changes to support VFIO Live Update:

- Puts VFIO Live Update support behind the CONFIG_VFIO_PCI_LIVEUPDATE config option (which requires CONFIG_VFIO_DEVICE_CDEV).
- Preserves VFIO cdev device FDs across a kexec Live Update session via LUO/KHO.
- Enforces that incoming preserved devices can only be retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD post-kexec (preventing legacy group/cdev opens from accessing uninitialized state).
- Quiesces the device prior to kexec in freeze() by resetting hardware, disabling bus mastering, and marking the device frozen to reject post-freeze IO/MMIO.
- Includes VFIO selftests (uapi & kexec tests with continuous DMA checks) and kernel documentation.

VFIO PCI Live Update Roadmap
----------------------------

We are planning to add VFIO PCI Live Update support in phases. Since full support of this feature will come in phase, VFIO PCI Liveupdate is controlled by CONFIG_VFIO_PCI_LIVEUPDATE config option.

This series is phase 1 below:

1. PCIe function (non-VF) preserved across Live Update without changing BDF
2. PCIe function (non-VF) preserved across Live Update without resetting
3. PCIe function (non-VF) preserved across Live Update with continuous DMA (noiommu)
4. PCIe function (non-VF) preserved across Live Update with continuous DMA (iommufd)
5. PCIe VF preserved across Live Update with continuous DMA (iommufd)

Dependencies
------------

This series has following dependencies as shown in the diagram

     |---------------------------|
     |         VFIO v5           |  <--- Sent in this series.
     |---------------------------|
     |  Liveupdate Selftests[1]  |
     |---------------------------|
     |        PCI v7 [2]         |
     |---------------------------|

[1]https://lore.kernel.org/all/[email protected]/
These selftests changes are needed by other selftests also (iommu, kvm), so, I have sent them separately.

[2]https://lore.kernel.org/linux-pci/[email protected]/
This is the PCI v7, which adds the live update support in PCI core.

Github branch I have mentioned at the top has all of these dependencies.

Testing
-------

Quoted 7 lines
Quoted 2 lines

Tested using VFIO Live Update selftests in both QEMU and bare-metal environment (Intel DSA PCIe device).

I want to make tests VFIO Live Update selftests in QEMU. But how to select a PCIe device?

what device do the PCI ID 0000:00:04.0 and 0000:6a:01.0 mean in the following testcase?

In my qemu,

00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Interrupt: pin A routed to IRQ 20
    Region 0: I/O ports at d040 [size=32]
    Region 1: Memory at f0400000 (32-bit, non-prefetchable) [size=4M]
    Region 2: Memory at f0800000 (32-bit, prefetchable) [size=16K]
    Kernel driver in use: vboxguest
    Kernel modules: vboxguest

I am wondering if the above pci device can work well with this patch set or not.

Zhu Yanjun

Quoted 104 lines

Zhu Yanjun

Quoted 102 lines
   $ ./setup.sh 0000:00:04.0
   $ ./vfio_pci_liveupdate_kexec_test --stage 1 0000:6a:01.0
   $ kexec --reuse-cmdline -l -s /boot/vmlinuz
   $ kexec -e
   $ ./setup.sh 0000:00:04.0
   $ ./vfio_pci_liveupdate_kexec_test --stage 2 0000:6a:01.0

Kernel command line options used:
- liveupdate=on
- kho=on
- vfio_iommu_type1.allow_unsafe_interrupts=Y
- vfio_pci.enable_sriov=Y
- vfio_pci.disable_denylist=Y
- vfio.enable_unsafe_noiommu_mode=Y

Changelog
---------

v5:
- Addressed Sashiko feedback.
- Removed condition to disable CONFIG_VFIO_PCI_DMABUF.
- Expanded vfio_find_device() helper to safely discover a registered vfio_device by matching criteria. Internal Sashiko instance found data race.
- Updated selftests to latest changes in VFIO selftests.
- Rebased on top of PCI Live Update series v7.

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 (7):
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
vfio: selftests: Expose iommu_modes to tests
vfio: selftests: Verify that opening VFIO device fails during Live
Update
vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test

Vipin Sharma (13):
vfio/pci: Factor out the reset logic in VFIO PCI device close path
vfio: Export various helpers from VFIO
vfio/pci: Export vfio_pci_dma_buf_move for vfio-pci module
liveupdate: Export symbols needed by modules
vfio/pci: Register a file handler with Live Update Orchestrator 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: selftests: Build liveupdate library in VFIO selftests
vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD
vfio: selftests: Add vfio_pci_liveupdate_kexec_test

  Documentation/core-api/liveupdate.rst         |   1 +
  .../driver-api/vfio_pci_liveupdate.rst        |  23 ++
  MAINTAINERS                                   |   2 +
  drivers/vfio/device_cdev.c                    |  67 +++-
  drivers/vfio/group.c                          |   9 +
  drivers/vfio/pci/Kconfig                      |  12 +
  drivers/vfio/pci/Makefile                     |   1 +
  drivers/vfio/pci/vfio_pci.c                   |  13 +-
  drivers/vfio/pci/vfio_pci_config.c            |   3 +
  drivers/vfio/pci/vfio_pci_core.c              | 119 +++---
  drivers/vfio/pci/vfio_pci_dmabuf.c            |   1 +
  drivers/vfio/pci/vfio_pci_liveupdate.c        | 340 ++++++++++++++++++
  drivers/vfio/pci/vfio_pci_priv.h              |  28 ++
  drivers/vfio/vfio.h                           |  18 +
  drivers/vfio/vfio_main.c                      |  67 +++-
  include/linux/kho/abi/vfio_pci.h              |  43 +++
  include/linux/vfio.h                          |  12 +
  include/linux/vfio_pci_core.h                 |   3 +
  kernel/liveupdate/luo_file.c                  |   2 +
  tools/testing/selftests/vfio/Makefile         |  23 +-
  .../vfio/lib/include/libvfio/iommu.h          |   2 +
  .../lib/include/libvfio/vfio_pci_device.h     |   3 +
  tools/testing/selftests/vfio/lib/iommu.c      |   4 +-
  .../selftests/vfio/lib/vfio_pci_device.c      |  25 +-
  .../vfio/vfio_pci_liveupdate_kexec_test.c     | 256 +++++++++++++
  .../vfio/vfio_pci_liveupdate_uapi_test.c      |  97 +++++
  26 files changed, 1097 insertions(+), 77 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: cbf37fff757e87376e80e11a8378393a8f25145f
prerequisite-patch-id: 85705fb54d3065efe1d87ab4b69e828a9f3404e7
prerequisite-patch-id: a33ae79b5fc0259bd013b430c18cc3d14a678599

#49 lore raw
Quoted 8 lines · Yanjun.Zhu
Quoted 6 lines · Yanjun.Zhu
Quoted 3 lines · Vipin Sharma

Testing
-------

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Tested using VFIO Live Update selftests in both QEMU and bare-metal environment (Intel DSA PCIe device).

I want to make tests VFIO Live Update selftests in QEMU. But how to select a PCIe device?

what device do the PCI ID 0000:00:04.0 and 0000:6a:01.0 mean in the following testcase?

Sorry, this was my copy-paste mistake when combining things from both qemu and baremetal. You only need one device not two separate ones.

For testing using QEMU, you can use QEMU PCI test device.

-device pci-testdev

In VM, use lspci command to find the BDF of the PCI device. It will show output like:

00:04.0 Unclassified device [00ff]: Red Hat, Inc. QEMU PCI Test Device

Then prefix the domain (generally, 0000) to the BDF and use the testing commands.

0000:6a:01.0 was the BDF of the Intel DSA device on my host. I incorrectly mixed two devices during my copy-paste.

Limitation of qemu pci-testdev is that it does not have the DMA capability. I used physical host with Intel DSA to verify that the device performing DMA during live update gets reset.

Quoted 16 lines
Quoted 1 line

In my qemu,

00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Interrupt: pin A routed to IRQ 20
    Region 0: I/O ports at d040 [size=32]
    Region 1: Memory at f0400000 (32-bit, non-prefetchable) [size=4M] Region 2: Memory at f0800000 (32-bit, prefetchable) [size=16K] Kernel driver in use: vboxguest
    Kernel modules: vboxguest

Quoted 2 lines

I am wondering if the above pci device can work well with this patch set or not.

I think you should be able to test Live Update with any PCI device which can be attached vfio-pci driver.

vfio_pci_liveupdate_kexec_test will initiate DMA if the VFIO selftest framework has the driver for the passed device (Intel DSA) otherwise it will just skip over the DMA flow and do the remaining things.

Let me know if you still face some issue in running Live Update, I will be happy to provide more details.

Thanks
Vipin

#50 lore raw
Quoted 51 lines · Vipin Sharma
Quoted 6 lines · Yanjun.Zhu
Quoted 5 lines · Yanjun.Zhu
Quoted 3 lines · Vipin Sharma

Testing
-------

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Tested using VFIO Live Update selftests in both QEMU and bare-metal environment (Intel DSA PCIe device).

I want to make tests VFIO Live Update selftests in QEMU. But how to select a PCIe device?

what device do the PCI ID 0000:00:04.0 and 0000:6a:01.0 mean in the following testcase?

Sorry, this was my copy-paste mistake when combining things from both qemu and baremetal. You only need one device not two separate ones.

For testing using QEMU, you can use QEMU PCI test device.

-device pci-testdev

In VM, use lspci command to find the BDF of the PCI device. It will show output like:

00:04.0 Unclassified device [00ff]: Red Hat, Inc. QEMU PCI Test Device

Then prefix the domain (generally, 0000) to the BDF and use the testing commands.

0000:6a:01.0 was the BDF of the Intel DSA device on my host. I incorrectly mixed two devices during my copy-paste.

Limitation of qemu pci-testdev is that it does not have the DMA capability. I used physical host with Intel DSA to verify that the device performing DMA during live update gets reset.

Quoted 15 lines

In my qemu,

00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr-
Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort-
<MAbort- >SERR- <PERR- INTx-
    Interrupt: pin A routed to IRQ 20
    Region 0: I/O ports at d040 [size=32]
    Region 1: Memory at f0400000 (32-bit, non-prefetchable) [size=4M] Region 2: Memory at f0800000 (32-bit, prefetchable) [size=16K] Kernel driver in use: vboxguest
    Kernel modules: vboxguest

Quoted 8 lines
Quoted 2 lines

I am wondering if the above pci device can work well with this patch set or not.

I think you should be able to test Live Update with any PCI device which can be attached vfio-pci driver.

vfio_pci_liveupdate_kexec_test will initiate DMA if the VFIO selftest framework has the driver for the passed device (Intel DSA) otherwise it will just skip over the DMA flow and do the remaining things.

Thanks a lot. I'll run some tests with QEMU's pci-testdev.

If I understand correctly, when using pci-testdev, only the DMA test case is expected not to work, while all the other test cases should work correctly.

Yanjun.Zhu

Quoted 6 lines

Let me know if you still face some issue in running Live Update, I will be happy to provide more details.

Thanks
Vipin

#51 lore raw
Quoted 62 lines · Yanjun.Zhu
Quoted 51 lines · Vipin Sharma
Quoted 6 lines · Yanjun.Zhu
Quoted 5 lines · Yanjun.Zhu
Quoted 3 lines · Vipin Sharma

Testing
-------

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Tested using VFIO Live Update selftests in both QEMU and bare-metal environment (Intel DSA PCIe device).

I want to make tests VFIO Live Update selftests in QEMU. But how to select a PCIe device?

what device do the PCI ID 0000:00:04.0 and 0000:6a:01.0 mean in the following testcase?

Sorry, this was my copy-paste mistake when combining things from both qemu and baremetal. You only need one device not two separate ones.

For testing using QEMU, you can use QEMU PCI test device.

-device pci-testdev

In VM, use lspci command to find the BDF of the PCI device. It will show output like:

00:04.0 Unclassified device [00ff]: Red Hat, Inc. QEMU PCI Test Device

Then prefix the domain (generally, 0000) to the BDF and use the testing commands.

0000:6a:01.0 was the BDF of the Intel DSA device on my host. I incorrectly mixed two devices during my copy-paste.

Limitation of qemu pci-testdev is that it does not have the DMA capability. I used physical host with Intel DSA to verify that the device performing DMA during live update gets reset.

Quoted 15 lines

In my qemu,

00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
    Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr-
Stepping- SERR- FastB2B- DisINTx-
    Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort-
<MAbort- >SERR- <PERR- INTx-
    Interrupt: pin A routed to IRQ 20
    Region 0: I/O ports at d040 [size=32]
    Region 1: Memory at f0400000 (32-bit, non-prefetchable) [size=4M] Region 2: Memory at f0800000 (32-bit, prefetchable) [size=16K] Kernel driver in use: vboxguest
    Kernel modules: vboxguest

Quoted 8 lines
Quoted 2 lines

I am wondering if the above pci device can work well with this patch set or not.

I think you should be able to test Live Update with any PCI device which can be attached vfio-pci driver.

vfio_pci_liveupdate_kexec_test will initiate DMA if the VFIO selftest framework has the driver for the passed device (Intel DSA) otherwise it will just skip over the DMA flow and do the remaining things.

Quoted 6 lines

Thanks a lot. I'll run some tests with QEMU's pci-testdev.

If I understand correctly, when using pci-testdev, only the DMA test case is expected not to work, while all the other test cases should work correctly.

Yes, other test cases should work.

#52 lore raw
In reply to Vipin Sharma
Quoted 10 lines · Vipin Sharma

Hello,

This series can be found on Github:

https://github.com/shvipin/linux vfio/liveupdate/v5

This series provides the base support to enable Live Update feature for VFIO PCI devices using the Live Update Orchestrator (LUO) and Kexec Handover (KHO).

Hi Alex, Pasha, Mike, and Pratyush,

I'd like to discuss which maintainer tree should take the VFIO Live Update series.

For context on related efforts:

- PCI Live Update is targeting the Live Update tree (maintained by Pasha, Mike, and Pratyush, with David Matlack maintaining the PCI-specific code).
https://lore.kernel.org/linux-pci/[email protected]/

- IOMMU Live Update is planned to go through the IOMMU tree.

    https://lore.kernel.org/linux-iommu/[email protected]/

Given these different approaches, what is your preference for routing the VFIO Live Update code?

Thanks
Vipin Sharma

#53 lore raw
Quoted 24 lines · Vipin Sharma
Quoted 10 lines · Vipin Sharma

Hello,

This series can be found on Github:

https://github.com/shvipin/linux vfio/liveupdate/v5

This series provides the base support to enable Live Update feature for VFIO PCI devices using the Live Update Orchestrator (LUO) and Kexec Handover (KHO).

Hi Alex, Pasha, Mike, and Pratyush,

I'd like to discuss which maintainer tree should take the VFIO Live Update series.

For context on related efforts:

- PCI Live Update is targeting the Live Update tree (maintained by Pasha, Mike, and Pratyush, with David Matlack maintaining the PCI-specific code).
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 6 lines

- IOMMU Live Update is planned to go through the IOMMU tree.

    https://lore.kernel.org/linux-iommu/[email protected]/

Given these different approaches, what is your preference for routing the VFIO Live Update code?

Hi Alex,

Gentle ping.

Thanks
Vipin