From patchwork Tue Mar 1 18:27:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8468731 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 368989F38C for ; Tue, 1 Mar 2016 18:33:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 600B6202C8 for ; Tue, 1 Mar 2016 18:33:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 86E6320266 for ; Tue, 1 Mar 2016 18:33:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aap4Y-0004zT-LV; Tue, 01 Mar 2016 18:31:02 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aap2V-0001bv-O2 for linux-arm-kernel@lists.infradead.org; Tue, 01 Mar 2016 18:28:58 +0000 Received: by mail-wm0-x22d.google.com with SMTP id p65so47898162wmp.1 for ; Tue, 01 Mar 2016 10:28:35 -0800 (PST) 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=VSf5UT350CDBtodCrBIQIOxmMZ0OkMLzl9T8aGkctZo=; b=B9dc4zNbHdx5MscoUuuL1c95q5zY8EarTxQQdBHShJTEecuSHvd4Z6FA/rPrCx0nVv UCVWef72YzY3Ht69J3ED7nMkZjNXiv+MDkFPJAx677Jo16R/9edds1FXmyDvODlZkwdM 1VIIbeYCnm4V0GxpJDJeJ+e1HMHrNNwzB5bT0= 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=VSf5UT350CDBtodCrBIQIOxmMZ0OkMLzl9T8aGkctZo=; b=alRHrTN3NbuF57WxvRXgIm97A/qLYTsQW8qYu5Cc6vBQ6p7rPUFNUrRd1YIj+Kl1BY dmIERafBzXXYYj4bEwy1VnkJjSmr/BzHPuBCLyrCDJur5WVOEaEMeAxfxslV4tBQE7o0 zQjl+CEyhCKUu88X4AHfiLalLGf22Jzhza+zzyE4Ri3yoR8bAww5mv2s6H2xjPq6j02X GJiZ/qJ1Aidmem8p3JvKbE6ye+m7l4rFUvcL6ITkVq41CYkye47vZ3KOpiFnkM3s99sb fJLqAPQhXKkA7qKoynnyYij4eqWJSxDRk+DXiz5Zpx5uuwNkPlNCrjikQqjp1X54yC2L 7FCg== X-Gm-Message-State: AD7BkJIc7ZSCjXUCata/4lSVq35nUvJW9VTKYsgh9N/a6qT/IbPWJka4wYe43H/FZKkJxiOY X-Received: by 10.194.249.42 with SMTP id yr10mr22054281wjc.12.1456856914034; Tue, 01 Mar 2016 10:28:34 -0800 (PST) Received: from new-host-8.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id k8sm32176385wjr.38.2016.03.01.10.28.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Mar 2016 10:28:32 -0800 (PST) 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 Subject: [RFC v5 07/17] dma-reserved-iommu: iommu_unmap_reserved Date: Tue, 1 Mar 2016 18:27:47 +0000 Message-Id: <1456856877-4817-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456856877-4817-1-git-send-email-eric.auger@linaro.org> References: <1456856877-4817-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160301_102856_121779_1389A1BC X-CRM114-Status: GOOD ( 11.39 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org, Manish.Jaggi@caviumnetworks.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, suravee.suthikulpanit@amd.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new function whose role is to unmap all allocated reserved IOVAs and free the reserved iova domain Signed-off-by: Eric Auger --- v3 -> v4: - previously "iommu/arm-smmu: relinquish reserved resources on domain deletion" --- drivers/iommu/dma-reserved-iommu.c | 27 ++++++++++++++++++++++++--- include/linux/dma-reserved-iommu.h | 7 +++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c index 537c83e..7217bb7 100644 --- a/drivers/iommu/dma-reserved-iommu.c +++ b/drivers/iommu/dma-reserved-iommu.c @@ -116,7 +116,7 @@ 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; @@ -124,11 +124,14 @@ void iommu_free_reserved_iova_domain(struct iommu_domain *domain) if (!iovad) return; - mutex_lock(&domain->reserved_mutex); - put_iova_domain(iovad); kfree(iovad); +} +void iommu_free_reserved_iova_domain(struct iommu_domain *domain) +{ + mutex_lock(&domain->reserved_mutex); + __iommu_free_reserved_iova_domain(domain); mutex_unlock(&domain->reserved_mutex); } EXPORT_SYMBOL_GPL(iommu_free_reserved_iova_domain); @@ -245,5 +248,23 @@ unlock: } EXPORT_SYMBOL_GPL(iommu_put_single_reserved); +void iommu_unmap_reserved(struct iommu_domain *domain) +{ + struct rb_node *node; + + mutex_lock(&domain->reserved_mutex); + while ((node = rb_first(&domain->reserved_binding_list))) { + struct iommu_reserved_binding *b = + rb_entry(node, struct iommu_reserved_binding, node); + + while (!kref_put(&b->kref, reserved_binding_release)) + ; + } + domain->reserved_binding_list = RB_ROOT; + __iommu_free_reserved_iova_domain(domain); + mutex_unlock(&domain->reserved_mutex); +} +EXPORT_SYMBOL_GPL(iommu_unmap_reserved); + diff --git a/include/linux/dma-reserved-iommu.h b/include/linux/dma-reserved-iommu.h index 71ec800..766c58c 100644 --- a/include/linux/dma-reserved-iommu.h +++ b/include/linux/dma-reserved-iommu.h @@ -66,6 +66,13 @@ int iommu_get_single_reserved(struct iommu_domain *domain, */ void iommu_put_single_reserved(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 */