[PATCH 2/5] iommu/qcom: Invalidate the same range on every context bank

Gopikrishna Garmidi gopikrishna.garmidi at oss.qualcomm.com
Mon Nov 30 03:48:10 PST 2026


qcom_iommu_tlb_inv_range_nosync() loops over the contexts of the
domain's fwspec, but updates its iova argument inside the loop: it ORs
the first context's ASID into it and advances it by the invalidated
size. The next context then starts from the end of the range with the
previous ASID masked off and re-ORed, so it invalidates
[iova + size, iova + 2 * size) instead of [iova, iova + size).

A master with more than one context bank therefore keeps stale TLB
entries for the unmapped range on every context but the first, which
allows DMA to reach memory that has already been unmapped.

Use a local address for each context.

Fixes: 0ae349a0f33f ("iommu/qcom: Add qcom_iommu")
Signed-off-by: Gopikrishna Garmidi <gopikrishna.garmidi at oss.qualcomm.com>
---
Found by reading the code with the help of an LLM.

 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 96903cd9cfc2..c52e7a9f8233 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -156,12 +156,13 @@ static void qcom_iommu_tlb_inv_range_nosync(unsigned long iova, size_t size,
 	for (i = 0; i < fwspec->num_ids; i++) {
 		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
 		size_t s = size;
+		unsigned long addr;
 
-		iova = (iova >> 12) << 12;
-		iova |= ctx->asid;
+		addr = (iova >> 12) << 12;
+		addr |= ctx->asid;
 		do {
-			iommu_writel(ctx, reg, iova);
-			iova += granule;
+			iommu_writel(ctx, reg, addr);
+			addr += granule;
 		} while (s -= granule);
 	}
 }
-- 
2.34.1




More information about the linux-arm-kernel mailing list