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