]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/arm-smmu-v3: Fix pgsize_bit for sva domains
authorBalbir Singh <balbirs@nvidia.com>
Sat, 12 Apr 2025 00:23:54 +0000 (10:23 +1000)
committerWill Deacon <will@kernel.org>
Thu, 17 Apr 2025 11:28:42 +0000 (12:28 +0100)
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: stable@vger.kernel.org
Fixes: eb6c97647be2 ("iommu/arm-smmu-v3: Avoid constructing invalid range commands")
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Balbir Singh <balbirs@nvidia.com>
Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20250412002354.3071449-1-balbirs@nvidia.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c

index 9ba596430e7cf9b0e67498a06f5b8f58021dfbb4..980cc6b33c430f627b5d777fb8b2057375af291e 100644 (file)
@@ -411,6 +411,12 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev,
                return ERR_CAST(smmu_domain);
        smmu_domain->domain.type = IOMMU_DOMAIN_SVA;
        smmu_domain->domain.ops = &arm_smmu_sva_domain_ops;
+
+       /*
+        * Choose page_size as the leaf page size for invalidation when
+        * ARM_SMMU_FEAT_RANGE_INV is present
+        */
+       smmu_domain->domain.pgsize_bitmap = PAGE_SIZE;
        smmu_domain->smmu = smmu;
 
        ret = xa_alloc(&arm_smmu_asid_xa, &asid, smmu_domain,