xref: /openbmc/linux/arch/s390/include/asm/ftrace.h (revision bacf743e)
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://bugs.llvm.org/show_bug.cgi?id=41424 */
13 #define ftrace_return_address(n) 0UL
14 #else
15 #define ftrace_return_address(n) __builtin_return_address(n)
16 #endif
17 
18 void ftrace_caller(void);
19 
20 extern void *ftrace_func;
21 
22 struct 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 
30 struct module;
31 struct dyn_ftrace;
32 
33 bool ftrace_need_init_nop(void);
34 #define ftrace_need_init_nop ftrace_need_init_nop
35 
36 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
37 #define ftrace_init_nop ftrace_init_nop
38 
39 static inline unsigned long ftrace_call_adjust(unsigned long addr)
40 {
41 	return addr;
42 }
43 
44 struct ftrace_regs {
45 	struct pt_regs regs;
46 };
47 
48 static __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 static __always_inline void ftrace_instruction_pointer_set(struct ftrace_regs *fregs,
58 							   unsigned long ip)
59 {
60 	fregs->regs.psw.addr = ip;
61 }
62 
63 /*
64  * When an ftrace registered caller is tracing a function that is
65  * also set by a register_ftrace_direct() call, it needs to be
66  * differentiated in the ftrace_caller trampoline. To do this,
67  * place the direct caller in the ORIG_GPR2 part of pt_regs. This
68  * tells the ftrace_caller that there's a direct caller.
69  */
70 static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
71 {
72 	regs->orig_gpr2 = addr;
73 }
74 
75 /*
76  * Even though the system call numbers are identical for s390/s390x a
77  * different system call table is used for compat tasks. This may lead
78  * to e.g. incorrect or missing trace event sysfs files.
79  * Therefore simply do not trace compat system calls at all.
80  * See kernel/trace/trace_syscalls.c.
81  */
82 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
83 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
84 {
85 	return is_compat_task();
86 }
87 
88 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
89 static inline bool arch_syscall_match_sym_name(const char *sym,
90 					       const char *name)
91 {
92 	/*
93 	 * Skip __s390_ and __s390x_ prefix - due to compat wrappers
94 	 * and aliasing some symbols of 64 bit system call functions
95 	 * may get the __s390_ prefix instead of the __s390x_ prefix.
96 	 */
97 	return !strcmp(sym + 7, name) || !strcmp(sym + 8, name);
98 }
99 
100 #endif /* __ASSEMBLY__ */
101 
102 #ifdef CONFIG_FUNCTION_TRACER
103 
104 #define FTRACE_NOP_INSN .word 0xc004, 0x0000, 0x0000 /* brcl 0,0 */
105 
106 #ifndef CC_USING_HOTPATCH
107 
108 #define FTRACE_GEN_MCOUNT_RECORD(name)		\
109 	.section __mcount_loc, "a", @progbits;	\
110 	.quad name;				\
111 	.previous;
112 
113 #else /* !CC_USING_HOTPATCH */
114 
115 #define FTRACE_GEN_MCOUNT_RECORD(name)
116 
117 #endif /* !CC_USING_HOTPATCH */
118 
119 #define FTRACE_GEN_NOP_ASM(name)		\
120 	FTRACE_GEN_MCOUNT_RECORD(name)		\
121 	FTRACE_NOP_INSN
122 
123 #else /* CONFIG_FUNCTION_TRACER */
124 
125 #define FTRACE_GEN_NOP_ASM(name)
126 
127 #endif /* CONFIG_FUNCTION_TRACER */
128 
129 #endif /* _ASM_S390_FTRACE_H */
130