@@ -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
@@ -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,
},
};
@@ -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);
@@ -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;
};
/**
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(-)