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