From patchwork Mon Apr 4 08:07:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 64957 Delivered-To: patches@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1047279lbc; Mon, 4 Apr 2016 01:07:33 -0700 (PDT) X-Received: by 10.112.210.200 with SMTP id mw8mr4739649lbc.16.1459757253206; Mon, 04 Apr 2016 01:07:33 -0700 (PDT) Return-Path: Received: from mail-lf0-x230.google.com (mail-lf0-x230.google.com. [2a00:1450:4010:c07::230]) by mx.google.com with ESMTPS id lb7si15247766lbc.89.2016.04.04.01.07.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Apr 2016 01:07:33 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:4010:c07::230 as permitted sender) client-ip=2a00:1450:4010:c07::230; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:4010:c07::230 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x230.google.com with SMTP id c126so38337953lfb.2 for ; Mon, 04 Apr 2016 01:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GQcH5kWyDGeQCQoZETehCdUvAPKCUMPVJZrKIRdBYn0=; b=Ibvcp63nqaDWBXExchAb88q2ugeLpncmEloZJ3Ve1awKtWwEBbFyKlRMEUWBFn5ehZ zd0/48Azx5Ut7kIChYNFvTL2fbhz0oa1u0WmsM4V1azIUjI+IiJWTY/gdNKoWjL4a54P Kdt+cz5zDlovjk2wMXSsGDE40TawweZ+uiPl8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GQcH5kWyDGeQCQoZETehCdUvAPKCUMPVJZrKIRdBYn0=; b=BVrfm56KCmW2LYsgalO4onlwoSMII9u5H9Mc0EcnddwtZIlEitUo7jaKPg1AVVKcEY to3g8icZYucxFabPiLC58VLhTmn7kiK8Ml3AjHdT9VG36+A1rEp13atgm04KLu1enXfQ ncxlPKpQqAprXCkajVh0UAU4qJd3MmTGpnn1pTqCiZ15nb5nBG/mX4N31WwlhNaZffNv myHTvtEg3mJ3R4xhddi3QYgiwbdE6lJHorpt3poymNQZo7gd4EABPm49bAAnXK0nmP6Z acs/kFcD4Ohfs5Sc2DwK3lPrTRmuL5ZfGoWoJPsTlXi8Ao1IlgkZScy0krKs4mY1d8WK 2zZA== X-Gm-Message-State: AD7BkJIq9jUsS234emcuULWb/qpYqykWw6wb52/qCCXhE7x5nGsbLbCqkbnUbxLrA/reXLzrMoo= X-Received: by 10.194.89.38 with SMTP id bl6mr12904272wjb.44.1459757252995; Mon, 04 Apr 2016 01:07:32 -0700 (PDT) Return-Path: Received: from new-host-2.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id m67sm7505239wma.3.2016.04.04.01.07.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Apr 2016 01:07:31 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, robin.murphy@arm.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, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: suravee.suthikulpanit@amd.com, patches@linaro.org, linux-kernel@vger.kernel.org, Manish.Jaggi@caviumnetworks.com, 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 Subject: [PATCH v6 7/7] dma-reserved-iommu: iommu_unmap_reserved Date: Mon, 4 Apr 2016 08:07:02 +0000 Message-Id: <1459757222-2668-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459757222-2668-1-git-send-email-eric.auger@linaro.org> References: <1459757222-2668-1-git-send-email-eric.auger@linaro.org> Introduce a new function whose role is to unmap all allocated reserved IOVAs and free the reserved iova domain Signed-off-by: Eric Auger --- v5 -> v6: - use spin_lock instead of mutex v3 -> v4: - previously "iommu/arm-smmu: relinquish reserved resources on domain deletion" --- drivers/iommu/dma-reserved-iommu.c | 45 ++++++++++++++++++++++++++++++++++---- include/linux/dma-reserved-iommu.h | 7 ++++++ 2 files changed, 48 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c index 3c759d9..c06c39e 100644 --- a/drivers/iommu/dma-reserved-iommu.c +++ b/drivers/iommu/dma-reserved-iommu.c @@ -119,20 +119,24 @@ unlock: } EXPORT_SYMBOL_GPL(iommu_alloc_reserved_iova_domain); -void iommu_free_reserved_iova_domain(struct iommu_domain *domain) +void __iommu_free_reserved_iova_domain(struct iommu_domain *domain) { struct iova_domain *iovad = (struct iova_domain *)domain->reserved_iova_cookie; - unsigned long flags; if (!iovad) return; - spin_lock_irqsave(&domain->reserved_lock, flags); - put_iova_domain(iovad); kfree(iovad); +} + +void iommu_free_reserved_iova_domain(struct iommu_domain *domain) +{ + unsigned long flags; + spin_lock_irqsave(&domain->reserved_lock, flags); + __iommu_free_reserved_iova_domain(domain); spin_unlock_irqrestore(&domain->reserved_lock, flags); } EXPORT_SYMBOL_GPL(iommu_free_reserved_iova_domain); @@ -281,4 +285,37 @@ unlock: EXPORT_SYMBOL_GPL(iommu_put_reserved_iova); +static void reserved_binding_release(struct kref *kref) +{ + struct iommu_reserved_binding *b = + container_of(kref, struct iommu_reserved_binding, kref); + struct iommu_domain *d = b->domain; + + delete_reserved_binding(d, b); +} + +void iommu_unmap_reserved(struct iommu_domain *domain) +{ + struct rb_node *node; + unsigned long flags; + + spin_lock_irqsave(&domain->reserved_lock, flags); + while ((node = rb_first(&domain->reserved_binding_list))) { + struct iommu_reserved_binding *b = + rb_entry(node, struct iommu_reserved_binding, node); + + unlink_reserved_binding(domain, b); + spin_unlock_irqrestore(&domain->reserved_lock, flags); + + while (!kref_put(&b->kref, reserved_binding_release)) + ; + spin_lock_irqsave(&domain->reserved_lock, flags); + } + domain->reserved_binding_list = RB_ROOT; + __iommu_free_reserved_iova_domain(domain); + spin_unlock_irqrestore(&domain->reserved_lock, flags); +} +EXPORT_SYMBOL_GPL(iommu_unmap_reserved); + + diff --git a/include/linux/dma-reserved-iommu.h b/include/linux/dma-reserved-iommu.h index dedea56..9fba930 100644 --- a/include/linux/dma-reserved-iommu.h +++ b/include/linux/dma-reserved-iommu.h @@ -68,6 +68,13 @@ int iommu_get_reserved_iova(struct iommu_domain *domain, */ void iommu_put_reserved_iova(struct iommu_domain *domain, dma_addr_t iova); +/** + * iommu_unmap_reserved: unmap & destroy the reserved iova bindings + * + * @domain: iommu domain handle + */ +void iommu_unmap_reserved(struct iommu_domain *domain); + #endif /* CONFIG_IOMMU_DMA_RESERVED */ #endif /* __KERNEL__ */ #endif /* __DMA_RESERVED_IOMMU_H */