1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * arch/arm64/include/asm/ftrace.h
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2013 Linaro Limited
6*4882a593Smuzhiyun * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun #ifndef __ASM_FTRACE_H
9*4882a593Smuzhiyun #define __ASM_FTRACE_H
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <asm/insn.h>
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #define HAVE_FUNCTION_GRAPH_FP_TEST
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
16*4882a593Smuzhiyun #define ARCH_SUPPORTS_FTRACE_OPS 1
17*4882a593Smuzhiyun #else
18*4882a593Smuzhiyun #define MCOUNT_ADDR ((unsigned long)_mcount)
19*4882a593Smuzhiyun #endif
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /* The BL at the callsite's adjusted rec->ip */
22*4882a593Smuzhiyun #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define FTRACE_PLT_IDX 0
25*4882a593Smuzhiyun #define FTRACE_REGS_PLT_IDX 1
26*4882a593Smuzhiyun #define NR_FTRACE_PLTS 2
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun * Currently, gcc tends to save the link register after the local variables
30*4882a593Smuzhiyun * on the stack. This causes the max stack tracer to report the function
31*4882a593Smuzhiyun * frame sizes for the wrong functions. By defining
32*4882a593Smuzhiyun * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect
33*4882a593Smuzhiyun * to find the return address on the stack after the local variables have
34*4882a593Smuzhiyun * been set up.
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * Note, this may change in the future, and we will need to deal with that
37*4882a593Smuzhiyun * if it were to happen.
38*4882a593Smuzhiyun */
39*4882a593Smuzhiyun #define ARCH_FTRACE_SHIFT_STACK_TRACER 1
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #ifndef __ASSEMBLY__
42*4882a593Smuzhiyun #include <linux/compat.h>
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun extern void _mcount(unsigned long);
45*4882a593Smuzhiyun extern void *return_address(unsigned int);
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun struct dyn_arch_ftrace {
48*4882a593Smuzhiyun /* No extra data needed for arm64 */
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun extern unsigned long ftrace_graph_call;
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun extern void return_to_handler(void);
54*4882a593Smuzhiyun
ftrace_call_adjust(unsigned long addr)55*4882a593Smuzhiyun static inline unsigned long ftrace_call_adjust(unsigned long addr)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun /*
58*4882a593Smuzhiyun * Adjust addr to point at the BL in the callsite.
59*4882a593Smuzhiyun * See ftrace_init_nop() for the callsite sequence.
60*4882a593Smuzhiyun */
61*4882a593Smuzhiyun if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
62*4882a593Smuzhiyun return addr + AARCH64_INSN_SIZE;
63*4882a593Smuzhiyun /*
64*4882a593Smuzhiyun * addr is the address of the mcount call instruction.
65*4882a593Smuzhiyun * recordmcount does the necessary offset calculation.
66*4882a593Smuzhiyun */
67*4882a593Smuzhiyun return addr;
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
71*4882a593Smuzhiyun struct dyn_ftrace;
72*4882a593Smuzhiyun int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
73*4882a593Smuzhiyun #define ftrace_init_nop ftrace_init_nop
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #define ftrace_return_address(n) return_address(n)
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /*
79*4882a593Smuzhiyun * Because AArch32 mode does not share the same syscall table with AArch64,
80*4882a593Smuzhiyun * tracing compat syscalls may result in reporting bogus syscalls or even
81*4882a593Smuzhiyun * hang-up, so just do not trace them.
82*4882a593Smuzhiyun * See kernel/trace/trace_syscalls.c
83*4882a593Smuzhiyun *
84*4882a593Smuzhiyun * x86 code says:
85*4882a593Smuzhiyun * If the user really wants these, then they should use the
86*4882a593Smuzhiyun * raw syscall tracepoints with filtering.
87*4882a593Smuzhiyun */
88*4882a593Smuzhiyun #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
arch_trace_is_compat_syscall(struct pt_regs * regs)89*4882a593Smuzhiyun static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun return is_compat_task();
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
95*4882a593Smuzhiyun
arch_syscall_match_sym_name(const char * sym,const char * name)96*4882a593Smuzhiyun static inline bool arch_syscall_match_sym_name(const char *sym,
97*4882a593Smuzhiyun const char *name)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun * Since all syscall functions have __arm64_ prefix, we must skip it.
101*4882a593Smuzhiyun * However, as we described above, we decided to ignore compat
102*4882a593Smuzhiyun * syscalls, so we don't care about __arm64_compat_ prefix here.
103*4882a593Smuzhiyun */
104*4882a593Smuzhiyun return !strcmp(sym + 8, name);
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun #endif /* ifndef __ASSEMBLY__ */
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun #endif /* __ASM_FTRACE_H */
109