xref: /openbmc/linux/arch/x86/include/asm/ftrace.h (revision 6c33a6f4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_FTRACE_H
3 #define _ASM_X86_FTRACE_H
4 
5 #ifdef CONFIG_FUNCTION_TRACER
6 #ifndef CC_USING_FENTRY
7 # error Compiler does not support fentry?
8 #endif
9 # define MCOUNT_ADDR		((unsigned long)(__fentry__))
10 #define MCOUNT_INSN_SIZE	5 /* sizeof mcount call */
11 
12 #ifdef CONFIG_DYNAMIC_FTRACE
13 #define ARCH_SUPPORTS_FTRACE_OPS 1
14 #endif
15 
16 #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
17 
18 #ifndef __ASSEMBLY__
19 extern atomic_t modifying_ftrace_code;
20 extern void __fentry__(void);
21 
22 static inline unsigned long ftrace_call_adjust(unsigned long addr)
23 {
24 	/*
25 	 * addr is the address of the mcount call instruction.
26 	 * recordmcount does the necessary offset calculation.
27 	 */
28 	return addr;
29 }
30 
31 /*
32  * When a ftrace registered caller is tracing a function that is
33  * also set by a register_ftrace_direct() call, it needs to be
34  * differentiated in the ftrace_caller trampoline. To do this, we
35  * place the direct caller in the ORIG_AX part of pt_regs. This
36  * tells the ftrace_caller that there's a direct caller.
37  */
38 static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
39 {
40 	/* Emulate a call */
41 	regs->orig_ax = addr;
42 }
43 
44 #ifdef CONFIG_DYNAMIC_FTRACE
45 
46 struct dyn_arch_ftrace {
47 	/* No extra data needed for x86 */
48 };
49 
50 #define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR
51 
52 #endif /*  CONFIG_DYNAMIC_FTRACE */
53 #endif /* __ASSEMBLY__ */
54 #endif /* CONFIG_FUNCTION_TRACER */
55 
56 
57 #ifndef __ASSEMBLY__
58 
59 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
60 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
61 {
62 	/*
63 	 * Compare the symbol name with the system call name. Skip the
64 	 * "__x64_sys", "__ia32_sys" or simple "sys" prefix.
65 	 */
66 	return !strcmp(sym + 3, name + 3) ||
67 		(!strncmp(sym, "__x64_", 6) && !strcmp(sym + 9, name + 3)) ||
68 		(!strncmp(sym, "__ia32_", 7) && !strcmp(sym + 10, name + 3));
69 }
70 
71 #ifndef COMPILE_OFFSETS
72 
73 #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_IA32_EMULATION)
74 #include <linux/compat.h>
75 
76 /*
77  * Because ia32 syscalls do not map to x86_64 syscall numbers
78  * this screws up the trace output when tracing a ia32 task.
79  * Instead of reporting bogus syscalls, just do not trace them.
80  *
81  * If the user really wants these, then they should use the
82  * raw syscall tracepoints with filtering.
83  */
84 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 1
85 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
86 {
87 	return in_32bit_syscall();
88 }
89 #endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_IA32_EMULATION */
90 #endif /* !COMPILE_OFFSETS */
91 #endif /* !__ASSEMBLY__ */
92 
93 #endif /* _ASM_X86_FTRACE_H */
94