History

Merge tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd

Pull iommufd updates from Jason Gunthorpe: "On top of the vfio updates is built some new iommufd functionality: - IOMMU_HWPT_ALLOC allows userspace to directly create the low level IO Page table objects and affiliate them with IOAS objects that hold the translation mapping. This is the basic functionality for the normal IOMMU_DOMAIN_PAGING domains. - VFIO_DEVICE_ATTACH_IOMMUFD_PT can be used to replace the current translation. This is wired up to through all the layers down to the driver so the driver has the ability to implement a hitless replacement. This is necessary to fully support guest behaviors when emulating HW (eg guest atomic change of translation) - IOMMU_GET_HW_INFO returns information about the IOMMU driver HW that owns a VFIO device. This includes support for the Intel iommu, and patches have been posted for all the other server IOMMU. Along the way are a number of internal items: - New iommufd kernel APIs: iommufd_ctx_has_group(), iommufd_device_to_ictx(), iommufd_device_to_id(), iommufd_access_detach(), iommufd_ctx_from_fd(), iommufd_device_replace() - iommufd now internally tracks iommu_groups as it needs some per-group data - Reorganize how the internal hwpt allocation flows to have more robust locking - Improve the access interfaces to support detach and replace of an IOAS from an access - New selftests and a rework of how the selftests creates a mock iommu driver to be more like a real iommu driver" Link: https://lore.kernel.org/lkml/ZO%2FTe6LU1ENf58ZW@nvidia.com/ * tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd: (34 commits) iommufd/selftest: Don't leak the platform device memory when unloading the module iommu/vt-d: Implement hw_info for iommu capability query iommufd/selftest: Add coverage for IOMMU_GET_HW_INFO ioctl iommufd: Add IOMMU_GET_HW_INFO iommu: Add new iommu op to get iommu hardware information iommu: Move dev_iommu_ops() to private header iommufd: Remove iommufd_ref_to_users() iommufd/selftest: Make the mock iommu driver into a real driver vfio: Support IO page table replacement iommufd/selftest: Add IOMMU_TEST_OP_ACCESS_REPLACE_IOAS coverage iommufd: Add iommufd_access_replace() API iommufd: Use iommufd_access_change_ioas in iommufd_access_destroy_object iommufd: Add iommufd_access_change_ioas(_id) helpers iommufd: Allow passing in iopt_access_list_id to iopt_remove_access() vfio: Do not allow !ops->dma_unmap in vfio_pin/unpin_pages() iommufd/selftest: Add a selftest for IOMMU_HWPT_ALLOC iommufd/selftest: Return the real idev id from selftest mock_domain iommufd: Add IOMMU_HWPT_ALLOC iommufd/selftest: Test iommufd_device_replace() iommufd: Make destroy_rwsem use a lock class per object type ...

Linus Torvalds committed 3 years ago

Commit 4debf772 parents ec0e2dc eb501c219 files · +1486 −355Browse files

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

Unified · Split

2 files
  1. include/uapi/linux/iommufd.h +97 −0
  2. include/uapi/linux/vfio.h +6 −0
