ftrace.h (3647B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _ASM_X86_FTRACE_H 3#define _ASM_X86_FTRACE_H 4 5#ifdef CONFIG_FUNCTION_TRACER 6#ifndef CC_USING_FENTRY 7# error Compiler does not support fentry? 8#endif 9# define MCOUNT_ADDR ((unsigned long)(__fentry__)) 10#define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */ 11 12/* Ignore unused weak functions which will have non zero offsets */ 13#ifdef CONFIG_HAVE_FENTRY 14# include <asm/ibt.h> 15/* Add offset for endbr64 if IBT enabled */ 16# define FTRACE_MCOUNT_MAX_OFFSET ENDBR_INSN_SIZE 17#endif 18 19#ifdef CONFIG_DYNAMIC_FTRACE 20#define ARCH_SUPPORTS_FTRACE_OPS 1 21#endif 22 23#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 24 25#ifndef __ASSEMBLY__ 26extern atomic_t modifying_ftrace_code; 27extern void __fentry__(void); 28 29static inline unsigned long ftrace_call_adjust(unsigned long addr) 30{ 31 /* 32 * addr is the address of the mcount call instruction. 33 * recordmcount does the necessary offset calculation. 34 */ 35 return addr; 36} 37 38/* 39 * When a ftrace registered caller is tracing a function that is 40 * also set by a register_ftrace_direct() call, it needs to be 41 * differentiated in the ftrace_caller trampoline. To do this, we 42 * place the direct caller in the ORIG_AX part of pt_regs. This 43 * tells the ftrace_caller that there's a direct caller. 44 */ 45static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr) 46{ 47 /* Emulate a call */ 48 regs->orig_ax = addr; 49} 50 51#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS 52struct ftrace_regs { 53 struct pt_regs regs; 54}; 55 56static __always_inline struct pt_regs * 57arch_ftrace_get_regs(struct ftrace_regs *fregs) 58{ 59 /* Only when FL_SAVE_REGS is set, cs will be non zero */ 60 if (!fregs->regs.cs) 61 return NULL; 62 return &fregs->regs; 63} 64 65#define ftrace_instruction_pointer_set(fregs, _ip) \ 66 do { (fregs)->regs.ip = (_ip); } while (0) 67 68struct ftrace_ops; 69#define ftrace_graph_func ftrace_graph_func 70void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, 71 struct ftrace_ops *op, struct ftrace_regs *fregs); 72#else 73#define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR 74#endif 75 76#ifdef CONFIG_DYNAMIC_FTRACE 77 78struct dyn_arch_ftrace { 79 /* No extra data needed for x86 */ 80}; 81 82#endif /* CONFIG_DYNAMIC_FTRACE */ 83#endif /* __ASSEMBLY__ */ 84#endif /* CONFIG_FUNCTION_TRACER */ 85 86 87#ifndef __ASSEMBLY__ 88 89#if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE) 90extern void set_ftrace_ops_ro(void); 91#else 92static inline void set_ftrace_ops_ro(void) { } 93#endif 94 95#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME 96static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) 97{ 98 /* 99 * Compare the symbol name with the system call name. Skip the 100 * "__x64_sys", "__ia32_sys", "__do_sys" or simple "sys" prefix. 101 */ 102 return !strcmp(sym + 3, name + 3) || 103 (!strncmp(sym, "__x64_", 6) && !strcmp(sym + 9, name + 3)) || 104 (!strncmp(sym, "__ia32_", 7) && !strcmp(sym + 10, name + 3)) || 105 (!strncmp(sym, "__do_sys", 8) && !strcmp(sym + 8, name + 3)); 106} 107 108#ifndef COMPILE_OFFSETS 109 110#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_IA32_EMULATION) 111#include <linux/compat.h> 112 113/* 114 * Because ia32 syscalls do not map to x86_64 syscall numbers 115 * this screws up the trace output when tracing a ia32 task. 116 * Instead of reporting bogus syscalls, just do not trace them. 117 * 118 * If the user really wants these, then they should use the 119 * raw syscall tracepoints with filtering. 120 */ 121#define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 1 122static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) 123{ 124 return in_32bit_syscall(); 125} 126#endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_IA32_EMULATION */ 127#endif /* !COMPILE_OFFSETS */ 128#endif /* !__ASSEMBLY__ */ 129 130#endif /* _ASM_X86_FTRACE_H */