1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm64/include/asm/ftrace.h
5 * Copyright (C) 2013 Linaro Limited
6 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
13 #define HAVE_FUNCTION_GRAPH_FP_TEST
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.
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
24 #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
26 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
27 #define ARCH_SUPPORTS_FTRACE_OPS 1
29 #define MCOUNT_ADDR ((unsigned long)_mcount)
32 /* The BL at the callsite's adjusted rec->ip */
33 #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
35 #define FTRACE_PLT_IDX 0
36 #define NR_FTRACE_PLTS 1
39 * Currently, gcc tends to save the link register after the local variables
40 * on the stack. This causes the max stack tracer to report the function
41 * frame sizes for the wrong functions. By defining
42 * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect
43 * to find the return address on the stack after the local variables have
46 * Note, this may change in the future, and we will need to deal with that
47 * if it were to happen.
49 #define ARCH_FTRACE_SHIFT_STACK_TRACER 1
52 #include <linux/compat.h>
54 extern void _mcount(unsigned long);
55 extern void *return_address(unsigned int);
57 struct dyn_arch_ftrace {
58 /* No extra data needed for arm64 */
61 extern unsigned long ftrace_graph_call;
63 extern void return_to_handler(void);
65 unsigned long ftrace_call_adjust(unsigned long addr);
67 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
71 #define arch_ftrace_get_regs(regs) NULL
75 unsigned long regs[9];
76 unsigned long __unused;
85 static __always_inline unsigned long
86 ftrace_regs_get_instruction_pointer(const struct ftrace_regs *fregs)
91 static __always_inline void
92 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
98 static __always_inline unsigned long
99 ftrace_regs_get_stack_pointer(const struct ftrace_regs *fregs)
104 static __always_inline unsigned long
105 ftrace_regs_get_argument(struct ftrace_regs *fregs, unsigned int n)
108 return fregs->regs[n];
112 static __always_inline unsigned long
113 ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
115 return fregs->regs[0];
118 static __always_inline void
119 ftrace_regs_set_return_value(struct ftrace_regs *fregs,
122 fregs->regs[0] = ret;
125 static __always_inline void
126 ftrace_override_function_with_return(struct ftrace_regs *fregs)
128 fregs->pc = fregs->lr;
131 int ftrace_regs_query_register_offset(const char *name);
133 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
134 #define ftrace_init_nop ftrace_init_nop
136 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
137 struct ftrace_ops *op, struct ftrace_regs *fregs);
138 #define ftrace_graph_func ftrace_graph_func
141 #define ftrace_return_address(n) return_address(n)
144 * Because AArch32 mode does not share the same syscall table with AArch64,
145 * tracing compat syscalls may result in reporting bogus syscalls or even
146 * hang-up, so just do not trace them.
147 * See kernel/trace/trace_syscalls.c
150 * If the user really wants these, then they should use the
151 * raw syscall tracepoints with filtering.
153 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
154 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
156 return is_compat_task();
159 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
161 static inline bool arch_syscall_match_sym_name(const char *sym,
165 * Since all syscall functions have __arm64_ prefix, we must skip it.
166 * However, as we described above, we decided to ignore compat
167 * syscalls, so we don't care about __arm64_compat_ prefix here.
169 return !strcmp(sym + 8, name);
171 #endif /* ifndef __ASSEMBLY__ */
173 #endif /* __ASM_FTRACE_H */