1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm64/include/asm/ftrace.h
5 * Copyright (C) 2013 Linaro Limited
13 #define HAVE_FUNCTION_GRAPH_FP_TEST
15 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
16 #define ARCH_SUPPORTS_FTRACE_OPS 1
18 #define MCOUNT_ADDR ((unsigned long)_mcount)
21 /* The BL at the callsite's adjusted rec->ip */
22 #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
24 #define FTRACE_PLT_IDX 0
25 #define NR_FTRACE_PLTS 1
28 * Currently, gcc tends to save the link register after the local variables
29 * on the stack. This causes the max stack tracer to report the function
30 * frame sizes for the wrong functions. By defining
31 * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect
32 * to find the return address on the stack after the local variables have
35 * Note, this may change in the future, and we will need to deal with that
36 * if it were to happen.
38 #define ARCH_FTRACE_SHIFT_STACK_TRACER 1
41 #include <linux/compat.h>
43 extern void _mcount(unsigned long);
44 extern void *return_address(unsigned int);
46 struct dyn_arch_ftrace {
47 /* No extra data needed for arm64 */
50 extern unsigned long ftrace_graph_call;
52 extern void return_to_handler(void);
54 unsigned long ftrace_call_adjust(unsigned long addr);
56 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
57 #define HAVE_ARCH_FTRACE_REGS
61 #define arch_ftrace_regs(fregs) ((struct __arch_ftrace_regs *)(fregs))
63 #define arch_ftrace_get_regs(regs) NULL
66 * Note: sizeof(struct ftrace_regs) must be a multiple of 16 to ensure correct
69 struct __arch_ftrace_regs {
71 unsigned long regs[9];
73 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
74 unsigned long direct_tramp;
76 unsigned long __unused;
86 static __always_inline unsigned long
87 ftrace_regs_get_instruction_pointer(const struct ftrace_regs *fregs)
89 return arch_ftrace_regs(fregs)->pc;
92 static __always_inline void
93 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
96 arch_ftrace_regs(fregs)->pc = pc;
99 static __always_inline unsigned long
100 ftrace_regs_get_stack_pointer(const struct ftrace_regs *fregs)
102 return arch_ftrace_regs(fregs)->sp;
105 static __always_inline unsigned long
106 ftrace_regs_get_argument(struct ftrace_regs *fregs, unsigned int n)
109 return arch_ftrace_regs(fregs)->regs[n];
113 static __always_inline unsigned long
114 ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
116 return arch_ftrace_regs(fregs)->regs[0];
119 static __always_inline void
120 ftrace_regs_set_return_value(struct ftrace_regs *fregs,
123 arch_ftrace_regs(fregs)->regs[0] = ret;
126 static __always_inline void
127 ftrace_override_function_with_return(struct ftrace_regs *fregs)
129 arch_ftrace_regs(fregs)->pc = arch_ftrace_regs(fregs)->lr;
132 int ftrace_regs_query_register_offset(const char *name);
134 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
135 #define ftrace_init_nop ftrace_init_nop
137 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
138 struct ftrace_ops *op, struct ftrace_regs *fregs);
139 #define ftrace_graph_func ftrace_graph_func
141 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
142 static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs,
146 * The ftrace trampoline will return to this address instead of the
147 * instrumented function.
149 arch_ftrace_regs(fregs)->direct_tramp = addr;
151 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
155 #define ftrace_return_address(n) return_address(n)
158 * Because AArch32 mode does not share the same syscall table with AArch64,
159 * tracing compat syscalls may result in reporting bogus syscalls or even
160 * hang-up, so just do not trace them.
161 * See kernel/trace/trace_syscalls.c
164 * If the user really wants these, then they should use the
165 * raw syscall tracepoints with filtering.
167 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
168 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
170 return is_compat_task();
173 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
175 static inline bool arch_syscall_match_sym_name(const char *sym,
179 * Since all syscall functions have __arm64_ prefix, we must skip it.
180 * However, as we described above, we decided to ignore compat
181 * syscalls, so we don't care about __arm64_compat_ prefix here.
183 return !strcmp(sym + 8, name);
185 #endif /* ifndef __ASSEMBLY__ */
188 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
189 struct fgraph_ret_regs {
191 unsigned long regs[8];
194 unsigned long __unused;
197 static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
199 return ret_regs->regs[0];
202 static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
207 void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
208 unsigned long frame_pointer);
210 #endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
213 #endif /* __ASM_FTRACE_H */