1
2
3
4
5
6
7#ifndef _LINUX_FTRACE_H
8#define _LINUX_FTRACE_H
9
10#include <linux/trace_recursion.h>
11#include <linux/trace_clock.h>
12#include <linux/kallsyms.h>
13#include <linux/linkage.h>
14#include <linux/bitops.h>
15#include <linux/ptrace.h>
16#include <linux/ktime.h>
17#include <linux/sched.h>
18#include <linux/types.h>
19#include <linux/init.h>
20#include <linux/fs.h>
21
22#include <asm/ftrace.h>
23
24
25
26
27
28
29#ifndef ARCH_SUPPORTS_FTRACE_OPS
30#define ARCH_SUPPORTS_FTRACE_OPS 0
31#endif
32
33#ifdef CONFIG_FUNCTION_TRACER
34struct ftrace_ops;
35struct ftrace_regs;
36
37
38
39
40
41
42
43
44#if !ARCH_SUPPORTS_FTRACE_OPS
45# define FTRACE_FORCE_LIST_FUNC 1
46void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip);
47#else
48# define FTRACE_FORCE_LIST_FUNC 0
49void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
50 struct ftrace_ops *op, struct ftrace_regs *fregs);
51#endif
52#endif
53
54
55#ifdef CONFIG_TRACING
56void trace_init(void);
57void early_trace_init(void);
58#else
59static inline void trace_init(void) { }
60static inline void early_trace_init(void) { }
61#endif
62
63struct module;
64struct ftrace_hash;
65struct ftrace_direct_func;
66
67#if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_MODULES) && \
68 defined(CONFIG_DYNAMIC_FTRACE)
69const char *
70ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
71 unsigned long *off, char **modname, char *sym);
72#else
73static inline const char *
74ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
75 unsigned long *off, char **modname, char *sym)
76{
77 return NULL;
78}
79#endif
80
81#if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
82int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
83 char *type, char *name,
84 char *module_name, int *exported);
85#else
86static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
87 char *type, char *name,
88 char *module_name, int *exported)
89{
90 return -1;
91}
92#endif
93
94#ifdef CONFIG_FUNCTION_TRACER
95
96extern int ftrace_enabled;
97extern int
98ftrace_enable_sysctl(struct ctl_table *table, int write,
99 void *buffer, size_t *lenp, loff_t *ppos);
100
101#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
102
103struct ftrace_regs {
104 struct pt_regs regs;
105};
106#define arch_ftrace_get_regs(fregs) (&(fregs)->regs)
107
108
109
110
111
112
113
114#define ftrace_instruction_pointer_set(fregs, ip) do { } while (0)
115#endif
116
117static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs)
118{
119 if (!fregs)
120 return NULL;
121
122 return arch_ftrace_get_regs(fregs);
123}
124
125typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
126 struct ftrace_ops *op, struct ftrace_regs *fregs);
127
128ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186enum {
187 FTRACE_OPS_FL_ENABLED = BIT(0),
188 FTRACE_OPS_FL_DYNAMIC = BIT(1),
189 FTRACE_OPS_FL_SAVE_REGS = BIT(2),
190 FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = BIT(3),
191 FTRACE_OPS_FL_RECURSION = BIT(4),
192 FTRACE_OPS_FL_STUB = BIT(5),
193 FTRACE_OPS_FL_INITIALIZED = BIT(6),
194 FTRACE_OPS_FL_DELETED = BIT(7),
195 FTRACE_OPS_FL_ADDING = BIT(8),
196 FTRACE_OPS_FL_REMOVING = BIT(9),
197 FTRACE_OPS_FL_MODIFYING = BIT(10),
198 FTRACE_OPS_FL_ALLOC_TRAMP = BIT(11),
199 FTRACE_OPS_FL_IPMODIFY = BIT(12),
200 FTRACE_OPS_FL_PID = BIT(13),
201 FTRACE_OPS_FL_RCU = BIT(14),
202 FTRACE_OPS_FL_TRACE_ARRAY = BIT(15),
203 FTRACE_OPS_FL_PERMANENT = BIT(16),
204 FTRACE_OPS_FL_DIRECT = BIT(17),
205};
206
207#ifdef CONFIG_DYNAMIC_FTRACE
208
209struct ftrace_ops_hash {
210 struct ftrace_hash __rcu *notrace_hash;
211 struct ftrace_hash __rcu *filter_hash;
212 struct mutex regex_lock;
213};
214
215void ftrace_free_init_mem(void);
216void ftrace_free_mem(struct module *mod, void *start, void *end);
217#else
218static inline void ftrace_free_init_mem(void) { }
219static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
220#endif
221
222
223
224
225
226
227
228
229
230
231
232
233struct ftrace_ops {
234 ftrace_func_t func;
235 struct ftrace_ops __rcu *next;
236 unsigned long flags;
237 void *private;
238 ftrace_func_t saved_func;
239#ifdef CONFIG_DYNAMIC_FTRACE
240 struct ftrace_ops_hash local_hash;
241 struct ftrace_ops_hash *func_hash;
242 struct ftrace_ops_hash old_hash;
243 unsigned long trampoline;
244 unsigned long trampoline_size;
245 struct list_head list;
246#endif
247};
248
249extern struct ftrace_ops __rcu *ftrace_ops_list;
250extern struct ftrace_ops ftrace_list_end;
251
252
253
254
255
256
257
258
259
260
261#define do_for_each_ftrace_op(op, list) \
262 op = rcu_dereference_raw_check(list); \
263 do
264
265
266
267
268#define while_for_each_ftrace_op(op) \
269 while (likely(op = rcu_dereference_raw_check((op)->next)) && \
270 unlikely((op) != &ftrace_list_end))
271
272
273
274
275enum ftrace_tracing_type_t {
276 FTRACE_TYPE_ENTER = 0,
277 FTRACE_TYPE_RETURN,
278};
279
280
281extern enum ftrace_tracing_type_t ftrace_tracing_type;
282
283
284
285
286
287
288
289
290int register_ftrace_function(struct ftrace_ops *ops);
291int unregister_ftrace_function(struct ftrace_ops *ops);
292
293extern void ftrace_stub(unsigned long a0, unsigned long a1,
294 struct ftrace_ops *op, struct ftrace_regs *fregs);
295
296#else
297
298
299
300
301#define register_ftrace_function(ops) ({ 0; })
302#define unregister_ftrace_function(ops) ({ 0; })
303static inline void ftrace_kill(void) { }
304static inline void ftrace_free_init_mem(void) { }
305static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
306#endif
307
308struct ftrace_func_entry {
309 struct hlist_node hlist;
310 unsigned long ip;
311 unsigned long direct;
312};
313
314struct dyn_ftrace;
315
316#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
317extern int ftrace_direct_func_count;
318int register_ftrace_direct(unsigned long ip, unsigned long addr);
319int unregister_ftrace_direct(unsigned long ip, unsigned long addr);
320int modify_ftrace_direct(unsigned long ip, unsigned long old_addr, unsigned long new_addr);
321struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr);
322int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
323 struct dyn_ftrace *rec,
324 unsigned long old_addr,
325 unsigned long new_addr);
326unsigned long ftrace_find_rec_direct(unsigned long ip);
327int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
328int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
329int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
330
331#else
332struct ftrace_ops;
333# define ftrace_direct_func_count 0
334static inline int register_ftrace_direct(unsigned long ip, unsigned long addr)
335{
336 return -ENOTSUPP;
337}
338static inline int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
339{
340 return -ENOTSUPP;
341}
342static inline int modify_ftrace_direct(unsigned long ip,
343 unsigned long old_addr, unsigned long new_addr)
344{
345 return -ENOTSUPP;
346}
347static inline struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr)
348{
349 return NULL;
350}
351static inline int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
352 struct dyn_ftrace *rec,
353 unsigned long old_addr,
354 unsigned long new_addr)
355{
356 return -ENODEV;
357}
358static inline unsigned long ftrace_find_rec_direct(unsigned long ip)
359{
360 return 0;
361}
362static inline int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
363{
364 return -ENODEV;
365}
366static inline int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
367{
368 return -ENODEV;
369}
370static inline int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
371{
372 return -ENODEV;
373}
374#endif
375
376#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
377
378
379
380
381
382
383
384
385
386
387
388
389
390static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs,
391 unsigned long addr) { }
392#endif
393
394#ifdef CONFIG_STACK_TRACER
395
396extern int stack_tracer_enabled;
397
398int stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
399 size_t *lenp, loff_t *ppos);
400
401
402DECLARE_PER_CPU(int, disable_stack_tracer);
403
404
405
406
407
408
409
410
411
412
413
414
415static inline void stack_tracer_disable(void)
416{
417
418 if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
419 WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
420 this_cpu_inc(disable_stack_tracer);
421}
422
423
424
425
426
427
428
429static inline void stack_tracer_enable(void)
430{
431 if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
432 WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
433 this_cpu_dec(disable_stack_tracer);
434}
435#else
436static inline void stack_tracer_disable(void) { }
437static inline void stack_tracer_enable(void) { }
438#endif
439
440#ifdef CONFIG_DYNAMIC_FTRACE
441
442int ftrace_arch_code_modify_prepare(void);
443int ftrace_arch_code_modify_post_process(void);
444
445enum ftrace_bug_type {
446 FTRACE_BUG_UNKNOWN,
447 FTRACE_BUG_INIT,
448 FTRACE_BUG_NOP,
449 FTRACE_BUG_CALL,
450 FTRACE_BUG_UPDATE,
451};
452extern enum ftrace_bug_type ftrace_bug_type;
453
454
455
456
457
458extern const void *ftrace_expected;
459
460void ftrace_bug(int err, struct dyn_ftrace *rec);
461
462struct seq_file;
463
464extern int ftrace_text_reserved(const void *start, const void *end);
465
466struct ftrace_ops *ftrace_ops_trampoline(unsigned long addr);
467
468bool is_ftrace_trampoline(unsigned long addr);
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490enum {
491 FTRACE_FL_ENABLED = (1UL << 31),
492 FTRACE_FL_REGS = (1UL << 30),
493 FTRACE_FL_REGS_EN = (1UL << 29),
494 FTRACE_FL_TRAMP = (1UL << 28),
495 FTRACE_FL_TRAMP_EN = (1UL << 27),
496 FTRACE_FL_IPMODIFY = (1UL << 26),
497 FTRACE_FL_DISABLED = (1UL << 25),
498 FTRACE_FL_DIRECT = (1UL << 24),
499 FTRACE_FL_DIRECT_EN = (1UL << 23),
500};
501
502#define FTRACE_REF_MAX_SHIFT 23
503#define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
504
505#define ftrace_rec_count(rec) ((rec)->flags & FTRACE_REF_MAX)
506
507struct dyn_ftrace {
508 unsigned long ip;
509 unsigned long flags;
510 struct dyn_arch_ftrace arch;
511};
512
513int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
514 int remove, int reset);
515int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
516 int len, int reset);
517int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
518 int len, int reset);
519void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
520void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
521void ftrace_free_filter(struct ftrace_ops *ops);
522void ftrace_ops_set_global_filter(struct ftrace_ops *ops);
523
524enum {
525 FTRACE_UPDATE_CALLS = (1 << 0),
526 FTRACE_DISABLE_CALLS = (1 << 1),
527 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
528 FTRACE_START_FUNC_RET = (1 << 3),
529 FTRACE_STOP_FUNC_RET = (1 << 4),
530 FTRACE_MAY_SLEEP = (1 << 5),
531};
532
533
534
535
536
537
538
539
540
541
542
543
544enum {
545 FTRACE_UPDATE_IGNORE,
546 FTRACE_UPDATE_MAKE_CALL,
547 FTRACE_UPDATE_MODIFY_CALL,
548 FTRACE_UPDATE_MAKE_NOP,
549};
550
551enum {
552 FTRACE_ITER_FILTER = (1 << 0),
553 FTRACE_ITER_NOTRACE = (1 << 1),
554 FTRACE_ITER_PRINTALL = (1 << 2),
555 FTRACE_ITER_DO_PROBES = (1 << 3),
556 FTRACE_ITER_PROBE = (1 << 4),
557 FTRACE_ITER_MOD = (1 << 5),
558 FTRACE_ITER_ENABLED = (1 << 6),
559};
560
561void arch_ftrace_update_code(int command);
562void arch_ftrace_update_trampoline(struct ftrace_ops *ops);
563void *arch_ftrace_trampoline_func(struct ftrace_ops *ops, struct dyn_ftrace *rec);
564void arch_ftrace_trampoline_free(struct ftrace_ops *ops);
565
566struct ftrace_rec_iter;
567
568struct ftrace_rec_iter *ftrace_rec_iter_start(void);
569struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
570struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
571
572#define for_ftrace_rec_iter(iter) \
573 for (iter = ftrace_rec_iter_start(); \
574 iter; \
575 iter = ftrace_rec_iter_next(iter))
576
577
578int ftrace_update_record(struct dyn_ftrace *rec, bool enable);
579int ftrace_test_record(struct dyn_ftrace *rec, bool enable);
580void ftrace_run_stop_machine(int command);
581unsigned long ftrace_location(unsigned long ip);
582unsigned long ftrace_location_range(unsigned long start, unsigned long end);
583unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
584unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
585
586extern ftrace_func_t ftrace_trace_function;
587
588int ftrace_regex_open(struct ftrace_ops *ops, int flag,
589 struct inode *inode, struct file *file);
590ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
591 size_t cnt, loff_t *ppos);
592ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
593 size_t cnt, loff_t *ppos);
594int ftrace_regex_release(struct inode *inode, struct file *file);
595
596void __init
597ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
598
599
600extern int ftrace_ip_converted(unsigned long ip);
601extern int ftrace_dyn_arch_init(void);
602extern void ftrace_replace_code(int enable);
603extern int ftrace_update_ftrace_func(ftrace_func_t func);
604extern void ftrace_caller(void);
605extern void ftrace_regs_caller(void);
606extern void ftrace_call(void);
607extern void ftrace_regs_call(void);
608extern void mcount_call(void);
609
610void ftrace_modify_all_code(int command);
611
612#ifndef FTRACE_ADDR
613#define FTRACE_ADDR ((unsigned long)ftrace_caller)
614#endif
615
616#ifndef FTRACE_GRAPH_ADDR
617#define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
618#endif
619
620#ifndef FTRACE_REGS_ADDR
621#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
622# define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
623#else
624# define FTRACE_REGS_ADDR FTRACE_ADDR
625#endif
626#endif
627
628
629
630
631
632
633
634#ifndef FTRACE_GRAPH_TRAMP_ADDR
635#define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
636#endif
637
638#ifdef CONFIG_FUNCTION_GRAPH_TRACER
639extern void ftrace_graph_caller(void);
640extern int ftrace_enable_ftrace_graph_caller(void);
641extern int ftrace_disable_ftrace_graph_caller(void);
642#else
643static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
644static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
645#endif
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668extern int ftrace_make_nop(struct module *mod,
669 struct dyn_ftrace *rec, unsigned long addr);
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684#ifndef ftrace_need_init_nop
685#define ftrace_need_init_nop() (!__is_defined(CC_USING_NOP_MCOUNT))
686#endif
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709#ifndef ftrace_init_nop
710static inline int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
711{
712 return ftrace_make_nop(mod, rec, MCOUNT_ADDR);
713}
714#endif
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
737
738#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
761 unsigned long addr);
762#else
763
764static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
765 unsigned long addr)
766{
767 return -EINVAL;
768}
769#endif
770
771
772extern int ftrace_arch_read_dyn_info(char *buf, int size);
773
774extern int skip_trace(unsigned long ip);
775extern void ftrace_module_init(struct module *mod);
776extern void ftrace_module_enable(struct module *mod);
777extern void ftrace_release_mod(struct module *mod);
778
779extern void ftrace_disable_daemon(void);
780extern void ftrace_enable_daemon(void);
781#else
782static inline int skip_trace(unsigned long ip) { return 0; }
783static inline void ftrace_disable_daemon(void) { }
784static inline void ftrace_enable_daemon(void) { }
785static inline void ftrace_module_init(struct module *mod) { }
786static inline void ftrace_module_enable(struct module *mod) { }
787static inline void ftrace_release_mod(struct module *mod) { }
788static inline int ftrace_text_reserved(const void *start, const void *end)
789{
790 return 0;
791}
792static inline unsigned long ftrace_location(unsigned long ip)
793{
794 return 0;
795}
796
797
798
799
800
801
802#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
803#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
804#define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
805#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
806#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
807#define ftrace_free_filter(ops) do { } while (0)
808#define ftrace_ops_set_global_filter(ops) do { } while (0)
809
810static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
811 size_t cnt, loff_t *ppos) { return -ENODEV; }
812static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
813 size_t cnt, loff_t *ppos) { return -ENODEV; }
814static inline int
815ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
816
817static inline bool is_ftrace_trampoline(unsigned long addr)
818{
819 return false;
820}
821#endif
822
823#ifdef CONFIG_FUNCTION_GRAPH_TRACER
824#ifndef ftrace_graph_func
825#define ftrace_graph_func ftrace_stub
826#define FTRACE_OPS_GRAPH_STUB FTRACE_OPS_FL_STUB
827#else
828#define FTRACE_OPS_GRAPH_STUB 0
829#endif
830#endif
831
832
833void ftrace_kill(void);
834
835static inline void tracer_disable(void)
836{
837#ifdef CONFIG_FUNCTION_TRACER
838 ftrace_enabled = 0;
839#endif
840}
841
842
843
844
845
846
847static inline int __ftrace_enabled_save(void)
848{
849#ifdef CONFIG_FUNCTION_TRACER
850 int saved_ftrace_enabled = ftrace_enabled;
851 ftrace_enabled = 0;
852 return saved_ftrace_enabled;
853#else
854 return 0;
855#endif
856}
857
858static inline void __ftrace_enabled_restore(int enabled)
859{
860#ifdef CONFIG_FUNCTION_TRACER
861 ftrace_enabled = enabled;
862#endif
863}
864
865
866#ifndef ftrace_return_address0
867# define ftrace_return_address0 __builtin_return_address(0)
868#endif
869
870
871#ifndef ftrace_return_address
872# ifdef CONFIG_FRAME_POINTER
873# define ftrace_return_address(n) __builtin_return_address(n)
874# else
875# define ftrace_return_address(n) 0UL
876# endif
877#endif
878
879#define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
880#define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
881#define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
882#define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
883#define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
884#define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
885#define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
886
887static inline unsigned long get_lock_parent_ip(void)
888{
889 unsigned long addr = CALLER_ADDR0;
890
891 if (!in_lock_functions(addr))
892 return addr;
893 addr = CALLER_ADDR1;
894 if (!in_lock_functions(addr))
895 return addr;
896 return CALLER_ADDR2;
897}
898
899#ifdef CONFIG_TRACE_PREEMPT_TOGGLE
900 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
901 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
902#else
903
904
905
906
907# define trace_preempt_on(a0, a1) do { } while (0)
908# define trace_preempt_off(a0, a1) do { } while (0)
909#endif
910
911#ifdef CONFIG_FTRACE_MCOUNT_RECORD
912extern void ftrace_init(void);
913#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
914#define FTRACE_CALLSITE_SECTION "__patchable_function_entries"
915#else
916#define FTRACE_CALLSITE_SECTION "__mcount_loc"
917#endif
918#else
919static inline void ftrace_init(void) { }
920#endif
921
922
923
924
925
926
927struct ftrace_graph_ent {
928 unsigned long func;
929 int depth;
930} __packed;
931
932
933
934
935
936
937struct ftrace_graph_ret {
938 unsigned long func;
939 int depth;
940
941 unsigned int overrun;
942 unsigned long long calltime;
943 unsigned long long rettime;
944} __packed;
945
946
947typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *);
948typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *);
949
950extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
951
952#ifdef CONFIG_FUNCTION_GRAPH_TRACER
953
954struct fgraph_ops {
955 trace_func_graph_ent_t entryfunc;
956 trace_func_graph_ret_t retfunc;
957};
958
959
960
961
962
963
964struct ftrace_ret_stack {
965 unsigned long ret;
966 unsigned long func;
967 unsigned long long calltime;
968#ifdef CONFIG_FUNCTION_PROFILER
969 unsigned long long subtime;
970#endif
971#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
972 unsigned long fp;
973#endif
974#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
975 unsigned long *retp;
976#endif
977};
978
979
980
981
982
983
984extern void return_to_handler(void);
985
986extern int
987function_graph_enter(unsigned long ret, unsigned long func,
988 unsigned long frame_pointer, unsigned long *retp);
989
990struct ftrace_ret_stack *
991ftrace_graph_get_ret_stack(struct task_struct *task, int idx);
992
993unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
994 unsigned long ret, unsigned long *retp);
995
996
997
998
999
1000
1001#define __notrace_funcgraph notrace
1002
1003#define FTRACE_RETFUNC_DEPTH 50
1004#define FTRACE_RETSTACK_ALLOC_SIZE 32
1005
1006extern int register_ftrace_graph(struct fgraph_ops *ops);
1007extern void unregister_ftrace_graph(struct fgraph_ops *ops);
1008
1009extern bool ftrace_graph_is_dead(void);
1010extern void ftrace_graph_stop(void);
1011
1012
1013extern trace_func_graph_ret_t ftrace_graph_return;
1014extern trace_func_graph_ent_t ftrace_graph_entry;
1015
1016extern void ftrace_graph_init_task(struct task_struct *t);
1017extern void ftrace_graph_exit_task(struct task_struct *t);
1018extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
1019
1020static inline void pause_graph_tracing(void)
1021{
1022 atomic_inc(¤t->tracing_graph_pause);
1023}
1024
1025static inline void unpause_graph_tracing(void)
1026{
1027 atomic_dec(¤t->tracing_graph_pause);
1028}
1029#else
1030
1031#define __notrace_funcgraph
1032
1033static inline void ftrace_graph_init_task(struct task_struct *t) { }
1034static inline void ftrace_graph_exit_task(struct task_struct *t) { }
1035static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
1036
1037
1038#define register_ftrace_graph(ops) ({ -1; })
1039#define unregister_ftrace_graph(ops) do { } while (0)
1040
1041static inline unsigned long
1042ftrace_graph_ret_addr(struct task_struct *task, int *idx, unsigned long ret,
1043 unsigned long *retp)
1044{
1045 return ret;
1046}
1047
1048static inline void pause_graph_tracing(void) { }
1049static inline void unpause_graph_tracing(void) { }
1050#endif
1051
1052#ifdef CONFIG_TRACING
1053
1054
1055enum {
1056 TSK_TRACE_FL_TRACE_BIT = 0,
1057 TSK_TRACE_FL_GRAPH_BIT = 1,
1058};
1059enum {
1060 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
1061 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
1062};
1063
1064static inline void set_tsk_trace_trace(struct task_struct *tsk)
1065{
1066 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
1067}
1068
1069static inline void clear_tsk_trace_trace(struct task_struct *tsk)
1070{
1071 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
1072}
1073
1074static inline int test_tsk_trace_trace(struct task_struct *tsk)
1075{
1076 return tsk->trace & TSK_TRACE_FL_TRACE;
1077}
1078
1079static inline void set_tsk_trace_graph(struct task_struct *tsk)
1080{
1081 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
1082}
1083
1084static inline void clear_tsk_trace_graph(struct task_struct *tsk)
1085{
1086 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
1087}
1088
1089static inline int test_tsk_trace_graph(struct task_struct *tsk)
1090{
1091 return tsk->trace & TSK_TRACE_FL_GRAPH;
1092}
1093
1094enum ftrace_dump_mode;
1095
1096extern enum ftrace_dump_mode ftrace_dump_on_oops;
1097extern int tracepoint_printk;
1098
1099extern void disable_trace_on_warning(void);
1100extern int __disable_trace_on_warning;
1101
1102int tracepoint_printk_sysctl(struct ctl_table *table, int write,
1103 void *buffer, size_t *lenp, loff_t *ppos);
1104
1105#else
1106static inline void disable_trace_on_warning(void) { }
1107#endif
1108
1109#ifdef CONFIG_FTRACE_SYSCALLS
1110
1111unsigned long arch_syscall_addr(int nr);
1112
1113#endif
1114
1115#endif
1116