From patchwork Fri Feb 26 17:35:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8440341 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 81DC99F2F0 for ; Fri, 26 Feb 2016 17:40:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ACB3920395 for ; Fri, 26 Feb 2016 17:40:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C82F8203B6 for ; Fri, 26 Feb 2016 17:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422840AbcBZRjr (ORCPT ); Fri, 26 Feb 2016 12:39:47 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:37065 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422866AbcBZRgT (ORCPT ); Fri, 26 Feb 2016 12:36:19 -0500 Received: by mail-wm0-f46.google.com with SMTP id g62so79661855wme.0 for ; Fri, 26 Feb 2016 09:36:19 -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=Rua2bUmYfUWf/PDgWUFkCDvuIBZSw52P0LjnWqLS1t30uFAq2XuIlkOQdeKFjdsPR+ 17VBWdFgk/To3sda/N3VnG8rinTtjYh2en53oUawTkPE8mC8EOcKfNjQ8cxJytw60bE1 Ey7Y2cseoI4ZMChmMaT8vKDDD2xWHx/6Vy6sI= 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=iTxIbLC7YxEZ+AqT3DTBdKWni3h26tg4FsX/fTrl2ZuklkuDtsSRmdwLPI4BW1ddqO 1vxzxcaOSvrhHJsgmP0P7ZJecTUmG1K/hn9IGTvo/UmQsoK3OwXrnN1qkogwa7aWrXe0 cWpl7zg4Lc5hhY7EBppPugOQ6oZQOCGySc1q+rWMPNvnjFYNoCeE/djiNS2m/t0U1pkn ZnJGFdraT3/Awf0oElgbYYjJO9UCVgLkSyyD0ML41APFCBXLr/HDahoGxb+KGB3PKa5s m2b/nKG9XY7Xzd+1LvJiySWk0Ye4rDQ7eOEpkH3BvSF1kKY3xyzO+I0ntRlqi7uOFTl6 XHxw== X-Gm-Message-State: AD7BkJIshH8+VotTiNSNMXSAHrerY9p40JunEqWhDmLiUpqmFD7HmUFhe9YKG8k4aWSo8Fe6 X-Received: by 10.194.57.244 with SMTP id l20mr2793759wjq.45.1456508178531; Fri, 26 Feb 2016 09:36:18 -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 77sm3750373wmp.18.2016.02.26.09.36.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 09:36:16 -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 v4 06/14] dma-reserved-iommu: iommu_unmap_reserved Date: Fri, 26 Feb 2016 17:35:46 +0000 Message-Id: <1456508154-2253-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456508154-2253-1-git-send-email-eric.auger@linaro.org> References: <1456508154-2253-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 */