History

Merge tag 'vfio-v6.6-rc1' of https://github.com/awilliam/linux-vfio

Pull VFIO updates from Alex Williamson: - VFIO direct character device (cdev) interface support. This extracts the vfio device fd from the container and group model, and is intended to be the native uAPI for use with IOMMUFD (Yi Liu) - Enhancements to the PCI hot reset interface in support of cdev usage (Yi Liu) - Fix a potential race between registering and unregistering vfio files in the kvm-vfio interface and extend use of a lock to avoid extra drop and acquires (Dmitry Torokhov) - A new vfio-pci variant driver for the AMD/Pensando Distributed Services Card (PDS) Ethernet device, supporting live migration (Brett Creeley) - Cleanups to remove redundant owner setup in cdx and fsl bus drivers, and simplify driver init/exit in fsl code (Li Zetao) - Fix uninitialized hole in data structure and pad capability structures for alignment (Stefan Hajnoczi) * tag 'vfio-v6.6-rc1' of https://github.com/awilliam/linux-vfio: (53 commits) vfio/pds: Send type for SUSPEND_STATUS command vfio/pds: fix return value in pds_vfio_get_lm_file() pds_core: Fix function header descriptions vfio: align capability structures vfio/type1: fix cap_migration information leak vfio/fsl-mc: Use module_fsl_mc_driver macro to simplify the code vfio/cdx: Remove redundant initialization owner in vfio_cdx_driver vfio/pds: Add Kconfig and documentation vfio/pds: Add support for firmware recovery vfio/pds: Add support for dirty page tracking vfio/pds: Add VFIO live migration support vfio/pds: register with the pds_core PF pds_core: Require callers of register/unregister to pass PF drvdata vfio/pds: Initial support for pds VFIO driver vfio: Commonize combine_ranges for use in other VFIO drivers kvm/vfio: avoid bouncing the mutex when adding and deleting groups kvm/vfio: ensure kvg instance stays around in kvm_vfio_group_add() docs: vfio: Add vfio device cdev description vfio: Compile vfio_group infrastructure optionally vfio: Move the IOMMU_CAP_CACHE_COHERENCY check in __vfio_register_dev() ...

Linus Torvalds committed 3 years ago

Commit ec0e2dc2 parents b6f6167 642265e55 files · +4350 −458Browse files

