openwrt/target/linux/generic/hack-6.12/301-01-module-permit-to-declare-custom-module-alloc-free-fu.patch
Christian Marangi a9c0f28951
generic: 6.12: move MIPS reloc patch from pending to hack and rework
Move MIPS reloc patch from pending to hack and rework it to adapt to new
kernel 6.12 version.

This required an additional patch. While at it also improve the text
with the original info without cut.

Link: https://github.com/openwrt/openwrt/pull/16547
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2025-04-30 16:26:32 +02:00

99 lines
2.7 KiB
Diff

From fec97dbb51697148ba881611f2b780a8d8a15885 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Mon, 14 Apr 2025 18:04:25 +0200
Subject: [PATCH 1/2] module: permit to declare custom module alloc/free
function
Permit to declare custom module alloc/free function that bypass the
execmem API. This works by making the alloc/free function weak
permitting an arch to declare a replacement for them.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
include/linux/moduleloader.h | 5 +++++
kernel/module/main.c | 33 ++++++++++++++++++++++++---------
2 files changed, 33 insertions(+), 9 deletions(-)
--- a/include/linux/moduleloader.h
+++ b/include/linux/moduleloader.h
@@ -122,4 +122,9 @@ void module_arch_cleanup(struct module *
/* Any cleanup before freeing mod->module_init */
void module_arch_freeing_init(struct module *mod);
+void *module_arch_mem_alloc(struct module_memory *mem,
+ enum mod_mem_type type);
+
+void module_arch_mem_free(struct module_memory *mem);
+
#endif
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1191,22 +1191,20 @@ void __weak module_arch_freeing_init(str
{
}
-static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
+void *__weak module_arch_mem_alloc(struct module_memory *mem,
+ enum mod_mem_type type)
{
- unsigned int size = PAGE_ALIGN(mod->mem[type].size);
enum execmem_type execmem_type;
void *ptr;
- mod->mem[type].size = size;
-
if (mod_mem_type_is_data(type))
execmem_type = EXECMEM_MODULE_DATA;
else
execmem_type = EXECMEM_MODULE_TEXT;
- ptr = execmem_alloc(execmem_type, size);
+ ptr = execmem_alloc(execmem_type, mem->size);
if (!ptr)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
/*
* The pointer to these blocks of memory are stored on the module
@@ -1221,21 +1219,38 @@ static int module_memory_alloc(struct mo
*/
kmemleak_not_leak(ptr);
+ return ptr;
+}
+
+static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
+{
+ unsigned int size = PAGE_ALIGN(mod->mem[type].size);
+ void *ptr;
+
+ mod->mem[type].size = size;
+
+ ptr = module_arch_mem_alloc(&mod->mem[type], type);
+ if (IS_ERR(ptr))
+ return PTR_ERR(ptr);
+
memset(ptr, 0, size);
mod->mem[type].base = ptr;
return 0;
}
+void __weak module_arch_mem_free(struct module_memory *mem)
+{
+ execmem_free(mem->base);
+}
+
static void module_memory_free(struct module *mod, enum mod_mem_type type,
bool unload_codetags)
{
- void *ptr = mod->mem[type].base;
-
if (!unload_codetags && mod_mem_type_is_core_data(type))
return;
- execmem_free(ptr);
+ module_arch_mem_free(&mod->mem[type]);
}
static void free_mod_mem(struct module *mod, bool unload_codetags)