]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommufd: Deal with IOMMU_HWPT_FAULT_ID_VALID in iommufd core
authorYi Liu <yi.l.liu@intel.com>
Sat, 7 Dec 2024 12:01:08 +0000 (04:01 -0800)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 11 Dec 2024 19:46:14 +0000 (15:46 -0400)
IOMMU_HWPT_FAULT_ID_VALID is used to mark if the fault_id field of
iommu_hwp_alloc is valid or not. As the fault_id field is handled in
the iommufd core, so it makes sense to sanitize the
IOMMU_HWPT_FAULT_ID_VALID flag in the iommufd core, and mask it out
before passing the user flags to the iommu drivers.

Link: https://patch.msgid.link/r/20241207120108.5640-1-yi.l.liu@intel.com
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.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/hw_pagetable.c
drivers/iommu/iommufd/selftest.c

index c7cc613050d933d76ebced5d556466da165571c2..5aa2e7af58b47b24ef11b7254e04e1e5a07716e3 100644 (file)
@@ -178,18 +178,12 @@ arm_vsmmu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
                              const struct iommu_user_data *user_data)
 {
        struct arm_vsmmu *vsmmu = container_of(viommu, struct arm_vsmmu, core);
-       const u32 SUPPORTED_FLAGS = IOMMU_HWPT_FAULT_ID_VALID;
        struct arm_smmu_nested_domain *nested_domain;
        struct iommu_hwpt_arm_smmuv3 arg;
        bool enable_ats = false;
        int ret;
 
-       /*
-        * Faults delivered to the nested domain are faults that originated by
-        * the S1 in the domain. The core code will match all PASIDs when
-        * delivering the fault due to user_pasid_table
-        */
-       if (flags & ~SUPPORTED_FLAGS)
+       if (flags)
                return ERR_PTR(-EOPNOTSUPP);
 
        ret = iommu_copy_struct_from_user(&arg, user_data,
index 7d0acb74d5a54386194d4df1ec01f6f69150fb02..c8f9c70a04ab481f8942a90f5f73105c365b65c5 100644 (file)
@@ -3340,8 +3340,7 @@ intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
        bool first_stage;
 
        if (flags &
-           (~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING
-              | IOMMU_HWPT_FAULT_ID_VALID)))
+           (~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING)))
                return ERR_PTR(-EOPNOTSUPP);
        if (nested_parent && !nested_supported(iommu))
                return ERR_PTR(-EOPNOTSUPP);
index ce03c380465154a4db1af4232989587c91d17c75..598be26a14e28e93fe86934e16c341dc48d60793 100644 (file)
@@ -140,8 +140,8 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
        hwpt_paging->nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT;
 
        if (ops->domain_alloc_paging_flags) {
-               hwpt->domain = ops->domain_alloc_paging_flags(idev->dev, flags,
-                                                             user_data);
+               hwpt->domain = ops->domain_alloc_paging_flags(idev->dev,
+                               flags & ~IOMMU_HWPT_FAULT_ID_VALID, user_data);
                if (IS_ERR(hwpt->domain)) {
                        rc = PTR_ERR(hwpt->domain);
                        hwpt->domain = NULL;
@@ -280,6 +280,8 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
        struct iommufd_hw_pagetable *hwpt;
        int rc;
 
+       if (flags & ~IOMMU_HWPT_FAULT_ID_VALID)
+               return ERR_PTR(-EOPNOTSUPP);
        if (!user_data->len)
                return ERR_PTR(-EOPNOTSUPP);
        if (!viommu->ops || !viommu->ops->alloc_domain_nested)
@@ -296,7 +298,9 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
        hwpt_nested->parent = viommu->hwpt;
 
        hwpt->domain =
-               viommu->ops->alloc_domain_nested(viommu, flags, user_data);
+               viommu->ops->alloc_domain_nested(viommu,
+                               flags & ~IOMMU_HWPT_FAULT_ID_VALID,
+                               user_data);
        if (IS_ERR(hwpt->domain)) {
                rc = PTR_ERR(hwpt->domain);
                hwpt->domain = NULL;
index 6512c1d163481f52a28fe5bba1cc748064cfa5ec..d40deb0a4f06215c3e53f4a2588f4d40d46e1067 100644 (file)
@@ -585,7 +585,7 @@ mock_viommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
        struct mock_viommu *mock_viommu = to_mock_viommu(viommu);
        struct mock_iommu_domain_nested *mock_nested;
 
-       if (flags & ~IOMMU_HWPT_FAULT_ID_VALID)
+       if (flags)
                return ERR_PTR(-EOPNOTSUPP);
 
        mock_nested = __mock_domain_alloc_nested(user_data);