Showing the changes to include/uapi/linux (2 of 55 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/kvm.h +10 −3
  2. include/uapi/linux/vfio.h +143 −1
include/uapi/linux/kvm.h+10−3
@@ -1418,9 +1418,16 @@ struct kvm_device_attr { · 1417 unmodified lines
14181418 __u64 addr; /* userspace address of attr data */
14191419 };
14201420
1421−#define KVM_DEV_VFIO_GROUP 1
1422−#define KVM_DEV_VFIO_GROUP_ADD 1
1423−#define KVM_DEV_VFIO_GROUP_DEL 2
1421+#define KVM_DEV_VFIO_FILE 1
1422+
1423+#define KVM_DEV_VFIO_FILE_ADD 1
1424+#define KVM_DEV_VFIO_FILE_DEL 2
1425+
1426+/* KVM_DEV_VFIO_GROUP aliases are for compile time uapi compatibility */
1427+#define KVM_DEV_VFIO_GROUP KVM_DEV_VFIO_FILE
1428+
1429+#define KVM_DEV_VFIO_GROUP_ADD KVM_DEV_VFIO_FILE_ADD
1430+#define KVM_DEV_VFIO_GROUP_DEL KVM_DEV_VFIO_FILE_DEL
14241431 #define KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE 3
14251432
14261433 enum kvm_device_type {
include/uapi/linux/vfio.h+143−1
@@ -217,6 +217,7 @@ struct vfio_device_info { · 216 unmodified lines
217217 __u32 num_regions; /* Max region index + 1 */
218218 __u32 num_irqs; /* Max IRQ index + 1 */
219219 __u32 cap_offset; /* Offset within info struct of first cap */
220+ __u32 pad;
220221 };
221222 #define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7)
222223
@@ -677,11 +678,60 @@ enum { · 454 unmodified lines
677678 * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 12,
678679 * struct vfio_pci_hot_reset_info)
679680 *
681+ * This command is used to query the affected devices in the hot reset for
682+ * a given device.
683+ *
684+ * This command always reports the segment, bus, and devfn information for
685+ * each affected device, and selectively reports the group_id or devid per
686+ * the way how the calling device is opened.
687+ *
688+ * - If the calling device is opened via the traditional group/container
689+ * API, group_id is reported. User should check if it has owned all
690+ * the affected devices and provides a set of group fds to prove the
691+ * ownership in VFIO_DEVICE_PCI_HOT_RESET ioctl.
692+ *
693+ * - If the calling device is opened as a cdev, devid is reported.
694+ * Flag VFIO_PCI_HOT_RESET_FLAG_DEV_ID is set to indicate this
695+ * data type. All the affected devices should be represented in
696+ * the dev_set, ex. bound to a vfio driver, and also be owned by
697+ * this interface which is determined by the following conditions:
698+ * 1) Has a valid devid within the iommufd_ctx of the calling device.
699+ * Ownership cannot be determined across separate iommufd_ctx and
700+ * the cdev calling conventions do not support a proof-of-ownership
701+ * model as provided in the legacy group interface. In this case
702+ * valid devid with value greater than zero is provided in the return
703+ * structure.
704+ * 2) Does not have a valid devid within the iommufd_ctx of the calling
705+ * device, but belongs to the same IOMMU group as the calling device
706+ * or another opened device that has a valid devid within the
707+ * iommufd_ctx of the calling device. This provides implicit ownership
708+ * for devices within the same DMA isolation context. In this case
709+ * the devid value of VFIO_PCI_DEVID_OWNED is provided in the return
710+ * structure.
711+ *
712+ * A devid value of VFIO_PCI_DEVID_NOT_OWNED is provided in the return
713+ * structure for affected devices where device is NOT represented in the
714+ * dev_set or ownership is not available. Such devices prevent the use
715+ * of VFIO_DEVICE_PCI_HOT_RESET ioctl outside of the proof-of-ownership
716+ * calling conventions (ie. via legacy group accessed devices). Flag
717+ * VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED would be set when all the
718+ * affected devices are represented in the dev_set and also owned by
719+ * the user. This flag is available only when
720+ * flag VFIO_PCI_HOT_RESET_FLAG_DEV_ID is set, otherwise reserved.
721+ * When set, user could invoke VFIO_DEVICE_PCI_HOT_RESET with a zero
722+ * length fd array on the calling device as the ownership is validated
723+ * by iommufd_ctx.
724+ *
680725 * Return: 0 on success, -errno on failure:
681726 * -enospc = insufficient buffer, -enodev = unsupported for device.
682727 */
683728 struct vfio_pci_dependent_device {
684− __u32 group_id;
729+ union {
730+ __u32 group_id;
731+ __u32 devid;
732+#define VFIO_PCI_DEVID_OWNED 0
733+#define VFIO_PCI_DEVID_NOT_OWNED -1
734+ };
685735 __u16 segment;
686736 __u8 bus;
687737 __u8 devfn; /* Use PCI_SLOT/PCI_FUNC */
@@ -690,6 +740,8 @@ struct vfio_pci_dependent_device { · 2 unmodified lines
690740 struct vfio_pci_hot_reset_info {
691741 __u32 argsz;
692742 __u32 flags;
743+#define VFIO_PCI_HOT_RESET_FLAG_DEV_ID (1 << 0)
744+#define VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED (1 << 1)
693745 __u32 count;
694746 struct vfio_pci_dependent_device devices[];
695747 };
@@ -700,6 +752,24 @@ struct vfio_pci_hot_reset_info { · 4 unmodified lines
700752 * VFIO_DEVICE_PCI_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 13,
701753 * struct vfio_pci_hot_reset)
702754 *
755+ * A PCI hot reset results in either a bus or slot reset which may affect
756+ * other devices sharing the bus/slot. The calling user must have
757+ * ownership of the full set of affected devices as determined by the
758+ * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO ioctl.
759+ *
760+ * When called on a device file descriptor acquired through the vfio
761+ * group interface, the user is required to provide proof of ownership
762+ * of those affected devices via the group_fds array in struct
763+ * vfio_pci_hot_reset.
764+ *
765+ * When called on a direct cdev opened vfio device, the flags field of
766+ * struct vfio_pci_hot_reset_info reports the ownership status of the
767+ * affected devices and this ioctl must be called with an empty group_fds
768+ * array. See above INFO ioctl definition for ownership requirements.
769+ *
770+ * Mixed usage of legacy groups and cdevs across the set of affected
771+ * devices is not supported.
772+ *
703773 * Return: 0 on success, -errno on failure.
704774 */
705775 struct vfio_pci_hot_reset {
@@ -828,6 +898,77 @@ struct vfio_device_feature { · 122 unmodified lines
828898
829899 #define VFIO_DEVICE_FEATURE _IO(VFIO_TYPE, VFIO_BASE + 17)
830900
901+/*
902+ * VFIO_DEVICE_BIND_IOMMUFD - _IOR(VFIO_TYPE, VFIO_BASE + 18,
903+ * struct vfio_device_bind_iommufd)
904+ * @argsz: User filled size of this data.
905+ * @flags: Must be 0.
906+ * @iommufd: iommufd to bind.
907+ * @out_devid: The device id generated by this bind. devid is a handle for
908+ * this device/iommufd bond and can be used in IOMMUFD commands.
909+ *
910+ * Bind a vfio_device to the specified iommufd.
911+ *
912+ * User is restricted from accessing the device before the binding operation
913+ * is completed. Only allowed on cdev fds.
914+ *
915+ * Unbind is automatically conducted when device fd is closed.
916+ *
917+ * Return: 0 on success, -errno on failure.
918+ */
919+struct vfio_device_bind_iommufd {
920+ __u32 argsz;
921+ __u32 flags;
922+ __s32 iommufd;
923+ __u32 out_devid;
924+};
925+
926+#define VFIO_DEVICE_BIND_IOMMUFD _IO(VFIO_TYPE, VFIO_BASE + 18)
927+
928+/*
929+ * VFIO_DEVICE_ATTACH_IOMMUFD_PT - _IOW(VFIO_TYPE, VFIO_BASE + 19,
930+ * struct vfio_device_attach_iommufd_pt)
931+ * @argsz: User filled size of this data.
932+ * @flags: Must be 0.
933+ * @pt_id: Input the target id which can represent an ioas or a hwpt
934+ * allocated via iommufd subsystem.
935+ * Output the input ioas id or the attached hwpt id which could
936+ * be the specified hwpt itself or a hwpt automatically created
937+ * for the specified ioas by kernel during the attachment.
938+ *
939+ * Associate the device with an address space within the bound iommufd.
940+ * Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close. This is only
941+ * allowed on cdev fds.
942+ *
943+ * Return: 0 on success, -errno on failure.
944+ */
945+struct vfio_device_attach_iommufd_pt {
946+ __u32 argsz;
947+ __u32 flags;
948+ __u32 pt_id;
949+};
950+
951+#define VFIO_DEVICE_ATTACH_IOMMUFD_PT _IO(VFIO_TYPE, VFIO_BASE + 19)
952+
953+/*
954+ * VFIO_DEVICE_DETACH_IOMMUFD_PT - _IOW(VFIO_TYPE, VFIO_BASE + 20,
955+ * struct vfio_device_detach_iommufd_pt)
956+ * @argsz: User filled size of this data.
957+ * @flags: Must be 0.
958+ *
959+ * Remove the association of the device and its current associated address
960+ * space. After it, the device should be in a blocking DMA state. This is only
961+ * allowed on cdev fds.
962+ *
963+ * Return: 0 on success, -errno on failure.
964+ */
965+struct vfio_device_detach_iommufd_pt {
966+ __u32 argsz;
967+ __u32 flags;
968+};
969+
970+#define VFIO_DEVICE_DETACH_IOMMUFD_PT _IO(VFIO_TYPE, VFIO_BASE + 20)
971+
831972 /*
832973 * Provide support for setting a PCI VF Token, which is used as a shared
833974 * secret between PF and VF drivers. This feature may only be set on a
@@ -1304,6 +1445,7 @@ struct vfio_iommu_type1_info { · 470 unmodified lines
13041445 #define VFIO_IOMMU_INFO_CAPS (1 << 1) /* Info supports caps */
13051446 __u64 iova_pgsizes; /* Bitmap of supported page sizes */
13061447 __u32 cap_offset; /* Offset within info struct of first cap */
1448+ __u32 pad;
13071449 };
13081450
13091451 /*