Blame view

include/linux/ftrace.h 33.6 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
9849ed4d7   Mike Frysinger   tracing/documenta...
2
3
  /*
   * Ftrace header.  For implementation details beyond the random comments
5fb94e9ca   Mauro Carvalho Chehab   docs: Fix some br...
4
   * scattered below, see: Documentation/trace/ftrace-design.rst
9849ed4d7   Mike Frysinger   tracing/documenta...
5
   */
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
6
7
  #ifndef _LINUX_FTRACE_H
  #define _LINUX_FTRACE_H
0012693ad   Frederic Weisbecker   tracing/function-...
8
  #include <linux/trace_clock.h>
5601020fe   Frederic Weisbecker   tracing/fastboot:...
9
  #include <linux/kallsyms.h>
0012693ad   Frederic Weisbecker   tracing/function-...
10
  #include <linux/linkage.h>
ea4e2bc4d   Steven Rostedt   ftrace: graph of ...
11
  #include <linux/bitops.h>
a1e2e31d1   Steven Rostedt   ftrace: Return pt...
12
  #include <linux/ptrace.h>
0012693ad   Frederic Weisbecker   tracing/function-...
13
  #include <linux/ktime.h>
21a8c466f   Frederic Weisbecker   tracing/ftrace: p...
14
  #include <linux/sched.h>
0012693ad   Frederic Weisbecker   tracing/function-...
15
16
17
  #include <linux/types.h>
  #include <linux/init.h>
  #include <linux/fs.h>
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
18

c79a61f55   Uwe Kleine-Koenig   tracing: make CAL...
19
  #include <asm/ftrace.h>
2f5f6ad93   Steven Rostedt   ftrace: Pass ftra...
20
21
22
23
24
25
26
27
  /*
   * If the arch supports passing the variable contents of
   * function_trace_op as the third parameter back from the
   * mcount call, then the arch should define this as 1.
   */
  #ifndef ARCH_SUPPORTS_FTRACE_OPS
  #define ARCH_SUPPORTS_FTRACE_OPS 0
  #endif
ccf3672d5   Steven Rostedt   ftrace: Consolida...
28
29
30
31
32
  /*
   * If the arch's mcount caller does not support all of ftrace's
   * features, then it must call an indirect function that
   * does. Or at least does enough to prevent any unwelcomed side effects.
   */
7544256aa   Steven Rostedt (Red Hat)   ftrace: Remove ch...
33
  #if !ARCH_SUPPORTS_FTRACE_OPS
ccf3672d5   Steven Rostedt   ftrace: Consolida...
34
35
36
37
  # define FTRACE_FORCE_LIST_FUNC 1
  #else
  # define FTRACE_FORCE_LIST_FUNC 0
  #endif
5f893b263   Steven Rostedt (Red Hat)   tracing: Move ena...
38
39
40
  /* Main tracing buffer and events set up */
  #ifdef CONFIG_TRACING
  void trace_init(void);
e725c731e   Steven Rostedt (VMware)   tracing: Split tr...
41
  void early_trace_init(void);
5f893b263   Steven Rostedt (Red Hat)   tracing: Move ena...
42
43
  #else
  static inline void trace_init(void) { }
e725c731e   Steven Rostedt (VMware)   tracing: Split tr...
44
  static inline void early_trace_init(void) { }
5f893b263   Steven Rostedt (Red Hat)   tracing: Move ena...
45
  #endif
ccf3672d5   Steven Rostedt   ftrace: Consolida...
46

de4772542   Paul Gortmaker   include: replace ...
47
  struct module;
04da85b86   Steven Rostedt   ftrace: Fix warni...
48
  struct ftrace_hash;
013bf0da0   Steven Rostedt (VMware)   ftrace: Add ftrac...
49
  struct ftrace_direct_func;
04da85b86   Steven Rostedt   ftrace: Fix warni...
50

aba4b5c22   Steven Rostedt (VMware)   ftrace: Save modu...
51
52
53
54
55
56
57
58
59
60
61
62
  #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_MODULES) && \
  	defined(CONFIG_DYNAMIC_FTRACE)
  const char *
  ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
  		   unsigned long *off, char **modname, char *sym);
  #else
  static inline const char *
  ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
  		   unsigned long *off, char **modname, char *sym)
  {
  	return NULL;
  }
fc0ea795f   Adrian Hunter   ftrace: Add symbo...
63
64
65
66
67
68
69
  #endif
  
  #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
  			   char *type, char *name,
  			   char *module_name, int *exported);
  #else
6171a0310   Steven Rostedt (VMware)   ftrace/kallsyms: ...
70
71
72
73
74
75
  static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
  					 char *type, char *name,
  					 char *module_name, int *exported)
  {
  	return -1;
  }
aba4b5c22   Steven Rostedt (VMware)   ftrace: Save modu...
76
  #endif
606576ce8   Steven Rostedt   ftrace: rename FT...
77
  #ifdef CONFIG_FUNCTION_TRACER
3e1932ad5   Ingo Molnar   tracing/fastboot:...
78

b0fc494fa   Steven Rostedt   ftrace: add ftrac...
79
80
81
  extern int ftrace_enabled;
  extern int
  ftrace_enable_sysctl(struct ctl_table *table, int write,
54fa9ba56   Tobias Klauser   ftrace: Let ftrac...
82
  		     void *buffer, size_t *lenp, loff_t *ppos);
b0fc494fa   Steven Rostedt   ftrace: add ftrac...
83

2f5f6ad93   Steven Rostedt   ftrace: Pass ftra...
84
85
86
  struct ftrace_ops;
  
  typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
a1e2e31d1   Steven Rostedt   ftrace: Return pt...
87
  			      struct ftrace_ops *op, struct pt_regs *regs);
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
88

873540598   Steven Rostedt (Red Hat)   ftrace: Add helpe...
89
  ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
