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