[PATCH v3 8/8] iommufd/selftest: Add coverage for IOPF test

2024-01-21 Thread Lu Baolu
Extend the selftest tool to add coverage of testing IOPF handling. This would include the following tests: - Allocating and destorying an iommufd fault object. - Allocating and destroying an IOPF-capable HWPT. - Attaching/detaching/replacing an IOPF-capable HWPT on a device. - Triggering an IOPF

[PATCH v3 7/8] iommufd/selftest: Add IOPF support for mock device

2024-01-21 Thread Lu Baolu
Extend the selftest mock device to support generating and responding to an IOPF. Also add an ioctl interface to userspace applications to trigger the IOPF on the mock device. This would allow userspace applications to test the IOMMUFD's handling of IOPFs without having to rely on any real

[PATCH v3 6/8] iommufd: IOPF-capable hw page table attach/detach/replace

2024-01-21 Thread Lu Baolu
The iopf-capable hw page table attach/detach/replace should use the iommu iopf-specific interfaces. The pointer to iommufd_device is stored in the private field of the attachment cookie, so that it can be easily retrieved in the fault handling paths. The references to iommufd_device and

[PATCH v3 5/8] iommufd: Associate fault object with iommufd_hw_pgtable

2024-01-21 Thread Lu Baolu
When allocating a user iommufd_hw_pagetable, the user space is allowed to associate a fault object with the hw_pagetable by specifying the fault object ID in the page table allocation data and setting the IOMMU_HWPT_FAULT_ID_VALID flag bit. On a successful return of hwpt allocation, the user can

[PATCH v3 4/8] iommufd: Add iommufd fault object

2024-01-21 Thread Lu Baolu
An iommufd fault object provides an interface for delivering I/O page faults to user space. These objects are created and destroyed by user space, and they can be associated with or dissociated from hardware page table objects during page table allocation or destruction. User space interacts with

[PATCH v3 3/8] iommufd: Add fault and response message definitions

2024-01-21 Thread Lu Baolu
iommu_hwpt_pgfaults represent fault messages that the userspace can retrieve. Multiple iommu_hwpt_pgfaults might be put in an iopf group, with the IOMMU_PGFAULT_FLAGS_LAST_PAGE flag set only for the last iommu_hwpt_pgfault. An iommu_hwpt_page_response is a response message that the userspace

[PATCH v3 2/8] iommu/sva: Use iopf domain attach/detach interface

2024-01-21 Thread Lu Baolu
The iommu sva implementation relies on iopf handling. Allocate an attachment cookie and use the iopf domain attach/detach interface. The SVA domain is guaranteed to be released after all outstanding page faults are handled. In the fault delivering path, the attachment cookie is retrieved, instead

[PATCH v3 1/8] iommu: Add iopf domain attach/detach/replace interface

2024-01-21 Thread Lu Baolu
There is a slight difference between iopf domains and non-iopf domains. In the latter, references to domains occur between attach and detach; While in the former, due to the existence of asynchronous iopf handling paths, references to the domain may occur after detach, which leads to potential UAF

[PATCH v3 0/8] IOMMUFD: Deliver IO page faults to user space

2024-01-21 Thread Lu Baolu
This series implements the functionality of delivering IO page faults to user space through the IOMMUFD framework. One feasible use case is the nested translation. Nested translation is a hardware feature that supports two-stage translation tables for IOMMU. The second-stage translation table is