e248491ac   Jiri Olsa   ftrace: Add enabl...
90
91
92
  /*
   * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
   * set in the flags member.
f8b8be8a3   Masami Hiramatsu   ftrace, kprobes: ...
93
94
95
   * CONTROL, SAVE_REGS, SAVE_REGS_IF_SUPPORTED, RECURSION_SAFE, STUB and
   * IPMODIFY are a kind of attribute flags which can be set only before
   * registering the ftrace_ops, and can not be modified while registered.
ad61dd303   Stephen Boyd   scripts/spelling....
96
   * Changing those attribute flags after registering ftrace_ops will
f8b8be8a3   Masami Hiramatsu   ftrace, kprobes: ...
97
   * cause unexpected results.
e248491ac   Jiri Olsa   ftrace: Add enabl...
98
99
   *
   * ENABLED - set/unset when ftrace_ops is registered/unregistered
e248491ac   Jiri Olsa   ftrace: Add enabl...
100
101
   * DYNAMIC - set when ftrace_ops is registered to denote dynamically
   *           allocated ftrace_ops which need special care
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
102
103
104
   * SAVE_REGS - The ftrace_ops wants regs saved at each function called
   *            and passed to the callback. If this flag is set, but the
   *            architecture does not support passing regs
06aeaaeab   Masami Hiramatsu   ftrace: Move ARCH...
105
   *            (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
106
107
108
109
110
111
112
113
114
115
   *            ftrace_ops will fail to register, unless the next flag
   *            is set.
   * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
   *            handler can handle an arch that does not save regs
   *            (the handler tests if regs == NULL), then it can set
   *            this flag instead. It will not fail registering the ftrace_ops
   *            but, the regs field will be NULL if the arch does not support
   *            passing regs to the handler.
   *            Note, if this flag is set, the SAVE_REGS flag will automatically
   *            get set upon registering the ftrace_ops, if the arch supports it.
4740974a6   Steven Rostedt   ftrace: Add defau...
116
117
118
119
   * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
   *            that the call back has its own recursion protection. If it does
   *            not set this, then the ftrace infrastructure will add recursion
   *            protection for the caller.
395b97a3a   Steven Rostedt (Red Hat)   ftrace: Do not ca...
120
   * STUB   - The ftrace_ops is just a place holder.
f04f24fb7   Masami Hiramatsu   ftrace, kprobes: ...
121
122
   * INITIALIZED - The ftrace_ops has already been initialized (first use time
   *            register_ftrace_function() is called, it will initialized the ops)
591dffdad   Steven Rostedt (Red Hat)   ftrace: Allow for...
123
   * DELETED - The ops are being deleted, do not let them be registered again.
e1effa014   Steven Rostedt (Red Hat)   ftrace: Annotate ...
124
125
126
   * ADDING  - The ops is in the process of being added.
   * REMOVING - The ops is in the process of being removed.
   * MODIFYING - The ops is in the process of changing its filter functions.
f3bea4911   Steven Rostedt (Red Hat)   ftrace/x86: Add d...
127
128
129
130
131
132
133
   * ALLOC_TRAMP - A dynamic trampoline was allocated by the core code.
   *            The arch specific code sets this flag when it allocated a
   *            trampoline. This lets the arch know that it can update the
   *            trampoline in case the callback function changes.
   *            The ftrace_ops trampoline can be set by the ftrace users, and
   *            in such cases the arch must not modify it. Only the arch ftrace
   *            core code should set this flag.
f8b8be8a3   Masami Hiramatsu   ftrace, kprobes: ...
134
135
136
137
   * IPMODIFY - The ops can modify the IP register. This can only be set with
   *            SAVE_REGS. If another ops with this flag set is already registered
   *            for any of the functions that this ops will be registered for, then
   *            this ops will fail to register or set_filter_ip.
e3eea1404   Steven Rostedt (Red Hat)   ftrace: Fix break...
138
   * PID     - Is affected by set_ftrace_pid (allows filtering on those pids)
d0ba52f1d   Steven Rostedt (VMware)   ftrace: Add missi...
139
   * RCU     - Set when the ops can only be called when RCU is watching.
8c08f0d5c   Steven Rostedt (VMware)   ftrace: Have cach...
140
   * TRACE_ARRAY - The ops->private points to a trace_array descriptor.
7162431dc   Miroslav Benes   ftrace: Introduce...
141
142
   * PERMANENT - Set when the ops is permanent and should not be affected by
   *             ftrace_enabled.
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
143
144
   * DIRECT - Used by the direct ftrace_ops helper for direct functions
   *            (internal ftrace only, should not be used by others)
e248491ac   Jiri Olsa   ftrace: Add enabl...
145
   */
b848914ce   Steven Rostedt   ftrace: Implement...
146
  enum {
b41db1328   Enrico Weigelt, metux IT consult   ftrace: Use BIT()...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  	FTRACE_OPS_FL_ENABLED			= BIT(0),
  	FTRACE_OPS_FL_DYNAMIC			= BIT(1),
  	FTRACE_OPS_FL_SAVE_REGS			= BIT(2),
  	FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED	= BIT(3),
  	FTRACE_OPS_FL_RECURSION_SAFE		= BIT(4),
  	FTRACE_OPS_FL_STUB			= BIT(5),
  	FTRACE_OPS_FL_INITIALIZED		= BIT(6),
  	FTRACE_OPS_FL_DELETED			= BIT(7),
  	FTRACE_OPS_FL_ADDING			= BIT(8),
  	FTRACE_OPS_FL_REMOVING			= BIT(9),
  	FTRACE_OPS_FL_MODIFYING			= BIT(10),
  	FTRACE_OPS_FL_ALLOC_TRAMP		= BIT(11),
  	FTRACE_OPS_FL_IPMODIFY			= BIT(12),
  	FTRACE_OPS_FL_PID			= BIT(13),
  	FTRACE_OPS_FL_RCU			= BIT(14),
  	FTRACE_OPS_FL_TRACE_ARRAY		= BIT(15),
  	FTRACE_OPS_FL_PERMANENT                 = BIT(16),
  	FTRACE_OPS_FL_DIRECT			= BIT(17),
b848914ce   Steven Rostedt   ftrace: Implement...
165
  };
33b7f99cf   Steven Rostedt (Red Hat)   ftrace: Allow ftr...
166
167
168
  #ifdef CONFIG_DYNAMIC_FTRACE
  /* The hash used to know what functions callbacks trace */
  struct ftrace_ops_hash {
f86f41805   Chunyan Zhang   trace: fix the er...
169
170
  	struct ftrace_hash __rcu	*notrace_hash;
  	struct ftrace_hash __rcu	*filter_hash;
33b7f99cf   Steven Rostedt (Red Hat)   ftrace: Allow ftr...
171
172
  	struct mutex			regex_lock;
  };
42c269c88   Steven Rostedt (VMware)   ftrace: Allow for...
173

b80f0f6c9   Steven Rostedt (VMware)   ftrace: Have init...
174
  void ftrace_free_init_mem(void);
aba4b5c22   Steven Rostedt (VMware)   ftrace: Save modu...
175
  void ftrace_free_mem(struct module *mod, void *start, void *end);
42c269c88   Steven Rostedt (VMware)   ftrace: Allow for...
176
  #else
b80f0f6c9   Steven Rostedt (VMware)   ftrace: Have init...
177
  static inline void ftrace_free_init_mem(void) { }
aba4b5c22   Steven Rostedt (VMware)   ftrace: Save modu...
178
  static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
33b7f99cf   Steven Rostedt (Red Hat)   ftrace: Allow ftr...
179
  #endif
b7e00a6c5   Steven Rostedt (Red Hat)   ftrace: Add priva...
180
  /*
ba27f2bc7   Steven Rostedt (Red Hat)   ftrace: Remove us...
181
182
183
184
185
   * Note, ftrace_ops can be referenced outside of RCU protection, unless
   * the RCU flag is set. If ftrace_ops is allocated and not part of kernel
   * core data, the unregistering of it will perform a scheduling on all CPUs
   * to make sure that there are no more users. Depending on the load of the
   * system that may take a bit of time.
b7e00a6c5   Steven Rostedt (Red Hat)   ftrace: Add priva...
186
187
188
189
190
   *
   * Any private data added must also take care not to be freed and if private
   * data is added to a ftrace_ops that is in core code, the user of the
   * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
   */
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
191
  struct ftrace_ops {
f45948e89   Steven Rostedt   ftrace: Create a ...
192
  	ftrace_func_t			func;
f86f41805   Chunyan Zhang   trace: fix the er...
193
  	struct ftrace_ops __rcu		*next;
b848914ce   Steven Rostedt   ftrace: Implement...
194
  	unsigned long			flags;
b7e00a6c5   Steven Rostedt (Red Hat)   ftrace: Add priva...
195
  	void				*private;
e3eea1404   Steven Rostedt (Red Hat)   ftrace: Fix break...
196
  	ftrace_func_t			saved_func;
f45948e89   Steven Rostedt   ftrace: Create a ...
197
  #ifdef CONFIG_DYNAMIC_FTRACE
33b7f99cf   Steven Rostedt (Red Hat)   ftrace: Allow ftr...
198
199
  	struct ftrace_ops_hash		local_hash;
  	struct ftrace_ops_hash		*func_hash;
fef5aeeee   Steven Rostedt (Red Hat)   ftrace: Replace t...
200
  	struct ftrace_ops_hash		old_hash;
79922b800   Steven Rostedt (Red Hat)   ftrace: Optimize ...
201
  	unsigned long			trampoline;
aec0be2d6   Steven Rostedt (Red Hat)   ftrace/x86/extabl...
202
  	unsigned long			trampoline_size;
fc0ea795f   Adrian Hunter   ftrace: Add symbo...
203
  	struct list_head		list;
f45948e89   Steven Rostedt   ftrace: Create a ...
204
  #endif
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
205
  };
