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 14*3b23e499STorsten Duwe 15*3b23e499STorsten Duwe #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 16*3b23e499STorsten Duwe #define ARCH_SUPPORTS_FTRACE_OPS 1 17*3b23e499STorsten Duwe #else 18819e50e2SAKASHI Takahiro #define MCOUNT_ADDR ((unsigned long)_mcount) 19*3b23e499STorsten Duwe #endif 20*3b23e499STorsten Duwe 21*3b23e499STorsten Duwe /* The BL at the callsite's adjusted rec->ip */ 22819e50e2SAKASHI Takahiro #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE 23819e50e2SAKASHI Takahiro 24*3b23e499STorsten Duwe #define FTRACE_PLT_IDX 0 25*3b23e499STorsten Duwe #define FTRACE_REGS_PLT_IDX 1 26*3b23e499STorsten Duwe #define NR_FTRACE_PLTS 2 27*3b23e499STorsten Duwe 28f7edb451SSteven Rostedt (VMware) /* 29f7edb451SSteven Rostedt (VMware) * Currently, gcc tends to save the link register after the local variables 30f7edb451SSteven Rostedt (VMware) * on the stack. This causes the max stack tracer to report the function 31f7edb451SSteven Rostedt (VMware) * frame sizes for the wrong functions. By defining 32f7edb451SSteven Rostedt (VMware) * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect 33f7edb451SSteven Rostedt (VMware) * to find the return address on the stack after the local variables have 34f7edb451SSteven Rostedt (VMware) * been set up. 35f7edb451SSteven Rostedt (VMware) * 36f7edb451SSteven Rostedt (VMware) * Note, this may change in the future, and we will need to deal with that 37f7edb451SSteven Rostedt (VMware) * if it were to happen. 38f7edb451SSteven Rostedt (VMware) */ 39f7edb451SSteven Rostedt (VMware) #define ARCH_FTRACE_SHIFT_STACK_TRACER 1 40f7edb451SSteven Rostedt (VMware) 41819e50e2SAKASHI Takahiro #ifndef __ASSEMBLY__ 42055b1212SAKASHI Takahiro #include <linux/compat.h> 43055b1212SAKASHI Takahiro 44819e50e2SAKASHI Takahiro extern void _mcount(unsigned long); 453711784eSAKASHI Takahiro extern void *return_address(unsigned int); 46bd7d38dbSAKASHI Takahiro 47bd7d38dbSAKASHI Takahiro struct dyn_arch_ftrace { 48bd7d38dbSAKASHI Takahiro /* No extra data needed for arm64 */ 49bd7d38dbSAKASHI Takahiro }; 50bd7d38dbSAKASHI Takahiro 51bd7d38dbSAKASHI Takahiro extern unsigned long ftrace_graph_call; 52bd7d38dbSAKASHI Takahiro 5320380bb3SAKASHI Takahiro extern void return_to_handler(void); 5420380bb3SAKASHI Takahiro 55bd7d38dbSAKASHI Takahiro static inline unsigned long ftrace_call_adjust(unsigned long addr) 56bd7d38dbSAKASHI Takahiro { 57bd7d38dbSAKASHI Takahiro /* 58*3b23e499STorsten Duwe * Adjust addr to point at the BL in the callsite. 59*3b23e499STorsten Duwe * See ftrace_init_nop() for the callsite sequence. 60*3b23e499STorsten Duwe */ 61*3b23e499STorsten Duwe if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) 62*3b23e499STorsten Duwe return addr + AARCH64_INSN_SIZE; 63*3b23e499STorsten Duwe /* 64bd7d38dbSAKASHI Takahiro * addr is the address of the mcount call instruction. 65bd7d38dbSAKASHI Takahiro * recordmcount does the necessary offset calculation. 66bd7d38dbSAKASHI Takahiro */ 67bd7d38dbSAKASHI Takahiro return addr; 68bd7d38dbSAKASHI Takahiro } 693711784eSAKASHI Takahiro 70*3b23e499STorsten Duwe #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 71*3b23e499STorsten Duwe struct dyn_ftrace; 72*3b23e499STorsten Duwe int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); 73*3b23e499STorsten Duwe #define ftrace_init_nop ftrace_init_nop 74*3b23e499STorsten Duwe #endif 75*3b23e499STorsten Duwe 763711784eSAKASHI Takahiro #define ftrace_return_address(n) return_address(n) 77055b1212SAKASHI Takahiro 78055b1212SAKASHI Takahiro /* 79055b1212SAKASHI Takahiro * Because AArch32 mode does not share the same syscall table with AArch64, 80055b1212SAKASHI Takahiro * tracing compat syscalls may result in reporting bogus syscalls or even 81055b1212SAKASHI Takahiro * hang-up, so just do not trace them. 82055b1212SAKASHI Takahiro * See kernel/trace/trace_syscalls.c 83055b1212SAKASHI Takahiro * 84055b1212SAKASHI Takahiro * x86 code says: 85ef769e32SAdam Buchbinder * If the user really wants these, then they should use the 86055b1212SAKASHI Takahiro * raw syscall tracepoints with filtering. 87055b1212SAKASHI Takahiro */ 88055b1212SAKASHI Takahiro #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 89055b1212SAKASHI Takahiro static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) 90055b1212SAKASHI Takahiro { 91055b1212SAKASHI Takahiro return is_compat_task(); 92055b1212SAKASHI Takahiro } 93874bfc6eSMasami Hiramatsu 94874bfc6eSMasami Hiramatsu #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME 95874bfc6eSMasami Hiramatsu 96874bfc6eSMasami Hiramatsu static inline bool arch_syscall_match_sym_name(const char *sym, 97874bfc6eSMasami Hiramatsu const char *name) 98874bfc6eSMasami Hiramatsu { 99874bfc6eSMasami Hiramatsu /* 100874bfc6eSMasami Hiramatsu * Since all syscall functions have __arm64_ prefix, we must skip it. 101874bfc6eSMasami Hiramatsu * However, as we described above, we decided to ignore compat 102874bfc6eSMasami Hiramatsu * syscalls, so we don't care about __arm64_compat_ prefix here. 103874bfc6eSMasami Hiramatsu */ 104874bfc6eSMasami Hiramatsu return !strcmp(sym + 8, name); 105874bfc6eSMasami Hiramatsu } 1063711784eSAKASHI Takahiro #endif /* ifndef __ASSEMBLY__ */ 107819e50e2SAKASHI Takahiro 108819e50e2SAKASHI Takahiro #endif /* __ASM_FTRACE_H */ 109