Skip to content

Commit 12f7802

Browse files
balbirs-nvwilldeacon
authored andcommitted
iommu/arm-smmu-v3: Fix pgsize_bit for sva domains
UBSan caught a bug with IOMMU SVA domains, where the reported exponent value in __arm_smmu_tlb_inv_range() was >= 64. __arm_smmu_tlb_inv_range() uses the domain's pgsize_bitmap to compute the number of pages to invalidate and the invalidation range. Currently arm_smmu_sva_domain_alloc() does not setup the iommu domain's pgsize_bitmap. This leads to __ffs() on the value returning 64 and that leads to undefined behaviour w.r.t. shift operations Fix this by initializing the iommu_domain's pgsize_bitmap to PAGE_SIZE. Effectively the code needs to use the smallest page size for invalidation Cc: [email protected] Fixes: eb6c976 ("iommu/arm-smmu-v3: Avoid constructing invalid range commands") Suggested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Balbir Singh <[email protected]> Cc: Jean-Philippe Brucker <[email protected]> Cc: Will Deacon <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jason Gunthorpe <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 45e00e3 commit 12f7802

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev,
411411
return ERR_CAST(smmu_domain);
412412
smmu_domain->domain.type = IOMMU_DOMAIN_SVA;
413413
smmu_domain->domain.ops = &arm_smmu_sva_domain_ops;
414+
415+
/*
416+
* Choose page_size as the leaf page size for invalidation when
417+
* ARM_SMMU_FEAT_RANGE_INV is present
418+
*/
419+
smmu_domain->domain.pgsize_bitmap = PAGE_SIZE;
414420
smmu_domain->smmu = smmu;
415421

416422
ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain,

0 commit comments

Comments
 (0)