mirror of
https://git.openwrt.org/openwrt/openwrt.git
synced 2025-05-18 12:26:41 +00:00
It seems that we need to override all execmem alloc/free callbacks,
not just for module. This is the default patch behavior in the 6.6
kernel. Fix the warning when the module is loaded:
root@OpenWrt:~# insmod mtd-rw i_want_a_brick=1
[ 1404.954813] mtd-rw: mtd0: setting writeable flag
[ 1404.959643] mtd-rw: mtd5: setting writeable flag
[ 1404.966396] ------------[ cut here ]------------
[ 1404.971119] WARNING: CPU: 0 PID: 8 at mm/vmalloc.c:3361 vfree+0x1ac/0x2c4
[ 1404.978146] Trying to vfree() nonexistent vm area (74cc6c73)
[ 1404.983901] Modules linked in: mtd_rw(O) ath9k(O) ath9k_common(O)...
[ 1405.043696] CPU: 0 UID: 0 PID: 8 Comm: kworker/0:1 Tainted: G W O 6.12.25 #0
[ 1405.052118] Tainted: [W]=WARN, [O]=OOT_MODULE
[ 1405.056536] Hardware name:
[ 1405.061222] Workqueue: events do_free_init
[ 1405.065408] Stack : 807865d8 80850000 81823f80 81857df8 00000000 00000d21 81823fd0 800ca130
[ 1405.073924] 81839e48 807865d8 808d20bf 807865d8 81857d1c 00000001 81857ce8 4951640f
[ 1405.082434] 00000000 00000000 807865d8 81857bf8 ffffefff 00000000 ffffffea 00000b5d
[ 1405.090944] 81857c04 00000b5d 808537b0 ffffffff 00000001 00000000 807865d8 81857df8
[ 1405.099453] 00000000 00000d21 81823fd0 8085119c 00000018 803f4828 00000000 80a00000
[ 1405.107963] ...
[ 1405.110454] Call Trace:
[ 1405.112935] [<80066910>] show_stack+0x28/0xf0
[ 1405.117392] [<8069f340>] dump_stack_lvl+0x48/0x7c
[ 1405.122186] [<80084ab8>] __warn+0x9c/0x118
[ 1405.126357] [<80084bc0>] warn_slowpath_fmt+0x8c/0xac
[ 1405.131399] [<801f02ec>] vfree+0x1ac/0x2c4
[ 1405.135570] [<800dde54>] do_free_init+0x50/0x84
[ 1405.140172] [<8009f4a0>] process_one_work+0x1b0/0x3dc
[ 1405.145312] [<800a022c>] worker_thread+0x308/0x478
[ 1405.150178] [<800a81c0>] kthread+0xf4/0x11c
[ 1405.154455] [<80061b58>] ret_from_kernel_thread+0x14/0x1c
[ 1405.159938]
[ 1405.161772] ---[ end trace 0000000000000000 ]---
Fixes: a9c0f28951
("generic: 6.12: move MIPS reloc patch from pending to hack and rework")
Ref: https://lore.kernel.org/all/20240505160628.2323363-1-rppt@kernel.org/
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Tested-by: Tony Ambardar <itugrok@yahoo.com>
Link: https://github.com/openwrt/openwrt/pull/18721
Signed-off-by: Robert Marko <robimarko@gmail.com>
63 lines
1.8 KiB
Diff
63 lines
1.8 KiB
Diff
From: Christian Marangi <ansuelsmth@gmail.com>
|
|
Date: Mon, 14 Apr 2025 18:04:25 +0200
|
|
Subject: [PATCH 1/2] mm: permit to declare custom execmem alloc/free function
|
|
|
|
Permit to declare custom execmem 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>
|
|
Co-authored-by: Shiji Yang <yangshiji66@outlook.com>
|
|
---
|
|
include/linux/moduleloader.h | 4 ++++
|
|
mm/execmem.c | 14 ++++++++++++--
|
|
2 files changed, 16 insertions(+), 2 deletions(-)
|
|
|
|
--- a/include/linux/moduleloader.h
|
|
+++ b/include/linux/moduleloader.h
|
|
@@ -122,4 +122,8 @@ void module_arch_cleanup(struct module *
|
|
/* Any cleanup before freeing mod->module_init */
|
|
void module_arch_freeing_init(struct module *mod);
|
|
|
|
+enum execmem_type;
|
|
+void *arch_execmem_alloc(enum execmem_type type, size_t size);
|
|
+void arch_execmem_free(void *ptr);
|
|
+
|
|
#endif
|
|
--- a/mm/execmem.c
|
|
+++ b/mm/execmem.c
|
|
@@ -52,14 +52,19 @@ static void *__execmem_alloc(struct exec
|
|
return kasan_reset_tag(p);
|
|
}
|
|
|
|
-void *execmem_alloc(enum execmem_type type, size_t size)
|
|
+void *__weak arch_execmem_alloc(enum execmem_type type, size_t size)
|
|
{
|
|
struct execmem_range *range = &execmem_info->ranges[type];
|
|
|
|
return __execmem_alloc(range, size);
|
|
}
|
|
|
|
-void execmem_free(void *ptr)
|
|
+void *execmem_alloc(enum execmem_type type, size_t size)
|
|
+{
|
|
+ return arch_execmem_alloc(type, size);
|
|
+}
|
|
+
|
|
+void __weak arch_execmem_free(void *ptr)
|
|
{
|
|
/*
|
|
* This memory may be RO, and freeing RO memory in an interrupt is not
|
|
@@ -69,6 +74,11 @@ void execmem_free(void *ptr)
|
|
vfree(ptr);
|
|
}
|
|
|
|
+void execmem_free(void *ptr)
|
|
+{
|
|
+ arch_execmem_free(ptr);
|
|
+}
|
|
+
|
|
static bool execmem_validate(struct execmem_info *info)
|
|
{
|
|
struct execmem_range *r = &info->ranges[EXECMEM_DEFAULT];
|