Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH 0/4] Separate the IOVA library from the intel-iommu driver
@ 2015-07-13 11:31 Sakari Ailus
       [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Sakari Ailus @ 2015-07-13 11:31 UTC (permalink / raw)
  To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ,
	jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

Hi folks,

This set separates the IOVA library from the intel-iommu driver, and makes
it usable for other implementations (such as DMA mapping) as well.

The RFC set can be found here:

<URL:http://iommu.linux-foundation.narkive.com/t0Fa600G/rfc-0-4-separate-the-iova-library-from-the-intel-iommu-driver>

Since the RFC:

- Rebase on current iommu next branch.

- Don't export get_vm_area_caller(). __get_vm_area() which is already
  exported can be used instead.

-- 
Kind regards,
Sakari

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] iommu: iova: Move iova cache management to the iova library
       [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2015-07-13 11:31   ` Sakari Ailus
  2015-07-13 11:31   ` [PATCH 2/4] iommu: iova: Export symbols Sakari Ailus
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2015-07-13 11:31 UTC (permalink / raw)
  To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ,
	jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

This is necessary to separate intel-iommu from the iova library.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/iommu/intel-iommu.c |  6 ++--
 drivers/iommu/iova.c        | 83 ++++++++++++++++++++++++++-------------------
 include/linux/iova.h        |  4 +--
 3 files changed, 54 insertions(+), 39 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a98a7b2..808e766 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3741,7 +3741,7 @@ static inline int iommu_devinfo_cache_init(void)
 static int __init iommu_init_mempool(void)
 {
 	int ret;
-	ret = iommu_iova_cache_init();
+	ret = iova_cache_get();
 	if (ret)
 		return ret;
 
@@ -3755,7 +3755,7 @@ static int __init iommu_init_mempool(void)
 
 	kmem_cache_destroy(iommu_domain_cache);
 domain_error:
-	iommu_iova_cache_destroy();
+	iova_cache_put();
 
 	return -ENOMEM;
 }
@@ -3764,7 +3764,7 @@ static void __init iommu_exit_mempool(void)
 {
 	kmem_cache_destroy(iommu_devinfo_cache);
 	kmem_cache_destroy(iommu_domain_cache);
-	iommu_iova_cache_destroy();
+	iova_cache_put();
 }
 
 static void quirk_ioat_snb_local_iommu(struct pci_dev *pdev)
diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index b7c3d92..400f4d1 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -20,40 +20,6 @@
 #include <linux/iova.h>
 #include <linux/slab.h>
 
-static struct kmem_cache *iommu_iova_cache;
-
-int iommu_iova_cache_init(void)
-{
-	int ret = 0;
-
-	iommu_iova_cache = kmem_cache_create("iommu_iova",
-					 sizeof(struct iova),
-					 0,
-					 SLAB_HWCACHE_ALIGN,
-					 NULL);
-	if (!iommu_iova_cache) {
-		pr_err("Couldn't create iova cache\n");
-		ret = -ENOMEM;
-	}
-
-	return ret;
-}
-
-void iommu_iova_cache_destroy(void)
-{
-	kmem_cache_destroy(iommu_iova_cache);
-}
-
-struct iova *alloc_iova_mem(void)
-{
-	return kmem_cache_alloc(iommu_iova_cache, GFP_ATOMIC);
-}
-
-void free_iova_mem(struct iova *iova)
-{
-	kmem_cache_free(iommu_iova_cache, iova);
-}
-
 void
 init_iova_domain(struct iova_domain *iovad, unsigned long granule,
 	unsigned long start_pfn, unsigned long pfn_32bit)
@@ -242,6 +208,55 @@ iova_insert_rbtree(struct rb_root *root, struct iova *iova)
 	rb_insert_color(&iova->node, root);
 }
 