59566b0b6   Steven Rostedt (VMware)   x86/ftrace: Have ...
206
207
208
209
  extern struct ftrace_ops __rcu *ftrace_ops_list;
  extern struct ftrace_ops ftrace_list_end;
  
  /*
40dc4a42b   Wei Yang   ftrace: ftrace_gl...
210
   * Traverse the ftrace_ops_list, invoking all entries.  The reason that we
59566b0b6   Steven Rostedt (VMware)   x86/ftrace: Have ...
211
212
213
   * can use rcu_dereference_raw_check() is that elements removed from this list
   * are simply leaked, so there is no need to interact with a grace-period
   * mechanism.  The rcu_dereference_raw_check() calls are needed to handle
40dc4a42b   Wei Yang   ftrace: ftrace_gl...
214
   * concurrent insertions into the ftrace_ops_list.
59566b0b6   Steven Rostedt (VMware)   x86/ftrace: Have ...
215
216
217
218
219
220
221
222
223
224
225
226
227
   *
   * Silly Alpha and silly pointer-speculation compiler optimizations!
   */
  #define do_for_each_ftrace_op(op, list)			\
  	op = rcu_dereference_raw_check(list);			\
  	do
  
  /*
   * Optimized for just a single item in the list (as that is the normal case).
   */
  #define while_for_each_ftrace_op(op)				\
  	while (likely(op = rcu_dereference_raw_check((op)->next)) &&	\
  	       unlikely((op) != &ftrace_list_end))
e7d3737ea   Frederic Weisbecker   tracing/function-...
228
229
230
231
232
233
234
235
236
237
  /*
   * Type of the current tracing.
   */
  enum ftrace_tracing_type_t {
  	FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  	FTRACE_TYPE_RETURN,	/* Hook the return of the function */
  };
  
  /* Current tracing type, default is FTRACE_TYPE_ENTER */
  extern enum ftrace_tracing_type_t ftrace_tracing_type;
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
238
239
240
241
242
243
244
245
246
  /*
   * The ftrace_ops must be a static and should also
   * be read_mostly.  These functions do modify read_mostly variables
   * so use them sparely. Never free an ftrace_op or modify the
   * next pointer after it has been registered. Even after unregistering
   * it, the next pointer may still be used internally.
   */
  int register_ftrace_function(struct ftrace_ops *ops);
  int unregister_ftrace_function(struct ftrace_ops *ops);
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
247

a1e2e31d1   Steven Rostedt   ftrace: Return pt...
248
249
  extern void ftrace_stub(unsigned long a0, unsigned long a1,
  			struct ftrace_ops *op, struct pt_regs *regs);
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
250

606576ce8   Steven Rostedt   ftrace: rename FT...
251
  #else /* !CONFIG_FUNCTION_TRACER */
4dbf6bc23   Steven Rostedt   tracing: Convert ...
252
253
254
255
256
257
  /*
   * (un)register_ftrace_function must be a macro since the ops parameter
   * must not be evaluated.
   */
  #define register_ftrace_function(ops) ({ 0; })
  #define unregister_ftrace_function(ops) ({ 0; })
81adbdc02   Steven Rostedt   ftrace: only have...
258
  static inline void ftrace_kill(void) { }
b80f0f6c9   Steven Rostedt (VMware)   ftrace: Have init...
259
  static inline void ftrace_free_init_mem(void) { }
aba4b5c22   Steven Rostedt (VMware)   ftrace: Save modu...
260
  static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
606576ce8   Steven Rostedt   ftrace: rename FT...
261
  #endif /* CONFIG_FUNCTION_TRACER */
352ad25aa   Steven Rostedt   ftrace: tracer fo...
262

ea806eb3e   Steven Rostedt (VMware)   ftrace: Add a hel...
263
264
265
266
267
268
269
  struct ftrace_func_entry {
  	struct hlist_node hlist;
  	unsigned long ip;
  	unsigned long direct; /* for direct lookup only */
  };
  
  struct dyn_ftrace;
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
270
  #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
a3ad1a7e3   Steven Rostedt (VMware)   ftrace/x86: Add a...
271
  extern int ftrace_direct_func_count;
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
272
273
  int register_ftrace_direct(unsigned long ip, unsigned long addr);
  int unregister_ftrace_direct(unsigned long ip, unsigned long addr);
0567d6809   Steven Rostedt (VMware)   ftrace: Add modif...
274
  int modify_ftrace_direct(unsigned long ip, unsigned long old_addr, unsigned long new_addr);
013bf0da0   Steven Rostedt (VMware)   ftrace: Add ftrac...
275
  struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr);
ea806eb3e   Steven Rostedt (VMware)   ftrace: Add a hel...
276
277
278
279
  int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
  				struct dyn_ftrace *rec,
  				unsigned long old_addr,
  				unsigned long new_addr);
ff205766d   Alexei Starovoitov   ftrace: Fix funct...
280
  unsigned long ftrace_find_rec_direct(unsigned long ip);
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
281
  #else
a3ad1a7e3   Steven Rostedt (VMware)   ftrace/x86: Add a...
282
  # define ftrace_direct_func_count 0
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
283
284
  static inline int register_ftrace_direct(unsigned long ip, unsigned long addr)
  {
eb01fedc3   Alexei Starovoitov   ftrace: Return EN...
285
  	return -ENOTSUPP;
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
286
287
288
  }
  static inline int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
  {
eb01fedc3   Alexei Starovoitov   ftrace: Return EN...
289
  	return -ENOTSUPP;
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
290
  }
0567d6809   Steven Rostedt (VMware)   ftrace: Add modif...
291
292
293
  static inline int modify_ftrace_direct(unsigned long ip,
  				       unsigned long old_addr, unsigned long new_addr)
  {
eb01fedc3   Alexei Starovoitov   ftrace: Return EN...
294
  	return -ENOTSUPP;
0567d6809   Steven Rostedt (VMware)   ftrace: Add modif...
295
  }
013bf0da0   Steven Rostedt (VMware)   ftrace: Add ftrac...
296
297
298
299
  static inline struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr)
  {
  	return NULL;
  }
ea806eb3e   Steven Rostedt (VMware)   ftrace: Add a hel...
300
301
302
303
304
305
306
  static inline int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
  					      struct dyn_ftrace *rec,
  					      unsigned long old_addr,
  					      unsigned long new_addr)
  {
  	return -ENODEV;
  }
ff205766d   Alexei Starovoitov   ftrace: Fix funct...
307
308
309
310
  static inline unsigned long ftrace_find_rec_direct(unsigned long ip)
  {
  	return 0;
  }
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
311
312
313
314
315
316
317
318
319
  #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
  
  #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  /*
   * This must be implemented by the architecture.
   * It is the way the ftrace direct_ops helper, when called
   * via ftrace (because there's other callbacks besides the
   * direct call), can inform the architecture's trampoline that this
   * routine has a direct caller, and what the caller is.
562955fe6   Steven Rostedt (VMware)   ftrace/x86: Add r...
320
321
322
323
324
325
   *
   * For example, in x86, it returns the direct caller
   * callback function via the regs->orig_ax parameter.
   * Then in the ftrace trampoline, if this is set, it makes
   * the return from the trampoline jump to the direct caller
   * instead of going back to the function it just traced.
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
326
327
328
329
   */
  static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs,
  						 unsigned long addr) { }
  #endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
f38f1d2aa   Steven Rostedt   trace: add a way ...
330
  #ifdef CONFIG_STACK_TRACER
bb99d8cce   AKASHI Takahiro   tracing: Allow ar...
331

f38f1d2aa   Steven Rostedt   trace: add a way ...
332
  extern int stack_tracer_enabled;
3d9a80729   Thomas Gleixner   tracing: Cleanup ...
333

7ff0d4490   Christoph Hellwig   trace: fix an inc...
334
335
  int stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
  		       size_t *lenp, loff_t *ppos);
5367278cb   Steven Rostedt (VMware)   tracing: Add stac...
336

