openwrt/target/linux/generic/hack-6.12/301-01-mm-permit-to-declare-custom-execmem-alloc-free-funct.patch
Mieczyslaw Nalewaj 141cb99b41 kernel/generic: restore files for v6.12
This is an automatically generated commit which aids following Kernel patch
history, as git will see the move and copy as a rename thus defeating the
purpose.

For the original discussion see:
https://lists.openwrt.org/pipermail/openwrt-devel/2023-October/041673.html

Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Link: https://github.com/openwrt/openwrt/pull/21078
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-03-28 11:51:09 +01:00

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];