1
2
3
4
5
6
7
8
9
10#include <linux/hardirq.h>
11#include <linux/uaccess.h>
12#include <linux/ftrace.h>
13#include <linux/kernel.h>
14#include <linux/types.h>
15#include <linux/kprobes.h>
16#include <trace/syscall.h>
17#include <asm/asm-offsets.h>
18
19#ifdef CONFIG_64BIT
20#define MCOUNT_OFFSET_RET 12
21#else
22#define MCOUNT_OFFSET_RET 22
23#endif
24
25#ifdef CONFIG_DYNAMIC_FTRACE
26
27void ftrace_disable_code(void);
28void ftrace_enable_insn(void);
29
30#ifdef CONFIG_64BIT
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55asm(
56 " .align 4\n"
57 "ftrace_disable_code:\n"
58 " jg 0f\n"
59 " lgr %r0,%r0\n"
60 " basr %r14,%r1\n"
61 "0:\n"
62 " .align 4\n"
63 "ftrace_enable_insn:\n"
64 " lg %r1,"__stringify(__LC_FTRACE_FUNC)"\n");
65
66#define FTRACE_INSN_SIZE 6
67
68#else
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99asm(
100 " .align 4\n"
101 "ftrace_disable_code:\n"
102 " j 1f\n"
103 " j 0f\n"
104 " .fill 12,1,0x07\n"
105 "0: basr %r14,%r14\n"
106 "1:\n"
107 " .align 4\n"
108 "ftrace_enable_insn:\n"
109 " l %r14,"__stringify(__LC_FTRACE_FUNC)"\n");
110
111#define FTRACE_INSN_SIZE 4
112
113#endif
114
115
116int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
117 unsigned long addr)
118{
119 if (probe_kernel_write((void *) rec->ip, ftrace_disable_code,
120 MCOUNT_INSN_SIZE))
121 return -EPERM;
122 return 0;
123}
124
125int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
126{
127 if (probe_kernel_write((void *) rec->ip, ftrace_enable_insn,
128 FTRACE_INSN_SIZE))
129 return -EPERM;
130 return 0;
131}
132
133int ftrace_update_ftrace_func(ftrace_func_t func)
134{
135 return 0;
136}
137
138int __init ftrace_dyn_arch_init(void *data)
139{
140 *(unsigned long *) data = 0;
141 return 0;
142}
143
144#endif
145
146#ifdef CONFIG_FUNCTION_GRAPH_TRACER
147
148
149
150
151unsigned long __kprobes prepare_ftrace_return(unsigned long parent,
152 unsigned long ip)
153{
154 struct ftrace_graph_ent trace;
155
156 if (unlikely(atomic_read(¤t->tracing_graph_pause)))
157 goto out;
158 if (ftrace_push_return_trace(parent, ip, &trace.depth, 0) == -EBUSY)
159 goto out;
160 trace.func = (ip & PSW_ADDR_INSN) - MCOUNT_OFFSET_RET;
161
162 if (!ftrace_graph_entry(&trace)) {
163 current->curr_ret_stack--;
164 goto out;
165 }
166 parent = (unsigned long) return_to_handler;
167out:
168 return parent;
169}
170
171#ifdef CONFIG_DYNAMIC_FTRACE
172
173
174
175
176
177
178
179int ftrace_enable_ftrace_graph_caller(void)
180{
181 unsigned short offset;
182
183 offset = ((void *) prepare_ftrace_return -
184 (void *) ftrace_graph_caller) / 2;
185 return probe_kernel_write(ftrace_graph_caller + 2,
186 &offset, sizeof(offset));
187}
188
189int ftrace_disable_ftrace_graph_caller(void)
190{
191 static unsigned short offset = 0x0002;
192
193 return probe_kernel_write(ftrace_graph_caller + 2,
194 &offset, sizeof(offset));
195}
196
197#endif
198#endif
199