8aaf1ee70   Steven Rostedt (VMware)   tracing: Rename t...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  /* DO NOT MODIFY THIS VARIABLE DIRECTLY! */
  DECLARE_PER_CPU(int, disable_stack_tracer);
  
  /**
   * stack_tracer_disable - temporarily disable the stack tracer
   *
   * There's a few locations (namely in RCU) where stack tracing
   * cannot be executed. This function is used to disable stack
   * tracing during those critical sections.
   *
   * This function must be called with preemption or interrupts
   * disabled and stack_tracer_enable() must be called shortly after
   * while preemption or interrupts are still disabled.
   */
  static inline void stack_tracer_disable(void)
  {
  	/* Preemption or interupts must be disabled */
60361e12d   Zev Weiss   ftrace: Fix debug...
354
  	if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
8aaf1ee70   Steven Rostedt (VMware)   tracing: Rename t...
355
356
357
358
359
360
361
362
363
364
365
366
  		WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
  	this_cpu_inc(disable_stack_tracer);
  }
  
  /**
   * stack_tracer_enable - re-enable the stack tracer
   *
   * After stack_tracer_disable() is called, stack_tracer_enable()
   * must be called shortly afterward.
   */
  static inline void stack_tracer_enable(void)
  {
60361e12d   Zev Weiss   ftrace: Fix debug...
367
  	if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
8aaf1ee70   Steven Rostedt (VMware)   tracing: Rename t...
368
369
370
  		WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
  	this_cpu_dec(disable_stack_tracer);
  }
5367278cb   Steven Rostedt (VMware)   tracing: Add stac...
371
372
373
  #else
  static inline void stack_tracer_disable(void) { }
  static inline void stack_tracer_enable(void) { }
f38f1d2aa   Steven Rostedt   trace: add a way ...
374
  #endif
3d0833953   Steven Rostedt   ftrace: dynamic e...
375
  #ifdef CONFIG_DYNAMIC_FTRACE
31e889098   Steven Rostedt   ftrace: pass modu...
376

000ab6911   Steven Rostedt   ftrace: allow arc...
377
378
  int ftrace_arch_code_modify_prepare(void);
  int ftrace_arch_code_modify_post_process(void);
02a392a04   Steven Rostedt (Red Hat)   ftrace: Add new t...
379
380
381
382
383
384
385
386
  enum ftrace_bug_type {
  	FTRACE_BUG_UNKNOWN,
  	FTRACE_BUG_INIT,
  	FTRACE_BUG_NOP,
  	FTRACE_BUG_CALL,
  	FTRACE_BUG_UPDATE,
  };
  extern enum ftrace_bug_type ftrace_bug_type;
b05086c77   Steven Rostedt (Red Hat)   ftrace: Add varia...
387
388
389
390
391
  /*
   * Archs can set this to point to a variable that holds the value that was
   * expected at the call site before calling ftrace_bug().
   */
  extern const void *ftrace_expected;
4fd3279b4   Steven Rostedt (Red Hat)   ftrace: Add more ...
392
  void ftrace_bug(int err, struct dyn_ftrace *rec);
c88fd8634   Steven Rostedt   ftrace: Allow arc...
393

809dcf29c   Steven Rostedt   ftrace: add prett...
394
  struct seq_file;
d88471cb8   Sasha Levin   ftrace: Constify ...
395
  extern int ftrace_text_reserved(const void *start, const void *end);
2cfa19780   Masami Hiramatsu   ftrace/alternativ...
396

6be7fa3c7   Steven Rostedt (VMware)   ftrace, orc, x86:...
397
  struct ftrace_ops *ftrace_ops_trampoline(unsigned long addr);
aec0be2d6   Steven Rostedt (Red Hat)   ftrace/x86/extabl...
398
  bool is_ftrace_trampoline(unsigned long addr);
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
399
400
401
402
403
404
405
406
407
408
  /*
   * The dyn_ftrace record's flags field is split into two parts.
   * the first part which is '0-FTRACE_REF_MAX' is a counter of
   * the number of callbacks that have registered the function that
   * the dyn_ftrace descriptor represents.
   *
   * The second part is a mask:
   *  ENABLED - the function is being traced
   *  REGS    - the record wants the function to save regs
   *  REGS_EN - the function is set up to save regs.
f8b8be8a3   Masami Hiramatsu   ftrace, kprobes: ...
409
   *  IPMODIFY - the record allows for the IP address to be changed.
b7ffffbb4   Steven Rostedt (Red Hat)   ftrace: Add infra...
410
   *  DISABLED - the record is not ready to be touched yet
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
411
   *  DIRECT   - there is a direct function to call
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
412
413
   *
   * When a new ftrace_ops is registered and wants a function to save
02dae28f0   Wei Yang   ftrace: Simplify ...
414
   * pt_regs, the rec->flags REGS is set. When the function has been
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
415
416
417
418
   * set up to save regs, the REG_EN flag is set. Once a function
   * starts saving regs it will do so until all ftrace_ops are removed
   * from tracing that function.
   */
3c1720f00   Steven Rostedt   ftrace: move memo...
419
  enum {
79922b800   Steven Rostedt (Red Hat)   ftrace: Optimize ...
420
  	FTRACE_FL_ENABLED	= (1UL << 31),
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
421
  	FTRACE_FL_REGS		= (1UL << 30),
79922b800   Steven Rostedt (Red Hat)   ftrace: Optimize ...
422
423
424
  	FTRACE_FL_REGS_EN	= (1UL << 29),
  	FTRACE_FL_TRAMP		= (1UL << 28),
  	FTRACE_FL_TRAMP_EN	= (1UL << 27),
f8b8be8a3   Masami Hiramatsu   ftrace, kprobes: ...
425
  	FTRACE_FL_IPMODIFY	= (1UL << 26),
b7ffffbb4   Steven Rostedt (Red Hat)   ftrace: Add infra...
426
  	FTRACE_FL_DISABLED	= (1UL << 25),
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
427
428
  	FTRACE_FL_DIRECT	= (1UL << 24),
  	FTRACE_FL_DIRECT_EN	= (1UL << 23),
3c1720f00   Steven Rostedt   ftrace: move memo...
429
  };
763e34e74   Steven Rostedt (VMware)   ftrace: Add regis...
430
  #define FTRACE_REF_MAX_SHIFT	23
cf2cb0b27   Steven Rostedt (Red Hat)   ftrace: Use macro...
431
  #define FTRACE_REF_MAX		((1UL << FTRACE_REF_MAX_SHIFT) - 1)
ed926f9b3   Steven Rostedt   ftrace: Use count...
432

02dae28f0   Wei Yang   ftrace: Simplify ...
433
  #define ftrace_rec_count(rec)	((rec)->flags & FTRACE_REF_MAX)
0376bde11   Steven Rostedt (Red Hat)   ftrace: Add ftrac...
434

3d0833953   Steven Rostedt   ftrace: dynamic e...
435
  struct dyn_ftrace {
a762782d7   Jiri Slaby   ftrace: Remove fr...
436
  	unsigned long		ip; /* address of mcount call-site */
85ae32ae0   Steven Rostedt   ftrace: Replace r...
437
  	unsigned long		flags;
a762782d7   Jiri Slaby   ftrace: Remove fr...
438
  	struct dyn_arch_ftrace	arch;
3d0833953   Steven Rostedt   ftrace: dynamic e...
439
  };
e1c08bdd9   Steven Rostedt   ftrace: force rec...
440
  int ftrace_force_update(void);
647664eaf   Masami Hiramatsu   ftrace: add ftrac...
441
442
  int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
  			 int remove, int reset);
ac483c446   Jiri Olsa   ftrace: Change fi...
443
  int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
936e074b2   Steven Rostedt   ftrace: Modify ft...
444
  		       int len, int reset);
ac483c446   Jiri Olsa   ftrace: Change fi...
445
  int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
936e074b2   Steven Rostedt   ftrace: Modify ft...
446
447
448
  			int len, int reset);
  void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
5500fa511   Jiri Olsa   ftrace, perf: Add...
449
  void ftrace_free_filter(struct ftrace_ops *ops);
d032ae892   Joel Fernandes   ftrace: Provide A...
450
  void ftrace_ops_set_global_filter(struct ftrace_ops *ops);
