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