include/uapi/linux/iommufd.h+97−0
@@ -45,6 +45,8 @@ enum { · 44 unmodified lines
4545 IOMMUFD_CMD_IOAS_UNMAP,
4646 IOMMUFD_CMD_OPTION,
4747 IOMMUFD_CMD_VFIO_IOAS,
48+ IOMMUFD_CMD_HWPT_ALLOC,
49+ IOMMUFD_CMD_GET_HW_INFO,
4850 };
4951
5052 /**
@@ -344,4 +346,99 @@ struct iommu_vfio_ioas { · 293 unmodified lines
344346 __u16 __reserved;
345347 };
346348 #define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS)
349+
350+/**
351+ * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC)
352+ * @size: sizeof(struct iommu_hwpt_alloc)
353+ * @flags: Must be 0
354+ * @dev_id: The device to allocate this HWPT for
355+ * @pt_id: The IOAS to connect this HWPT to
356+ * @out_hwpt_id: The ID of the new HWPT
357+ * @__reserved: Must be 0
358+ *
359+ * Explicitly allocate a hardware page table object. This is the same object
360+ * type that is returned by iommufd_device_attach() and represents the
361+ * underlying iommu driver's iommu_domain kernel object.
362+ *
363+ * A HWPT will be created with the IOVA mappings from the given IOAS.
364+ */
365+struct iommu_hwpt_alloc {
366+ __u32 size;
367+ __u32 flags;
368+ __u32 dev_id;
369+ __u32 pt_id;
370+ __u32 out_hwpt_id;
371+ __u32 __reserved;
372+};
373+#define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC)
374+
375+/**
376+ * struct iommu_hw_info_vtd - Intel VT-d hardware information
377+ *
378+ * @flags: Must be 0
379+ * @__reserved: Must be 0
380+ *
381+ * @cap_reg: Value of Intel VT-d capability register defined in VT-d spec
382+ * section 11.4.2 Capability Register.
383+ * @ecap_reg: Value of Intel VT-d capability register defined in VT-d spec
384+ * section 11.4.3 Extended Capability Register.
385+ *
386+ * User needs to understand the Intel VT-d specification to decode the
387+ * register value.
388+ */
389+struct iommu_hw_info_vtd {
390+ __u32 flags;
391+ __u32 __reserved;
392+ __aligned_u64 cap_reg;
393+ __aligned_u64 ecap_reg;
394+};
395+
396+/**
397+ * enum iommu_hw_info_type - IOMMU Hardware Info Types
398+ * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware
399+ * info
400+ * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type
401+ */
402+enum iommu_hw_info_type {
403+ IOMMU_HW_INFO_TYPE_NONE,
404+ IOMMU_HW_INFO_TYPE_INTEL_VTD,
405+};
406+
407+/**
408+ * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO)
409+ * @size: sizeof(struct iommu_hw_info)
410+ * @flags: Must be 0
411+ * @dev_id: The device bound to the iommufd
412+ * @data_len: Input the length of a user buffer in bytes. Output the length of
413+ * data that kernel supports
414+ * @data_uptr: User pointer to a user-space buffer used by the kernel to fill
415+ * the iommu type specific hardware information data
416+ * @out_data_type: Output the iommu hardware info type as defined in the enum
417+ * iommu_hw_info_type.
418+ * @__reserved: Must be 0
419+ *
420+ * Query an iommu type specific hardware information data from an iommu behind
421+ * a given device that has been bound to iommufd. This hardware info data will
422+ * be used to sync capabilities between the virtual iommu and the physical
423+ * iommu, e.g. a nested translation setup needs to check the hardware info, so
424+ * a guest stage-1 page table can be compatible with the physical iommu.
425+ *
426+ * To capture an iommu type specific hardware information data, @data_uptr and
427+ * its length @data_len must be provided. Trailing bytes will be zeroed if the
428+ * user buffer is larger than the data that kernel has. Otherwise, kernel only
429+ * fills the buffer using the given length in @data_len. If the ioctl succeeds,
430+ * @data_len will be updated to the length that kernel actually supports,
431+ * @out_data_type will be filled to decode the data filled in the buffer
432+ * pointed by @data_uptr. Input @data_len == zero is allowed.
433+ */
434+struct iommu_hw_info {
435+ __u32 size;
436+ __u32 flags;
437+ __u32 dev_id;
438+ __u32 data_len;
439+ __aligned_u64 data_uptr;
440+ __u32 out_data_type;
441+ __u32 __reserved;
442+};
443+#define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO)
347444 #endif
include/uapi/linux/vfio.h+6−0
@@ -940,6 +940,12 @@ struct vfio_device_bind_iommufd { · 939 unmodified lines
940940 * Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close. This is only
941941 * allowed on cdev fds.
942942 *
943+ * If a vfio device is currently attached to a valid hw_pagetable, without doing
944+ * a VFIO_DEVICE_DETACH_IOMMUFD_PT, a second VFIO_DEVICE_ATTACH_IOMMUFD_PT ioctl
945+ * passing in another hw_pagetable (hwpt) id is allowed. This action, also known
946+ * as a hw_pagetable replacement, will replace the device's currently attached
947+ * hw_pagetable with a new hw_pagetable corresponding to the given pt_id.
948+ *
943949 * Return: 0 on success, -errno on failure.
944950 */
945951 struct vfio_device_attach_iommufd_pt {