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