e1c08bdd9   Steven Rostedt   ftrace: force rec...
451

c88fd8634   Steven Rostedt   ftrace: Allow arc...
452
453
454
455
456
457
  enum {
  	FTRACE_UPDATE_CALLS		= (1 << 0),
  	FTRACE_DISABLE_CALLS		= (1 << 1),
  	FTRACE_UPDATE_TRACE_FUNC	= (1 << 2),
  	FTRACE_START_FUNC_RET		= (1 << 3),
  	FTRACE_STOP_FUNC_RET		= (1 << 4),
a0572f687   Steven Rostedt (VMware)   ftrace: Allow ftr...
458
  	FTRACE_MAY_SLEEP		= (1 << 5),
c88fd8634   Steven Rostedt   ftrace: Allow arc...
459
  };
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
460
461
462
463
464
465
466
467
468
  /*
   * The FTRACE_UPDATE_* enum is used to pass information back
   * from the ftrace_update_record() and ftrace_test_record()
   * functions. These are called by the code update routines
   * to find out what is to be done for a given function.
   *
   *  IGNORE           - The function is already what we want it to be
   *  MAKE_CALL        - Start tracing the function
   *  MODIFY_CALL      - Stop saving regs for the function
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
469
470
   *  MAKE_NOP         - Stop tracing the function
   */
c88fd8634   Steven Rostedt   ftrace: Allow arc...
471
472
473
  enum {
  	FTRACE_UPDATE_IGNORE,
  	FTRACE_UPDATE_MAKE_CALL,
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
474
  	FTRACE_UPDATE_MODIFY_CALL,
c88fd8634   Steven Rostedt   ftrace: Allow arc...
475
476
  	FTRACE_UPDATE_MAKE_NOP,
  };
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
477
478
479
480
  enum {
  	FTRACE_ITER_FILTER	= (1 << 0),
  	FTRACE_ITER_NOTRACE	= (1 << 1),
  	FTRACE_ITER_PRINTALL	= (1 << 2),
eee8ded13   Steven Rostedt (VMware)   ftrace: Have the ...
481
482
  	FTRACE_ITER_DO_PROBES	= (1 << 3),
  	FTRACE_ITER_PROBE	= (1 << 4),
5985ea8bd   Steven Rostedt (VMware)   ftrace: Have the ...
483
484
  	FTRACE_ITER_MOD		= (1 << 5),
  	FTRACE_ITER_ENABLED	= (1 << 6),
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
485
  };
c88fd8634   Steven Rostedt   ftrace: Allow arc...
486
  void arch_ftrace_update_code(int command);
89f579ce9   Yi Wang   x86/headers: Fix ...
487
488
489
  void arch_ftrace_update_trampoline(struct ftrace_ops *ops);
  void *arch_ftrace_trampoline_func(struct ftrace_ops *ops, struct dyn_ftrace *rec);
  void arch_ftrace_trampoline_free(struct ftrace_ops *ops);
c88fd8634   Steven Rostedt   ftrace: Allow arc...
490
491
492
493
494
495
  
  struct ftrace_rec_iter;
  
  struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
08d636b6d   Steven Rostedt   ftrace/x86: Have ...
496
497
498
499
  #define for_ftrace_rec_iter(iter)		\
  	for (iter = ftrace_rec_iter_start();	\
  	     iter;				\
  	     iter = ftrace_rec_iter_next(iter))
7375dca16   Steven Rostedt (VMware)   ftrace: Make enab...
500
501
  int ftrace_update_record(struct dyn_ftrace *rec, bool enable);
  int ftrace_test_record(struct dyn_ftrace *rec, bool enable);
c88fd8634   Steven Rostedt   ftrace: Allow arc...
502
  void ftrace_run_stop_machine(int command);
f0cf973a2   Steven Rostedt   ftrace: Return re...
503
  unsigned long ftrace_location(unsigned long ip);
04cf31a75   Michael Ellerman   ftrace: Make ftra...
504
  unsigned long ftrace_location_range(unsigned long start, unsigned long end);
7413af1fb   Steven Rostedt (Red Hat)   ftrace: Make get_...
505
506
  unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
  unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
c88fd8634   Steven Rostedt   ftrace: Allow arc...
507
508
  
  extern ftrace_func_t ftrace_trace_function;
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
509
510
511
512
513
514
  int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  		  struct inode *inode, struct file *file);
  ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  			    size_t cnt, loff_t *ppos);
  ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  			     size_t cnt, loff_t *ppos);
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
515
  int ftrace_regex_release(struct inode *inode, struct file *file);
2a85a37f1   Steven Rostedt   ftrace: Allow acc...
516
517
  void __init
  ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
3d0833953   Steven Rostedt   ftrace: dynamic e...
518
  /* defined in arch */
3c1720f00   Steven Rostedt   ftrace: move memo...
519
  extern int ftrace_ip_converted(unsigned long ip);
3a36cb11c   Jiri Slaby   ftrace: Do not pa...
520
  extern int ftrace_dyn_arch_init(void);
e4f5d5440   Steven Rostedt   ftrace/x86: Have ...
521
  extern void ftrace_replace_code(int enable);
d61f82d06   Steven Rostedt   ftrace: use dynam...
522
523
  extern int ftrace_update_ftrace_func(ftrace_func_t func);
  extern void ftrace_caller(void);
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
524
  extern void ftrace_regs_caller(void);
d61f82d06   Steven Rostedt   ftrace: use dynam...
525
  extern void ftrace_call(void);
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
526
  extern void ftrace_regs_call(void);
d61f82d06   Steven Rostedt   ftrace: use dynam...
527
  extern void mcount_call(void);
f00012074   Shaohua Li   ftrace, ia64: Add...
528

8ed3e2cfe   Steven Rostedt   ftrace: Make ftra...
529
  void ftrace_modify_all_code(int command);
f00012074   Shaohua Li   ftrace, ia64: Add...
530
531
532
  #ifndef FTRACE_ADDR
  #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  #endif
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
533

79922b800   Steven Rostedt (Red Hat)   ftrace: Optimize ...
534
535
536
  #ifndef FTRACE_GRAPH_ADDR
  #define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
  #endif
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
537
  #ifndef FTRACE_REGS_ADDR
06aeaaeab   Masami Hiramatsu   ftrace: Move ARCH...
538
  #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
539
540
541
542
543
  # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
  #else
  # define FTRACE_REGS_ADDR FTRACE_ADDR
  #endif
  #endif
646d7043a   Steven Rostedt (Red Hat)   ftrace: Allow arc...
544
545
546
547
548
549
550
551
552
  /*
   * If an arch would like functions that are only traced
   * by the function graph tracer to jump directly to its own
   * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
   * to be that address to jump to.
   */
  #ifndef FTRACE_GRAPH_TRAMP_ADDR
  #define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
  #endif
fb52607af   Frederic Weisbecker   tracing/function-...
553
554
  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  extern void ftrace_graph_caller(void);
5a45cfe1c   Steven Rostedt   ftrace: use code ...
555
556
557
558
559
  extern int ftrace_enable_ftrace_graph_caller(void);
  extern int ftrace_disable_ftrace_graph_caller(void);
  #else
  static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
e7d3737ea   Frederic Weisbecker   tracing/function-...
560
  #endif
ad90c0e3c   Steven Rostedt   ftrace: user upda...
561

31e889098   Steven Rostedt   ftrace: pass modu...
562
  /**
57794a9d4   Wenji Huang   trace: trivial fi...
563
   * ftrace_make_nop - convert code into nop
31e889098   Steven Rostedt   ftrace: pass modu...
564
   * @mod: module structure if called by module load initialization
fbf6c73c5   Mark Rutland   ftrace: add ftrac...
565
   * @rec: the call site record (e.g. mcount/fentry)
31e889098   Steven Rostedt   ftrace: pass modu...
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
   * @addr: the address that the call site should be calling
   *
   * This is a very sensitive operation and great care needs
   * to be taken by the arch.  The operation should carefully
   * read the location, check to see if what is read is indeed
   * what we expect it to be, and then on success of the compare,
   * it should write to the location.
   *
   * The code segment at @rec->ip should be a caller to @addr
   *
   * Return must be:
   *  0 on success
   *  -EFAULT on error reading the location
   *  -EINVAL on a failed compare of the contents
   *  -EPERM  on error writing to the location
   * Any other value will be considered a failure.
   */
  extern int ftrace_make_nop(struct module *mod,
  			   struct dyn_ftrace *rec, unsigned long addr);
