Skip to content

Commit 62622a8

Browse files
nicolincjgunthorpe
authored andcommitted
iommu: Allow an input type in hw_info op
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>
1 parent 035c921 commit 62622a8

6 files changed

Lines changed: 20 additions & 2 deletions

File tree

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length,
1515
u32 __iomem *base_idr;
1616
unsigned int i;
1717

18+
if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
19+
*type != IOMMU_HW_INFO_TYPE_ARM_SMMUV3)
20+
return ERR_PTR(-EOPNOTSUPP);
21+
1822
info = kzalloc(sizeof(*info), GFP_KERNEL);
1923
if (!info)
2024
return ERR_PTR(-ENOMEM);

drivers/iommu/intel/iommu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,10 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length,
40984098
struct intel_iommu *iommu = info->iommu;
40994099
struct iommu_hw_info_vtd *vtd;
41004100

4101+
if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
4102+
*type != IOMMU_HW_INFO_TYPE_INTEL_VTD)
4103+
return ERR_PTR(-EOPNOTSUPP);
4104+
41014105
vtd = kzalloc(sizeof(*vtd), GFP_KERNEL);
41024106
if (!vtd)
41034107
return ERR_PTR(-ENOMEM);

drivers/iommu/iommufd/device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,9 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
15121512
cmd->__reserved[2])
15131513
return -EOPNOTSUPP;
15141514

1515+
/* Clear the type field since drivers don't support a random input */
1516+
cmd->out_data_type = IOMMU_HW_INFO_TYPE_DEFAULT;
1517+
15151518
idev = iommufd_get_device(ucmd, cmd->dev_id);
15161519
if (IS_ERR(idev))
15171520
return PTR_ERR(idev);

drivers/iommu/iommufd/selftest.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length,
310310
{
311311
struct iommu_test_hw_info *info;
312312

313+
if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
314+
*type != IOMMU_HW_INFO_TYPE_SELFTEST)
315+
return ERR_PTR(-EOPNOTSUPP);
316+
313317
info = kzalloc(sizeof(*info), GFP_KERNEL);
314318
if (!info)
315319
return ERR_PTR(-ENOMEM);

include/linux/iommu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data,
603603
* @capable: check capability
604604
* @hw_info: report iommu hardware information. The data buffer returned by this
605605
* op is allocated in the iommu driver and freed by the caller after
606-
* use.
606+
* use. @type can input a requested type and output a supported type.
607+
* Driver should reject an unsupported data @type input
607608
* @domain_alloc: Do not use in new drivers
608609
* @domain_alloc_identity: allocate an IDENTITY domain. Drivers should prefer to
609610
* use identity_domain instead. This should only be used

include/uapi/linux/iommufd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,15 @@ struct iommu_hw_info_arm_smmuv3 {
593593

594594
/**
595595
* enum iommu_hw_info_type - IOMMU Hardware Info Types
596-
* @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware
596+
* @IOMMU_HW_INFO_TYPE_NONE: Output by the drivers that do not report hardware
597597
* info
598+
* @IOMMU_HW_INFO_TYPE_DEFAULT: Input to request for a default type
598599
* @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type
599600
* @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type
600601
*/
601602
enum iommu_hw_info_type {
602603
IOMMU_HW_INFO_TYPE_NONE = 0,
604+
IOMMU_HW_INFO_TYPE_DEFAULT = 0,
603605
IOMMU_HW_INFO_TYPE_INTEL_VTD = 1,
604606
IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2,
605607
};

0 commit comments

Comments
 (0)