Skip to contentSkip to conversation

iommu/arm-smmu-v3: Fix pgsize_bit for sva domains

PATCH In review Qinxin Xia 1 participant 2 messages May 25 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Qinxin Xia

author
#1 lore raw

PATCH 4/4 iommu/arm-smmu-v3: Fix pgsize_bit for sva domains

From: Balbir Singh <[email protected]>

mainline inclusion
from mainline-v6.15-rc5
commit 12f78021973ae422564b234136c702a305932d73
category: bugfix
bugzilla: https://atomgit.com/openeuler/kernel/issues/9215
CVE: NA

Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=12f78021973ae422564b234136c702a305932d73

----------------------------------------------------------------------

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

Fixes eb6c97647be2 ("iommu/arm-smmu-v3: Avoid constructing invalid range commands")
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +6 -0
index 9342fac71801..4075ef00c4c9 100644
@@ -402,6 +402,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,
Signature · 1 line
2.33.0
author
#2 lore raw

Sorry for the noise – I forgot to use --suppress-cc=all when sending the patch. Please ignore the previous email. Thanks.

Quoted 61 lines · Qinxin Xia

From: Balbir Singh <[email protected]>

mainline inclusion
from mainline-v6.15-rc5
commit 12f78021973ae422564b234136c702a305932d73
category: bugfix
bugzilla: https://atomgit.com/openeuler/kernel/issues/9215
CVE: NA

Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=12f78021973ae422564b234136c702a305932d73

----------------------------------------------------------------------

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

Fixes eb6c97647be2 ("iommu/arm-smmu-v3: Avoid constructing invalid range commands")
---
  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +6 -0
index 9342fac71801..4075ef00c4c9 100644
@@ -402,6 +402,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,
Signature · 2 lines
Thanks,
Qinxin