a26a2a273   Steven Rostedt   ftrace: nmi safe ...
585

fbf6c73c5   Mark Rutland   ftrace: add ftrac...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
  
  /**
   * ftrace_init_nop - initialize a nop call site
   * @mod: module structure if called by module load initialization
   * @rec: the call site record (e.g. mcount/fentry)
   *
   * This is a very sensitive operation and great care needs
   * to be taken by the arch.  The operation should carefully
   * read the location, check to see if what is read is indeed
   * what we expect it to be, and then on success of the compare,
   * it should write to the location.
   *
   * The code segment at @rec->ip should contain the contents created by
   * the compiler
   *
   * Return must be:
   *  0 on success
   *  -EFAULT on error reading the location
   *  -EINVAL on a failed compare of the contents
   *  -EPERM  on error writing to the location
   * Any other value will be considered a failure.
   */
  #ifndef ftrace_init_nop
  static inline int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
  {
  	return ftrace_make_nop(mod, rec, MCOUNT_ADDR);
  }
  #endif
593eb8a2d   Steven Rostedt   ftrace: return er...
614
  /**
31e889098   Steven Rostedt   ftrace: pass modu...
615
   * ftrace_make_call - convert a nop call site into a call to addr
fbf6c73c5   Mark Rutland   ftrace: add ftrac...
616
   * @rec: the call site record (e.g. mcount/fentry)
31e889098   Steven Rostedt   ftrace: pass modu...
617
   * @addr: the address that the call site should call
593eb8a2d   Steven Rostedt   ftrace: return er...
618
619
620
621
622
623
624
   *
   * This is a very sensitive operation and great care needs
   * to be taken by the arch.  The operation should carefully
   * read the location, check to see if what is read is indeed
   * what we expect it to be, and then on success of the compare,
   * it should write to the location.
   *
31e889098   Steven Rostedt   ftrace: pass modu...
625
626
   * The code segment at @rec->ip should be a nop
   *
593eb8a2d   Steven Rostedt   ftrace: return er...
627
628
629
630
631
632
633
   * Return must be:
   *  0 on success
   *  -EFAULT on error reading the location
   *  -EINVAL on a failed compare of the contents
   *  -EPERM  on error writing to the location
   * Any other value will be considered a failure.
   */
31e889098   Steven Rostedt   ftrace: pass modu...
634
  extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
06aeaaeab   Masami Hiramatsu   ftrace: Move ARCH...
635
  #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
636
637
  /**
   * ftrace_modify_call - convert from one addr to another (no nop)
fbf6c73c5   Mark Rutland   ftrace: add ftrac...
638
   * @rec: the call site record (e.g. mcount/fentry)
08f6fba50   Steven Rostedt   ftrace/x86: Add s...
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
   * @old_addr: the address expected to be currently called to
   * @addr: the address to change to
   *
   * This is a very sensitive operation and great care needs
   * to be taken by the arch.  The operation should carefully
   * read the location, check to see if what is read is indeed
   * what we expect it to be, and then on success of the compare,
   * it should write to the location.
   *
   * The code segment at @rec->ip should be a caller to @old_addr
   *
   * Return must be:
   *  0 on success
   *  -EFAULT on error reading the location
   *  -EINVAL on a failed compare of the contents
   *  -EPERM  on error writing to the location
   * Any other value will be considered a failure.
   */
  extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  			      unsigned long addr);
  #else
  /* Should never be called */
  static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  				     unsigned long addr)
  {
  	return -EINVAL;
  }
  #endif
31e889098   Steven Rostedt   ftrace: pass modu...
667
668
  /* May be defined in arch */
  extern int ftrace_arch_read_dyn_info(char *buf, int size);
593eb8a2d   Steven Rostedt   ftrace: return er...
669

ecea656d1   Abhishek Sagar   ftrace: freeze kp...
670
  extern int skip_trace(unsigned long ip);
a949ae560   Steven Rostedt (Red Hat)   ftrace/module: Ha...
671
  extern void ftrace_module_init(struct module *mod);
7dcd182be   Jessica Yu   ftrace/module: re...
672
  extern void ftrace_module_enable(struct module *mod);
049fb9bd4   Steven Rostedt (Red Hat)   ftrace/module: Ca...
673
  extern void ftrace_release_mod(struct module *mod);
ecea656d1   Abhishek Sagar   ftrace: freeze kp...
674

c0719e5a4   Steven Rostedt   ftrace: use ftrac...
675
676
  extern void ftrace_disable_daemon(void);
  extern void ftrace_enable_daemon(void);
4dc936769   Steven Rostedt   ftrace: Make ftra...
677
  #else /* CONFIG_DYNAMIC_FTRACE */
4dbf6bc23   Steven Rostedt   tracing: Convert ...
678
679
  static inline int skip_trace(unsigned long ip) { return 0; }
  static inline int ftrace_force_update(void) { return 0; }
4dbf6bc23   Steven Rostedt   tracing: Convert ...
680
681
  static inline void ftrace_disable_daemon(void) { }
  static inline void ftrace_enable_daemon(void) { }
7dcd182be   Jessica Yu   ftrace/module: re...
682
683
684
  static inline void ftrace_module_init(struct module *mod) { }
  static inline void ftrace_module_enable(struct module *mod) { }
  static inline void ftrace_release_mod(struct module *mod) { }
d88471cb8   Sasha Levin   ftrace: Constify ...
685
  static inline int ftrace_text_reserved(const void *start, const void *end)
2cfa19780   Masami Hiramatsu   ftrace/alternativ...
686
687
688
  {
  	return 0;
  }
4dc936769   Steven Rostedt   ftrace: Make ftra...
689
690
691
692
  static inline unsigned long ftrace_location(unsigned long ip)
  {
  	return 0;
  }
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
693
694
695
696
697
698
699
  
  /*
   * Again users of functions that have ftrace_ops may not
   * have them defined when ftrace is not enabled, but these
   * functions may still be called. Use a macro instead of inline.
   */
  #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
96de37b62   Steven Rostedt   tracing: Fix comp...
700
  #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
647664eaf   Masami Hiramatsu   ftrace: add ftrac...
701
  #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
5500fa511   Jiri Olsa   ftrace, perf: Add...
702
703
704
  #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  #define ftrace_free_filter(ops) do { } while (0)
d032ae892   Joel Fernandes   ftrace: Provide A...
705
  #define ftrace_ops_set_global_filter(ops) do { } while (0)
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
706
707
708
709
710
  
  static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  			    size_t cnt, loff_t *ppos) { return -ENODEV; }
  static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  			     size_t cnt, loff_t *ppos) { return -ENODEV; }
fc13cb0ce   Steven Rostedt   ftrace: Allow oth...
711
712
  static inline int
  ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
aec0be2d6   Steven Rostedt (Red Hat)   ftrace/x86/extabl...
713
714
715
716
717
  
  static inline bool is_ftrace_trampoline(unsigned long addr)
  {
  	return false;
  }
ecea656d1   Abhishek Sagar   ftrace: freeze kp...
718
  #endif /* CONFIG_DYNAMIC_FTRACE */
352ad25aa   Steven Rostedt   ftrace: tracer fo...
719

aeaee8a2c   Ingo Molnar   ftrace: build fix
720
721
  /* totally disable ftrace - can not re-enable after this */
  void ftrace_kill(void);
