xref: /linux/arch/powerpc/include/asm/ftrace.h (revision 0a1d4434db5f86c50018fe0aab299ac97dc15b76)
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 #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
12 
13 #ifndef __ASSEMBLY__
14 extern void _mcount(void);
15 
16 static inline unsigned long ftrace_call_adjust(unsigned long addr)
17 {
18        /* relocation of mcount call site is the same as the address */
19        return addr;
20 }
21 
22 unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
23 				    unsigned long sp);
24 
25 struct dyn_arch_ftrace {
26 	struct module *mod;
27 };
28 
29 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
30 struct ftrace_regs {
31 	struct pt_regs regs;
32 };
33 
34 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
35 {
36 	/* We clear regs.msr in ftrace_call */
37 	return fregs->regs.msr ? &fregs->regs : NULL;
38 }
39 
40 static __always_inline void
41 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
42 				    unsigned long ip)
43 {
44 	regs_set_return_ip(&fregs->regs, ip);
45 }
46 
47 static __always_inline unsigned long
48 ftrace_regs_get_instruction_pointer(struct ftrace_regs *fregs)
49 {
50 	return instruction_pointer(&fregs->regs);
51 }
52 
53 #define ftrace_regs_get_argument(fregs, n) \
54 	regs_get_kernel_argument(&(fregs)->regs, n)
55 #define ftrace_regs_get_stack_pointer(fregs) \
56 	kernel_stack_pointer(&(fregs)->regs)
57 #define ftrace_regs_return_value(fregs) \
58 	regs_return_value(&(fregs)->regs)
59 #define ftrace_regs_set_return_value(fregs, ret) \
60 	regs_set_return_value(&(fregs)->regs, ret)
61 #define ftrace_override_function_with_return(fregs) \
62 	override_function_with_return(&(fregs)->regs)
63 #define ftrace_regs_query_register_offset(name) \
64 	regs_query_register_offset(name)
65 
66 struct ftrace_ops;
67 
68 #define ftrace_graph_func ftrace_graph_func
69 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
70 		       struct ftrace_ops *op, struct ftrace_regs *fregs);
71 #endif
72 #endif /* __ASSEMBLY__ */
73 
74 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
75 #define ARCH_SUPPORTS_FTRACE_OPS 1
76 #endif
77 #endif /* CONFIG_FUNCTION_TRACER */
78 
79 #ifndef __ASSEMBLY__
80 #ifdef CONFIG_FTRACE_SYSCALLS
81 /*
82  * Some syscall entry functions on powerpc start with "ppc_" (fork and clone,
83  * for instance) or ppc32_/ppc64_. We should also match the sys_ variant with
84  * those.
85  */
86 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
87 #ifdef CONFIG_PPC64_ELF_ABI_V1
88 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
89 {
90 	/* We need to skip past the initial dot, and the __se_sys alias */
91 	return !strcmp(sym + 1, name) ||
92 		(!strncmp(sym, ".__se_sys", 9) && !strcmp(sym + 6, name)) ||
93 		(!strncmp(sym, ".ppc_", 5) && !strcmp(sym + 5, name + 4)) ||
94 		(!strncmp(sym, ".ppc32_", 7) && !strcmp(sym + 7, name + 4)) ||
95 		(!strncmp(sym, ".ppc64_", 7) && !strcmp(sym + 7, name + 4));
96 }
97 #else
98 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
99 {
100 	return !strcmp(sym, name) ||
101 		(!strncmp(sym, "__se_sys", 8) && !strcmp(sym + 5, name)) ||
102 		(!strncmp(sym, "ppc_", 4) && !strcmp(sym + 4, name + 4)) ||
103 		(!strncmp(sym, "ppc32_", 6) && !strcmp(sym + 6, name + 4)) ||
104 		(!strncmp(sym, "ppc64_", 6) && !strcmp(sym + 6, name + 4));
105 }
106 #endif /* CONFIG_PPC64_ELF_ABI_V1 */
107 #endif /* CONFIG_FTRACE_SYSCALLS */
108 
109 #if defined(CONFIG_PPC64) && defined(CONFIG_FUNCTION_TRACER)
110 #include <asm/paca.h>
111 
112 static inline void this_cpu_disable_ftrace(void)
113 {
114 	get_paca()->ftrace_enabled = 0;
115 }
116 
117 static inline void this_cpu_enable_ftrace(void)
118 {
119 	get_paca()->ftrace_enabled = 1;
120 }
121 
122 /* Disable ftrace on this CPU if possible (may not be implemented) */
123 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled)
124 {
125 	get_paca()->ftrace_enabled = ftrace_enabled;
126 }
127 
128 static inline u8 this_cpu_get_ftrace_enabled(void)
129 {
130 	return get_paca()->ftrace_enabled;
131 }
132 
133 void ftrace_free_init_tramp(void);
134 #else /* CONFIG_PPC64 */
135 static inline void this_cpu_disable_ftrace(void) { }
136 static inline void this_cpu_enable_ftrace(void) { }
137 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { }
138 static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; }
139 static inline void ftrace_free_init_tramp(void) { }
140 #endif /* CONFIG_PPC64 */
141 #endif /* !__ASSEMBLY__ */
142 
143 #endif /* _ASM_POWERPC_FTRACE */
144