[PATCH v4 11/12] iommu/tegra-smmu: Release previous address space on paging domain switch
From: Mikko Perttunen
Date: Tue Nov 17 2026 - 19:38:00 EST
The tegra-smmu driver currently prepares an address space for each
SWGROUP when attaching a paging domain, but only unprepares it when
attaching the identity domain. In the present world without DMA default
(paging) domains, this broadly works, since drivers attaching a paging
domain will go from identity to paging and then back to identity when
detaching.
Once DMA default domains are enabled, attachments can go directly from
one paging domain to another. This leaks references to the previous
address space, keeping its ASID and page directory DMA mapping alive.
Fix this by having tegra_smmu_attach_dev also unprepare any previously
attached address spaces.
Signed-off-by: Mikko Perttunen <mperttunen@xxxxxxxxxx>
---
drivers/iommu/tegra-smmu.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index d0d23435d5b7..0e8414d8a504 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -507,24 +507,27 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain,
if (!fwspec)
return -ENOENT;
+ if (!fwspec->num_ids)
+ return -ENODEV;
+
for (index = 0; index < fwspec->num_ids; index++) {
err = tegra_smmu_as_prepare(smmu, as);
if (err)
- goto disable;
+ goto unprepare;
+ }
+ for (index = 0; index < fwspec->num_ids; index++)
tegra_smmu_enable(smmu, fwspec->ids[index], as->id);
- }
- if (index == 0)
- return -ENODEV;
+ if (old && (old->type & __IOMMU_DOMAIN_PAGING))
+ for (index = 0; index < fwspec->num_ids; index++)
+ tegra_smmu_as_unprepare(smmu, to_smmu_as(old));
return 0;
-disable:
- while (index--) {
- tegra_smmu_disable(smmu, fwspec->ids[index], as->id);
+unprepare:
+ while (index--)
tegra_smmu_as_unprepare(smmu, as);
- }
return err;
}
--
2.56.1