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: Auger Eric X-Patchwork-Id: 63330 Delivered-To: patches@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1981542lbc; Tue, 1 Mar 2016 10:28:34 -0800 (PST) X-Received: by 10.194.94.229 with SMTP id df5mr25959096wjb.133.1456856914247; Tue, 01 Mar 2016 10:28:34 -0800 (PST) Return-Path: Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com. [2a00:1450:400c:c09::22e]) by mx.google.com with ESMTPS id q199si407578wmd.117.2016.03.01.10.28.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Mar 2016 10:28:34 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22e as permitted sender) client-ip=2a00:1450:400c:c09::22e; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22e as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-wm0-x22e.google.com with SMTP id p65so47898161wmp.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=AONv0U11gQ+ToufgeKhfRRe6319iLUMXt+qcr9o66nqtXJpDyAWyYWx3QAsWKbV4jc Qgv5Gmiv1GYlcMmFm94QDrDylJOpBedXFIEJvlFWjkBt6I7q2eXP01vkqhwf37MPf2X5 vopch3bF3/5LYamjQ8bELxAPD1bPz1AH4YdOeUcWp6/x/4dCzKRIJbzbUCfIV42G0iYz 0XgXEDpFHnWG7djbmVXMDfTMuXAk+u9j8Oq/r6Pqwbhw4aqlOSb5PW1SOLUbIKLNW598 MBCVdwYd75v7aymhbSSwanB4xv8QWgRTm0huvRrP9OMYGf2X6mJb1qnD90S7CAXydUma MmYg== X-Gm-Message-State: AD7BkJIFcLr9jnmH4Hg++Vhws10eJktZV8rGYjJKhXAWMzaZ8BcZ9mOiRzP3wuTD/52b9pmYuAg= X-Received: by 10.194.249.42 with SMTP id yr10mr22054281wjc.12.1456856914034; Tue, 01 Mar 2016 10:28:34 -0800 (PST) Return-Path: 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> 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(-) -- 1.9.1 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 */