f43fdad86   Ingo Molnar   ftrace: fix kexec
722
723
  static inline void tracer_disable(void)
  {
606576ce8   Steven Rostedt   ftrace: rename FT...
724
  #ifdef CONFIG_FUNCTION_TRACER
f43fdad86   Ingo Molnar   ftrace: fix kexec
725
726
727
  	ftrace_enabled = 0;
  #endif
  }
370027358   Huang Ying   ftrace: fix incor...
728
729
  /*
   * Ftrace disable/restore without lock. Some synchronization mechanism
9bdeb7b5d   Huang Ying   kexec jump: __ftr...
730
   * must be used to prevent ftrace_enabled to be changed between
370027358   Huang Ying   ftrace: fix incor...
731
732
   * disable/restore.
   */
9bdeb7b5d   Huang Ying   kexec jump: __ftr...
733
734
  static inline int __ftrace_enabled_save(void)
  {
606576ce8   Steven Rostedt   ftrace: rename FT...
735
  #ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5d   Huang Ying   kexec jump: __ftr...
736
737
738
739
740
741
742
743
744
745
  	int saved_ftrace_enabled = ftrace_enabled;
  	ftrace_enabled = 0;
  	return saved_ftrace_enabled;
  #else
  	return 0;
  #endif
  }
  
  static inline void __ftrace_enabled_restore(int enabled)
  {
606576ce8   Steven Rostedt   ftrace: rename FT...
746
  #ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5d   Huang Ying   kexec jump: __ftr...
747
748
749
  	ftrace_enabled = enabled;
  #endif
  }
eed542d69   AKASHI Takahiro   ftrace: Make CALL...
750
751
752
753
754
755
756
  /* All archs should have this, but we define it for consistency */
  #ifndef ftrace_return_address0
  # define ftrace_return_address0 __builtin_return_address(0)
  #endif
  
  /* Archs may use other ways for ADDR1 and beyond */
  #ifndef ftrace_return_address
c79a61f55   Uwe Kleine-Koenig   tracing: make CAL...
757
  # ifdef CONFIG_FRAME_POINTER
eed542d69   AKASHI Takahiro   ftrace: Make CALL...
758
  #  define ftrace_return_address(n) __builtin_return_address(n)
c79a61f55   Uwe Kleine-Koenig   tracing: make CAL...
759
  # else
eed542d69   AKASHI Takahiro   ftrace: Make CALL...
760
  #  define ftrace_return_address(n) 0UL
c79a61f55   Uwe Kleine-Koenig   tracing: make CAL...
761
  # endif
eed542d69   AKASHI Takahiro   ftrace: Make CALL...
762
763
764
765
766
767
768
769
770
  #endif
  
  #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
  #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
  #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
  #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
  #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
  #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
352ad25aa   Steven Rostedt   ftrace: tracer fo...
771

f904f5826   Sebastian Andrzej Siewior   sched/debug: Fix ...
772
773
774
775
776
777
778
779
780
781
782
  static inline unsigned long get_lock_parent_ip(void)
  {
  	unsigned long addr = CALLER_ADDR0;
  
  	if (!in_lock_functions(addr))
  		return addr;
  	addr = CALLER_ADDR1;
  	if (!in_lock_functions(addr))
  		return addr;
  	return CALLER_ADDR2;
  }
c3bc8fd63   Joel Fernandes (Google)   tracing: Centrali...
783
  #ifdef CONFIG_TRACE_PREEMPT_TOGGLE
489f13961   Ingo Molnar   ftrace: fix build...
784
785
    extern void trace_preempt_on(unsigned long a0, unsigned long a1);
    extern void trace_preempt_off(unsigned long a0, unsigned long a1);
6cd8a4bb2   Steven Rostedt   ftrace: trace pre...
786
  #else
b02ee9a33   Minho Ban   tracing: Prevent ...
787
788
789
790
791
792
  /*
   * Use defines instead of static inlines because some arches will make code out
   * of the CALLER_ADDR, when we really want these to be a real nop.
   */
  # define trace_preempt_on(a0, a1) do { } while (0)
  # define trace_preempt_off(a0, a1) do { } while (0)
6cd8a4bb2   Steven Rostedt   ftrace: trace pre...
793
  #endif
68bf21aa1   Steven Rostedt   ftrace: mcount ca...
794
795
  #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  extern void ftrace_init(void);
a1326b17a   Mark Rutland   module/ftrace: ha...
796
797
798
799
800
  #ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
  #define FTRACE_CALLSITE_SECTION	"__patchable_function_entries"
  #else
  #define FTRACE_CALLSITE_SECTION	"__mcount_loc"
  #endif
68bf21aa1   Steven Rostedt   ftrace: mcount ca...
801
802
803
  #else
  static inline void ftrace_init(void) { }
  #endif
71566a0d1   Frederic Weisbecker   tracing/fastboot:...
804
  /*
287b6e68c   Frederic Weisbecker   tracing/function-...
805
   * Structure that defines an entry function trace.
a4a551b8f   Namhyung Kim   ftrace: Reduce si...
806
807
   * It's already packed but the attribute "packed" is needed
   * to remove extra padding at the end.
287b6e68c   Frederic Weisbecker   tracing/function-...
808
809
810
811
   */
  struct ftrace_graph_ent {
  	unsigned long func; /* Current function */
  	int depth;
a4a551b8f   Namhyung Kim   ftrace: Reduce si...
812
  } __packed;
dd0e545f0   Steven Rostedt   ftrace: printk fo...
813

71566a0d1   Frederic Weisbecker   tracing/fastboot:...
814
  /*
caf4b323b   Frederic Weisbecker   tracing, x86: add...
815
   * Structure that defines a return function trace.
a4a551b8f   Namhyung Kim   ftrace: Reduce si...
816
817
   * It's already packed but the attribute "packed" is needed
   * to remove extra padding at the end.
caf4b323b   Frederic Weisbecker   tracing, x86: add...
818
   */
fb52607af   Frederic Weisbecker   tracing/function-...
819
  struct ftrace_graph_ret {
caf4b323b   Frederic Weisbecker   tracing, x86: add...
820
  	unsigned long func; /* Current function */
0231022cc   Frederic Weisbecker   tracing/function-...
821
822
  	/* Number of functions that overran the depth limit for current task */
  	unsigned long overrun;
a4a551b8f   Namhyung Kim   ftrace: Reduce si...
823
824
  	unsigned long long calltime;
  	unsigned long long rettime;
287b6e68c   Frederic Weisbecker   tracing/function-...
825
  	int depth;
a4a551b8f   Namhyung Kim   ftrace: Reduce si...
826
  } __packed;
caf4b323b   Frederic Weisbecker   tracing, x86: add...
827

62b915f10   Jiri Olsa   tracing: Add grap...
828
829
830
  /* Type of the callback handlers for tracing function graph*/
  typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
e8025bab7   Steven Rostedt (VMware)   function_graph: P...
831
  extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
fb52607af   Frederic Weisbecker   tracing/function-...
832
  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8b96f0119   Frederic Weisbecker   tracing/function-...
833

688f7089d   Steven Rostedt (VMware)   fgraph: Add new f...
834
835
836
837
  struct fgraph_ops {
  	trace_func_graph_ent_t		entryfunc;
  	trace_func_graph_ret_t		retfunc;
  };
8b96f0119   Frederic Weisbecker   tracing/function-...
838
  /*
712406a6b   Steven Rostedt   tracing/function-...
839
840
841
842
843
844
845
846
   * Stack of return addresses for functions
   * of a thread.
   * Used in struct thread_info
   */
  struct ftrace_ret_stack {
  	unsigned long ret;
  	unsigned long func;
  	unsigned long long calltime;
8861dd303   Namhyung Kim   ftrace: Access re...
847
  #ifdef CONFIG_FUNCTION_PROFILER
a2a16d6a3   Steven Rostedt   function-graph: a...
848
  	unsigned long long subtime;
8861dd303   Namhyung Kim   ftrace: Access re...
849
  #endif
daa460a88   Josh Poimboeuf   ftrace: Only allo...
850
  #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
71e308a23   Steven Rostedt   function-graph: a...
851
  	unsigned long fp;
daa460a88   Josh Poimboeuf   ftrace: Only allo...
852
  #endif
9a7c348ba   Josh Poimboeuf   ftrace: Add retur...
853
854
855
  #ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
  	unsigned long *retp;
  #endif
712406a6b   Steven Rostedt   tracing/function-...
856
857
858
859
860
861
862
863
864
865
  };
  
  /*
   * Primary handler of a function return.
   * It relays on ftrace_return_to_handler.
   * Defined in entry_32/64.S
   */
  extern void return_to_handler(void);
  
  extern int
