Skip to content

Commit c714f15

Browse files
LuBaolujgunthorpe
authored andcommitted
iommufd: Add fault and response message definitions
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 should send to the kernel after finishing handling a group of fault messages. The @dev_id, @Pasid, and @grpid fields in the message identify an outstanding iopf group for a device. The @cookie field, which matches the cookie field of the last fault in the group, will be used by the kernel to look up the pending message. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 8519e68 commit c714f15

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

include/uapi/linux/iommufd.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,4 +692,87 @@ struct iommu_hwpt_invalidate {
692692
__u32 __reserved;
693693
};
694694
#define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE)
695+
696+
/**
697+
* enum iommu_hwpt_pgfault_flags - flags for struct iommu_hwpt_pgfault
698+
* @IOMMU_PGFAULT_FLAGS_PASID_VALID: The pasid field of the fault data is
699+
* valid.
700+
* @IOMMU_PGFAULT_FLAGS_LAST_PAGE: It's the last fault of a fault group.
701+
*/
702+
enum iommu_hwpt_pgfault_flags {
703+
IOMMU_PGFAULT_FLAGS_PASID_VALID = (1 << 0),
704+
IOMMU_PGFAULT_FLAGS_LAST_PAGE = (1 << 1),
705+
};
706+
707+
/**
708+
* enum iommu_hwpt_pgfault_perm - perm bits for struct iommu_hwpt_pgfault
709+
* @IOMMU_PGFAULT_PERM_READ: request for read permission
710+
* @IOMMU_PGFAULT_PERM_WRITE: request for write permission
711+
* @IOMMU_PGFAULT_PERM_EXEC: (PCIE 10.4.1) request with a PASID that has the
712+
* Execute Requested bit set in PASID TLP Prefix.
713+
* @IOMMU_PGFAULT_PERM_PRIV: (PCIE 10.4.1) request with a PASID that has the
714+
* Privileged Mode Requested bit set in PASID TLP
715+
* Prefix.
716+
*/
717+
enum iommu_hwpt_pgfault_perm {
718+
IOMMU_PGFAULT_PERM_READ = (1 << 0),
719+
IOMMU_PGFAULT_PERM_WRITE = (1 << 1),
720+
IOMMU_PGFAULT_PERM_EXEC = (1 << 2),
721+
IOMMU_PGFAULT_PERM_PRIV = (1 << 3),
722+
};
723+
724+
/**
725+
* struct iommu_hwpt_pgfault - iommu page fault data
726+
* @flags: Combination of enum iommu_hwpt_pgfault_flags
727+
* @dev_id: id of the originated device
728+
* @pasid: Process Address Space ID
729+
* @grpid: Page Request Group Index
730+
* @perm: Combination of enum iommu_hwpt_pgfault_perm
731+
* @addr: Fault address
732+
* @length: a hint of how much data the requestor is expecting to fetch. For
733+
* example, if the PRI initiator knows it is going to do a 10MB
734+
* transfer, it could fill in 10MB and the OS could pre-fault in
735+
* 10MB of IOVA. It's default to 0 if there's no such hint.
736+
* @cookie: kernel-managed cookie identifying a group of fault messages. The
737+
* cookie number encoded in the last page fault of the group should
738+
* be echoed back in the response message.
739+
*/
740+
struct iommu_hwpt_pgfault {
741+
__u32 flags;
742+
__u32 dev_id;
743+
__u32 pasid;
744+
__u32 grpid;
745+
__u32 perm;
746+
__u64 addr;
747+
__u32 length;
748+
__u32 cookie;
749+
};
750+
751+
/**
752+
* enum iommufd_page_response_code - Return status of fault handlers
753+
* @IOMMUFD_PAGE_RESP_SUCCESS: Fault has been handled and the page tables
754+
* populated, retry the access. This is the
755+
* "Success" defined in PCI 10.4.2.1.
756+
* @IOMMUFD_PAGE_RESP_INVALID: Could not handle this fault, don't retry the
757+
* access. This is the "Invalid Request" in PCI
758+
* 10.4.2.1.
759+
* @IOMMUFD_PAGE_RESP_FAILURE: General error. Drop all subsequent faults from
760+
* this device if possible. This is the "Response
761+
* Failure" in PCI 10.4.2.1.
762+
*/
763+
enum iommufd_page_response_code {
764+
IOMMUFD_PAGE_RESP_SUCCESS = 0,
765+
IOMMUFD_PAGE_RESP_INVALID,
766+
IOMMUFD_PAGE_RESP_FAILURE,
767+
};
768+
769+
/**
770+
* struct iommu_hwpt_page_response - IOMMU page fault response
771+
* @cookie: The kernel-managed cookie reported in the fault message.
772+
* @code: One of response code in enum iommufd_page_response_code.
773+
*/
774+
struct iommu_hwpt_page_response {
775+
__u32 cookie;
776+
__u32 code;
777+
};
695778
#endif

0 commit comments

Comments
 (0)