From e6a18bb617e4b9714fc3e7e110ff8fa638433936 Mon Sep 17 00:00:00 2001 From: Prakash Gupta Date: Mon, 18 Sep 2017 14:34:11 +0530 Subject: [PATCH] iommu: free io pgtable during domain detach. Pagetable pgd is allocated in arm_smmu_init_domain_context and is freed in arm_smmu_domain_free. Client can attach/detach domain without freeing the same. This causes memory leak. This was introduced with commit fe676929a960 ("iommu/arm-smmu: fix a DOMAIN_ATTR_DYNAMIC memory leak") Free io pgtables in arm_smmu_destroy_domain_context, which is invoked at the time of domain detach. Change-Id: Ib53e4efdd8dca33437596f3f0ccaa8ccaae79ca0 Signed-off-by: Prakash Gupta --- drivers/iommu/arm-smmu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index b30739de79e7..62230d30d101 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1956,10 +1956,20 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain) cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); writel_relaxed(0, cb_base + ARM_SMMU_CB_SCTLR); - arm_smmu_tlb_inv_context(smmu_domain); - arm_smmu_disable_clocks(smmu_domain->smmu); + if (smmu_domain->pgtbl_ops) { + free_io_pgtable_ops(smmu_domain->pgtbl_ops); + /* unassign any freed page table memory */ + if (arm_smmu_is_master_side_secure(smmu_domain)) { + arm_smmu_secure_domain_lock(smmu_domain); + arm_smmu_secure_pool_destroy(smmu_domain); + arm_smmu_unassign_table(smmu_domain); + arm_smmu_secure_domain_unlock(smmu_domain); + } + smmu_domain->pgtbl_ops = NULL; + } + free_irqs: if (cfg->irptndx != INVALID_IRPTNDX) { irq = smmu->irqs[smmu->num_global_irqs + cfg->irptndx];