[PATCH v2 02/10] s390/ftrace: Serialize text patching with text_mutex
From: Heiko Carstens
Date: Tue Oct 27 2026 - 10:35:01 EST
Add ftrace_arch_code_modify_prepare() and extend
ftrace_arch_code_modify_post_process() to acquire and release
text_mutex when ftrace code is modified.
Also add locking to ftrace_init_nop(). This way s390 uses text_mutex
like e.g. x86 and riscv.
This is part of larger series where at the end s390_kernel_write()
requires that callers hold text_mutex for serialization.
Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/kernel/ftrace.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/s390/kernel/ftrace.c b/arch/s390/kernel/ftrace.c
index e94bb98f5231..2f0c4ef1b2d6 100644
--- a/arch/s390/kernel/ftrace.c
+++ b/arch/s390/kernel/ftrace.c
@@ -8,6 +8,7 @@
*/
#include <linux/hardirq.h>
+#include <linux/memory.h>
#include <linux/uaccess.h>
#include <linux/ftrace.h>
#include <linux/kernel.h>
@@ -90,6 +91,8 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
BUILD_BUG_ON(sizeof(struct ftrace_hotpatch_trampoline) !=
SIZEOF_FTRACE_HOTPATCH_TRAMPOLINE);
+ guard(mutex)(&text_mutex);
+
next_trampoline = &next_vmlinux_trampoline;
trampolines_end = __ftrace_hotpatch_trampolines_end;
shared = ftrace_shared_hotpatch_trampoline(NULL);
@@ -247,13 +250,21 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
return 0;
}
+void ftrace_arch_code_modify_prepare(void)
+ __acquires(&text_mutex)
+{
+ mutex_lock(&text_mutex);
+}
+
void arch_ftrace_update_code(int command)
{
ftrace_modify_all_code(command);
}
void ftrace_arch_code_modify_post_process(void)
+ __releases(&text_mutex)
{
+ mutex_unlock(&text_mutex);
/*
* Flush any pre-fetched instructions on all
* CPUs to make the new code visible.
--
2.53.0