]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/ftrace: enable EXECMEM_ROX_CACHE for ftrace allocations
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Sun, 13 Jul 2025 07:17:30 +0000 (10:17 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 2 Aug 2025 19:06:12 +0000 (12:06 -0700)
For the most part ftrace uses text poking and can handle ROX memory.  The
only place that requires writable memory is create_trampoline() that
updates the allocated memory and in the end makes it ROX.

Use execmem_alloc_rw() in x86::ftrace::alloc_tramp() and enable ROX cache
for EXECMEM_FTRACE when configuration and CPU features allow that.

Link: https://lkml.kernel.org/r/20250713071730.4117334-9-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Daniel Gomez <da.gomez@samsung.com>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/x86/kernel/ftrace.c
arch/x86/mm/init.c

index 252e82bcfd2f7c949fe09937328af1ffbd627ed3..4450acec93903de10301686c6d261e7855c4bd77 100644 (file)
@@ -263,7 +263,7 @@ void arch_ftrace_update_code(int command)
 
 static inline void *alloc_tramp(unsigned long size)
 {
-       return execmem_alloc(EXECMEM_FTRACE, size);
+       return execmem_alloc_rw(EXECMEM_FTRACE, size);
 }
 static inline void tramp_free(void *tramp)
 {
index 442fafd8ff52e160a8713e339ca597f3a28e3eff..bb57e93b4caf16e4ceb4797bb6d5ecd2b38de7e6 100644 (file)
@@ -1105,7 +1105,14 @@ struct execmem_info __init *execmem_arch_setup(void)
                                .pgprot = PAGE_KERNEL_ROX,
                                .alignment = MODULE_ALIGN,
                        },
-                       [EXECMEM_FTRACE ... EXECMEM_BPF] = {
+                       [EXECMEM_FTRACE] = {
+                               .flags  = flags,
+                               .start  = start,
+                               .end    = MODULES_END,
+                               .pgprot = pgprot,
+                               .alignment = MODULE_ALIGN,
+                       },
+                       [EXECMEM_BPF] = {
                                .flags  = EXECMEM_KASAN_SHADOW,
                                .start  = start,
                                .end    = MODULES_END,