Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 __ASSEMBLY__
19extern void _mcount(void);
20
21unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
22 unsigned long sp);
23
24struct module;
25struct dyn_ftrace;
26struct 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)
35int 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
40static __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
46static __always_inline void
47ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
48 unsigned long ip)
49{
50 regs_set_return_ip(&arch_ftrace_regs(fregs)->regs, ip);
51}
52
53struct ftrace_ops;
54
55#define ftrace_graph_func ftrace_graph_func
56void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
57 struct ftrace_ops *op, struct ftrace_regs *fregs);
58#endif
59#endif /* __ASSEMBLY__ */
60
61#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
62#define ARCH_SUPPORTS_FTRACE_OPS 1
63#endif
64#endif /* CONFIG_FUNCTION_TRACER */
65
66#ifndef __ASSEMBLY__
67#ifdef CONFIG_FTRACE_SYSCALLS
68/*
69 * Some syscall entry functions on powerpc start with "ppc_" (fork and clone,
70 * for instance) or ppc32_/ppc64_. We should also match the sys_ variant with
71 * those.
72 */
73#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
74static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
75{
76 return !strcmp(sym, name) ||
77 (!strncmp(sym, "__se_sys", 8) && !strcmp(sym + 5, name)) ||
78 (!strncmp(sym, "ppc_", 4) && !strcmp(sym + 4, name + 4)) ||
79 (!strncmp(sym, "ppc32_", 6) && !strcmp(sym + 6, name + 4)) ||
80 (!strncmp(sym, "ppc64_", 6) && !strcmp(sym + 6, name + 4));
81}
82#endif /* CONFIG_FTRACE_SYSCALLS */
83
84#if defined(CONFIG_PPC64) && defined(CONFIG_FUNCTION_TRACER)
85#include <asm/paca.h>
86
87static inline void this_cpu_disable_ftrace(void)
88{
89 get_paca()->ftrace_enabled = 0;
90}
91
92static inline void this_cpu_enable_ftrace(void)
93{
94 get_paca()->ftrace_enabled = 1;
95}
96
97/* Disable ftrace on this CPU if possible (may not be implemented) */
98static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled)
99{
100 get_paca()->ftrace_enabled = ftrace_enabled;
101}
102
103static inline u8 this_cpu_get_ftrace_enabled(void)
104{
105 return get_paca()->ftrace_enabled;
106}
107#else /* CONFIG_PPC64 */
108static inline void this_cpu_disable_ftrace(void) { }
109static inline void this_cpu_enable_ftrace(void) { }
110static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { }
111static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; }
112#endif /* CONFIG_PPC64 */
113
114#ifdef CONFIG_FUNCTION_TRACER
115extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[];
116#ifdef CONFIG_PPC_FTRACE_OUT_OF_LINE
117struct ftrace_ool_stub {
118#ifdef CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS
119 struct ftrace_ops *ftrace_op;
120#endif
121 u32 insn[4];
122} __aligned(sizeof(unsigned long));
123extern struct ftrace_ool_stub ftrace_ool_stub_text_end[], ftrace_ool_stub_text[],
124 ftrace_ool_stub_inittext[];
125extern unsigned int ftrace_ool_stub_text_end_count, ftrace_ool_stub_text_count,
126 ftrace_ool_stub_inittext_count;
127#endif
128void ftrace_free_init_tramp(void);
129unsigned long ftrace_call_adjust(unsigned long addr);
130
131#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
132/*
133 * When an ftrace registered caller is tracing a function that is also set by a
134 * register_ftrace_direct() call, it needs to be differentiated in the
135 * ftrace_caller trampoline so that the direct call can be invoked after the
136 * other ftrace ops. To do this, place the direct caller in the orig_gpr3 field
137 * of pt_regs. This tells ftrace_caller that there's a direct caller.
138 */
139static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr)
140{
141 struct pt_regs *regs = &arch_ftrace_regs(fregs)->regs;
142
143 regs->orig_gpr3 = addr;
144}
145#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
146#else
147static inline void ftrace_free_init_tramp(void) { }
148static inline unsigned long ftrace_call_adjust(unsigned long addr) { return addr; }
149#endif
150#endif /* !__ASSEMBLY__ */
151
152#endif /* _ASM_POWERPC_FTRACE */