tracing: Cleanup code by removing init "char *name"
[linux-2.6-block.git] / include / linux / ftrace.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
9849ed4d
MF
2/*
3 * Ftrace header. For implementation details beyond the random comments
5fb94e9c 4 * scattered below, see: Documentation/trace/ftrace-design.rst
9849ed4d
MF
5 */
6
16444a8a
ACM
7#ifndef _LINUX_FTRACE_H
8#define _LINUX_FTRACE_H
9
0264c8c9 10#include <linux/trace_recursion.h>
0012693a 11#include <linux/trace_clock.h>
18bfee32 12#include <linux/jump_label.h>
5601020f 13#include <linux/kallsyms.h>
0012693a 14#include <linux/linkage.h>
ea4e2bc4 15#include <linux/bitops.h>
a1e2e31d 16#include <linux/ptrace.h>
0012693a 17#include <linux/ktime.h>
21a8c466 18#include <linux/sched.h>
0012693a
FW
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/fs.h>
16444a8a 22
c79a61f5
UKK
23#include <asm/ftrace.h>
24
2f5f6ad9
SR
25/*
26 * If the arch supports passing the variable contents of
27 * function_trace_op as the third parameter back from the
28 * mcount call, then the arch should define this as 1.
29 */
30#ifndef ARCH_SUPPORTS_FTRACE_OPS
31#define ARCH_SUPPORTS_FTRACE_OPS 0
32#endif
33
380af29b
SRG
34#ifdef CONFIG_TRACING
35extern void ftrace_boot_snapshot(void);
36#else
37static inline void ftrace_boot_snapshot(void) { }
38#endif
39
34cdd18b
SRV
40#ifdef CONFIG_FUNCTION_TRACER
41struct ftrace_ops;
42struct ftrace_regs;
ccf3672d
SR
43/*
44 * If the arch's mcount caller does not support all of ftrace's
45 * features, then it must call an indirect function that
f2cc020d 46 * does. Or at least does enough to prevent any unwelcome side effects.
34cdd18b
SRV
47 *
48 * Also define the function prototype that these architectures use
49 * to call the ftrace_ops_list_func().
ccf3672d 50 */
7544256a 51#if !ARCH_SUPPORTS_FTRACE_OPS
ccf3672d 52# define FTRACE_FORCE_LIST_FUNC 1
34cdd18b 53void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip);
ccf3672d
SR
54#else
55# define FTRACE_FORCE_LIST_FUNC 0
34cdd18b
SRV
56void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
57 struct ftrace_ops *op, struct ftrace_regs *fregs);
ccf3672d 58#endif
34cdd18b 59#endif /* CONFIG_FUNCTION_TRACER */
ccf3672d 60
5f893b26
SRRH
61/* Main tracing buffer and events set up */
62#ifdef CONFIG_TRACING
63void trace_init(void);
e725c731 64void early_trace_init(void);
5f893b26
SRRH
65#else
66static inline void trace_init(void) { }
e725c731 67static inline void early_trace_init(void) { }
5f893b26 68#endif
ccf3672d 69
de477254 70struct module;
04da85b8 71struct ftrace_hash;
013bf0da 72struct ftrace_direct_func;
04da85b8 73
aba4b5c2
SRV
74#if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_MODULES) && \
75 defined(CONFIG_DYNAMIC_FTRACE)
76const char *
77ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
78 unsigned long *off, char **modname, char *sym);
79#else
80static inline const char *
81ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
82 unsigned long *off, char **modname, char *sym)
83{
84 return NULL;
85}
fc0ea795
AH
86#endif
87
88#if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
89int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
90 char *type, char *name,
91 char *module_name, int *exported);
92#else
6171a031
SRV
93static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
94 char *type, char *name,
95 char *module_name, int *exported)
96{
97 return -1;
98}
aba4b5c2
SRV
99#endif
100
606576ce 101#ifdef CONFIG_FUNCTION_TRACER
3e1932ad 102
b0fc494f
SR
103extern int ftrace_enabled;
104extern int
105ftrace_enable_sysctl(struct ctl_table *table, int write,
54fa9ba5 106 void *buffer, size_t *lenp, loff_t *ppos);
b0fc494f 107
02a474ca
SRV
108#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
109
d19ad077
SRV
110struct ftrace_regs {
111 struct pt_regs regs;
112};
02a474ca
SRV
113#define arch_ftrace_get_regs(fregs) (&(fregs)->regs)
114
2860cd8a
SRV
115/*
116 * ftrace_instruction_pointer_set() is to be defined by the architecture
117 * if to allow setting of the instruction pointer from the ftrace_regs
118 * when HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports
119 * live kernel patching.
120 */
121#define ftrace_instruction_pointer_set(fregs, ip) do { } while (0)
02a474ca 122#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
d19ad077
SRV
123
124static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs)
125{
126 if (!fregs)
127 return NULL;
128
02a474ca 129 return arch_ftrace_get_regs(fregs);
d19ad077
SRV
130}
131
2f5f6ad9 132typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
d19ad077 133 struct ftrace_ops *op, struct ftrace_regs *fregs);
16444a8a 134
87354059
SRRH
135ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
136
e248491a
JO
137/*
138 * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
139 * set in the flags member.
a25d036d 140 * CONTROL, SAVE_REGS, SAVE_REGS_IF_SUPPORTED, RECURSION, STUB and
f8b8be8a
MH
141 * IPMODIFY are a kind of attribute flags which can be set only before
142 * registering the ftrace_ops, and can not be modified while registered.
ad61dd30 143 * Changing those attribute flags after registering ftrace_ops will
f8b8be8a 144 * cause unexpected results.
e248491a
JO
145 *
146 * ENABLED - set/unset when ftrace_ops is registered/unregistered
e248491a
JO
147 * DYNAMIC - set when ftrace_ops is registered to denote dynamically
148 * allocated ftrace_ops which need special care
08f6fba5
SR
149 * SAVE_REGS - The ftrace_ops wants regs saved at each function called
150 * and passed to the callback. If this flag is set, but the
151 * architecture does not support passing regs
06aeaaea 152 * (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
08f6fba5
SR
153 * ftrace_ops will fail to register, unless the next flag
154 * is set.
155 * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
156 * handler can handle an arch that does not save regs
157 * (the handler tests if regs == NULL), then it can set
158 * this flag instead. It will not fail registering the ftrace_ops
159 * but, the regs field will be NULL if the arch does not support
160 * passing regs to the handler.
161 * Note, if this flag is set, the SAVE_REGS flag will automatically
162 * get set upon registering the ftrace_ops, if the arch supports it.
a25d036d
SRV
163 * RECURSION - The ftrace_ops can set this to tell the ftrace infrastructure
164 * that the call back needs recursion protection. If it does
165 * not set this, then the ftrace infrastructure will assume
166 * that the callback can handle recursion on its own.
395b97a3 167 * STUB - The ftrace_ops is just a place holder.
f04f24fb
MH
168 * INITIALIZED - The ftrace_ops has already been initialized (first use time
169 * register_ftrace_function() is called, it will initialized the ops)
591dffda 170 * DELETED - The ops are being deleted, do not let them be registered again.
e1effa01
SRRH
171 * ADDING - The ops is in the process of being added.
172 * REMOVING - The ops is in the process of being removed.
173 * MODIFYING - The ops is in the process of changing its filter functions.
f3bea491
SRRH
174 * ALLOC_TRAMP - A dynamic trampoline was allocated by the core code.
175 * The arch specific code sets this flag when it allocated a
176 * trampoline. This lets the arch know that it can update the
177 * trampoline in case the callback function changes.
178 * The ftrace_ops trampoline can be set by the ftrace users, and
179 * in such cases the arch must not modify it. Only the arch ftrace
180 * core code should set this flag.
f8b8be8a
MH
181 * IPMODIFY - The ops can modify the IP register. This can only be set with
182 * SAVE_REGS. If another ops with this flag set is already registered
183 * for any of the functions that this ops will be registered for, then
184 * this ops will fail to register or set_filter_ip.
e3eea140 185 * PID - Is affected by set_ftrace_pid (allows filtering on those pids)
d0ba52f1 186 * RCU - Set when the ops can only be called when RCU is watching.
8c08f0d5 187 * TRACE_ARRAY - The ops->private points to a trace_array descriptor.
7162431d
MB
188 * PERMANENT - Set when the ops is permanent and should not be affected by
189 * ftrace_enabled.
763e34e7
SRV
190 * DIRECT - Used by the direct ftrace_ops helper for direct functions
191 * (internal ftrace only, should not be used by others)
e248491a 192 */
b848914c 193enum {
b41db132
EWI
194 FTRACE_OPS_FL_ENABLED = BIT(0),
195 FTRACE_OPS_FL_DYNAMIC = BIT(1),
196 FTRACE_OPS_FL_SAVE_REGS = BIT(2),
197 FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = BIT(3),
a25d036d 198 FTRACE_OPS_FL_RECURSION = BIT(4),
b41db132
EWI
199 FTRACE_OPS_FL_STUB = BIT(5),
200 FTRACE_OPS_FL_INITIALIZED = BIT(6),
201 FTRACE_OPS_FL_DELETED = BIT(7),
202 FTRACE_OPS_FL_ADDING = BIT(8),
203 FTRACE_OPS_FL_REMOVING = BIT(9),
204 FTRACE_OPS_FL_MODIFYING = BIT(10),
205 FTRACE_OPS_FL_ALLOC_TRAMP = BIT(11),
206 FTRACE_OPS_FL_IPMODIFY = BIT(12),
207 FTRACE_OPS_FL_PID = BIT(13),
208 FTRACE_OPS_FL_RCU = BIT(14),
209 FTRACE_OPS_FL_TRACE_ARRAY = BIT(15),
210 FTRACE_OPS_FL_PERMANENT = BIT(16),
211 FTRACE_OPS_FL_DIRECT = BIT(17),
b848914c
SR
212};
213
33b7f99c
SRRH
214#ifdef CONFIG_DYNAMIC_FTRACE
215/* The hash used to know what functions callbacks trace */
216struct ftrace_ops_hash {
f86f4180
CZ
217 struct ftrace_hash __rcu *notrace_hash;
218 struct ftrace_hash __rcu *filter_hash;
33b7f99c
SRRH
219 struct mutex regex_lock;
220};
42c269c8 221
b80f0f6c 222void ftrace_free_init_mem(void);
aba4b5c2 223void ftrace_free_mem(struct module *mod, void *start, void *end);
42c269c8 224#else
380af29b
SRG
225static inline void ftrace_free_init_mem(void)
226{
227 ftrace_boot_snapshot();
228}
aba4b5c2 229static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
33b7f99c
SRRH
230#endif
231
b7e00a6c 232/*
ba27f2bc
SRRH
233 * Note, ftrace_ops can be referenced outside of RCU protection, unless
234 * the RCU flag is set. If ftrace_ops is allocated and not part of kernel
235 * core data, the unregistering of it will perform a scheduling on all CPUs
236 * to make sure that there are no more users. Depending on the load of the
237 * system that may take a bit of time.
b7e00a6c
SRRH
238 *
239 * Any private data added must also take care not to be freed and if private
240 * data is added to a ftrace_ops that is in core code, the user of the
241 * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
242 */
16444a8a 243struct ftrace_ops {
f45948e8 244 ftrace_func_t func;
f86f4180 245 struct ftrace_ops __rcu *next;
b848914c 246 unsigned long flags;
b7e00a6c 247 void *private;
e3eea140 248 ftrace_func_t saved_func;
f45948e8 249#ifdef CONFIG_DYNAMIC_FTRACE
33b7f99c
SRRH
250 struct ftrace_ops_hash local_hash;
251 struct ftrace_ops_hash *func_hash;
fef5aeee 252 struct ftrace_ops_hash old_hash;
79922b80 253 unsigned long trampoline;
aec0be2d 254 unsigned long trampoline_size;
fc0ea795 255 struct list_head list;
f45948e8 256#endif
16444a8a
ACM
257};
258
59566b0b
SRV
259extern struct ftrace_ops __rcu *ftrace_ops_list;
260extern struct ftrace_ops ftrace_list_end;
261
262/*
40dc4a42 263 * Traverse the ftrace_ops_list, invoking all entries. The reason that we
59566b0b
SRV
264 * can use rcu_dereference_raw_check() is that elements removed from this list
265 * are simply leaked, so there is no need to interact with a grace-period
266 * mechanism. The rcu_dereference_raw_check() calls are needed to handle
40dc4a42 267 * concurrent insertions into the ftrace_ops_list.
59566b0b
SRV
268 *
269 * Silly Alpha and silly pointer-speculation compiler optimizations!
270 */
271#define do_for_each_ftrace_op(op, list) \
272 op = rcu_dereference_raw_check(list); \
273 do
274
275/*
276 * Optimized for just a single item in the list (as that is the normal case).
277 */
278#define while_for_each_ftrace_op(op) \
279 while (likely(op = rcu_dereference_raw_check((op)->next)) && \
280 unlikely((op) != &ftrace_list_end))
281
e7d3737e
FW
282/*
283 * Type of the current tracing.
284 */
285enum ftrace_tracing_type_t {
286 FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
287 FTRACE_TYPE_RETURN, /* Hook the return of the function */
288};
289
290/* Current tracing type, default is FTRACE_TYPE_ENTER */
291extern enum ftrace_tracing_type_t ftrace_tracing_type;
292
16444a8a
ACM
293/*
294 * The ftrace_ops must be a static and should also
295 * be read_mostly. These functions do modify read_mostly variables
296 * so use them sparely. Never free an ftrace_op or modify the
297 * next pointer after it has been registered. Even after unregistering
298 * it, the next pointer may still be used internally.
299 */
300int register_ftrace_function(struct ftrace_ops *ops);
301int unregister_ftrace_function(struct ftrace_ops *ops);
16444a8a 302
a1e2e31d 303extern void ftrace_stub(unsigned long a0, unsigned long a1,
d19ad077 304 struct ftrace_ops *op, struct ftrace_regs *fregs);
16444a8a 305
606576ce 306#else /* !CONFIG_FUNCTION_TRACER */
4dbf6bc2
SR
307/*
308 * (un)register_ftrace_function must be a macro since the ops parameter
309 * must not be evaluated.
310 */
311#define register_ftrace_function(ops) ({ 0; })
312#define unregister_ftrace_function(ops) ({ 0; })
81adbdc0 313static inline void ftrace_kill(void) { }
b80f0f6c 314static inline void ftrace_free_init_mem(void) { }
aba4b5c2 315static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
606576ce 316#endif /* CONFIG_FUNCTION_TRACER */
352ad25a 317
ea806eb3
SRV
318struct ftrace_func_entry {
319 struct hlist_node hlist;
320 unsigned long ip;
321 unsigned long direct; /* for direct lookup only */
322};
323
324struct dyn_ftrace;
325
763e34e7 326#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
a3ad1a7e 327extern int ftrace_direct_func_count;
763e34e7
SRV
328int register_ftrace_direct(unsigned long ip, unsigned long addr);
329int unregister_ftrace_direct(unsigned long ip, unsigned long addr);
0567d680 330int modify_ftrace_direct(unsigned long ip, unsigned long old_addr, unsigned long new_addr);
013bf0da 331struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr);
ea806eb3
SRV
332int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
333 struct dyn_ftrace *rec,
334 unsigned long old_addr,
335 unsigned long new_addr);
ff205766 336unsigned long ftrace_find_rec_direct(unsigned long ip);
f64dd462
JO
337int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
338int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
ccf5a89e
JO
339int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
340
763e34e7 341#else
f64dd462 342struct ftrace_ops;
a3ad1a7e 343# define ftrace_direct_func_count 0
763e34e7
SRV
344static inline int register_ftrace_direct(unsigned long ip, unsigned long addr)
345{
eb01fedc 346 return -ENOTSUPP;
763e34e7
SRV
347}
348static inline int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
349{
eb01fedc 350 return -ENOTSUPP;
763e34e7 351}
0567d680
SRV
352static inline int modify_ftrace_direct(unsigned long ip,
353 unsigned long old_addr, unsigned long new_addr)
354{
eb01fedc 355 return -ENOTSUPP;
0567d680 356}
013bf0da
SRV
357static inline struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr)
358{
359 return NULL;
360}
ea806eb3
SRV
361static inline int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
362 struct dyn_ftrace *rec,
363 unsigned long old_addr,
364 unsigned long new_addr)
365{
366 return -ENODEV;
367}
ff205766
AS
368static inline unsigned long ftrace_find_rec_direct(unsigned long ip)
369{
370 return 0;
371}
f64dd462
JO
372static inline int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
373{
374 return -ENODEV;
375}
376static inline int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
377{
378 return -ENODEV;
379}
ccf5a89e
JO
380static inline int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
381{
382 return -ENODEV;
383}
763e34e7
SRV
384#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
385
386#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
387/*
388 * This must be implemented by the architecture.
389 * It is the way the ftrace direct_ops helper, when called
390 * via ftrace (because there's other callbacks besides the
391 * direct call), can inform the architecture's trampoline that this
392 * routine has a direct caller, and what the caller is.
562955fe
SRV
393 *
394 * For example, in x86, it returns the direct caller
395 * callback function via the regs->orig_ax parameter.
396 * Then in the ftrace trampoline, if this is set, it makes
397 * the return from the trampoline jump to the direct caller
398 * instead of going back to the function it just traced.
763e34e7
SRV
399 */
400static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs,
401 unsigned long addr) { }
402#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
403
f38f1d2a 404#ifdef CONFIG_STACK_TRACER
bb99d8cc 405
f38f1d2a 406extern int stack_tracer_enabled;
3d9a8072 407
7ff0d449
CH
408int stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
409 size_t *lenp, loff_t *ppos);
5367278c 410
8aaf1ee7
SRV
411/* DO NOT MODIFY THIS VARIABLE DIRECTLY! */
412DECLARE_PER_CPU(int, disable_stack_tracer);
413
414/**
415 * stack_tracer_disable - temporarily disable the stack tracer
416 *
417 * There's a few locations (namely in RCU) where stack tracing
418 * cannot be executed. This function is used to disable stack
419 * tracing during those critical sections.
420 *
421 * This function must be called with preemption or interrupts
422 * disabled and stack_tracer_enable() must be called shortly after
423 * while preemption or interrupts are still disabled.
424 */
425static inline void stack_tracer_disable(void)
426{
f2cc020d 427 /* Preemption or interrupts must be disabled */
60361e12 428 if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
8aaf1ee7
SRV
429 WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
430 this_cpu_inc(disable_stack_tracer);
431}
432
433/**
434 * stack_tracer_enable - re-enable the stack tracer
435 *
436 * After stack_tracer_disable() is called, stack_tracer_enable()
437 * must be called shortly afterward.
438 */
439static inline void stack_tracer_enable(void)
440{
60361e12 441 if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
8aaf1ee7
SRV
442 WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
443 this_cpu_dec(disable_stack_tracer);
444}
5367278c
SRV
445#else
446static inline void stack_tracer_disable(void) { }
447static inline void stack_tracer_enable(void) { }
f38f1d2a
SR
448#endif
449
3d083395 450#ifdef CONFIG_DYNAMIC_FTRACE
31e88909 451
000ab691
SR
452int ftrace_arch_code_modify_prepare(void);
453int ftrace_arch_code_modify_post_process(void);
454
02a392a0
SRRH
455enum ftrace_bug_type {
456 FTRACE_BUG_UNKNOWN,
457 FTRACE_BUG_INIT,
458 FTRACE_BUG_NOP,
459 FTRACE_BUG_CALL,
460 FTRACE_BUG_UPDATE,
461};
462extern enum ftrace_bug_type ftrace_bug_type;
463
b05086c7
SRRH
464/*
465 * Archs can set this to point to a variable that holds the value that was
466 * expected at the call site before calling ftrace_bug().
467 */
468extern const void *ftrace_expected;
469
4fd3279b 470void ftrace_bug(int err, struct dyn_ftrace *rec);
c88fd863 471
809dcf29
SR
472struct seq_file;
473
d88471cb 474extern int ftrace_text_reserved(const void *start, const void *end);
2cfa1978 475
6be7fa3c
SRV
476struct ftrace_ops *ftrace_ops_trampoline(unsigned long addr);
477
aec0be2d
SRRH
478bool is_ftrace_trampoline(unsigned long addr);
479
08f6fba5
SR
480/*
481 * The dyn_ftrace record's flags field is split into two parts.
482 * the first part which is '0-FTRACE_REF_MAX' is a counter of
483 * the number of callbacks that have registered the function that
484 * the dyn_ftrace descriptor represents.
485 *
486 * The second part is a mask:
487 * ENABLED - the function is being traced
488 * REGS - the record wants the function to save regs
489 * REGS_EN - the function is set up to save regs.
f8b8be8a 490 * IPMODIFY - the record allows for the IP address to be changed.
b7ffffbb 491 * DISABLED - the record is not ready to be touched yet
763e34e7 492 * DIRECT - there is a direct function to call
08f6fba5
SR
493 *
494 * When a new ftrace_ops is registered and wants a function to save
02dae28f 495 * pt_regs, the rec->flags REGS is set. When the function has been
08f6fba5
SR
496 * set up to save regs, the REG_EN flag is set. Once a function
497 * starts saving regs it will do so until all ftrace_ops are removed
498 * from tracing that function.
499 */
3c1720f0 500enum {
79922b80 501 FTRACE_FL_ENABLED = (1UL << 31),
08f6fba5 502 FTRACE_FL_REGS = (1UL << 30),
79922b80
SRRH
503 FTRACE_FL_REGS_EN = (1UL << 29),
504 FTRACE_FL_TRAMP = (1UL << 28),
505 FTRACE_FL_TRAMP_EN = (1UL << 27),
f8b8be8a 506 FTRACE_FL_IPMODIFY = (1UL << 26),
b7ffffbb 507 FTRACE_FL_DISABLED = (1UL << 25),
763e34e7
SRV
508 FTRACE_FL_DIRECT = (1UL << 24),
509 FTRACE_FL_DIRECT_EN = (1UL << 23),
3c1720f0
SR
510};
511
763e34e7 512#define FTRACE_REF_MAX_SHIFT 23
cf2cb0b2 513#define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
ed926f9b 514
02dae28f 515#define ftrace_rec_count(rec) ((rec)->flags & FTRACE_REF_MAX)
0376bde1 516
3d083395 517struct dyn_ftrace {
a762782d 518 unsigned long ip; /* address of mcount call-site */
85ae32ae 519 unsigned long flags;
a762782d 520 struct dyn_arch_ftrace arch;
3d083395
SR
521};
522
647664ea
MH
523int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
524 int remove, int reset);
4f554e95
JO
525int ftrace_set_filter_ips(struct ftrace_ops *ops, unsigned long *ips,
526 unsigned int cnt, int remove, int reset);
ac483c44 527int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
936e074b 528 int len, int reset);
ac483c44 529int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
936e074b
SR
530 int len, int reset);
531void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
532void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
5500fa51 533void ftrace_free_filter(struct ftrace_ops *ops);
d032ae89 534void ftrace_ops_set_global_filter(struct ftrace_ops *ops);
e1c08bdd 535
c88fd863
SR
536enum {
537 FTRACE_UPDATE_CALLS = (1 << 0),
538 FTRACE_DISABLE_CALLS = (1 << 1),
539 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
540 FTRACE_START_FUNC_RET = (1 << 3),
541 FTRACE_STOP_FUNC_RET = (1 << 4),
a0572f68 542 FTRACE_MAY_SLEEP = (1 << 5),
c88fd863
SR
543};
544
08f6fba5
SR
545/*
546 * The FTRACE_UPDATE_* enum is used to pass information back
547 * from the ftrace_update_record() and ftrace_test_record()
548 * functions. These are called by the code update routines
549 * to find out what is to be done for a given function.
550 *
551 * IGNORE - The function is already what we want it to be
552 * MAKE_CALL - Start tracing the function
553 * MODIFY_CALL - Stop saving regs for the function
08f6fba5
SR
554 * MAKE_NOP - Stop tracing the function
555 */
c88fd863
SR
556enum {
557 FTRACE_UPDATE_IGNORE,
558 FTRACE_UPDATE_MAKE_CALL,
08f6fba5 559 FTRACE_UPDATE_MODIFY_CALL,
c88fd863
SR
560 FTRACE_UPDATE_MAKE_NOP,
561};
562
fc13cb0c
SR
563enum {
564 FTRACE_ITER_FILTER = (1 << 0),
565 FTRACE_ITER_NOTRACE = (1 << 1),
566 FTRACE_ITER_PRINTALL = (1 << 2),
eee8ded1
SRV
567 FTRACE_ITER_DO_PROBES = (1 << 3),
568 FTRACE_ITER_PROBE = (1 << 4),
5985ea8b
SRV
569 FTRACE_ITER_MOD = (1 << 5),
570 FTRACE_ITER_ENABLED = (1 << 6),
fc13cb0c
SR
571};
572
c88fd863 573void arch_ftrace_update_code(int command);
89f579ce
YW
574void arch_ftrace_update_trampoline(struct ftrace_ops *ops);
575void *arch_ftrace_trampoline_func(struct ftrace_ops *ops, struct dyn_ftrace *rec);
576void arch_ftrace_trampoline_free(struct ftrace_ops *ops);
c88fd863
SR
577
578struct ftrace_rec_iter;
579
580struct ftrace_rec_iter *ftrace_rec_iter_start(void);
581struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
582struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
583
08d636b6
SR
584#define for_ftrace_rec_iter(iter) \
585 for (iter = ftrace_rec_iter_start(); \
586 iter; \
587 iter = ftrace_rec_iter_next(iter))
588
589
7375dca1
SRV
590int ftrace_update_record(struct dyn_ftrace *rec, bool enable);
591int ftrace_test_record(struct dyn_ftrace *rec, bool enable);
c88fd863 592void ftrace_run_stop_machine(int command);
f0cf973a 593unsigned long ftrace_location(unsigned long ip);
04cf31a7 594unsigned long ftrace_location_range(unsigned long start, unsigned long end);
7413af1f
SRRH
595unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
596unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
c88fd863
SR
597
598extern ftrace_func_t ftrace_trace_function;
599
fc13cb0c
SR
600int ftrace_regex_open(struct ftrace_ops *ops, int flag,
601 struct inode *inode, struct file *file);
602ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
603 size_t cnt, loff_t *ppos);
604ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
605 size_t cnt, loff_t *ppos);
fc13cb0c
SR
606int ftrace_regex_release(struct inode *inode, struct file *file);
607
2a85a37f
SR
608void __init
609ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
610
3d083395 611/* defined in arch */
3c1720f0 612extern int ftrace_ip_converted(unsigned long ip);
3a36cb11 613extern int ftrace_dyn_arch_init(void);
e4f5d544 614extern void ftrace_replace_code(int enable);
d61f82d0
SR
615extern int ftrace_update_ftrace_func(ftrace_func_t func);
616extern void ftrace_caller(void);
08f6fba5 617extern void ftrace_regs_caller(void);
d61f82d0 618extern void ftrace_call(void);
08f6fba5 619extern void ftrace_regs_call(void);
d61f82d0 620extern void mcount_call(void);
f0001207 621
8ed3e2cf
SR
622void ftrace_modify_all_code(int command);
623
f0001207
SL
624#ifndef FTRACE_ADDR
625#define FTRACE_ADDR ((unsigned long)ftrace_caller)
626#endif
08f6fba5 627
79922b80
SRRH
628#ifndef FTRACE_GRAPH_ADDR
629#define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
630#endif
631
08f6fba5 632#ifndef FTRACE_REGS_ADDR
06aeaaea 633#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
08f6fba5
SR
634# define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
635#else
636# define FTRACE_REGS_ADDR FTRACE_ADDR
637#endif
638#endif
639
646d7043
SRRH
640/*
641 * If an arch would like functions that are only traced
642 * by the function graph tracer to jump directly to its own
643 * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
644 * to be that address to jump to.
645 */
646#ifndef FTRACE_GRAPH_TRAMP_ADDR
647#define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
648#endif
649
fb52607a
FW
650#ifdef CONFIG_FUNCTION_GRAPH_TRACER
651extern void ftrace_graph_caller(void);
5a45cfe1
SR
652extern int ftrace_enable_ftrace_graph_caller(void);
653extern int ftrace_disable_ftrace_graph_caller(void);
654#else
655static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
656static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
e7d3737e 657#endif
ad90c0e3 658
31e88909 659/**
57794a9d 660 * ftrace_make_nop - convert code into nop
31e88909 661 * @mod: module structure if called by module load initialization
fbf6c73c 662 * @rec: the call site record (e.g. mcount/fentry)
31e88909
SR
663 * @addr: the address that the call site should be calling
664 *
665 * This is a very sensitive operation and great care needs
666 * to be taken by the arch. The operation should carefully
667 * read the location, check to see if what is read is indeed
668 * what we expect it to be, and then on success of the compare,
669 * it should write to the location.
670 *
671 * The code segment at @rec->ip should be a caller to @addr
672 *
673 * Return must be:
674 * 0 on success
675 * -EFAULT on error reading the location
676 * -EINVAL on a failed compare of the contents
677 * -EPERM on error writing to the location
678 * Any other value will be considered a failure.
679 */
680extern int ftrace_make_nop(struct module *mod,
681 struct dyn_ftrace *rec, unsigned long addr);
a26a2a27 682
67ccddf8
IL
683/**
684 * ftrace_need_init_nop - return whether nop call sites should be initialized
685 *
686 * Normally the compiler's -mnop-mcount generates suitable nops, so we don't
687 * need to call ftrace_init_nop() if the code is built with that flag.
688 * Architectures where this is not always the case may define their own
689 * condition.
690 *
691 * Return must be:
692 * 0 if ftrace_init_nop() should be called
693 * Nonzero if ftrace_init_nop() should not be called
694 */
695
696#ifndef ftrace_need_init_nop
697#define ftrace_need_init_nop() (!__is_defined(CC_USING_NOP_MCOUNT))
698#endif
fbf6c73c
MR
699
700/**
701 * ftrace_init_nop - initialize a nop call site
702 * @mod: module structure if called by module load initialization
703 * @rec: the call site record (e.g. mcount/fentry)
704 *
705 * This is a very sensitive operation and great care needs
706 * to be taken by the arch. The operation should carefully
707 * read the location, check to see if what is read is indeed
708 * what we expect it to be, and then on success of the compare,
709 * it should write to the location.
710 *
711 * The code segment at @rec->ip should contain the contents created by
712 * the compiler
713 *
714 * Return must be:
715 * 0 on success
716 * -EFAULT on error reading the location
717 * -EINVAL on a failed compare of the contents
718 * -EPERM on error writing to the location
719 * Any other value will be considered a failure.
720 */
721#ifndef ftrace_init_nop
722static inline int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
723{
724 return ftrace_make_nop(mod, rec, MCOUNT_ADDR);
725}
726#endif
727
593eb8a2 728/**
31e88909 729 * ftrace_make_call - convert a nop call site into a call to addr
fbf6c73c 730 * @rec: the call site record (e.g. mcount/fentry)
31e88909 731 * @addr: the address that the call site should call
593eb8a2
SR
732 *
733 * This is a very sensitive operation and great care needs
734 * to be taken by the arch. The operation should carefully
735 * read the location, check to see if what is read is indeed
736 * what we expect it to be, and then on success of the compare,
737 * it should write to the location.
738 *
31e88909
SR
739 * The code segment at @rec->ip should be a nop
740 *
593eb8a2
SR
741 * Return must be:
742 * 0 on success
743 * -EFAULT on error reading the location
744 * -EINVAL on a failed compare of the contents
745 * -EPERM on error writing to the location
746 * Any other value will be considered a failure.
747 */
31e88909
SR
748extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
749
06aeaaea 750#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
08f6fba5
SR
751/**
752 * ftrace_modify_call - convert from one addr to another (no nop)
fbf6c73c 753 * @rec: the call site record (e.g. mcount/fentry)
08f6fba5
SR
754 * @old_addr: the address expected to be currently called to
755 * @addr: the address to change to
756 *
757 * This is a very sensitive operation and great care needs
758 * to be taken by the arch. The operation should carefully
759 * read the location, check to see if what is read is indeed
760 * what we expect it to be, and then on success of the compare,
761 * it should write to the location.
762 *
763 * The code segment at @rec->ip should be a caller to @old_addr
764 *
765 * Return must be:
766 * 0 on success
767 * -EFAULT on error reading the location
768 * -EINVAL on a failed compare of the contents
769 * -EPERM on error writing to the location
770 * Any other value will be considered a failure.
771 */
772extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
773 unsigned long addr);
774#else
775/* Should never be called */
776static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
777 unsigned long addr)
778{
779 return -EINVAL;
780}
781#endif
782
31e88909
SR
783/* May be defined in arch */
784extern int ftrace_arch_read_dyn_info(char *buf, int size);
593eb8a2 785
ecea656d 786extern int skip_trace(unsigned long ip);
a949ae56 787extern void ftrace_module_init(struct module *mod);
7dcd182b 788extern void ftrace_module_enable(struct module *mod);
049fb9bd 789extern void ftrace_release_mod(struct module *mod);
ecea656d 790
c0719e5a
SR
791extern void ftrace_disable_daemon(void);
792extern void ftrace_enable_daemon(void);
4dc93676 793#else /* CONFIG_DYNAMIC_FTRACE */
4dbf6bc2 794static inline int skip_trace(unsigned long ip) { return 0; }
4dbf6bc2
SR
795static inline void ftrace_disable_daemon(void) { }
796static inline void ftrace_enable_daemon(void) { }
7dcd182b
JY
797static inline void ftrace_module_init(struct module *mod) { }
798static inline void ftrace_module_enable(struct module *mod) { }
799static inline void ftrace_release_mod(struct module *mod) { }
d88471cb 800static inline int ftrace_text_reserved(const void *start, const void *end)
2cfa1978
MH
801{
802 return 0;
803}
4dc93676
SR
804static inline unsigned long ftrace_location(unsigned long ip)
805{
806 return 0;
807}
fc13cb0c
SR
808
809/*
810 * Again users of functions that have ftrace_ops may not
811 * have them defined when ftrace is not enabled, but these
812 * functions may still be called. Use a macro instead of inline.
813 */
814#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
96de37b6 815#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
647664ea 816#define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
4f554e95 817#define ftrace_set_filter_ips(ops, ips, cnt, remove, reset) ({ -ENODEV; })
5500fa51
JO
818#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
819#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
820#define ftrace_free_filter(ops) do { } while (0)
d032ae89 821#define ftrace_ops_set_global_filter(ops) do { } while (0)
fc13cb0c
SR
822
823static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
824 size_t cnt, loff_t *ppos) { return -ENODEV; }
825static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
826 size_t cnt, loff_t *ppos) { return -ENODEV; }
fc13cb0c
SR
827static inline int
828ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
aec0be2d
SRRH
829
830static inline bool is_ftrace_trampoline(unsigned long addr)
831{
832 return false;
833}
ecea656d 834#endif /* CONFIG_DYNAMIC_FTRACE */
352ad25a 835
0c0593b4
SRV
836#ifdef CONFIG_FUNCTION_GRAPH_TRACER
837#ifndef ftrace_graph_func
838#define ftrace_graph_func ftrace_stub
839#define FTRACE_OPS_GRAPH_STUB FTRACE_OPS_FL_STUB
840#else
841#define FTRACE_OPS_GRAPH_STUB 0
842#endif
843#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
844
aeaee8a2
IM
845/* totally disable ftrace - can not re-enable after this */
846void ftrace_kill(void);
847
f43fdad8
IM
848static inline void tracer_disable(void)
849{
606576ce 850#ifdef CONFIG_FUNCTION_TRACER
f43fdad8
IM
851 ftrace_enabled = 0;
852#endif
853}
854
37002735
HY
855/*
856 * Ftrace disable/restore without lock. Some synchronization mechanism
9bdeb7b5 857 * must be used to prevent ftrace_enabled to be changed between
37002735
HY
858 * disable/restore.
859 */
9bdeb7b5
HY
860static inline int __ftrace_enabled_save(void)
861{
606576ce 862#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
863 int saved_ftrace_enabled = ftrace_enabled;
864 ftrace_enabled = 0;
865 return saved_ftrace_enabled;
866#else
867 return 0;
868#endif
869}
870
871static inline void __ftrace_enabled_restore(int enabled)
872{
606576ce 873#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
874 ftrace_enabled = enabled;
875#endif
876}
877
eed542d6
AT
878/* All archs should have this, but we define it for consistency */
879#ifndef ftrace_return_address0
880# define ftrace_return_address0 __builtin_return_address(0)
881#endif
882
883/* Archs may use other ways for ADDR1 and beyond */
884#ifndef ftrace_return_address
c79a61f5 885# ifdef CONFIG_FRAME_POINTER
eed542d6 886# define ftrace_return_address(n) __builtin_return_address(n)
c79a61f5 887# else
eed542d6 888# define ftrace_return_address(n) 0UL
c79a61f5 889# endif
eed542d6
AT
890#endif
891
892#define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
893#define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
894#define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
895#define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
896#define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
897#define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
898#define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
352ad25a 899
f904f582
SAS
900static inline unsigned long get_lock_parent_ip(void)
901{
902 unsigned long addr = CALLER_ADDR0;
903
904 if (!in_lock_functions(addr))
905 return addr;
906 addr = CALLER_ADDR1;
907 if (!in_lock_functions(addr))
908 return addr;
909 return CALLER_ADDR2;
910}
911
c3bc8fd6 912#ifdef CONFIG_TRACE_PREEMPT_TOGGLE
489f1396
IM
913 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
914 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
6cd8a4bb 915#else
b02ee9a3
MB
916/*
917 * Use defines instead of static inlines because some arches will make code out
918 * of the CALLER_ADDR, when we really want these to be a real nop.
919 */
920# define trace_preempt_on(a0, a1) do { } while (0)
921# define trace_preempt_off(a0, a1) do { } while (0)
6cd8a4bb
SR
922#endif
923
68bf21aa
SR
924#ifdef CONFIG_FTRACE_MCOUNT_RECORD
925extern void ftrace_init(void);
a1326b17
MR
926#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
927#define FTRACE_CALLSITE_SECTION "__patchable_function_entries"
928#else
929#define FTRACE_CALLSITE_SECTION "__mcount_loc"
930#endif
68bf21aa
SR
931#else
932static inline void ftrace_init(void) { }
933#endif
934
287b6e68
FW
935/*
936 * Structure that defines an entry function trace.
a4a551b8
NK
937 * It's already packed but the attribute "packed" is needed
938 * to remove extra padding at the end.
287b6e68
FW
939 */
940struct ftrace_graph_ent {
941 unsigned long func; /* Current function */
942 int depth;
a4a551b8 943} __packed;
dd0e545f 944
caf4b323
FW
945/*
946 * Structure that defines a return function trace.
a4a551b8
NK
947 * It's already packed but the attribute "packed" is needed
948 * to remove extra padding at the end.
caf4b323 949 */
fb52607a 950struct ftrace_graph_ret {
caf4b323 951 unsigned long func; /* Current function */
60602cb5 952 int depth;
0231022c 953 /* Number of functions that overran the depth limit for current task */
60602cb5 954 unsigned int overrun;
a4a551b8
NK
955 unsigned long long calltime;
956 unsigned long long rettime;
a4a551b8 957} __packed;
caf4b323 958
62b915f1
JO
959/* Type of the callback handlers for tracing function graph*/
960typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
961typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
962
e8025bab
SRV
963extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
964
fb52607a 965#ifdef CONFIG_FUNCTION_GRAPH_TRACER
8b96f011 966
688f7089
SRV
967struct fgraph_ops {
968 trace_func_graph_ent_t entryfunc;
969 trace_func_graph_ret_t retfunc;
970};
971
712406a6
SR
972/*
973 * Stack of return addresses for functions
974 * of a thread.
975 * Used in struct thread_info
976 */
977struct ftrace_ret_stack {
978 unsigned long ret;
979 unsigned long func;
980 unsigned long long calltime;
8861dd30 981#ifdef CONFIG_FUNCTION_PROFILER
a2a16d6a 982 unsigned long long subtime;
8861dd30 983#endif
daa460a8 984#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
71e308a2 985 unsigned long fp;
daa460a8 986#endif
9a7c348b
JP
987#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
988 unsigned long *retp;
989#endif
712406a6
SR
990};
991
992/*
993 * Primary handler of a function return.
994 * It relays on ftrace_return_to_handler.
995 * Defined in entry_32/64.S
996 */
997extern void return_to_handler(void);
998
999extern int
8114865f
SRV
1000function_graph_enter(unsigned long ret, unsigned long func,
1001 unsigned long frame_pointer, unsigned long *retp);
712406a6 1002
b0e21a61
SRV
1003struct ftrace_ret_stack *
1004ftrace_graph_get_ret_stack(struct task_struct *task, int idx);
1005
223918e3
JP
1006unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
1007 unsigned long ret, unsigned long *retp);
1008
8b96f011
FW
1009/*
1010 * Sometimes we don't want to trace a function with the function
1011 * graph tracer but we want them to keep traced by the usual function
1012 * tracer if the function graph tracer is not configured.
1013 */
1014#define __notrace_funcgraph notrace
1015
f201ae23
FW
1016#define FTRACE_RETFUNC_DEPTH 50
1017#define FTRACE_RETSTACK_ALLOC_SIZE 32
688f7089
SRV
1018
1019extern int register_ftrace_graph(struct fgraph_ops *ops);
1020extern void unregister_ftrace_graph(struct fgraph_ops *ops);
287b6e68 1021
18bfee32
CL
1022/**
1023 * ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
1024 *
1025 * ftrace_graph_stop() is called when a severe error is detected in
1026 * the function graph tracing. This function is called by the critical
1027 * paths of function graph to keep those paths from doing any more harm.
1028 */
1029DECLARE_STATIC_KEY_FALSE(kill_ftrace_graph);
1030
1031static inline bool ftrace_graph_is_dead(void)
1032{
1033 return static_branch_unlikely(&kill_ftrace_graph);
1034}
1035
14a866c5
SR
1036extern void ftrace_graph_stop(void);
1037
287b6e68
FW
1038/* The current handlers in use */
1039extern trace_func_graph_ret_t ftrace_graph_return;
1040extern trace_func_graph_ent_t ftrace_graph_entry;
caf4b323 1041
fb52607a
FW
1042extern void ftrace_graph_init_task(struct task_struct *t);
1043extern void ftrace_graph_exit_task(struct task_struct *t);
868baf07 1044extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
21a8c466 1045
380c4b14
FW
1046static inline void pause_graph_tracing(void)
1047{
1048 atomic_inc(&current->tracing_graph_pause);
1049}
1050
1051static inline void unpause_graph_tracing(void)
1052{
1053 atomic_dec(&current->tracing_graph_pause);
1054}
5ac9f622 1055#else /* !CONFIG_FUNCTION_GRAPH_TRACER */
8b96f011
FW
1056
1057#define __notrace_funcgraph
1058
fb52607a
FW
1059static inline void ftrace_graph_init_task(struct task_struct *t) { }
1060static inline void ftrace_graph_exit_task(struct task_struct *t) { }
868baf07 1061static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
21a8c466 1062
688f7089
SRV
1063/* Define as macros as fgraph_ops may not be defined */
1064#define register_ftrace_graph(ops) ({ -1; })
1065#define unregister_ftrace_graph(ops) do { } while (0)
380c4b14 1066
223918e3
JP
1067static inline unsigned long
1068ftrace_graph_ret_addr(struct task_struct *task, int *idx, unsigned long ret,
1069 unsigned long *retp)
1070{
1071 return ret;
1072}
1073
380c4b14
FW
1074static inline void pause_graph_tracing(void) { }
1075static inline void unpause_graph_tracing(void) { }
5ac9f622 1076#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
caf4b323 1077
ea4e2bc4 1078#ifdef CONFIG_TRACING
ea4e2bc4
SR
1079
1080/* flags for current->trace */
1081enum {
1082 TSK_TRACE_FL_TRACE_BIT = 0,
1083 TSK_TRACE_FL_GRAPH_BIT = 1,
1084};
1085enum {
1086 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
1087 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
1088};
1089
1090static inline void set_tsk_trace_trace(struct task_struct *tsk)
1091{
1092 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
1093}
1094
1095static inline void clear_tsk_trace_trace(struct task_struct *tsk)
1096{
1097 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
1098}
1099
1100static inline int test_tsk_trace_trace(struct task_struct *tsk)
1101{
1102 return tsk->trace & TSK_TRACE_FL_TRACE;
1103}
1104
1105static inline void set_tsk_trace_graph(struct task_struct *tsk)
1106{
1107 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
1108}
1109
1110static inline void clear_tsk_trace_graph(struct task_struct *tsk)
1111{
1112 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
1113}
1114
1115static inline int test_tsk_trace_graph(struct task_struct *tsk)
1116{
1117 return tsk->trace & TSK_TRACE_FL_GRAPH;
1118}
1119
cecbca96
FW
1120enum ftrace_dump_mode;
1121
1122extern enum ftrace_dump_mode ftrace_dump_on_oops;
0daa2302 1123extern int tracepoint_printk;
526211bc 1124
de7edd31
SRRH
1125extern void disable_trace_on_warning(void);
1126extern int __disable_trace_on_warning;
1127
42391745 1128int tracepoint_printk_sysctl(struct ctl_table *table, int write,
32927393 1129 void *buffer, size_t *lenp, loff_t *ppos);
42391745 1130
de7edd31
SRRH
1131#else /* CONFIG_TRACING */
1132static inline void disable_trace_on_warning(void) { }
ea4e2bc4
SR
1133#endif /* CONFIG_TRACING */
1134
e7b8e675
MF
1135#ifdef CONFIG_FTRACE_SYSCALLS
1136
1137unsigned long arch_syscall_addr(int nr);
1138
1139#endif /* CONFIG_FTRACE_SYSCALLS */
1140
16444a8a 1141#endif /* _LINUX_FTRACE_H */