Skip to content

Commit 95d4782

Browse files
nicolincwilldeacon
authored andcommitted
iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()
The arm_smmu_mm_invalidate_range function is designed to be called by mm core for Shared Virtual Addressing purpose between IOMMU and CPU MMU. However, the ways of two subsystems defining their "end" addresses are slightly different. IOMMU defines its "end" address using the last address of an address range, while mm core defines that using the following address of an address range: include/linux/mm_types.h: unsigned long vm_end; /* The first byte after our end address ... This mismatch resulted in an incorrect calculation for size so it failed to be page-size aligned. Further, it caused a dead loop at "while (iova < end)" check in __arm_smmu_tlb_inv_range function. This patch fixes the issue by doing the calculation correctly. Fixes: 2f7e8c5 ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops") Cc: stable@vger.kernel.org Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Link: https://lore.kernel.org/r/20220419210158.21320-1-nicolinc@nvidia.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 3123109 commit 95d4782

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn,
183183
{
184184
struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn);
185185
struct arm_smmu_domain *smmu_domain = smmu_mn->domain;
186-
size_t size = end - start + 1;
186+
size_t size;
187+
188+
/*
189+
* The mm_types defines vm_end as the first byte after the end address,
190+
* different from IOMMU subsystem using the last address of an address
191+
* range. So do a simple translation here by calculating size correctly.
192+
*/
193+
size = end - start;
187194

188195
if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM))
189196
arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid,

0 commit comments

Comments
 (0)