xref: /linux/arch/s390/include/asm/ftrace.h (revision 2697b79a469b68e3ad3640f55284359c1396278d)
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 unsigned long return_address(unsigned int n);
12 #define ftrace_return_address(n) return_address(n)
13 
14 void ftrace_caller(void);
15 
16 extern void *ftrace_func;
17 
18 struct dyn_arch_ftrace { };
19 
20 #define MCOUNT_ADDR 0
21 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
22 
23 #define KPROBE_ON_FTRACE_NOP	0
24 #define KPROBE_ON_FTRACE_CALL	1
25 
26 struct module;
27 struct dyn_ftrace;
28 
29 bool ftrace_need_init_nop(void);
30 #define ftrace_need_init_nop ftrace_need_init_nop
31 
32 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
33 #define ftrace_init_nop ftrace_init_nop
34 
35 static inline unsigned long ftrace_call_adjust(unsigned long addr)
36 {
37 	return addr;
38 }
39 
40 struct ftrace_regs {
41 	struct pt_regs regs;
42 };
43 
44 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
45 {
46 	struct pt_regs *regs = &fregs->regs;
47 
48 	if (test_pt_regs_flag(regs, PIF_FTRACE_FULL_REGS))
49 		return regs;
50 	return NULL;
51 }
52 
53 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
54 struct fgraph_ret_regs {
55 	unsigned long gpr2;
56 	unsigned long fp;
57 };
58 
59 static __always_inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
60 {
61 	return ret_regs->gpr2;
62 }
63 
64 static __always_inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
65 {
66 	return ret_regs->fp;
67 }
68 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
69 
70 static __always_inline unsigned long
71 ftrace_regs_get_instruction_pointer(const struct ftrace_regs *fregs)
72 {
73 	return fregs->regs.psw.addr;
74 }
75 
76 static __always_inline void
77 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
78 				    unsigned long ip)
79 {
80 	fregs->regs.psw.addr = ip;
81 }
82 
83 #define ftrace_regs_get_argument(fregs, n) \
84 	regs_get_kernel_argument(&(fregs)->regs, n)
85 #define ftrace_regs_get_stack_pointer(fregs) \
86 	kernel_stack_pointer(&(fregs)->regs)
87 #define ftrace_regs_return_value(fregs) \
88 	regs_return_value(&(fregs)->regs)
89 #define ftrace_regs_set_return_value(fregs, ret) \
90 	regs_set_return_value(&(fregs)->regs, ret)
91 #define ftrace_override_function_with_return(fregs) \
92 	override_function_with_return(&(fregs)->regs)
93 #define ftrace_regs_query_register_offset(name) \
94 	regs_query_register_offset(name)
95 
96 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
97 /*
98  * When an ftrace registered caller is tracing a function that is
99  * also set by a register_ftrace_direct() call, it needs to be
100  * differentiated in the ftrace_caller trampoline. To do this,
101  * place the direct caller in the ORIG_GPR2 part of pt_regs. This
102  * tells the ftrace_caller that there's a direct caller.
103  */
104 static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr)
105 {
106 	struct pt_regs *regs = &fregs->regs;
107 	regs->orig_gpr2 = addr;
108 }
109 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
110 
111 /*
112  * Even though the system call numbers are identical for s390/s390x a
113  * different system call table is used for compat tasks. This may lead
114  * to e.g. incorrect or missing trace event sysfs files.
115  * Therefore simply do not trace compat system calls at all.
116  * See kernel/trace/trace_syscalls.c.
117  */
118 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
119 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
120 {
121 	return is_compat_task();
122 }
123 
124 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
125 static inline bool arch_syscall_match_sym_name(const char *sym,
126 					       const char *name)
127 {
128 	/*
129 	 * Skip __s390_ and __s390x_ prefix - due to compat wrappers
130 	 * and aliasing some symbols of 64 bit system call functions
131 	 * may get the __s390_ prefix instead of the __s390x_ prefix.
132 	 */
133 	return !strcmp(sym + 7, name) || !strcmp(sym + 8, name);
134 }
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