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: 8440421 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 3F2E49F52D for ; Fri, 26 Feb 2016 17:43:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E96F203AD for ; Fri, 26 Feb 2016 17:43:39 +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 814B720395 for ; Fri, 26 Feb 2016 17:43:38 +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 1aZMOr-0007E8-V9; Fri, 26 Feb 2016 17:41:58 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZMJh-0001m3-HL for linux-arm-kernel@lists.infradead.org; Fri, 26 Feb 2016 17:36:43 +0000 Received: by mail-wm0-x22b.google.com with SMTP id g62so81593171wme.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=TJavPM4fBbdvqmMbZnQP0B+MoK9urhLCIozTC0y2AME1jkdg7nCekBV+Mb70oap/2h OnBtd2JtItoGhNTEQ3EYgBrlQzd418NBbrEdJIuH0pccLBsf0lbKzoFMv42jS6HoXVEx yaAYgBiVdcLdF1yJpZOUHDP02E4yAKt0Okf4k2UR77vjgj0cbHaQ166BQ2nta5uiLqYU I2/93sruHTnvwYwDCjyX3uauNhaDgGHpZFc7xrxSYrobw7089mbY95iHsTJuBdDMGOEv G5HQbRRt2FLbGwCCBYyaQmIzm8f6b6tWQRenSXfTrny3Gs48X7L8tGx5qK+x0+BihFAt hMUA== X-Gm-Message-State: AD7BkJLN7LEKrTd0Et1SpHlDk6HfFn+NKSnTg/r/5AkoFkmR1ITtYByXxKhU5ee+ellCn2RL 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160226_093638_103468_412061B8 X-CRM114-Status: GOOD ( 10.82 ) 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 */