Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/ftrace: Remove ftrace init tramp once kernel init is complete

Stop using the ftrace trampoline for init section once kernel init is
complete.

Fixes: 67361cf8071286 ("powerpc/ftrace: Handle large kernel configs")
Cc: stable@vger.kernel.org # v4.20+
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220516071422.463738-1-naveen.n.rao@linux.vnet.ibm.com

authored by

Naveen N. Rao and committed by
Michael Ellerman
84ade0a6 5fe85516

+17 -4
+3 -1
arch/powerpc/include/asm/ftrace.h
··· 86 86 #endif /* CONFIG_PPC64_ELF_ABI_V1 */ 87 87 #endif /* CONFIG_FTRACE_SYSCALLS */ 88 88 89 - #ifdef CONFIG_PPC64 89 + #if defined(CONFIG_PPC64) && defined(CONFIG_FUNCTION_TRACER) 90 90 #include <asm/paca.h> 91 91 92 92 static inline void this_cpu_disable_ftrace(void) ··· 110 110 return get_paca()->ftrace_enabled; 111 111 } 112 112 113 + void ftrace_free_init_tramp(void); 113 114 #else /* CONFIG_PPC64 */ 114 115 static inline void this_cpu_disable_ftrace(void) { } 115 116 static inline void this_cpu_enable_ftrace(void) { } 116 117 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { } 117 118 static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; } 119 + static inline void ftrace_free_init_tramp(void) { } 118 120 #endif /* CONFIG_PPC64 */ 119 121 #endif /* !__ASSEMBLY__ */ 120 122
+12 -3
arch/powerpc/kernel/trace/ftrace.c
··· 257 257 258 258 /* Is this a known long jump tramp? */ 259 259 for (i = 0; i < NUM_FTRACE_TRAMPS; i++) 260 - if (!ftrace_tramps[i]) 261 - break; 262 - else if (ftrace_tramps[i] == tramp) 260 + if (ftrace_tramps[i] == tramp) 263 261 return 0; 264 262 265 263 /* New trampoline -- read where this goes */ ··· 707 709 #define PACATOC offsetof(struct paca_struct, kernel_toc) 708 710 709 711 extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[]; 712 + 713 + void ftrace_free_init_tramp(void) 714 + { 715 + int i; 716 + 717 + for (i = 0; i < NUM_FTRACE_TRAMPS && ftrace_tramps[i]; i++) 718 + if (ftrace_tramps[i] == (unsigned long)ftrace_tramp_init) { 719 + ftrace_tramps[i] = 0; 720 + return; 721 + } 722 + } 710 723 711 724 int __init ftrace_dyn_arch_init(void) 712 725 {
+2
arch/powerpc/mm/mem.c
··· 22 22 #include <asm/kasan.h> 23 23 #include <asm/svm.h> 24 24 #include <asm/mmzone.h> 25 + #include <asm/ftrace.h> 25 26 #include <asm/code-patching.h> 26 27 27 28 #include <mm/mmu_decl.h> ··· 315 314 mark_initmem_nx(); 316 315 static_branch_enable(&init_mem_is_free); 317 316 free_initmem_default(POISON_FREE_INITMEM); 317 + ftrace_free_init_tramp(); 318 318 } 319 319 320 320 /*