From: Eric Auger <eric.auger@linaro.org>
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,
Jean-Philippe.Brucker@arm.com, julien.grall@arm.com
Subject: [PATCH v6 7/7] dma-reserved-iommu: iommu_unmap_reserved
Date: Mon, 4 Apr 2016 08:07:02 +0000 [thread overview]
Message-ID: <1459757222-2668-8-git-send-email-eric.auger@linaro.org> (raw)
In-Reply-To: <1459757222-2668-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 <eric.auger@linaro.org>
---
v5 -> v6:
- use spin_lock instead of mutex
v3 -> v4:
- previously "iommu/arm-smmu: relinquish reserved resources on
domain deletion"
---
drivers/iommu/dma-reserved-iommu.c | 45 ++++++++++++++++++++++++++++++++++----
include/linux/dma-reserved-iommu.h | 7 ++++++
2 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/dma-reserved-iommu.c b/drivers/iommu/dma-reserved-iommu.c
index 3c759d9..c06c39e 100644
--- a/drivers/iommu/dma-reserved-iommu.c
+++ b/drivers/iommu/dma-reserved-iommu.c
@@ -119,20 +119,24 @@ 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;
- unsigned long flags;
if (!iovad)
return;
- spin_lock_irqsave(&domain->reserved_lock, flags);
-
put_iova_domain(iovad);
kfree(iovad);
+}
+
+void iommu_free_reserved_iova_domain(struct iommu_domain *domain)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&domain->reserved_lock, flags);
+ __iommu_free_reserved_iova_domain(domain);
spin_unlock_irqrestore(&domain->reserved_lock, flags);
}
EXPORT_SYMBOL_GPL(iommu_free_reserved_iova_domain);
@@ -281,4 +285,37 @@ unlock:
EXPORT_SYMBOL_GPL(iommu_put_reserved_iova);
+static void reserved_binding_release(struct kref *kref)
+{
+ struct iommu_reserved_binding *b =
+ container_of(kref, struct iommu_reserved_binding, kref);
+ struct iommu_domain *d = b->domain;
+
+ delete_reserved_binding(d, b);
+}
+
+void iommu_unmap_reserved(struct iommu_domain *domain)
+{
+ struct rb_node *node;
+ unsigned long flags;
+
+ spin_lock_irqsave(&domain->reserved_lock, flags);
+ while ((node = rb_first(&domain->reserved_binding_list))) {
+ struct iommu_reserved_binding *b =
+ rb_entry(node, struct iommu_reserved_binding, node);
+
+ unlink_reserved_binding(domain, b);
+ spin_unlock_irqrestore(&domain->reserved_lock, flags);
+
+ while (!kref_put(&b->kref, reserved_binding_release))
+ ;
+ spin_lock_irqsave(&domain->reserved_lock, flags);
+ }
+ domain->reserved_binding_list = RB_ROOT;
+ __iommu_free_reserved_iova_domain(domain);
+ spin_unlock_irqrestore(&domain->reserved_lock, flags);
+}
+EXPORT_SYMBOL_GPL(iommu_unmap_reserved);
+
+
diff --git a/include/linux/dma-reserved-iommu.h b/include/linux/dma-reserved-iommu.h
index dedea56..9fba930 100644
--- a/include/linux/dma-reserved-iommu.h
+++ b/include/linux/dma-reserved-iommu.h
@@ -68,6 +68,13 @@ int iommu_get_reserved_iova(struct iommu_domain *domain,
*/
void iommu_put_reserved_iova(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 */
--
1.9.1
next prev parent reply other threads:[~2016-04-04 8:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-04 8:06 [PATCH v6 0/7] KVM PCIe/MSI passthrough on ARM/ARM64: kernel part 1/3: iommu changes Eric Auger
2016-04-04 8:06 ` [PATCH v6 1/7] iommu: Add DOMAIN_ATTR_MSI_MAPPING attribute Eric Auger
2016-04-04 8:06 ` [PATCH v6 2/7] iommu/arm-smmu: advertise " Eric Auger
2016-04-04 8:06 ` [PATCH v6 3/7] iommu: introduce a reserved iova cookie Eric Auger
2016-04-04 8:06 ` [PATCH v6 4/7] dma-reserved-iommu: alloc/free_reserved_iova_domain Eric Auger
2016-04-06 23:00 ` Alex Williamson
2016-04-07 9:33 ` Eric Auger
2016-04-04 8:07 ` [PATCH v6 5/7] dma-reserved-iommu: reserved binding rb-tree and helpers Eric Auger
2016-04-04 8:07 ` [PATCH v6 6/7] dma-reserved-iommu: iommu_get/put_single_reserved Eric Auger
2016-04-06 23:12 ` Alex Williamson
2016-04-07 9:33 ` Eric Auger
2016-04-07 14:38 ` Jean-Philippe Brucker
2016-04-07 16:44 ` Eric Auger
2016-04-04 8:07 ` Eric Auger [this message]
2016-04-06 23:15 ` [PATCH v6 0/7] KVM PCIe/MSI passthrough on ARM/ARM64: kernel part 1/3: iommu changes Alex Williamson
2016-04-07 12:28 ` Eric Auger
2016-04-07 17:50 ` Alex Williamson
2016-04-08 13:31 ` Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1459757222-2668-8-git-send-email-eric.auger@linaro.org \
--to=eric.auger@linaro.org \
--cc=Bharat.Bhushan@freescale.com \
--cc=Jean-Philippe.Brucker@arm.com \
--cc=Manish.Jaggi@caviumnetworks.com \
--cc=alex.williamson@redhat.com \
--cc=christoffer.dall@linaro.org \
--cc=eric.auger@st.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jason@lakedaemon.net \
--cc=joro@8bytes.org \
--cc=julien.grall@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=p.fedin@samsung.com \
--cc=patches@linaro.org \
--cc=pranav.sawargaonkar@gmail.com \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).