+static struct kmem_cache *iova_cache;
+static unsigned int iova_cache_users;
+static DEFINE_MUTEX(iova_cache_mutex);
+
+struct iova *alloc_iova_mem(void)
+{
+	return kmem_cache_alloc(iova_cache, GFP_ATOMIC);
+}
+EXPORT_SYMBOL(alloc_iova_mem);
+
+void free_iova_mem(struct iova *iova)
+{
+	kmem_cache_free(iova_cache, iova);
+}
+EXPORT_SYMBOL(free_iova_mem);
+
+int iova_cache_get(void)
+{
+	mutex_lock(&iova_cache_mutex);
+	if (!iova_cache_users) {
+		iova_cache = kmem_cache_create(
+			"iommu_iova", sizeof(struct iova), 0,
+			SLAB_HWCACHE_ALIGN, NULL);
+		if (!iova_cache) {
+			mutex_unlock(&iova_cache_mutex);
+			printk(KERN_ERR "Couldn't create iova cache\n");
+			return -ENOMEM;
+		}
+	}
+
+	iova_cache_users++;
+	mutex_unlock(&iova_cache_mutex);
+
+	return 0;
+}
+
+void iova_cache_put(void)
+{
+	mutex_lock(&iova_cache_mutex);
+	if (WARN_ON(!iova_cache_users)) {
+		mutex_unlock(&iova_cache_mutex);
+		return;
+	}
+	iova_cache_users--;
+	if (!iova_cache_users)
+		kmem_cache_destroy(iova_cache);
+	mutex_unlock(&iova_cache_mutex);
+}
+
 /**
  * alloc_iova - allocates an iova
  * @iovad: - iova domain in question
diff --git a/include/linux/iova.h b/include/linux/iova.h
index 3920a19..92f7177 100644
--- a/include/linux/iova.h
+++ b/include/linux/iova.h
@@ -68,8 +68,8 @@ static inline unsigned long iova_pfn(struct iova_domain *iovad, dma_addr_t iova)
 	return iova >> iova_shift(iovad);
 }
 
-int iommu_iova_cache_init(void);
-void iommu_iova_cache_destroy(void);
+int iova_cache_get(void);
+void iova_cache_put(void);
 
 struct iova *alloc_iova_mem(void);
 void free_iova_mem(struct iova *iova);
-- 
2.1.0.231.g7484e3b

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] iommu: iova: Export symbols
       [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  2015-07-13 11:31   ` [PATCH 1/4] iommu: iova: Move iova cache management to the iova library Sakari Ailus
@ 2015-07-13 11:31   ` Sakari Ailus
  2015-07-13 11:31   ` [PATCH 3/4] iommu: Make the iova library a module Sakari Ailus
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2015-07-13 11:31 UTC (permalink / raw)
  To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ,
	jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

Use EXPORT_SYMBOL_GPL() to export the iova library symbols. The symbols
include:

	init_iova_domain();
	iova_cache_get();
	iova_cache_put();
	iova_cache_init();
	alloc_iova();
	find_iova();
	__free_iova();
	free_iova();
	put_iova_domain();
	reserve_iova();
	copy_reserved_iova();

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/iommu/iova.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 400f4d1..dd87123 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -38,6 +38,7 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule,
 	iovad->start_pfn = start_pfn;
 	iovad->dma_32bit_pfn = pfn_32bit;
 }
+EXPORT_SYMBOL_GPL(init_iova_domain);
 
 static struct rb_node *
 __get_cached_rbnode(struct iova_domain *iovad, unsigned long *limit_pfn)
@@ -243,6 +244,7 @@ int iova_cache_get(void)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(iova_cache_get);
 
 void iova_cache_put(void)
 {
@@ -256,6 +258,7 @@ void iova_cache_put(void)
 		kmem_cache_destroy(iova_cache);
 	mutex_unlock(&iova_cache_mutex);
 }
+EXPORT_SYMBOL_GPL(iova_cache_put);
 
 /**
  * alloc_iova - allocates an iova
@@ -296,6 +299,7 @@ alloc_iova(struct iova_domain *iovad, unsigned long size,
 
 	return new_iova;
 }
+EXPORT_SYMBOL_GPL(alloc_iova);
 
 /**
  * find_iova - find's an iova for a given pfn
@@ -336,6 +340,7 @@ struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn)
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(find_iova);
 
 /**
  * __free_iova - frees the given iova
@@ -354,6 +359,7 @@ __free_iova(struct iova_domain *iovad, struct iova *iova)
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
 	free_iova_mem(iova);
 }
+EXPORT_SYMBOL_GPL(__free_iova);
 
 /**
  * free_iova - finds and frees the iova for a given pfn
@@ -371,6 +377,7 @@ free_iova(struct iova_domain *iovad, unsigned long pfn)
 		__free_iova(iovad, iova);
 
 }
+EXPORT_SYMBOL_GPL(free_iova);
 
 /**
  * put_iova_domain - destroys the iova doamin
@@ -393,6 +400,7 @@ void put_iova_domain(struct iova_domain *iovad)
 	}
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
 }
+EXPORT_SYMBOL_GPL(put_iova_domain);
 
 static int
 __is_range_overlap(struct rb_node *node,
@@ -482,6 +490,7 @@ finish:
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
 	return iova;
 }
+EXPORT_SYMBOL_GPL(reserve_iova);
 
 /**
  * copy_reserved_iova - copies the reserved between domains
@@ -508,6 +517,7 @@ copy_reserved_iova(struct iova_domain *from, struct iova_domain *to)
 	}
 	spin_unlock_irqrestore(&from->iova_rbtree_lock, flags);
 }
+EXPORT_SYMBOL_GPL(copy_reserved_iova);
 
 struct iova *
 split_and_remove_iova(struct iova_domain *iovad, struct iova *iova,
-- 
2.1.0.231.g7484e3b

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] iommu: Make the iova library a module
       [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  2015-07-13 11:31   ` [PATCH 1/4] iommu: iova: Move iova cache management to the iova library Sakari Ailus
  2015-07-13 11:31   ` [PATCH 2/4] iommu: iova: Export symbols Sakari Ailus
@ 2015-07-13 11:31   ` Sakari Ailus
  2015-07-13 11:31   ` [PATCH 4/4] mm: EXPORT_SYMBOL_GPL(find_vm_area); Sakari Ailus
  2015-07-28 13:25   ` [PATCH 0/4] Separate the IOVA library from the intel-iommu driver David Woodhouse
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2015-07-13 11:31 UTC (permalink / raw)
  To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ,
	jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

The iova library has use outside the intel-iommu driver, thus make it a
module.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/iommu/Kconfig | 2 +-
 drivers/iommu/iova.c  | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 40f37a2..e7e9a51b 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -42,7 +42,7 @@ config IOMMU_IO_PGTABLE_LPAE_SELFTEST
 endmenu
 
 config IOMMU_IOVA
-	bool
+	tristate
 
 config OF_IOMMU
        def_bool y
diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index dd87123..dd64d33 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -18,6 +18,7 @@
  */
 
 #include <linux/iova.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 
 void
