1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_FTRACE 3 #define _ASM_POWERPC_FTRACE 4 5 #include <asm/types.h> 6 7 #ifdef CONFIG_FUNCTION_TRACER 8 #define MCOUNT_ADDR ((unsigned long)(_mcount)) 9 #define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */ 10 11 /* Ignore unused weak functions which will have larger offsets */ 12 #if defined(CONFIG_MPROFILE_KERNEL) || defined(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY) 13 #define FTRACE_MCOUNT_MAX_OFFSET 16 14 #elif defined(CONFIG_PPC32) 15 #define FTRACE_MCOUNT_MAX_OFFSET 8 16 #endif 17 18 #ifndef __ASSEMBLER__ 19 extern void _mcount(void); 20 21 unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip, 22 unsigned long sp); 23 24 struct module; 25 struct dyn_ftrace; 26 struct dyn_arch_ftrace { 27 #ifdef CONFIG_PPC_FTRACE_OUT_OF_LINE 28 /* pointer to the associated out-of-line stub */ 29 unsigned long ool_stub; 30 #endif 31 }; 32 33 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS 34 #define ftrace_need_init_nop() (true) 35 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); 36 #define ftrace_init_nop ftrace_init_nop 37 38 #include <linux/ftrace_regs.h> 39 40 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) 41 { 42 /* We clear regs.msr in ftrace_call */ 43 return arch_ftrace_regs(fregs)->regs.msr ? &arch_ftrace_regs(fregs)->regs : NULL; 44 } 45 46 #define arch_ftrace_fill_perf_regs(fregs, _regs) do { \ 47 (_regs)->result = 0; \ 48 (_regs)->nip = arch_ftrace_regs(fregs)->regs.nip; \ 49 (_regs)->gpr[1] = arch_ftrace_regs(fregs)->regs.gpr[1]; \ 50 asm volatile("mfmsr %0" : "=r" ((_regs)->msr)); \ 51 } while (0) 52 53 #undef ftrace_regs_get_return_value 54 static __always_inline unsigned long 55 ftrace_regs_get_return_value(const struct ftrace_regs *fregs) 56 { 57 return arch_ftrace_regs(fregs)->regs.gpr[3]; 58 } 59 #define ftrace_regs_get_return_value ftrace_regs_get_return_value 60 61 #undef ftrace_regs_get_frame_pointer 62 static __always_inline unsigned long 63 ftrace_regs_get_frame_pointer(const struct ftrace_regs *fregs) 64 { 65 return arch_ftrace_regs(fregs)->regs.gpr[1]; 66 } 67 68 static __always_inline void 69 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, 70 unsigned long ip) 71 { 72 regs_set_return_ip(&arch_ftrace_regs(fregs)->regs, ip); 73 } 74 75 static __always_inline unsigned long 76 ftrace_regs_get_return_address(struct ftrace_regs *fregs) 77 { 78 return arch_ftrace_regs(fregs)->regs.link; 79 } 80 81 struct ftrace_ops; 82 83 #define ftrace_graph_func ftrace_graph_func 84 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, 85 struct ftrace_ops *op, struct ftrace_regs *fregs); 86 #endif 87 #endif /* __ASSEMBLER__ */ 88 89 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 90 #define ARCH_SUPPORTS_FTRACE_OPS 1 91 #endif 92 #endif /* CONFIG_FUNCTION_TRACER */ 93 94 #ifndef __ASSEMBLER__ 95 #ifdef CONFIG_FTRACE_SYSCALLS 96 /* 97 * Some syscall entry functions on powerpc start with "ppc_" (fork and clone, 98 * for instance) or ppc32_/ppc64_. We should also match the sys_ variant with 99 * those. 100 */ 101 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME 102 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) 103 { 104 return !strcmp(sym, name) || 105 (!strncmp(sym, "__se_sys", 8) && !strcmp(sym + 5, name)) || 106 (!strncmp(sym, "ppc_", 4) && !strcmp(sym + 4, name + 4)) || 107 (!strncmp(sym, "ppc32_", 6) && !strcmp(sym + 6, name + 4)) || 108 (!strncmp(sym, "ppc64_", 6) && !strcmp(sym + 6, name + 4)); 109 } 110 #endif /* CONFIG_FTRACE_SYSCALLS */ 111 112 #if defined(CONFIG_PPC64) && defined(CONFIG_FUNCTION_TRACER) 113 #include <asm/paca.h> 114 115 static inline void this_cpu_disable_ftrace(void) 116 { 117 get_paca()->ftrace_enabled = 0; 118 } 119 120 static inline void this_cpu_enable_ftrace(void) 121 { 122 get_paca()->ftrace_enabled = 1; 123 } 124 125 /* Disable ftrace on this CPU if possible (may not be implemented) */ 126 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) 127 { 128 get_paca()->ftrace_enabled = ftrace_enabled; 129 } 130 131 static inline u8 this_cpu_get_ftrace_enabled(void) 132 { 133 return get_paca()->ftrace_enabled; 134 } 135 #else /* CONFIG_PPC64 */ 136 static inline void this_cpu_disable_ftrace(void) { } 137 static inline void this_cpu_enable_ftrace(void) { } 138 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { } 139 static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; } 140 #endif /* CONFIG_PPC64 */ 141 142 #ifdef CONFIG_FUNCTION_TRACER 143 extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[]; 144 #ifdef CONFIG_PPC_FTRACE_OUT_OF_LINE 145 struct ftrace_ool_stub { 146 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS 147 struct ftrace_ops *ftrace_op; 148 #endif 149 u32 insn[4]; 150 } __aligned(sizeof(unsigned long)); 151 extern struct ftrace_ool_stub ftrace_ool_stub_text_end[], ftrace_ool_stub_text[], 152 ftrace_ool_stub_inittext[]; 153 extern unsigned int ftrace_ool_stub_text_end_count, ftrace_ool_stub_text_count, 154 ftrace_ool_stub_inittext_count; 155 #endif 156 void ftrace_free_init_tramp(void); 157 unsigned long ftrace_call_adjust(unsigned long addr); 158 159 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS 160 /* 161 * When an ftrace registered caller is tracing a function that is also set by a 162 * register_ftrace_direct() call, it needs to be differentiated in the 163 * ftrace_caller trampoline so that the direct call can be invoked after the 164 * other ftrace ops. To do this, place the direct caller in the orig_gpr3 field 165 * of pt_regs. This tells ftrace_caller that there's a direct caller. 166 */ 167 static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr) 168 { 169 struct pt_regs *regs = &arch_ftrace_regs(fregs)->regs; 170 171 regs->orig_gpr3 = addr; 172 } 173 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ 174 #else 175 static inline void ftrace_free_init_tramp(void) { } 176 static inline unsigned long ftrace_call_adjust(unsigned long addr) { return addr; } 177 #endif 178 #endif /* !__ASSEMBLER__ */ 179 180 #endif /* _ASM_POWERPC_FTRACE */ 181