Skip to content

Commit 11534b4

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd: Deal with IOMMU_HWPT_FAULT_ID_VALID in iommufd core
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/[email protected] Signed-off-by: Yi Liu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent d61927d commit 11534b4

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,12 @@ arm_vsmmu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
178178
const struct iommu_user_data *user_data)
179179
{
180180
struct arm_vsmmu *vsmmu = container_of(viommu, struct arm_vsmmu, core);
181-
const u32 SUPPORTED_FLAGS = IOMMU_HWPT_FAULT_ID_VALID;
182181
struct arm_smmu_nested_domain *nested_domain;
183182
struct iommu_hwpt_arm_smmuv3 arg;
184183
bool enable_ats = false;
185184
int ret;
186185

187-
/*
188-
* Faults delivered to the nested domain are faults that originated by
189-
* the S1 in the domain. The core code will match all PASIDs when
190-
* delivering the fault due to user_pasid_table
191-
*/
192-
if (flags & ~SUPPORTED_FLAGS)
186+
if (flags)
193187
return ERR_PTR(-EOPNOTSUPP);
194188

195189
ret = iommu_copy_struct_from_user(&arg, user_data,

drivers/iommu/intel/iommu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,8 +3340,7 @@ intel_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
33403340
bool first_stage;
33413341

33423342
if (flags &
3343-
(~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING
3344-
| IOMMU_HWPT_FAULT_ID_VALID)))
3343+
(~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING)))
33453344
return ERR_PTR(-EOPNOTSUPP);
33463345
if (nested_parent && !nested_supported(iommu))
33473346
return ERR_PTR(-EOPNOTSUPP);

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
140140
hwpt_paging->nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT;
141141

142142
if (ops->domain_alloc_paging_flags) {
143-
hwpt->domain = ops->domain_alloc_paging_flags(idev->dev, flags,
144-
user_data);
143+
hwpt->domain = ops->domain_alloc_paging_flags(idev->dev,
144+
flags & ~IOMMU_HWPT_FAULT_ID_VALID, user_data);
145145
if (IS_ERR(hwpt->domain)) {
146146
rc = PTR_ERR(hwpt->domain);
147147
hwpt->domain = NULL;
@@ -280,6 +280,8 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
280280
struct iommufd_hw_pagetable *hwpt;
281281
int rc;
282282

283+
if (flags & ~IOMMU_HWPT_FAULT_ID_VALID)
284+
return ERR_PTR(-EOPNOTSUPP);
283285
if (!user_data->len)
284286
return ERR_PTR(-EOPNOTSUPP);
285287
if (!viommu->ops || !viommu->ops->alloc_domain_nested)
@@ -296,7 +298,9 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
296298
hwpt_nested->parent = viommu->hwpt;
297299

298300
hwpt->domain =
299-
viommu->ops->alloc_domain_nested(viommu, flags, user_data);
301+
viommu->ops->alloc_domain_nested(viommu,
302+
flags & ~IOMMU_HWPT_FAULT_ID_VALID,
303+
user_data);
300304
if (IS_ERR(hwpt->domain)) {
301305
rc = PTR_ERR(hwpt->domain);
302306
hwpt->domain = NULL;

drivers/iommu/iommufd/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ mock_viommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
585585
struct mock_viommu *mock_viommu = to_mock_viommu(viommu);
586586
struct mock_iommu_domain_nested *mock_nested;
587587

588-
if (flags & ~IOMMU_HWPT_FAULT_ID_VALID)
588+
if (flags)
589589
return ERR_PTR(-EOPNOTSUPP);
590590

591591
mock_nested = __mock_domain_alloc_nested(user_data);

0 commit comments

Comments
 (0)