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
905905 * VFIO_DEVICE_BIND_IOMMUFD - _IOR(VFIO_TYPE, VFIO_BASE + 18,
906906 * struct vfio_device_bind_iommufd)
907907 * @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_*
909909 * @iommufd: iommufd to bind.
910910 * @out_devid: The device id generated by this bind. devid is a handle for
911911 * 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.
912914 *
913915 * Bind a vfio_device to the specified iommufd.
914916 *
@@ -917,13 +919,21 @@ struct vfio_device_feature { · 2 unmodified lines
917919 *
918920 * Unbind is automatically conducted when device fd is closed.
919921 *
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+ *
920928 * Return: 0 on success, -errno on failure.
921929 */
922930 struct vfio_device_bind_iommufd {
923931 __u32 argsz;
924932 __u32 flags;
933+#define VFIO_DEVICE_BIND_FLAG_TOKEN (1 << 0)
925934 __s32 iommufd;
926935 __u32 out_devid;
936+ __aligned_u64 token_uuid_ptr;
927937 };
928938
929939 #define VFIO_DEVICE_BIND_IOMMUFD _IO(VFIO_TYPE, VFIO_BASE + 18)