linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Isaac J. Manjarres" <isaacm@codeaurora.org>
To: iommu@lists.linux-foundation.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, freedreno@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org
Cc: "Isaac J. Manjarres" <isaacm@codeaurora.org>,
	will@kernel.org, joro@8bytes.org, pdaly@codeaurora.org,
	pratikp@codeaurora.org, kernel-team@android.com,
	robin.murphy@arm.com
Subject: [PATCH v2 2/7] iommu/io-pgtable: Add refcounting for io-pgtable format modules
Date: Mon, 21 Dec 2020 16:44:31 -0800	[thread overview]
Message-ID: <1608597876-32367-3-git-send-email-isaacm@codeaurora.org> (raw)
In-Reply-To: <1608597876-32367-1-git-send-email-isaacm@codeaurora.org>

In preparation for modularizing io-pgtable formats, add support
for reference counting the io-pgtable format modules to ensure
that the modules are not unloaded while they are in use.

Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
---
 drivers/iommu/io-pgtable-arm-v7s.c |  1 +
 drivers/iommu/io-pgtable-arm.c     |  5 +++++
 drivers/iommu/io-pgtable.c         | 12 ++++++++++--
 include/linux/io-pgtable.h         |  2 ++
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
index 89aad2f..a5cb755a 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -840,6 +840,7 @@ static struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns = {
 	.fmt	= ARM_V7S,
 	.alloc	= arm_v7s_alloc_pgtable,
 	.free	= arm_v7s_free_pgtable,
+	.owner	= THIS_MODULE,
 };
 
 #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
index ff0ea2f..e8b1e34 100644
--- a/drivers/iommu/io-pgtable-arm.c
+++ b/drivers/iommu/io-pgtable-arm.c
@@ -1049,26 +1049,31 @@ static struct io_pgtable_init_fns io_pgtable_arm_lpae_init_fns[] = {
 		.fmt	= ARM_32_LPAE_S1,
 		.alloc	= arm_32_lpae_alloc_pgtable_s1,
 		.free	= arm_lpae_free_pgtable,
+		.owner	= THIS_MODULE,
 	},
 	{
 		.fmt	= ARM_32_LPAE_S2,
 		.alloc	= arm_32_lpae_alloc_pgtable_s2,
 		.free	= arm_lpae_free_pgtable,
+		.owner	= THIS_MODULE,
 	},
 	{
 		.fmt	= ARM_64_LPAE_S1,
 		.alloc	= arm_64_lpae_alloc_pgtable_s1,
 		.free	= arm_lpae_free_pgtable,
+		.owner	= THIS_MODULE,
 	},
 	{
 		.fmt	= ARM_64_LPAE_S2,
 		.alloc	= arm_64_lpae_alloc_pgtable_s2,
 		.free	= arm_lpae_free_pgtable,
+		.owner	= THIS_MODULE,
 	},
 	{
 		.fmt	= ARM_MALI_LPAE,
 		.alloc	= arm_mali_lpae_alloc_pgtable,
 		.free	= arm_lpae_free_pgtable,
+		.owner	= THIS_MODULE,
 	},
 };
 
diff --git a/drivers/iommu/io-pgtable.c b/drivers/iommu/io-pgtable.c
index 2c6eb2e..cc83542 100644
--- a/drivers/iommu/io-pgtable.c
+++ b/drivers/iommu/io-pgtable.c
@@ -10,6 +10,7 @@
 #include <linux/bug.h>
 #include <linux/io-pgtable.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/rwlock.h>
 #include <linux/slab.h>
 #include <linux/types.h>
@@ -52,9 +53,14 @@ struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
 	if (!fns)
 		return NULL;
 
+	if (!try_module_get(fns->owner))
+		return NULL;
+
 	iop = fns->alloc(cfg, cookie);
-	if (!iop)
+	if (!iop) {
+		module_put(fns->owner);
 		return NULL;
+	}
 
 	iop->fmt	= fmt;
 	iop->cookie	= cookie;
@@ -79,8 +85,10 @@ void free_io_pgtable_ops(struct io_pgtable_ops *ops)
 	iop = io_pgtable_ops_to_pgtable(ops);
 	io_pgtable_tlb_flush_all(iop);
 	fns = io_pgtable_get_init_fns(iop->fmt);
-	if (fns)
+	if (fns) {
 		fns->free(iop);
+		module_put(fns->owner);
+	}
 }
 EXPORT_SYMBOL_GPL(free_io_pgtable_ops);
 
diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h
index 45b367ce..a03b262 100644
--- a/include/linux/io-pgtable.h
+++ b/include/linux/io-pgtable.h
@@ -169,11 +169,13 @@ struct io_pgtable_ops {
  * @fmt:   The page table format.
  * @alloc: Allocate a set of page tables described by cfg.
  * @free:  Free the page tables associated with iop.
+ * @owner: Driver module providing these ops.
  */
 struct io_pgtable_init_fns {
 	enum io_pgtable_fmt fmt;
 	struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie);
 	void (*free)(struct io_pgtable *iop);
+	struct module *owner;
 };
 
 /**
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


  parent reply	other threads:[~2020-12-22  0:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-22  0:44 [RFC PATCH v2 0/7] iommu: Permit modular builds of io-pgtable drivers Isaac J. Manjarres
2020-12-22  0:44 ` [PATCH v2 1/7] iommu/io-pgtable: Introduce dynamic io-pgtable fmt registration Isaac J. Manjarres
2020-12-22 19:27   ` Robin Murphy
2020-12-22 19:54     ` isaacm
2020-12-23 13:44       ` Robin Murphy
2020-12-23 15:14         ` isaacm
2020-12-23 15:38   ` Georgi Djakov
2020-12-23 19:17   ` kernel test robot
2020-12-22  0:44 ` Isaac J. Manjarres [this message]
2020-12-22  0:44 ` [PATCH v2 3/7] iommu/arm-smmu: Add dependency on io-pgtable format modules Isaac J. Manjarres
2020-12-22 19:27   ` Robin Murphy
2020-12-22 19:49     ` isaacm
2020-12-23 13:05       ` Robin Murphy
2020-12-23 15:10         ` isaacm
2020-12-22  0:44 ` [PATCH v2 4/7] iommu/arm-smmu-v3: Add dependency on io-pgtable-arm format module Isaac J. Manjarres
2020-12-22  0:44 ` [PATCH v2 5/7] drm/msm: " Isaac J. Manjarres
2021-01-18 21:16   ` Rob Clark
2021-01-18 21:39     ` Will Deacon
2021-01-19 17:19       ` Rob Clark
2020-12-22  0:44 ` [PATCH v2 6/7] drm/panfrost: " Isaac J. Manjarres
2020-12-22  0:44 ` [PATCH v2 7/7] iommu/io-pgtable-arm: Allow building modular io-pgtable fmts Isaac J. Manjarres

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=1608597876-32367-3-git-send-email-isaacm@codeaurora.org \
    --to=isaacm@codeaurora.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=kernel-team@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pdaly@codeaurora.org \
    --cc=pratikp@codeaurora.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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).