@@ -559,3 +560,6 @@ error:
 		free_iova_mem(prev);
 	return NULL;
 }
+
+MODULE_AUTHOR("Anil S Keshavamurthy <anil.s.keshavamurthy-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>");
+MODULE_LICENSE("GPL");
-- 
2.1.0.231.g7484e3b

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] mm: EXPORT_SYMBOL_GPL(find_vm_area);
       [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
                     ` (2 preceding siblings ...)
  2015-07-13 11:31   ` [PATCH 3/4] iommu: Make the iova library a module Sakari Ailus
@ 2015-07-13 11:31   ` Sakari Ailus
  2015-07-28 13:25   ` [PATCH 0/4] Separate the IOVA library from the intel-iommu driver David Woodhouse
  4 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2015-07-13 11:31 UTC (permalink / raw)
  To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ,
	jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

find_vm_area() is needed in implementing the DMA mapping API as a module.
Device specific IOMMUs with associated DMA mapping implementations should be
buildable as modules.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 mm/vmalloc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 2faaa29..d06db45 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1416,6 +1416,7 @@ struct vm_struct *find_vm_area(const void *addr)
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(find_vm_area);
 
 /**
  *	remove_vm_area  -  find and remove a continuous kernel virtual area
-- 
2.1.0.231.g7484e3b

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Separate the IOVA library from the intel-iommu driver
       [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
                     ` (3 preceding siblings ...)
  2015-07-13 11:31   ` [PATCH 4/4] mm: EXPORT_SYMBOL_GPL(find_vm_area); Sakari Ailus
@ 2015-07-28 13:25   ` David Woodhouse
       [not found]     ` <1438089947.26913.155.camel-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
  4 siblings, 1 reply; 7+ messages in thread
From: David Woodhouse @ 2015-07-28 13:25 UTC (permalink / raw)
  To: Sakari Ailus, jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA


[-- Attachment #1.1: Type: text/plain, Size: 505 bytes --]

On Mon, 2015-07-13 at 14:31 +0300, Sakari Ailus wrote:
> Hi folks,
> 
> This set separates the IOVA library from the intel-iommu driver, and makes
> it usable for other implementations (such as DMA mapping) as well.

Thanks. I've applied patches ##1-3 to my tree. The fourth patch ideally
wants to go elsewhere.

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org                              Intel Corporation

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5691 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Separate the IOVA library from the intel-iommu driver
       [not found]     ` <1438089947.26913.155.camel-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
@ 2015-09-14 18:17       ` Robin Murphy
  0 siblings, 0 replies; 7+ messages in thread
From: Robin Murphy @ 2015-09-14 18:17 UTC (permalink / raw)
  To: David Woodhouse, Sakari Ailus,
	jian.xu.zheng-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org

Hi David,

On 28/07/15 14:25, David Woodhouse wrote:
> On Mon, 2015-07-13 at 14:31 +0300, Sakari Ailus wrote:
>> Hi folks,
>>
>> This set separates the IOVA library from the intel-iommu driver, and makes
>> it usable for other implementations (such as DMA mapping) as well.
>
> Thanks. I've applied patches ##1-3 to my tree. The fourth patch ideally
> wants to go elsewhere.
>

This doesn't seem to have made 4.3-rc1, despite having been in -next for 
a while. Were you planning to push it for 4.3, or is it waiting on 
further development?

Thanks,
Robin.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-14 18:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-13 11:31 [PATCH 0/4] Separate the IOVA library from the intel-iommu driver Sakari Ailus
     [not found] ` <1436787091-11943-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-07-13 11:31   ` [PATCH 1/4] iommu: iova: Move iova cache management to the iova library Sakari Ailus
2015-07-13 11:31   ` [PATCH 2/4] iommu: iova: Export symbols Sakari Ailus
2015-07-13 11:31   ` [PATCH 3/4] iommu: Make the iova library a module Sakari Ailus
2015-07-13 11:31   ` [PATCH 4/4] mm: EXPORT_SYMBOL_GPL(find_vm_area); Sakari Ailus
2015-07-28 13:25   ` [PATCH 0/4] Separate the IOVA library from the intel-iommu driver David Woodhouse
     [not found]     ` <1438089947.26913.155.camel-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-09-14 18:17       ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox