History

vfio/pci: Do vf_token checks for VFIO_DEVICE_BIND_IOMMUFD

This was missed during the initial implementation. The VFIO PCI encodes the vf_token inside the device name when opening the device from the group FD, something like: "0000:04:10.0 vf_token=bd8d9d2b-5a5f-4f5a-a211-f591514ba1f3" This is used to control access to a VF unless there is co-ordination with the owner of the PF. Since we no longer have a device name in the cdev path, pass the token directly through VFIO_DEVICE_BIND_IOMMUFD using an optional field indicated by VFIO_DEVICE_BIND_FLAG_TOKEN.

Jason Gunthorpe committed 1 year ago

Commit 86624ba1 parent b30601912 files · +76 −12Browse files

Showing the changes to include/uapi/linux (1 of 12 files). Show all

Unified · Split

include/uapi/linux/vfio.h+11−1
@@ -905,10 +905,12 @@ struct vfio_device_feature { · 904 unmodified lines
905 * VFIO_DEVICE_BIND_IOMMUFD - _IOR(VFIO_TYPE, VFIO_BASE + 18,905 * VFIO_DEVICE_BIND_IOMMUFD - _IOR(VFIO_TYPE, VFIO_BASE + 18,
906 * struct vfio_device_bind_iommufd)906 * struct vfio_device_bind_iommufd)
907 * @argsz: User filled size of this data.907 * @argsz: User filled size of this data.
908 * @flags: Must be 0.908 * @flags: Must be 0 or a bit flags of VFIO_DEVICE_BIND_*
909 * @iommufd: iommufd to bind.909 * @iommufd: iommufd to bind.
910 * @out_devid: The device id generated by this bind. devid is a handle for910 * @out_devid: The device id generated by this bind. devid is a handle for
911 * this device/iommufd bond and can be used in IOMMUFD commands.911 * this device/iommufd bond and can be used in IOMMUFD commands.
912 * @token_uuid_ptr: Valid if VFIO_DEVICE_BIND_FLAG_TOKEN. Points to a 16 byte
913 * UUID in the same format as VFIO_DEVICE_FEATURE_PCI_VF_TOKEN.
912 *914 *
913 * Bind a vfio_device to the specified iommufd.915 * Bind a vfio_device to the specified iommufd.
914 *916 *
@@ -917,13 +919,21 @@ struct vfio_device_feature { · 2 unmodified lines
917 *919 *
918 * Unbind is automatically conducted when device fd is closed.920 * Unbind is automatically conducted when device fd is closed.
919 *921 *
922 * A token is sometimes required to open the device, unless this is known to be
923 * needed VFIO_DEVICE_BIND_FLAG_TOKEN should not be set and token_uuid_ptr is
924 * ignored. The only case today is a PF/VF relationship where the VF bind must
925 * be provided the same token as VFIO_DEVICE_FEATURE_PCI_VF_TOKEN provided to
926 * the PF.
927 *
920 * Return: 0 on success, -errno on failure.928 * Return: 0 on success, -errno on failure.
921 */929 */
922struct vfio_device_bind_iommufd {930struct vfio_device_bind_iommufd {
923 __u32 argsz;931 __u32 argsz;
924 __u32 flags;932 __u32 flags;
933#define VFIO_DEVICE_BIND_FLAG_TOKEN (1 << 0)
925 __s32 iommufd;934 __s32 iommufd;
926 __u32 out_devid;935 __u32 out_devid;
936 __aligned_u64 token_uuid_ptr;
927};937};
928 938
929#define VFIO_DEVICE_BIND_IOMMUFD _IO(VFIO_TYPE, VFIO_BASE + 18)939#define VFIO_DEVICE_BIND_IOMMUFD _IO(VFIO_TYPE, VFIO_BASE + 18)