]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu: Allow an input type in hw_info op
authorNicolin Chen <nicolinc@nvidia.com>
Thu, 10 Jul 2025 05:59:12 +0000 (22:59 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 11 Jul 2025 17:34:35 +0000 (14:34 -0300)
The hw_info uAPI will support a bidirectional data_type field that can be
used as an input field for user space to request for a specific info data.

To prepare for the uAPI update, change the iommu layer first:
 - Add a new IOMMU_HW_INFO_TYPE_DEFAULT as an input, for which driver can
   output its only (or firstly) supported type
 - Update the kdoc accordingly
 - Roll out the type validation in the existing drivers

Link: https://patch.msgid.link/r/00f4a2d3d930721f61367014717b3ba2d1e82a81.1752126748.git.nicolinc@nvidia.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
drivers/iommu/intel/iommu.c
drivers/iommu/iommufd/device.c
drivers/iommu/iommufd/selftest.c
include/linux/iommu.h
include/uapi/linux/iommufd.h

index 170d6916284870bd1cd4d12237b737ebf1247fc8..eb9fe1f6311a00fecca09e0ccc584593895eb45d 100644 (file)
@@ -15,6 +15,10 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length,
        u32 __iomem *base_idr;
        unsigned int i;
 
+       if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
+           *type != IOMMU_HW_INFO_TYPE_ARM_SMMUV3)
+               return ERR_PTR(-EOPNOTSUPP);
+
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
                return ERR_PTR(-ENOMEM);
index 850f1a6f548cc9a6a57b96d1522ea9b647a4c900..5f75faffca15a849bdd9f590a9d56b104bc2bb63 100644 (file)
@@ -4098,6 +4098,10 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length,
        struct intel_iommu *iommu = info->iommu;
        struct iommu_hw_info_vtd *vtd;
 
+       if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
+           *type != IOMMU_HW_INFO_TYPE_INTEL_VTD)
+               return ERR_PTR(-EOPNOTSUPP);
+
        vtd = kzalloc(sizeof(*vtd), GFP_KERNEL);
        if (!vtd)
                return ERR_PTR(-ENOMEM);
index 0567faff5680f5866955c321442548b31bd68bce..14955dc43892d000720844ffe1d2fd13ea267d00 100644 (file)
@@ -1512,6 +1512,9 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
            cmd->__reserved[2])
                return -EOPNOTSUPP;
 
+       /* Clear the type field since drivers don't support a random input */
+       cmd->out_data_type = IOMMU_HW_INFO_TYPE_DEFAULT;
+
        idev = iommufd_get_device(ucmd, cmd->dev_id);
        if (IS_ERR(idev))
                return PTR_ERR(idev);
index 8b2c44b3253077a030da75a15cd60d289c70fffd..a5dc36219a90c644277bba86d70641d8f3bab85f 100644 (file)
@@ -310,6 +310,10 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length,
 {
        struct iommu_test_hw_info *info;
 
+       if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
+           *type != IOMMU_HW_INFO_TYPE_SELFTEST)
+               return ERR_PTR(-EOPNOTSUPP);
+
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
                return ERR_PTR(-ENOMEM);
index e06a0fbe4bc77dfb5cc20a215af31aa2b47bf65b..e8b59ef54e4870da68e303c936e87feb7597a920 100644 (file)
@@ -603,7 +603,8 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data,
  * @capable: check capability
  * @hw_info: report iommu hardware information. The data buffer returned by this
  *           op is allocated in the iommu driver and freed by the caller after
- *           use.
+ *           use. @type can input a requested type and output a supported type.
+ *           Driver should reject an unsupported data @type input
  * @domain_alloc: Do not use in new drivers
  * @domain_alloc_identity: allocate an IDENTITY domain. Drivers should prefer to
  *                         use identity_domain instead. This should only be used
index b928c1ed23959921165aa9c462c45d6a4c6aa080..9c8c304b5de22b90ebf05c48219bd000f84cf66a 100644 (file)
@@ -593,13 +593,15 @@ struct iommu_hw_info_arm_smmuv3 {
 
 /**
  * enum iommu_hw_info_type - IOMMU Hardware Info Types
- * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware
+ * @IOMMU_HW_INFO_TYPE_NONE: Output by the drivers that do not report hardware
  *                           info
+ * @IOMMU_HW_INFO_TYPE_DEFAULT: Input to request for a default type
  * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type
  * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type
  */
 enum iommu_hw_info_type {
        IOMMU_HW_INFO_TYPE_NONE = 0,
+       IOMMU_HW_INFO_TYPE_DEFAULT = 0,
        IOMMU_HW_INFO_TYPE_INTEL_VTD = 1,
        IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2,
 };