[PATCH v4 9/9] iommufd/selftest: Add coverage for IOPF test

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

[PATCH v4 8/9] iommufd/selftest: Add IOPF support for mock device

2024-04-02 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 hardware.

[PATCH v4 7/9] iommufd: Associate fault object with iommufd_hw_pgtable

2024-04-02 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 r

[PATCH v4 6/9] iommufd: Add iommufd fault object

2024-04-02 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 v4 5/9] iommufd: Add fault and response message definitions

2024-04-02 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 shoul

[PATCH v4 4/9] iommufd: Fault-capable hw page table attach/detach/replace

2024-04-02 Thread Lu Baolu
Add iopf-capable hw page table attach/detach/replace helpers. The pointer to iommufd_device is stored in the domain attachment handle, so that it can be echo'ed back in the iopf_group. The iopf-capable hw page tables can only be attached to devices that support the IOMMU_DEV_FEAT_IOPF feature. On

[PATCH v4 3/9] iommu: Add attachment handle to struct iopf_group

2024-04-02 Thread Lu Baolu
Previously, the domain that a page fault targets is stored in an iopf_group, which represents a minimal set of page faults. With the introduction of attachment handle, replace the domain with the handle so that the fault handler can obtain more information as needed when handling the faults. iommu

[PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-02 Thread Lu Baolu
The struct sva_iommu represents a bond of an SVA domain and a device. It is functionally equivalent to the iommu_attach_handle. To avoid code duplication, replace sva_iommu with the iommu_attach_handle and remove the code that manages sva_iommu. Signed-off-by: Lu Baolu --- include/linux/iommu.h

[PATCH v4 1/9] iommu: Introduce domain attachment handle

2024-04-02 Thread Lu Baolu
Currently, when attaching a domain to a device or its PASID, domain is stored within the iommu group. It could be retrieved for use during the window between attachment and detachment. With new features introduced, there's a need to store more information than just a domain pointer. This informati

[PATCH v4 0/9] IOMMUFD: Deliver IO page faults to user space

2024-04-02 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 ma