8114865ff   Steven Rostedt (VMware)   function_graph: C...
866
867
  function_graph_enter(unsigned long ret, unsigned long func,
  		     unsigned long frame_pointer, unsigned long *retp);
712406a6b   Steven Rostedt   tracing/function-...
868

b0e21a61d   Steven Rostedt (VMware)   function_graph: H...
869
870
  struct ftrace_ret_stack *
  ftrace_graph_get_ret_stack(struct task_struct *task, int idx);
223918e32   Josh Poimboeuf   ftrace: Add ftrac...
871
872
  unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
  				    unsigned long ret, unsigned long *retp);
712406a6b   Steven Rostedt   tracing/function-...
873
  /*
8b96f0119   Frederic Weisbecker   tracing/function-...
874
875
876
877
878
   * Sometimes we don't want to trace a function with the function
   * graph tracer but we want them to keep traced by the usual function
   * tracer if the function graph tracer is not configured.
   */
  #define __notrace_funcgraph		notrace
f201ae235   Frederic Weisbecker   tracing/function-...
879
880
  #define FTRACE_RETFUNC_DEPTH 50
  #define FTRACE_RETSTACK_ALLOC_SIZE 32
688f7089d   Steven Rostedt (VMware)   fgraph: Add new f...
881
882
883
  
  extern int register_ftrace_graph(struct fgraph_ops *ops);
  extern void unregister_ftrace_graph(struct fgraph_ops *ops);
287b6e68c   Frederic Weisbecker   tracing/function-...
884

1b2f121c1   Steven Rostedt (Red Hat)   ftrace-graph: Rem...
885
  extern bool ftrace_graph_is_dead(void);
14a866c56   Steven Rostedt   ftrace: add ftrac...
886
  extern void ftrace_graph_stop(void);
287b6e68c   Frederic Weisbecker   tracing/function-...
887
888
889
  /* The current handlers in use */
  extern trace_func_graph_ret_t ftrace_graph_return;
  extern trace_func_graph_ent_t ftrace_graph_entry;
caf4b323b   Frederic Weisbecker   tracing, x86: add...
890

fb52607af   Frederic Weisbecker   tracing/function-...
891
892
  extern void ftrace_graph_init_task(struct task_struct *t);
  extern void ftrace_graph_exit_task(struct task_struct *t);
868baf07b   Steven Rostedt   ftrace: Fix memor...
893
  extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
21a8c466f   Frederic Weisbecker   tracing/ftrace: p...
894

380c4b141   Frederic Weisbecker   tracing/function-...
895
896
897
898
899
900
901
902
903
  static inline void pause_graph_tracing(void)
  {
  	atomic_inc(&current->tracing_graph_pause);
  }
  
  static inline void unpause_graph_tracing(void)
  {
  	atomic_dec(&current->tracing_graph_pause);
  }
5ac9f6226   Steven Rostedt   function-graph: a...
904
  #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
8b96f0119   Frederic Weisbecker   tracing/function-...
905
906
  
  #define __notrace_funcgraph
fb52607af   Frederic Weisbecker   tracing/function-...
907
908
  static inline void ftrace_graph_init_task(struct task_struct *t) { }
  static inline void ftrace_graph_exit_task(struct task_struct *t) { }
868baf07b   Steven Rostedt   ftrace: Fix memor...
909
  static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
21a8c466f   Frederic Weisbecker   tracing/ftrace: p...
910

688f7089d   Steven Rostedt (VMware)   fgraph: Add new f...
911
912
913
  /* Define as macros as fgraph_ops may not be defined */
  #define register_ftrace_graph(ops) ({ -1; })
  #define unregister_ftrace_graph(ops) do { } while (0)
380c4b141   Frederic Weisbecker   tracing/function-...
914

223918e32   Josh Poimboeuf   ftrace: Add ftrac...
915
916
917
918
919
920
  static inline unsigned long
  ftrace_graph_ret_addr(struct task_struct *task, int *idx, unsigned long ret,
  		      unsigned long *retp)
  {
  	return ret;
  }
380c4b141   Frederic Weisbecker   tracing/function-...
921
922
  static inline void pause_graph_tracing(void) { }
  static inline void unpause_graph_tracing(void) { }
5ac9f6226   Steven Rostedt   function-graph: a...
923
  #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
caf4b323b   Frederic Weisbecker   tracing, x86: add...
924

ea4e2bc4d   Steven Rostedt   ftrace: graph of ...
925
  #ifdef CONFIG_TRACING
ea4e2bc4d   Steven Rostedt   ftrace: graph of ...
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
  
  /* flags for current->trace */
  enum {
  	TSK_TRACE_FL_TRACE_BIT	= 0,
  	TSK_TRACE_FL_GRAPH_BIT	= 1,
  };
  enum {
  	TSK_TRACE_FL_TRACE	= 1 << TSK_TRACE_FL_TRACE_BIT,
  	TSK_TRACE_FL_GRAPH	= 1 << TSK_TRACE_FL_GRAPH_BIT,
  };
  
  static inline void set_tsk_trace_trace(struct task_struct *tsk)
  {
  	set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  }
  
  static inline void clear_tsk_trace_trace(struct task_struct *tsk)
  {
  	clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  }
  
  static inline int test_tsk_trace_trace(struct task_struct *tsk)
  {
  	return tsk->trace & TSK_TRACE_FL_TRACE;
  }
  
  static inline void set_tsk_trace_graph(struct task_struct *tsk)
  {
  	set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  }
  
  static inline void clear_tsk_trace_graph(struct task_struct *tsk)
  {
  	clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  }
  
  static inline int test_tsk_trace_graph(struct task_struct *tsk)
  {
  	return tsk->trace & TSK_TRACE_FL_GRAPH;
  }
cecbca96d   Frederic Weisbecker   tracing: Dump eit...
966
967
968
  enum ftrace_dump_mode;
  
  extern enum ftrace_dump_mode ftrace_dump_on_oops;
0daa23029   Steven Rostedt (Red Hat)   tracing: Add tp_p...
969
  extern int tracepoint_printk;
526211bc5   Ingo Molnar   tracing: move uti...
970

de7edd314   Steven Rostedt (Red Hat)   tracing: Disable ...
971
972
  extern void disable_trace_on_warning(void);
  extern int __disable_trace_on_warning;
423917457   Steven Rostedt (Red Hat)   tracing: Make tra...
973
  int tracepoint_printk_sysctl(struct ctl_table *table, int write,
32927393d   Christoph Hellwig   sysctl: pass kern...
974
  			     void *buffer, size_t *lenp, loff_t *ppos);
423917457   Steven Rostedt (Red Hat)   tracing: Make tra...
975

de7edd314   Steven Rostedt (Red Hat)   tracing: Disable ...
976
977
  #else /* CONFIG_TRACING */
  static inline void  disable_trace_on_warning(void) { }
ea4e2bc4d   Steven Rostedt   ftrace: graph of ...
978
  #endif /* CONFIG_TRACING */
e7b8e675d   Mike Frysinger   tracing: Unify ar...
979
980
981
982
983
  #ifdef CONFIG_FTRACE_SYSCALLS
  
  unsigned long arch_syscall_addr(int nr);
  
  #endif /* CONFIG_FTRACE_SYSCALLS */
16444a8a4   Arnaldo Carvalho de Melo   ftrace: add basic...
984
  #endif /* _LINUX_FTRACE_H */