Merge tag 'smp-urgent-2023-09-02' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / arch / powerpc / include / asm / ftrace.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
ccbfac29
SR
2#ifndef _ASM_POWERPC_FTRACE
3#define _ASM_POWERPC_FTRACE
4
f55d9665
ME
5#include <asm/types.h>
6
606576ce 7#ifdef CONFIG_FUNCTION_TRACER
c93bf928 8#define MCOUNT_ADDR ((unsigned long)(_mcount))
395a59d0
AS
9#define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */
10
370011a2
NR
11#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
12
7af82ff9 13/* Ignore unused weak functions which will have larger offsets */
0f71dcfb 14#if defined(CONFIG_MPROFILE_KERNEL) || defined(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY)
f6834c8c 15#define FTRACE_MCOUNT_MAX_OFFSET 16
7af82ff9
NR
16#elif defined(CONFIG_PPC32)
17#define FTRACE_MCOUNT_MAX_OFFSET 8
18#endif
19
d95bf254 20#ifndef __ASSEMBLY__
ccbfac29 21extern void _mcount(void);
8fd6e5a8 22
8fd6e5a8
SR
23static inline unsigned long ftrace_call_adjust(unsigned long addr)
24{
0f71dcfb
NR
25 if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY))
26 addr += MCOUNT_INSN_SIZE;
27
8fd6e5a8
SR
28 return addr;
29}
30
76222808
CL
31unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
32 unsigned long sp);
33
cc93b923
NR
34struct module;
35struct dyn_ftrace;
8fd6e5a8 36struct dyn_arch_ftrace {
f48cb8b4 37 struct module *mod;
8fd6e5a8 38};
40b035ef
CL
39
40#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
cc93b923
NR
41#define ftrace_need_init_nop() (true)
42int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
43#define ftrace_init_nop ftrace_init_nop
44
40b035ef
CL
45struct ftrace_regs {
46 struct pt_regs regs;
47};
48
49static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
50{
fc75f873
CL
51 /* We clear regs.msr in ftrace_call */
52 return fregs->regs.msr ? &fregs->regs : NULL;
40b035ef
CL
53}
54
0ef86097
MR
55static __always_inline void
56ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
57 unsigned long ip)
40b035ef
CL
58{
59 regs_set_return_ip(&fregs->regs, ip);
60}
83021378 61
94d095ff
MR
62static __always_inline unsigned long
63ftrace_regs_get_instruction_pointer(struct ftrace_regs *fregs)
64{
65 return instruction_pointer(&fregs->regs);
66}
67
68#define ftrace_regs_get_argument(fregs, n) \
69 regs_get_kernel_argument(&(fregs)->regs, n)
70#define ftrace_regs_get_stack_pointer(fregs) \
71 kernel_stack_pointer(&(fregs)->regs)
72#define ftrace_regs_return_value(fregs) \
73 regs_return_value(&(fregs)->regs)
74#define ftrace_regs_set_return_value(fregs, ret) \
75 regs_set_return_value(&(fregs)->regs, ret)
76#define ftrace_override_function_with_return(fregs) \
77 override_function_with_return(&(fregs)->regs)
78#define ftrace_regs_query_register_offset(name) \
79 regs_query_register_offset(name)
80
83021378
CL
81struct ftrace_ops;
82
83#define ftrace_graph_func ftrace_graph_func
84void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
85 struct ftrace_ops *op, struct ftrace_regs *fregs);
40b035ef 86#endif
8fd6e5a8 87#endif /* __ASSEMBLY__ */
ccbfac29 88
15308664
TD
89#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
90#define ARCH_SUPPORTS_FTRACE_OPS 1
91#endif
0c0c5230 92#endif /* CONFIG_FUNCTION_TRACER */
395a59d0 93
c3e59d77 94#ifndef __ASSEMBLY__
f1079d3a 95#ifdef CONFIG_FTRACE_SYSCALLS
edf6a2df
NR
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 */
02424d89 101#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
edf6a2df
NR
102static 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));
02424d89 109}
f1079d3a 110#endif /* CONFIG_FTRACE_SYSCALLS */
acd55b10 111
84ade0a6 112#if defined(CONFIG_PPC64) && defined(CONFIG_FUNCTION_TRACER)
acd55b10
NR
113#include <asm/paca.h>
114
115static inline void this_cpu_disable_ftrace(void)
116{
117 get_paca()->ftrace_enabled = 0;
118}
119
120static inline void this_cpu_enable_ftrace(void)
121{
122 get_paca()->ftrace_enabled = 1;
123}
f2d7f62e
NP
124
125/* Disable ftrace on this CPU if possible (may not be implemented) */
126static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled)
127{
128 get_paca()->ftrace_enabled = ftrace_enabled;
129}
130
131static inline u8 this_cpu_get_ftrace_enabled(void)
132{
133 return get_paca()->ftrace_enabled;
134}
acd55b10
NR
135#else /* CONFIG_PPC64 */
136static inline void this_cpu_disable_ftrace(void) { }
137static inline void this_cpu_enable_ftrace(void) { }
f2d7f62e
NP
138static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { }
139static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; }
acd55b10 140#endif /* CONFIG_PPC64 */
f3993a03
NR
141
142#ifdef CONFIG_FUNCTION_TRACER
143extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[];
144void ftrace_free_init_tramp(void);
145#else
146static inline void ftrace_free_init_tramp(void) { }
147#endif
c3e59d77 148#endif /* !__ASSEMBLY__ */
02424d89 149
395a59d0 150#endif /* _ASM_POWERPC_FTRACE */