xref: /openbmc/linux/arch/arm64/include/asm/ftrace.h (revision 55eb9a6c)
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 
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 struct ftrace_ops;
84 struct ftrace_regs;
85 
86 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
87 #define ftrace_init_nop ftrace_init_nop
88 
89 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
90 		       struct ftrace_ops *op, struct ftrace_regs *fregs);
91 #define ftrace_graph_func ftrace_graph_func
92 #endif
93 
94 #define ftrace_return_address(n) return_address(n)
95 
96 /*
97  * Because AArch32 mode does not share the same syscall table with AArch64,
98  * tracing compat syscalls may result in reporting bogus syscalls or even
99  * hang-up, so just do not trace them.
100  * See kernel/trace/trace_syscalls.c
101  *
102  * x86 code says:
103  * If the user really wants these, then they should use the
104  * raw syscall tracepoints with filtering.
105  */
106 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
107 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
108 {
109 	return is_compat_task();
110 }
111 
112 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
113 
114 static inline bool arch_syscall_match_sym_name(const char *sym,
115 					       const char *name)
116 {
117 	/*
118 	 * Since all syscall functions have __arm64_ prefix, we must skip it.
119 	 * However, as we described above, we decided to ignore compat
120 	 * syscalls, so we don't care about __arm64_compat_ prefix here.
121 	 */
122 	return !strcmp(sym + 8, name);
123 }
124 #endif /* ifndef __ASSEMBLY__ */
125 
126 #endif /* __ASM_FTRACE_H */
127