1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2819e50e2SAKASHI Takahiro /* 3819e50e2SAKASHI Takahiro * arch/arm64/include/asm/ftrace.h 4819e50e2SAKASHI Takahiro * 5819e50e2SAKASHI Takahiro * Copyright (C) 2013 Linaro Limited 6819e50e2SAKASHI Takahiro * Author: AKASHI Takahiro <takahiro.akashi@linaro.org> 7819e50e2SAKASHI Takahiro */ 8819e50e2SAKASHI Takahiro #ifndef __ASM_FTRACE_H 9819e50e2SAKASHI Takahiro #define __ASM_FTRACE_H 10819e50e2SAKASHI Takahiro 11819e50e2SAKASHI Takahiro #include <asm/insn.h> 12819e50e2SAKASHI Takahiro 135c176affSMark Rutland #define HAVE_FUNCTION_GRAPH_FP_TEST 143b23e499STorsten Duwe 15c6d3cd32SMark Rutland /* 16c6d3cd32SMark Rutland * HAVE_FUNCTION_GRAPH_RET_ADDR_PTR means that the architecture can provide a 17c6d3cd32SMark Rutland * "return address pointer" which can be used to uniquely identify a return 18c6d3cd32SMark Rutland * address which has been overwritten. 19c6d3cd32SMark Rutland * 20c6d3cd32SMark Rutland * On arm64 we use the address of the caller's frame record, which remains the 21c6d3cd32SMark Rutland * same for the lifetime of the instrumented function, unlike the return 22c6d3cd32SMark Rutland * address in the LR. 23c6d3cd32SMark Rutland */ 24c6d3cd32SMark Rutland #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 25c6d3cd32SMark Rutland 263b23e499STorsten Duwe #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 273b23e499STorsten Duwe #define ARCH_SUPPORTS_FTRACE_OPS 1 283b23e499STorsten Duwe #else 29*607289a7SSami Tolvanen #define MCOUNT_ADDR ((unsigned long)_mcount) 303b23e499STorsten Duwe #endif 313b23e499STorsten Duwe 323b23e499STorsten Duwe /* The BL at the callsite's adjusted rec->ip */ 33819e50e2SAKASHI Takahiro #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE 34819e50e2SAKASHI Takahiro 353b23e499STorsten Duwe #define FTRACE_PLT_IDX 0 363b23e499STorsten Duwe #define FTRACE_REGS_PLT_IDX 1 373b23e499STorsten Duwe #define NR_FTRACE_PLTS 2 383b23e499STorsten Duwe 39f7edb451SSteven Rostedt (VMware) /* 40f7edb451SSteven Rostedt (VMware) * Currently, gcc tends to save the link register after the local variables 41f7edb451SSteven Rostedt (VMware) * on the stack. This causes the max stack tracer to report the function 42f7edb451SSteven Rostedt (VMware) * frame sizes for the wrong functions. By defining 43f7edb451SSteven Rostedt (VMware) * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect 44f7edb451SSteven Rostedt (VMware) * to find the return address on the stack after the local variables have 45f7edb451SSteven Rostedt (VMware) * been set up. 46f7edb451SSteven Rostedt (VMware) * 47f7edb451SSteven Rostedt (VMware) * Note, this may change in the future, and we will need to deal with that 48f7edb451SSteven Rostedt (VMware) * if it were to happen. 49f7edb451SSteven Rostedt (VMware) */ 50f7edb451SSteven Rostedt (VMware) #define ARCH_FTRACE_SHIFT_STACK_TRACER 1 51f7edb451SSteven Rostedt (VMware) 52819e50e2SAKASHI Takahiro #ifndef __ASSEMBLY__ 53055b1212SAKASHI Takahiro #include <linux/compat.h> 54055b1212SAKASHI Takahiro 55819e50e2SAKASHI Takahiro extern void _mcount(unsigned long); 563711784eSAKASHI Takahiro extern void *return_address(unsigned int); 57bd7d38dbSAKASHI Takahiro 58bd7d38dbSAKASHI Takahiro struct dyn_arch_ftrace { 59bd7d38dbSAKASHI Takahiro /* No extra data needed for arm64 */ 60bd7d38dbSAKASHI Takahiro }; 61bd7d38dbSAKASHI Takahiro 62bd7d38dbSAKASHI Takahiro extern unsigned long ftrace_graph_call; 63bd7d38dbSAKASHI Takahiro 6420380bb3SAKASHI Takahiro extern void return_to_handler(void); 6520380bb3SAKASHI Takahiro 66bd7d38dbSAKASHI Takahiro static inline unsigned long ftrace_call_adjust(unsigned long addr) 67bd7d38dbSAKASHI Takahiro { 68bd7d38dbSAKASHI Takahiro /* 693b23e499STorsten Duwe * Adjust addr to point at the BL in the callsite. 703b23e499STorsten Duwe * See ftrace_init_nop() for the callsite sequence. 713b23e499STorsten Duwe */ 723b23e499STorsten Duwe if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) 733b23e499STorsten Duwe return addr + AARCH64_INSN_SIZE; 743b23e499STorsten Duwe /* 75bd7d38dbSAKASHI Takahiro * addr is the address of the mcount call instruction. 76bd7d38dbSAKASHI Takahiro * recordmcount does the necessary offset calculation. 77bd7d38dbSAKASHI Takahiro */ 78bd7d38dbSAKASHI Takahiro return addr; 79bd7d38dbSAKASHI Takahiro } 803711784eSAKASHI Takahiro 813b23e499STorsten Duwe #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 823b23e499STorsten Duwe struct dyn_ftrace; 83c4a0ebf8SChengming Zhou struct ftrace_ops; 84c4a0ebf8SChengming Zhou struct ftrace_regs; 85c4a0ebf8SChengming Zhou 863b23e499STorsten Duwe int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); 873b23e499STorsten Duwe #define ftrace_init_nop ftrace_init_nop 88c4a0ebf8SChengming Zhou 89c4a0ebf8SChengming Zhou void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, 90c4a0ebf8SChengming Zhou struct ftrace_ops *op, struct ftrace_regs *fregs); 91c4a0ebf8SChengming Zhou #define ftrace_graph_func ftrace_graph_func 923b23e499STorsten Duwe #endif 933b23e499STorsten Duwe 943711784eSAKASHI Takahiro #define ftrace_return_address(n) return_address(n) 95055b1212SAKASHI Takahiro 96055b1212SAKASHI Takahiro /* 97055b1212SAKASHI Takahiro * Because AArch32 mode does not share the same syscall table with AArch64, 98055b1212SAKASHI Takahiro * tracing compat syscalls may result in reporting bogus syscalls or even 99055b1212SAKASHI Takahiro * hang-up, so just do not trace them. 100055b1212SAKASHI Takahiro * See kernel/trace/trace_syscalls.c 101055b1212SAKASHI Takahiro * 102055b1212SAKASHI Takahiro * x86 code says: 103ef769e32SAdam Buchbinder * If the user really wants these, then they should use the 104055b1212SAKASHI Takahiro * raw syscall tracepoints with filtering. 105055b1212SAKASHI Takahiro */ 106055b1212SAKASHI Takahiro #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 107055b1212SAKASHI Takahiro static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) 108055b1212SAKASHI Takahiro { 109055b1212SAKASHI Takahiro return is_compat_task(); 110055b1212SAKASHI Takahiro } 111874bfc6eSMasami Hiramatsu 112874bfc6eSMasami Hiramatsu #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME 113874bfc6eSMasami Hiramatsu 114874bfc6eSMasami Hiramatsu static inline bool arch_syscall_match_sym_name(const char *sym, 115874bfc6eSMasami Hiramatsu const char *name) 116874bfc6eSMasami Hiramatsu { 117874bfc6eSMasami Hiramatsu /* 118874bfc6eSMasami Hiramatsu * Since all syscall functions have __arm64_ prefix, we must skip it. 119874bfc6eSMasami Hiramatsu * However, as we described above, we decided to ignore compat 120874bfc6eSMasami Hiramatsu * syscalls, so we don't care about __arm64_compat_ prefix here. 121874bfc6eSMasami Hiramatsu */ 122874bfc6eSMasami Hiramatsu return !strcmp(sym + 8, name); 123874bfc6eSMasami Hiramatsu } 1243711784eSAKASHI Takahiro #endif /* ifndef __ASSEMBLY__ */ 125819e50e2SAKASHI Takahiro 126819e50e2SAKASHI Takahiro #endif /* __ASM_FTRACE_H */ 127