[Intel-gfx] [PATCH v3 03/15] vfio: Accept vfio device file in the driver facing kAPI

Liu, Yi L yi.l.liu at intel.com
Tue Feb 14 02:02:37 UTC 2023


> From: Jason Gunthorpe <jgg at nvidia.com>
> Sent: Tuesday, February 14, 2023 7:44 AM
> 
> On Mon, Feb 13, 2023 at 07:13:36AM -0800, Yi Liu wrote:
> > +static struct vfio_device *vfio_device_from_file(struct file *file)
> > +{
> > +	struct vfio_device_file *df = file->private_data;
> > +
> > +	if (file->f_op != &vfio_device_fops)
> > +		return NULL;
> > +	return df->device;
> > +}
> > +
> >  /**
> >   * vfio_file_is_valid - True if the file is usable with VFIO APIS
> >   * @file: VFIO group file or VFIO device file
> >   */
> >  bool vfio_file_is_valid(struct file *file)
> >  {
> > -	return vfio_group_from_file(file);
> > +	return vfio_group_from_file(file) ||
> > +	       vfio_device_from_file(file);
> >  }
> >  EXPORT_SYMBOL_GPL(vfio_file_is_valid);
> 
> This can only succeed on a device cdev that has been fully opened.

Actually, we cannot. This is used in the kvm-vfio code to see if the
user-provided fd is vfio fds in the SET_KVM path. And we don't
have the device cdev fully opened until BIND_IOMMUFD. But we do
need to invoke SET_KVM before issuing BIND_IOMMUFD as the device
open needs kvm pointer. So if we cannot apply fully opened limit to this
interface. Maybe an updated function comment is needed.

" vfio_file_is_valid - True if the file is vfio files (group or device)"

Regards,
Yi Liu


More information about the Intel-gfx mailing list