1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _ASM_S390_FTRACE_H 3#define _ASM_S390_FTRACE_H 4 5#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 6#define ARCH_SUPPORTS_FTRACE_OPS 1 7#define MCOUNT_INSN_SIZE 6 8 9#ifndef __ASSEMBLY__ 10 11#ifdef CONFIG_CC_IS_CLANG 12/* https://llvm.org/pr41424 */ 13#define ftrace_return_address(n) 0UL 14#else 15#define ftrace_return_address(n) __builtin_return_address(n) 16#endif 17 18void ftrace_caller(void); 19 20extern void *ftrace_func; 21 22struct dyn_arch_ftrace { }; 23 24#define MCOUNT_ADDR 0 25#define FTRACE_ADDR ((unsigned long)ftrace_caller) 26 27#define KPROBE_ON_FTRACE_NOP 0 28#define KPROBE_ON_FTRACE_CALL 1 29 30struct module; 31struct dyn_ftrace; 32 33bool ftrace_need_init_nop(void); 34#define ftrace_need_init_nop ftrace_need_init_nop 35 36int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); 37#define ftrace_init_nop ftrace_init_nop 38 39static inline unsigned long ftrace_call_adjust(unsigned long addr) 40{ 41 return addr; 42} 43 44struct ftrace_regs { 45 struct pt_regs regs; 46}; 47 48static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) 49{ 50 struct pt_regs *regs = &fregs->regs; 51 52 if (test_pt_regs_flag(regs, PIF_FTRACE_FULL_REGS)) 53 return regs; 54 return NULL; 55} 56 57#ifdef CONFIG_FUNCTION_GRAPH_TRACER 58struct fgraph_ret_regs { 59 unsigned long gpr2; 60 unsigned long fp; 61}; 62 63static __always_inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs) 64{ 65 return ret_regs->gpr2; 66} 67 68static __always_inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs) 69{ 70 return ret_regs->fp; 71} 72#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ 73 74static __always_inline unsigned long 75ftrace_regs_get_instruction_pointer(const struct ftrace_regs *fregs) 76{ 77 return fregs->regs.psw.addr; 78} 79 80static __always_inline void 81ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, 82 unsigned long ip) 83{ 84 fregs->regs.psw.addr = ip; 85} 86 87#define ftrace_regs_get_argument(fregs, n) \ 88 regs_get_kernel_argument(&(fregs)->regs, n) 89#define ftrace_regs_get_stack_pointer(fregs) \ 90 kernel_stack_pointer(&(fregs)->regs) 91#define ftrace_regs_return_value(fregs) \ 92 regs_return_value(&(fregs)->regs) 93#define ftrace_regs_set_return_value(fregs, ret) \ 94 regs_set_return_value(&(fregs)->regs, ret) 95#define ftrace_override_function_with_return(fregs) \ 96 override_function_with_return(&(fregs)->regs) 97#define ftrace_regs_query_register_offset(name) \ 98 regs_query_register_offset(name) 99 100#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS 101/* 102 * When an ftrace registered caller is tracing a function that is 103 * also set by a register_ftrace_direct() call, it needs to be 104 * differentiated in the ftrace_caller trampoline. To do this, 105 * place the direct caller in the ORIG_GPR2 part of pt_regs. This 106 * tells the ftrace_caller that there's a direct caller. 107 */ 108static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr) 109{ 110 struct pt_regs *regs = &fregs->regs; 111 regs->orig_gpr2 = addr; 112} 113#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ 114 115/* 116 * Even though the system call numbers are identical for s390/s390x a 117 * different system call table is used for compat tasks. This may lead 118 * to e.g. incorrect or missing trace event sysfs files. 119 * Therefore simply do not trace compat system calls at all. 120 * See kernel/trace/trace_syscalls.c. 121 */ 122#define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 123static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) 124{ 125 return is_compat_task(); 126} 127 128#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME 129static inline bool arch_syscall_match_sym_name(const char *sym, 130 const char *name) 131{ 132 /* 133 * Skip __s390_ and __s390x_ prefix - due to compat wrappers 134 * and aliasing some symbols of 64 bit system call functions 135 * may get the __s390_ prefix instead of the __s390x_ prefix. 136 */ 137 return !strcmp(sym + 7, name) || !strcmp(sym + 8, name); 138} 139 140#endif /* __ASSEMBLY__ */ 141 142#ifdef CONFIG_FUNCTION_TRACER 143 144#define FTRACE_NOP_INSN .word 0xc004, 0x0000, 0x0000 /* brcl 0,0 */ 145 146#ifndef CC_USING_HOTPATCH 147 148#define FTRACE_GEN_MCOUNT_RECORD(name) \ 149 .section __mcount_loc, "a", @progbits; \ 150 .quad name; \ 151 .previous; 152 153#else /* !CC_USING_HOTPATCH */ 154 155#define FTRACE_GEN_MCOUNT_RECORD(name) 156 157#endif /* !CC_USING_HOTPATCH */ 158 159#define FTRACE_GEN_NOP_ASM(name) \ 160 FTRACE_GEN_MCOUNT_RECORD(name) \ 161 FTRACE_NOP_INSN 162 163#else /* CONFIG_FUNCTION_TRACER */ 164 165#define FTRACE_GEN_NOP_ASM(name) 166 167#endif /* CONFIG_FUNCTION_TRACER */ 168 169#endif /* _ASM_S390_FTRACE_H */ 170