linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ashutosh Dixit <ashutosh.dixit@intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	David Woodhouse <David.Woodhouse@intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	iommu@lists.linux-foundation.org,
	Ashutosh Dixit <ashutosh.dixit@intel.com>,
	Sudeep Dutt <sudeep.dutt@intel.com>,
	Nikhil Rao <nikhil.rao@intel.com>
Subject: [PATCH char-misc-next v2 01/22] iommu: iova: Move iova cache management to the iova library
Date: Tue, 29 Sep 2015 18:07:02 -0700	[thread overview]
Message-ID: <40199221085e2c4a0ea5d4328b6457be99be0f09.1443573394.git.ashutosh.dixit@intel.com> (raw)
In-Reply-To: <cover.1443573394.git.ashutosh.dixit@intel.com>

From: Sakari Ailus <sakari.ailus@linux.intel.com>

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

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
 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 2d7349a..7b27bcd 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -3711,7 +3711,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;
 
@@ -3725,7 +3725,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;
 }
@@ -3734,7 +3734,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.0.0.rc3.2.g998f840


  reply	other threads:[~2015-09-30  0:41 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30  1:06 [PATCH char-misc-next v2 00/22] misc: mic: Enable COSM and remaining SCIF functionality Ashutosh Dixit
2015-09-30  1:07 ` Ashutosh Dixit [this message]
2015-09-30  1:07 ` [PATCH char-misc-next v2 02/22] iommu: iova: Export symbols Ashutosh Dixit
2015-09-30  1:08 ` [PATCH char-misc-next v2 03/22] iommu: Make the iova library a module Ashutosh Dixit
2015-09-30  1:09 ` [PATCH char-misc-next v2 04/22] iommu: Allow iova to be used without requiring IOMMU_SUPPORT Ashutosh Dixit
2015-10-05 10:50   ` Woodhouse, David
2015-10-05 17:38     ` Sudeep Dutt
2015-10-06  5:12       ` gregkh
2015-10-06  5:20         ` gregkh
2015-10-06  5:23           ` Sudeep Dutt
2015-10-06  7:56             ` gregkh
2015-10-06  8:05               ` Sudeep Dutt
2015-10-06  8:33                 ` gregkh
2015-10-06 12:04                   ` Sudeep Dutt
2015-09-30  1:09 ` [PATCH char-misc-next v2 05/22] dma: Add support to program MIC x100 status descriptiors Ashutosh Dixit
2015-09-30  1:10 ` [PATCH char-misc-next v2 06/22] misc: mic: SCIF poll Ashutosh Dixit
2015-09-30  1:11 ` [PATCH char-misc-next v2 07/22] misc: mic: Add support for kernel mode SCIF clients Ashutosh Dixit
2015-09-30  1:12 ` [PATCH char-misc-next v2 08/22] misc: mic: MIC COSM bus Ashutosh Dixit
2015-09-30  1:12 ` [PATCH char-misc-next v2 09/22] misc: mic: Coprocessor State Management (COSM) driver Ashutosh Dixit
2015-09-30  1:12 ` [PATCH char-misc-next v2 10/22] misc: mic: COSM SCIF server Ashutosh Dixit
2015-09-30  1:13 ` [PATCH char-misc-next v2 11/22] misc: mic: COSM client driver Ashutosh Dixit
2015-09-30  1:13 ` [PATCH char-misc-next v2 12/22] misc: mic: Remove COSM functionality from the MIC host driver Ashutosh Dixit
2015-09-30  1:13 ` [PATCH char-misc-next v2 13/22] misc: mic: Remove COSM functionality from the MIC card driver Ashutosh Dixit
2015-09-30  1:14 ` [PATCH char-misc-next v2 14/22] misc: mic: Update MIC host daemon with COSM changes Ashutosh Dixit
2015-09-30  1:15 ` [PATCH char-misc-next v2 15/22] misc: mic: SCIF RMA header file and IOCTL changes Ashutosh Dixit
2015-09-30  1:15 ` [PATCH char-misc-next v2 16/22] misc: mic: SCIF RMA header file Ashutosh Dixit
2015-09-30  1:15 ` [PATCH char-misc-next v2 17/22] misc: mic: SCIF memory registration and unregistration Ashutosh Dixit
2015-09-30  1:15 ` [PATCH char-misc-next v2 18/22] misc: mic: SCIF RMA list operations Ashutosh Dixit
2015-09-30  1:15 ` [PATCH char-misc-next v2 19/22] misc: mic: SCIF remote memory map/unmap interface Ashutosh Dixit
2015-09-30  1:16 ` [PATCH char-misc-next v2 20/22] misc: mic: SCIF DMA and CPU copy interface Ashutosh Dixit
2015-09-30  1:16 ` [PATCH char-misc-next v2 21/22] misc: mic: SCIF fence Ashutosh Dixit
2015-09-30  1:16 ` [PATCH char-misc-next v2 22/22] misc: mic: SCIF RMA nodeqp and minor miscellaneous changes Ashutosh Dixit

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=40199221085e2c4a0ea5d4328b6457be99be0f09.1443573394.git.ashutosh.dixit@intel.com \
    --to=ashutosh.dixit@intel.com \
    --cc=David.Woodhouse@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nikhil.rao@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sudeep.dutt@intel.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).