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: 8468751 Return-Path: X-Original-To: patchwork-kvm@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 F3C5A9F38C for ; Tue, 1 Mar 2016 18:33:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27DCC20115 for ; Tue, 1 Mar 2016 18:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35CA8202EC for ; Tue, 1 Mar 2016 18:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753494AbcCASdm (ORCPT ); Tue, 1 Mar 2016 13:33:42 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:38005 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752013AbcCAS2f (ORCPT ); Tue, 1 Mar 2016 13:28:35 -0500 Received: by mail-wm0-f45.google.com with SMTP id l68so45907615wml.1 for ; Tue, 01 Mar 2016 10:28:34 -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=Fld0hufe5wc2IRYql8oxQoC2Fmohnafqxhp2/k7LklAMlUDakYaujyleXHwJTykN5o lIpvvcF9Nvi9c7EmsbXOSJhvB6N/9/I6XUeTF8beyA68RaOSd5U3nTruefjZa8iusRKd G2LV7GxMQRaqCqKKd++19lGNI5ug38BPxILQT/smnYtVpvrM/9BbSgzK3TywLATnKb0l xWRsNZSQyxGdQROLlRIV10jjlIhWuIvLpFX/WfKhhxgx4nGtjq2CTjAxi8DsXTMkBfNL 5M0/YucyOyCXtaSAgD4Odwyy8xo/olNY3FJ+/Nwyyz7x/qvHijAqzmUS9sMI3Rm3/pIY PFGg== X-Gm-Message-State: AD7BkJIlPrUYaJreTjeDxiYmPrVwfJchbaCLeRKvzUKkdVbpMtbwweSsr4RKoI5CpcqaotB0 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 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 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 */