iommufd: Add capabilities to IOMMU_GET_HW_INFO
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 24 Oct 2023 13:50:59 +0000 (14:50 +0100)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 24 Oct 2023 14:58:43 +0000 (11:58 -0300)
Extend IOMMUFD_CMD_GET_HW_INFO op to query generic iommu capabilities for a
given device.

Capabilities are IOMMU agnostic and use device_iommu_capable() API passing
one of the IOMMU_CAP_*. Enumerate IOMMU_CAP_DIRTY_TRACKING for now in the
out_capabilities field returned back to userspace.

Link: https://lore.kernel.org/r/20231024135109.73787-9-joao.m.martins@oracle.com
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/device.c
include/uapi/linux/iommufd.h

index e88fa73a45e6f111b526f60fccbd5eb11140c82b..2a41fd2b6ef8e13b0c39e512dd484ec5c9ebab21 100644 (file)
@@ -1185,6 +1185,10 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
         */
        cmd->data_len = data_len;
 
+       cmd->out_capabilities = 0;
+       if (device_iommu_capable(idev->dev, IOMMU_CAP_DIRTY_TRACKING))
+               cmd->out_capabilities |= IOMMU_HW_CAP_DIRTY_TRACKING;
+
        rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
 out_free:
        kfree(data);
index dce38e32ca841accf3f5b1a85014b6a38eae45ee..036ebc6c19cf9ed75e1e9c08ac57e56b9a7f454e 100644 (file)
@@ -418,6 +418,20 @@ enum iommu_hw_info_type {
        IOMMU_HW_INFO_TYPE_INTEL_VTD,
 };
 
+/**
+ * enum iommufd_hw_capabilities
+ * @IOMMU_HW_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
+ *                               If available, it means the following APIs
+ *                               are supported:
+ *
+ *                                   IOMMU_HWPT_GET_DIRTY_BITMAP
+ *                                   IOMMU_HWPT_SET_DIRTY_TRACKING
+ *
+ */
+enum iommufd_hw_capabilities {
+       IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0,
+};
+
 /**
  * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO)
  * @size: sizeof(struct iommu_hw_info)
@@ -429,6 +443,8 @@ enum iommu_hw_info_type {
  *             the iommu type specific hardware information data
  * @out_data_type: Output the iommu hardware info type as defined in the enum
  *                 iommu_hw_info_type.
+ * @out_capabilities: Output the generic iommu capability info type as defined
+ *                    in the enum iommu_hw_capabilities.
  * @__reserved: Must be 0
  *
  * Query an iommu type specific hardware information data from an iommu behind
@@ -453,6 +469,7 @@ struct iommu_hw_info {
        __aligned_u64 data_uptr;
        __u32 out_data_type;
        __u32 __reserved;
+       __aligned_u64 out_capabilities;
 };
 #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO)