On Sun, May 17, 2026 at 12:04:04PM -0700, Zhu Yanjun wrote:
>
> 在 2026/5/11 16:47, 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.
> >
> > Reviewed-by: Pranjal Shrivastava <[email protected]>
> > Signed-off-by: David Matlack <[email protected]>
> > Co-developed-by: Vipin Sharma <[email protected]>
> > Signed-off-by: Vipin Sharma <[email protected]>
> > ---
> > 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(+)
> >
> > diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c
> > index 1ab07ccaf3ab..4df0495941c6 100644
> > --- a/drivers/vfio/device_cdev.c
> > +++ b/drivers/vfio/device_cdev.c
> > @@ -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;
>
> When vfio_liveupdate_incoming_is_preserved(device) returns true,
> vfio_device_put_registration(device) is not called in this path.
>
> Is vfio_device_put_registration(device) instead invoked from the
> err_free_device_file error handling path?
Yes, at the end of vfio_device_cdev_open(), goto label first frees the
device file object and then calls the vfio_device_put_registration().
This is the same error handlign flow as in the if(!file) {} code in the
above function.