ftrace: Add new type to distinguish what kind of ftrace_bug()
[cascardo/linux.git] / include / linux / ftrace.h
1 /*
2  * Ftrace header.  For implementation details beyond the random comments
3  * scattered below, see: Documentation/trace/ftrace-design.txt
4  */
5
6 #ifndef _LINUX_FTRACE_H
7 #define _LINUX_FTRACE_H
8
9 #include <linux/trace_clock.h>
10 #include <linux/kallsyms.h>
11 #include <linux/linkage.h>
12 #include <linux/bitops.h>
13 #include <linux/ptrace.h>
14 #include <linux/ktime.h>
15 #include <linux/sched.h>
16 #include <linux/types.h>
17 #include <linux/init.h>
18 #include <linux/fs.h>
19
20 #include <asm/ftrace.h>
21
22 /*
23  * If the arch supports passing the variable contents of
24  * function_trace_op as the third parameter back from the
25  * mcount call, then the arch should define this as 1.
26  */
27 #ifndef ARCH_SUPPORTS_FTRACE_OPS
28 #define ARCH_SUPPORTS_FTRACE_OPS 0
29 #endif
30
31 /*
32  * If the arch's mcount caller does not support all of ftrace's
33  * features, then it must call an indirect function that
34  * does. Or at least does enough to prevent any unwelcomed side effects.
35  */
36 #if !ARCH_SUPPORTS_FTRACE_OPS
37 # define FTRACE_FORCE_LIST_FUNC 1
38 #else
39 # define FTRACE_FORCE_LIST_FUNC 0
40 #endif
41
42 /* Main tracing buffer and events set up */
43 #ifdef CONFIG_TRACING
44 void trace_init(void);
45 #else
46 static inline void trace_init(void) { }
47 #endif
48
49 struct module;
50 struct ftrace_hash;
51
52 #ifdef CONFIG_FUNCTION_TRACER
53
54 extern int ftrace_enabled;
55 extern int
56 ftrace_enable_sysctl(struct ctl_table *table, int write,
57                      void __user *buffer, size_t *lenp,
58                      loff_t *ppos);
59
60 struct ftrace_ops;
61
62 typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
63                               struct ftrace_ops *op, struct pt_regs *regs);
64
65 ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
66
67 /*
68  * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
69  * set in the flags member.
70  * CONTROL, SAVE_REGS, SAVE_REGS_IF_SUPPORTED, RECURSION_SAFE, STUB and
71  * IPMODIFY are a kind of attribute flags which can be set only before
72  * registering the ftrace_ops, and can not be modified while registered.
73  * Changing those attribute flags after regsitering ftrace_ops will
74  * cause unexpected results.
75  *
76  * ENABLED - set/unset when ftrace_ops is registered/unregistered
77  * DYNAMIC - set when ftrace_ops is registered to denote dynamically
78  *           allocated ftrace_ops which need special care
79  * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
80  *           could be controled by following calls:
81  *             ftrace_function_local_enable
82  *             ftrace_function_local_disable
83  * SAVE_REGS - The ftrace_ops wants regs saved at each function called
84  *            and passed to the callback. If this flag is set, but the
85  *            architecture does not support passing regs
86  *            (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
87  *            ftrace_ops will fail to register, unless the next flag
88  *            is set.
89  * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
90  *            handler can handle an arch that does not save regs
91  *            (the handler tests if regs == NULL), then it can set
92  *            this flag instead. It will not fail registering the ftrace_ops
93  *            but, the regs field will be NULL if the arch does not support
94  *            passing regs to the handler.
95  *            Note, if this flag is set, the SAVE_REGS flag will automatically
96  *            get set upon registering the ftrace_ops, if the arch supports it.
97  * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
98  *            that the call back has its own recursion protection. If it does
99  *            not set this, then the ftrace infrastructure will add recursion
100  *            protection for the caller.
101  * STUB   - The ftrace_ops is just a place holder.
102  * INITIALIZED - The ftrace_ops has already been initialized (first use time
103  *            register_ftrace_function() is called, it will initialized the ops)
104  * DELETED - The ops are being deleted, do not let them be registered again.
105  * ADDING  - The ops is in the process of being added.
106  * REMOVING - The ops is in the process of being removed.
107  * MODIFYING - The ops is in the process of changing its filter functions.
108  * ALLOC_TRAMP - A dynamic trampoline was allocated by the core code.
109  *            The arch specific code sets this flag when it allocated a
110  *            trampoline. This lets the arch know that it can update the
111  *            trampoline in case the callback function changes.
112  *            The ftrace_ops trampoline can be set by the ftrace users, and
113  *            in such cases the arch must not modify it. Only the arch ftrace
114  *            core code should set this flag.
115  * IPMODIFY - The ops can modify the IP register. This can only be set with
116  *            SAVE_REGS. If another ops with this flag set is already registered
117  *            for any of the functions that this ops will be registered for, then
118  *            this ops will fail to register or set_filter_ip.
119  * PID     - Is affected by set_ftrace_pid (allows filtering on those pids)
120  */
121 enum {
122         FTRACE_OPS_FL_ENABLED                   = 1 << 0,
123         FTRACE_OPS_FL_DYNAMIC                   = 1 << 1,
124         FTRACE_OPS_FL_CONTROL                   = 1 << 2,
125         FTRACE_OPS_FL_SAVE_REGS                 = 1 << 3,
126         FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED    = 1 << 4,
127         FTRACE_OPS_FL_RECURSION_SAFE            = 1 << 5,
128         FTRACE_OPS_FL_STUB                      = 1 << 6,
129         FTRACE_OPS_FL_INITIALIZED               = 1 << 7,
130         FTRACE_OPS_FL_DELETED                   = 1 << 8,
131         FTRACE_OPS_FL_ADDING                    = 1 << 9,
132         FTRACE_OPS_FL_REMOVING                  = 1 << 10,
133         FTRACE_OPS_FL_MODIFYING                 = 1 << 11,
134         FTRACE_OPS_FL_ALLOC_TRAMP               = 1 << 12,
135         FTRACE_OPS_FL_IPMODIFY                  = 1 << 13,
136         FTRACE_OPS_FL_PID                       = 1 << 14,
137 };
138
139 #ifdef CONFIG_DYNAMIC_FTRACE
140 /* The hash used to know what functions callbacks trace */
141 struct ftrace_ops_hash {
142         struct ftrace_hash              *notrace_hash;
143         struct ftrace_hash              *filter_hash;
144         struct mutex                    regex_lock;
145 };
146 #endif
147
148 /*
149  * Note, ftrace_ops can be referenced outside of RCU protection.
150  * (Although, for perf, the control ops prevent that). If ftrace_ops is
151  * allocated and not part of kernel core data, the unregistering of it will
152  * perform a scheduling on all CPUs to make sure that there are no more users.
153  * Depending on the load of the system that may take a bit of time.
154  *
155  * Any private data added must also take care not to be freed and if private
156  * data is added to a ftrace_ops that is in core code, the user of the
157  * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
158  */
159 struct ftrace_ops {
160         ftrace_func_t                   func;
161         struct ftrace_ops               *next;
162         unsigned long                   flags;
163         void                            *private;
164         ftrace_func_t                   saved_func;
165         int __percpu                    *disabled;
166 #ifdef CONFIG_DYNAMIC_FTRACE
167         int                             nr_trampolines;
168         struct ftrace_ops_hash          local_hash;
169         struct ftrace_ops_hash          *func_hash;
170         struct ftrace_ops_hash          old_hash;
171         unsigned long                   trampoline;
172         unsigned long                   trampoline_size;
173 #endif
174 };
175
176 /*
177  * Type of the current tracing.
178  */
179 enum ftrace_tracing_type_t {
180         FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
181         FTRACE_TYPE_RETURN,     /* Hook the return of the function */
182 };
183
184 /* Current tracing type, default is FTRACE_TYPE_ENTER */
185 extern enum ftrace_tracing_type_t ftrace_tracing_type;
186
187 /*
188  * The ftrace_ops must be a static and should also
189  * be read_mostly.  These functions do modify read_mostly variables
190  * so use them sparely. Never free an ftrace_op or modify the
191  * next pointer after it has been registered. Even after unregistering
192  * it, the next pointer may still be used internally.
193  */
194 int register_ftrace_function(struct ftrace_ops *ops);
195 int unregister_ftrace_function(struct ftrace_ops *ops);
196 void clear_ftrace_function(void);
197
198 /**
199  * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
200  *
201  * This function enables tracing on current cpu by decreasing
202  * the per cpu control variable.
203  * It must be called with preemption disabled and only on ftrace_ops
204  * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
205  * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
206  */
207 static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
208 {
209         if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
210                 return;
211
212         (*this_cpu_ptr(ops->disabled))--;
213 }
214
215 /**
216  * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
217  *
218  * This function enables tracing on current cpu by decreasing
219  * the per cpu control variable.
220  * It must be called with preemption disabled and only on ftrace_ops
221  * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
222  * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
223  */
224 static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
225 {
226         if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
227                 return;
228
229         (*this_cpu_ptr(ops->disabled))++;
230 }
231
232 /**
233  * ftrace_function_local_disabled - returns ftrace_ops disabled value
234  *                                  on current cpu
235  *
236  * This function returns value of ftrace_ops::disabled on current cpu.
237  * It must be called with preemption disabled and only on ftrace_ops
238  * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
239  * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
240  */
241 static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
242 {
243         WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
244         return *this_cpu_ptr(ops->disabled);
245 }
246
247 extern void ftrace_stub(unsigned long a0, unsigned long a1,
248                         struct ftrace_ops *op, struct pt_regs *regs);
249
250 #else /* !CONFIG_FUNCTION_TRACER */
251 /*
252  * (un)register_ftrace_function must be a macro since the ops parameter
253  * must not be evaluated.
254  */
255 #define register_ftrace_function(ops) ({ 0; })
256 #define unregister_ftrace_function(ops) ({ 0; })
257 static inline int ftrace_nr_registered_ops(void)
258 {
259         return 0;
260 }
261 static inline void clear_ftrace_function(void) { }
262 static inline void ftrace_kill(void) { }
263 #endif /* CONFIG_FUNCTION_TRACER */
264
265 #ifdef CONFIG_STACK_TRACER
266
267 #define STACK_TRACE_ENTRIES 500
268
269 struct stack_trace;
270
271 extern unsigned stack_trace_index[];
272 extern struct stack_trace stack_trace_max;
273 extern unsigned long stack_trace_max_size;
274 extern arch_spinlock_t stack_trace_max_lock;
275
276 extern int stack_tracer_enabled;
277 void stack_trace_print(void);
278 int
279 stack_trace_sysctl(struct ctl_table *table, int write,
280                    void __user *buffer, size_t *lenp,
281                    loff_t *ppos);
282 #endif
283
284 struct ftrace_func_command {
285         struct list_head        list;
286         char                    *name;
287         int                     (*func)(struct ftrace_hash *hash,
288                                         char *func, char *cmd,
289                                         char *params, int enable);
290 };
291
292 #ifdef CONFIG_DYNAMIC_FTRACE
293
294 int ftrace_arch_code_modify_prepare(void);
295 int ftrace_arch_code_modify_post_process(void);
296
297 struct dyn_ftrace;
298
299 enum ftrace_bug_type {
300         FTRACE_BUG_UNKNOWN,
301         FTRACE_BUG_INIT,
302         FTRACE_BUG_NOP,
303         FTRACE_BUG_CALL,
304         FTRACE_BUG_UPDATE,
305 };
306 extern enum ftrace_bug_type ftrace_bug_type;
307
308 void ftrace_bug(int err, struct dyn_ftrace *rec);
309
310 struct seq_file;
311
312 struct ftrace_probe_ops {
313         void                    (*func)(unsigned long ip,
314                                         unsigned long parent_ip,
315                                         void **data);
316         int                     (*init)(struct ftrace_probe_ops *ops,
317                                         unsigned long ip, void **data);
318         void                    (*free)(struct ftrace_probe_ops *ops,
319                                         unsigned long ip, void **data);
320         int                     (*print)(struct seq_file *m,
321                                          unsigned long ip,
322                                          struct ftrace_probe_ops *ops,
323                                          void *data);
324 };
325
326 extern int
327 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
328                               void *data);
329 extern void
330 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
331                                 void *data);
332 extern void
333 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
334 extern void unregister_ftrace_function_probe_all(char *glob);
335
336 extern int ftrace_text_reserved(const void *start, const void *end);
337
338 extern int ftrace_nr_registered_ops(void);
339
340 bool is_ftrace_trampoline(unsigned long addr);
341
342 /*
343  * The dyn_ftrace record's flags field is split into two parts.
344  * the first part which is '0-FTRACE_REF_MAX' is a counter of
345  * the number of callbacks that have registered the function that
346  * the dyn_ftrace descriptor represents.
347  *
348  * The second part is a mask:
349  *  ENABLED - the function is being traced
350  *  REGS    - the record wants the function to save regs
351  *  REGS_EN - the function is set up to save regs.
352  *  IPMODIFY - the record allows for the IP address to be changed.
353  *
354  * When a new ftrace_ops is registered and wants a function to save
355  * pt_regs, the rec->flag REGS is set. When the function has been
356  * set up to save regs, the REG_EN flag is set. Once a function
357  * starts saving regs it will do so until all ftrace_ops are removed
358  * from tracing that function.
359  */
360 enum {
361         FTRACE_FL_ENABLED       = (1UL << 31),
362         FTRACE_FL_REGS          = (1UL << 30),
363         FTRACE_FL_REGS_EN       = (1UL << 29),
364         FTRACE_FL_TRAMP         = (1UL << 28),
365         FTRACE_FL_TRAMP_EN      = (1UL << 27),
366         FTRACE_FL_IPMODIFY      = (1UL << 26),
367 };
368
369 #define FTRACE_REF_MAX_SHIFT    26
370 #define FTRACE_FL_BITS          6
371 #define FTRACE_FL_MASKED_BITS   ((1UL << FTRACE_FL_BITS) - 1)
372 #define FTRACE_FL_MASK          (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
373 #define FTRACE_REF_MAX          ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
374
375 #define ftrace_rec_count(rec)   ((rec)->flags & ~FTRACE_FL_MASK)
376
377 struct dyn_ftrace {
378         unsigned long           ip; /* address of mcount call-site */
379         unsigned long           flags;
380         struct dyn_arch_ftrace  arch;
381 };
382
383 int ftrace_force_update(void);
384 int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
385                          int remove, int reset);
386 int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
387                        int len, int reset);
388 int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
389                         int len, int reset);
390 void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
391 void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
392 void ftrace_free_filter(struct ftrace_ops *ops);
393
394 int register_ftrace_command(struct ftrace_func_command *cmd);
395 int unregister_ftrace_command(struct ftrace_func_command *cmd);
396
397 enum {
398         FTRACE_UPDATE_CALLS             = (1 << 0),
399         FTRACE_DISABLE_CALLS            = (1 << 1),
400         FTRACE_UPDATE_TRACE_FUNC        = (1 << 2),
401         FTRACE_START_FUNC_RET           = (1 << 3),
402         FTRACE_STOP_FUNC_RET            = (1 << 4),
403 };
404
405 /*
406  * The FTRACE_UPDATE_* enum is used to pass information back
407  * from the ftrace_update_record() and ftrace_test_record()
408  * functions. These are called by the code update routines
409  * to find out what is to be done for a given function.
410  *
411  *  IGNORE           - The function is already what we want it to be
412  *  MAKE_CALL        - Start tracing the function
413  *  MODIFY_CALL      - Stop saving regs for the function
414  *  MAKE_NOP         - Stop tracing the function
415  */
416 enum {
417         FTRACE_UPDATE_IGNORE,
418         FTRACE_UPDATE_MAKE_CALL,
419         FTRACE_UPDATE_MODIFY_CALL,
420         FTRACE_UPDATE_MAKE_NOP,
421 };
422
423 enum {
424         FTRACE_ITER_FILTER      = (1 << 0),
425         FTRACE_ITER_NOTRACE     = (1 << 1),
426         FTRACE_ITER_PRINTALL    = (1 << 2),
427         FTRACE_ITER_DO_HASH     = (1 << 3),
428         FTRACE_ITER_HASH        = (1 << 4),
429         FTRACE_ITER_ENABLED     = (1 << 5),
430 };
431
432 void arch_ftrace_update_code(int command);
433
434 struct ftrace_rec_iter;
435
436 struct ftrace_rec_iter *ftrace_rec_iter_start(void);
437 struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
438 struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
439
440 #define for_ftrace_rec_iter(iter)               \
441         for (iter = ftrace_rec_iter_start();    \
442              iter;                              \
443              iter = ftrace_rec_iter_next(iter))
444
445
446 int ftrace_update_record(struct dyn_ftrace *rec, int enable);
447 int ftrace_test_record(struct dyn_ftrace *rec, int enable);
448 void ftrace_run_stop_machine(int command);
449 unsigned long ftrace_location(unsigned long ip);
450 unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
451 unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
452
453 extern ftrace_func_t ftrace_trace_function;
454
455 int ftrace_regex_open(struct ftrace_ops *ops, int flag,
456                   struct inode *inode, struct file *file);
457 ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
458                             size_t cnt, loff_t *ppos);
459 ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
460                              size_t cnt, loff_t *ppos);
461 int ftrace_regex_release(struct inode *inode, struct file *file);
462
463 void __init
464 ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
465
466 /* defined in arch */
467 extern int ftrace_ip_converted(unsigned long ip);
468 extern int ftrace_dyn_arch_init(void);
469 extern void ftrace_replace_code(int enable);
470 extern int ftrace_update_ftrace_func(ftrace_func_t func);
471 extern void ftrace_caller(void);
472 extern void ftrace_regs_caller(void);
473 extern void ftrace_call(void);
474 extern void ftrace_regs_call(void);
475 extern void mcount_call(void);
476
477 void ftrace_modify_all_code(int command);
478
479 #ifndef FTRACE_ADDR
480 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
481 #endif
482
483 #ifndef FTRACE_GRAPH_ADDR
484 #define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
485 #endif
486
487 #ifndef FTRACE_REGS_ADDR
488 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
489 # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
490 #else
491 # define FTRACE_REGS_ADDR FTRACE_ADDR
492 #endif
493 #endif
494
495 /*
496  * If an arch would like functions that are only traced
497  * by the function graph tracer to jump directly to its own
498  * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
499  * to be that address to jump to.
500  */
501 #ifndef FTRACE_GRAPH_TRAMP_ADDR
502 #define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
503 #endif
504
505 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
506 extern void ftrace_graph_caller(void);
507 extern int ftrace_enable_ftrace_graph_caller(void);
508 extern int ftrace_disable_ftrace_graph_caller(void);
509 #else
510 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
511 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
512 #endif
513
514 /**
515  * ftrace_make_nop - convert code into nop
516  * @mod: module structure if called by module load initialization
517  * @rec: the mcount call site record
518  * @addr: the address that the call site should be calling
519  *
520  * This is a very sensitive operation and great care needs
521  * to be taken by the arch.  The operation should carefully
522  * read the location, check to see if what is read is indeed
523  * what we expect it to be, and then on success of the compare,
524  * it should write to the location.
525  *
526  * The code segment at @rec->ip should be a caller to @addr
527  *
528  * Return must be:
529  *  0 on success
530  *  -EFAULT on error reading the location
531  *  -EINVAL on a failed compare of the contents
532  *  -EPERM  on error writing to the location
533  * Any other value will be considered a failure.
534  */
535 extern int ftrace_make_nop(struct module *mod,
536                            struct dyn_ftrace *rec, unsigned long addr);
537
538 /**
539  * ftrace_make_call - convert a nop call site into a call to addr
540  * @rec: the mcount call site record
541  * @addr: the address that the call site should call
542  *
543  * This is a very sensitive operation and great care needs
544  * to be taken by the arch.  The operation should carefully
545  * read the location, check to see if what is read is indeed
546  * what we expect it to be, and then on success of the compare,
547  * it should write to the location.
548  *
549  * The code segment at @rec->ip should be a nop
550  *
551  * Return must be:
552  *  0 on success
553  *  -EFAULT on error reading the location
554  *  -EINVAL on a failed compare of the contents
555  *  -EPERM  on error writing to the location
556  * Any other value will be considered a failure.
557  */
558 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
559
560 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
561 /**
562  * ftrace_modify_call - convert from one addr to another (no nop)
563  * @rec: the mcount call site record
564  * @old_addr: the address expected to be currently called to
565  * @addr: the address to change to
566  *
567  * This is a very sensitive operation and great care needs
568  * to be taken by the arch.  The operation should carefully
569  * read the location, check to see if what is read is indeed
570  * what we expect it to be, and then on success of the compare,
571  * it should write to the location.
572  *
573  * The code segment at @rec->ip should be a caller to @old_addr
574  *
575  * Return must be:
576  *  0 on success
577  *  -EFAULT on error reading the location
578  *  -EINVAL on a failed compare of the contents
579  *  -EPERM  on error writing to the location
580  * Any other value will be considered a failure.
581  */
582 extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
583                               unsigned long addr);
584 #else
585 /* Should never be called */
586 static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
587                                      unsigned long addr)
588 {
589         return -EINVAL;
590 }
591 #endif
592
593 /* May be defined in arch */
594 extern int ftrace_arch_read_dyn_info(char *buf, int size);
595
596 extern int skip_trace(unsigned long ip);
597 extern void ftrace_module_init(struct module *mod);
598
599 extern void ftrace_disable_daemon(void);
600 extern void ftrace_enable_daemon(void);
601 #else /* CONFIG_DYNAMIC_FTRACE */
602 static inline int skip_trace(unsigned long ip) { return 0; }
603 static inline int ftrace_force_update(void) { return 0; }
604 static inline void ftrace_disable_daemon(void) { }
605 static inline void ftrace_enable_daemon(void) { }
606 static inline void ftrace_release_mod(struct module *mod) {}
607 static inline void ftrace_module_init(struct module *mod) {}
608 static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
609 {
610         return -EINVAL;
611 }
612 static inline __init int unregister_ftrace_command(char *cmd_name)
613 {
614         return -EINVAL;
615 }
616 static inline int ftrace_text_reserved(const void *start, const void *end)
617 {
618         return 0;
619 }
620 static inline unsigned long ftrace_location(unsigned long ip)
621 {
622         return 0;
623 }
624
625 /*
626  * Again users of functions that have ftrace_ops may not
627  * have them defined when ftrace is not enabled, but these
628  * functions may still be called. Use a macro instead of inline.
629  */
630 #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
631 #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
632 #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
633 #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
634 #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
635 #define ftrace_free_filter(ops) do { } while (0)
636
637 static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
638                             size_t cnt, loff_t *ppos) { return -ENODEV; }
639 static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
640                              size_t cnt, loff_t *ppos) { return -ENODEV; }
641 static inline int
642 ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
643
644 static inline bool is_ftrace_trampoline(unsigned long addr)
645 {
646         return false;
647 }
648 #endif /* CONFIG_DYNAMIC_FTRACE */
649
650 /* totally disable ftrace - can not re-enable after this */
651 void ftrace_kill(void);
652
653 static inline void tracer_disable(void)
654 {
655 #ifdef CONFIG_FUNCTION_TRACER
656         ftrace_enabled = 0;
657 #endif
658 }
659
660 /*
661  * Ftrace disable/restore without lock. Some synchronization mechanism
662  * must be used to prevent ftrace_enabled to be changed between
663  * disable/restore.
664  */
665 static inline int __ftrace_enabled_save(void)
666 {
667 #ifdef CONFIG_FUNCTION_TRACER
668         int saved_ftrace_enabled = ftrace_enabled;
669         ftrace_enabled = 0;
670         return saved_ftrace_enabled;
671 #else
672         return 0;
673 #endif
674 }
675
676 static inline void __ftrace_enabled_restore(int enabled)
677 {
678 #ifdef CONFIG_FUNCTION_TRACER
679         ftrace_enabled = enabled;
680 #endif
681 }
682
683 /* All archs should have this, but we define it for consistency */
684 #ifndef ftrace_return_address0
685 # define ftrace_return_address0 __builtin_return_address(0)
686 #endif
687
688 /* Archs may use other ways for ADDR1 and beyond */
689 #ifndef ftrace_return_address
690 # ifdef CONFIG_FRAME_POINTER
691 #  define ftrace_return_address(n) __builtin_return_address(n)
692 # else
693 #  define ftrace_return_address(n) 0UL
694 # endif
695 #endif
696
697 #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
698 #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
699 #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
700 #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
701 #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
702 #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
703 #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
704
705 #ifdef CONFIG_IRQSOFF_TRACER
706   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
707   extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
708 #else
709   static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
710   static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
711 #endif
712
713 #ifdef CONFIG_PREEMPT_TRACER
714   extern void trace_preempt_on(unsigned long a0, unsigned long a1);
715   extern void trace_preempt_off(unsigned long a0, unsigned long a1);
716 #else
717 /*
718  * Use defines instead of static inlines because some arches will make code out
719  * of the CALLER_ADDR, when we really want these to be a real nop.
720  */
721 # define trace_preempt_on(a0, a1) do { } while (0)
722 # define trace_preempt_off(a0, a1) do { } while (0)
723 #endif
724
725 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
726 extern void ftrace_init(void);
727 #else
728 static inline void ftrace_init(void) { }
729 #endif
730
731 /*
732  * Structure that defines an entry function trace.
733  */
734 struct ftrace_graph_ent {
735         unsigned long func; /* Current function */
736         int depth;
737 };
738
739 /*
740  * Structure that defines a return function trace.
741  */
742 struct ftrace_graph_ret {
743         unsigned long func; /* Current function */
744         unsigned long long calltime;
745         unsigned long long rettime;
746         /* Number of functions that overran the depth limit for current task */
747         unsigned long overrun;
748         int depth;
749 };
750
751 /* Type of the callback handlers for tracing function graph*/
752 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
753 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
754
755 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
756
757 /* for init task */
758 #define INIT_FTRACE_GRAPH               .ret_stack = NULL,
759
760 /*
761  * Stack of return addresses for functions
762  * of a thread.
763  * Used in struct thread_info
764  */
765 struct ftrace_ret_stack {
766         unsigned long ret;
767         unsigned long func;
768         unsigned long long calltime;
769         unsigned long long subtime;
770         unsigned long fp;
771 };
772
773 /*
774  * Primary handler of a function return.
775  * It relays on ftrace_return_to_handler.
776  * Defined in entry_32/64.S
777  */
778 extern void return_to_handler(void);
779
780 extern int
781 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
782                          unsigned long frame_pointer);
783
784 /*
785  * Sometimes we don't want to trace a function with the function
786  * graph tracer but we want them to keep traced by the usual function
787  * tracer if the function graph tracer is not configured.
788  */
789 #define __notrace_funcgraph             notrace
790
791 /*
792  * We want to which function is an entrypoint of a hardirq.
793  * That will help us to put a signal on output.
794  */
795 #define __irq_entry              __attribute__((__section__(".irqentry.text")))
796
797 /* Limits of hardirq entrypoints */
798 extern char __irqentry_text_start[];
799 extern char __irqentry_text_end[];
800
801 #define FTRACE_NOTRACE_DEPTH 65536
802 #define FTRACE_RETFUNC_DEPTH 50
803 #define FTRACE_RETSTACK_ALLOC_SIZE 32
804 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
805                                 trace_func_graph_ent_t entryfunc);
806
807 extern bool ftrace_graph_is_dead(void);
808 extern void ftrace_graph_stop(void);
809
810 /* The current handlers in use */
811 extern trace_func_graph_ret_t ftrace_graph_return;
812 extern trace_func_graph_ent_t ftrace_graph_entry;
813
814 extern void unregister_ftrace_graph(void);
815
816 extern void ftrace_graph_init_task(struct task_struct *t);
817 extern void ftrace_graph_exit_task(struct task_struct *t);
818 extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
819
820 static inline int task_curr_ret_stack(struct task_struct *t)
821 {
822         return t->curr_ret_stack;
823 }
824
825 static inline void pause_graph_tracing(void)
826 {
827         atomic_inc(&current->tracing_graph_pause);
828 }
829
830 static inline void unpause_graph_tracing(void)
831 {
832         atomic_dec(&current->tracing_graph_pause);
833 }
834 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
835
836 #define __notrace_funcgraph
837 #define __irq_entry
838 #define INIT_FTRACE_GRAPH
839
840 static inline void ftrace_graph_init_task(struct task_struct *t) { }
841 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
842 static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
843
844 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
845                           trace_func_graph_ent_t entryfunc)
846 {
847         return -1;
848 }
849 static inline void unregister_ftrace_graph(void) { }
850
851 static inline int task_curr_ret_stack(struct task_struct *tsk)
852 {
853         return -1;
854 }
855
856 static inline void pause_graph_tracing(void) { }
857 static inline void unpause_graph_tracing(void) { }
858 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
859
860 #ifdef CONFIG_TRACING
861
862 /* flags for current->trace */
863 enum {
864         TSK_TRACE_FL_TRACE_BIT  = 0,
865         TSK_TRACE_FL_GRAPH_BIT  = 1,
866 };
867 enum {
868         TSK_TRACE_FL_TRACE      = 1 << TSK_TRACE_FL_TRACE_BIT,
869         TSK_TRACE_FL_GRAPH      = 1 << TSK_TRACE_FL_GRAPH_BIT,
870 };
871
872 static inline void set_tsk_trace_trace(struct task_struct *tsk)
873 {
874         set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
875 }
876
877 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
878 {
879         clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
880 }
881
882 static inline int test_tsk_trace_trace(struct task_struct *tsk)
883 {
884         return tsk->trace & TSK_TRACE_FL_TRACE;
885 }
886
887 static inline void set_tsk_trace_graph(struct task_struct *tsk)
888 {
889         set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
890 }
891
892 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
893 {
894         clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
895 }
896
897 static inline int test_tsk_trace_graph(struct task_struct *tsk)
898 {
899         return tsk->trace & TSK_TRACE_FL_GRAPH;
900 }
901
902 enum ftrace_dump_mode;
903
904 extern enum ftrace_dump_mode ftrace_dump_on_oops;
905 extern int tracepoint_printk;
906
907 extern void disable_trace_on_warning(void);
908 extern int __disable_trace_on_warning;
909
910 #ifdef CONFIG_PREEMPT
911 #define INIT_TRACE_RECURSION            .trace_recursion = 0,
912 #endif
913
914 #else /* CONFIG_TRACING */
915 static inline void  disable_trace_on_warning(void) { }
916 #endif /* CONFIG_TRACING */
917
918 #ifndef INIT_TRACE_RECURSION
919 #define INIT_TRACE_RECURSION
920 #endif
921
922 #ifdef CONFIG_FTRACE_SYSCALLS
923
924 unsigned long arch_syscall_addr(int nr);
925
926 #endif /* CONFIG_FTRACE_SYSCALLS */
927
928 #endif /* _LINUX_FTRACE_H */