Re: [PATCH v6 11/27] vfio/pci: Retrieve preserved device files after Live Update
From: Vipin Sharma
Date: Wed Nov 18 2026 - 02:51:41 EST
On Fri, Nov 06, 2026 at 05:19:28PM +0000, David Matlack wrote:
> On Mon Nov 2, 2026 at 3:36 PM UTC, Vipin Sharma wrote:
> > During retrieve():
> > * Validate the handed-over struct vfio_pci_core_device_ser header,
> > sizes, and flags.
> > * Locate the registered vfio-pci device matching the serialized domain
> > and BDF (requiring device->ops == &vfio_pci_ops) under the device
> > lock. vfio-pci registers the vfio device before its probe completes,
> > and the probe holds that lock, so a device that is still being probed
> > is not returned.
> [...]
> > * Open and return an anonymous VFIO cdev file via
> > vfio_device_liveupdate_cdev_open().
>
> Here's an idea for how the device file could be created on retrieve,
> which I'd like to hear your thoughts on.
>
> The patches from Pasha at [1] lets userspace pass a
> file-handler-specific argument to LIVEUPDATE_SESSION_RETRIEVE_FD. In the
> next version of the tmpfs series, I'm planning to use that to have
> userspace create the file and pass it in the argument, and the kernel
> then restores the preserved file into it.
>
> I wonder if VFIO should work the same way, e.g.:
>
> struct liveupdate_vfio_retrieve_arg {
> __u32 size;
> __s32 fd;
> };
>
> Userspace would open /dev/vfio/devices/noiommu-vfioX itself and pass
> the fd. retrieve() would check that it's an unbound vfio-pci cdev file
> for the preserved device (domain/BDF, noiommu, incoming, cfg_size),
> attach the incoming state to that file, and LUO would track that file
> as the retrieved file. VFIO_DEVICE_BIND_IOMMUFD would then take over the
> device as it does now. Since VFIO preservation is new, the argument
> could simply be required.
>
> I think this could get rid of some of the special handling:
>
> - There'd be no need to fake a cdev open with an anonymous inode, so
> PATCH 09 and PATCH 10 could probably be dropped.
>
> - retrieve() wouldn't need to look up the device by BDF, or reason
> about racing with probe under the device lock. If userspace was able
> to open the cdev, the device is registered and probed.
>
> - The device file would be opened through the normal cdev path, so the
> usual permission and LSM checks on the device node would apply.
>
> - It would be the same model across file types.
>
> A few things I think would need care if you go this way. The file check
> and the attach would need to happen under dev_set->lock so they can't
> race with a concurrent VFIO_DEVICE_BIND_IOMMUFD on the same fd. And the
> incoming state should probably be tied to that specific
> vfio_device_file rather than just the vdev, so only the file passed to
> RETRIEVE_FD can take over the device.
>
> It would also change PATCH 12. Opening the cdev of an incoming device
> would have to succeed, so the check would move to the first open of the
> device instead: fail with -EBUSY if the device is incoming and the file
> being bound doesn't have the incoming state attached. That one check in
> vfio-pci would also cover VFIO_GROUP_GET_DEVICE_FD, which opens the
> device right away, so vfio_liveupdate_incoming_is_preserved() and its
> dev_is_pci() special case could be dropped from the VFIO core.
>
> The next tmpfs version will also add a way for a file handler to say a
> failed retrieve can be retried, and a helper to claim an existing file
> before restoring into it (so a file LUO already manages, e.g. one that
> is preserved in an outgoing session, is rejected). Both seem useful
> here too, e.g. so that a mistake in the argument (wrong fd, an fd for
> another device, an already bound fd) doesn't make the device
> unretrievable. I'll Cc you when I send it, and I'm happy to share the
> branch before then.
>
> What do you think?
Overall, I agree with the strategy. I think VFIO cdev retrieval should
happen as the flow you mentioned above. I want to hightlight two things:
1. This will lead to lot of code changes happening in vfio core. This
means VFIO PCI live update code change will spill in vfio core.
Should I create a config VFIO_LIVEUPDATE for VFIO core code. It will
not be visible menuconfig option but selected when
VFIO_PCI_LIVEUPDATE is enabled.
2. List of other inflight series that this series will depend on is
increasing. It will be 3 (reset function, pci saved state, and
restore into fd).
For '2', should I send v7 without changes you are recommending in this
patch and future version of this series can transition to the approach
you are suggesting after LUO changes are landed. VFIO liveupdate series
will go through more iterations, so we will have opportunity to make the
change. WDYT?
>
> [1] https://lore.kernel.org/kexec/20261103010216.3447716-1-dmatlack@xxxxxxxxxx/