Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751597AbcDTRfw (ORCPT ); Wed, 20 Apr 2016 13:35:52 -0400 Received: from foss.arm.com ([217.140.101.70]:49731 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750807AbcDTRfv (ORCPT ); Wed, 20 Apr 2016 13:35:51 -0400 Subject: Re: [PATCH v7 10/10] iommu/arm-smmu: call iommu_free_reserved_iova_domain on domain destruction To: Eric Auger , eric.auger@st.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org References: <1461084994-2355-1-git-send-email-eric.auger@linaro.org> <1461084994-2355-11-git-send-email-eric.auger@linaro.org> Cc: patches@linaro.org, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, Jean-Philippe.Brucker@arm.com, julien.grall@arm.com From: Robin Murphy Message-ID: <5717BDF1.7030400@arm.com> Date: Wed, 20 Apr 2016 18:35:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1461084994-2355-11-git-send-email-eric.auger@linaro.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2132 Lines: 68 On 19/04/16 17:56, Eric Auger wrote: > When the domain gets destroyed, let's make sure all reserved iova > resources get released. > > Choice is made to put that call in arm-smmu(-v3).c to do something similar > to what was done for iommu_put_dma_cookie. > > Signed-off-by: Eric Auger > > --- > > v7: new > --- > drivers/iommu/arm-smmu-v3.c | 2 ++ > drivers/iommu/arm-smmu.c | 2 ++ > 2 files changed, 4 insertions(+) > > diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c > index a077a35..afd0dac 100644 > --- a/drivers/iommu/arm-smmu-v3.c > +++ b/drivers/iommu/arm-smmu-v3.c > @@ -22,6 +22,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -1444,6 +1445,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) > struct arm_smmu_device *smmu = smmu_domain->smmu; > > iommu_put_dma_cookie(domain); > + iommu_free_reserved_iova_domain(domain); Yikes! No, drivers shouldn't be randomly freeing things they didn't allocate - the owner of the domain, who presumably allocated the thing, can call that right _before_ they call iommu_domain_free(). > free_io_pgtable_ops(smmu_domain->pgtbl_ops); > > /* Free the CD and ASID, if we allocated them */ > diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c > index 8cd7b8a..492339f 100644 > --- a/drivers/iommu/arm-smmu.c > +++ b/drivers/iommu/arm-smmu.c > @@ -30,6 +30,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -1009,6 +1010,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) > * already been detached. > */ > iommu_put_dma_cookie(domain); > + iommu_free_reserved_iova_domain(domain); ...which has the added bonus of preventing needless duplication everywhere. Robin. > arm_smmu_destroy_domain_context(domain); > kfree(smmu_domain); > } >