xref: /linux/kernel/trace/trace.h (revision 3c6e577d5ae705edebed9882ff474d7a48a47dd2)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #ifndef _LINUX_KERNEL_TRACE_H
4 #define _LINUX_KERNEL_TRACE_H
5 
6 #include <linux/fs.h>
7 #include <linux/atomic.h>
8 #include <linux/sched.h>
9 #include <linux/clocksource.h>
10 #include <linux/ring_buffer.h>
11 #include <linux/mmiotrace.h>
12 #include <linux/tracepoint.h>
13 #include <linux/ftrace.h>
14 #include <linux/trace.h>
15 #include <linux/hw_breakpoint.h>
16 #include <linux/trace_seq.h>
17 #include <linux/trace_events.h>
18 #include <linux/compiler.h>
19 #include <linux/glob.h>
20 #include <linux/irq_work.h>
21 #include <linux/workqueue.h>
22 #include <linux/ctype.h>
23 #include <linux/once_lite.h>
24 #include <linux/ftrace_regs.h>
25 #include <linux/llist.h>
26 
27 #include "pid_list.h"
28 
29 #ifdef CONFIG_FTRACE_SYSCALLS
30 #include <asm/unistd.h>		/* For NR_syscalls	     */
31 #include <asm/syscall.h>	/* some archs define it here */
32 #endif
33 
34 #define TRACE_MODE_WRITE	0640
35 #define TRACE_MODE_READ		0440
36 
37 enum trace_type {
38 	__TRACE_FIRST_TYPE = 0,
39 
40 	TRACE_FN,
41 	TRACE_CTX,
42 	TRACE_WAKE,
43 	TRACE_STACK,
44 	TRACE_PRINT,
45 	TRACE_BPRINT,
46 	TRACE_MMIO_RW,
47 	TRACE_MMIO_MAP,
48 	TRACE_BRANCH,
49 	TRACE_GRAPH_RET,
50 	TRACE_GRAPH_ENT,
51 	TRACE_GRAPH_RETADDR_ENT,
52 	TRACE_USER_STACK,
53 	TRACE_BLK,
54 	TRACE_BPUTS,
55 	TRACE_HWLAT,
56 	TRACE_OSNOISE,
57 	TRACE_TIMERLAT,
58 	TRACE_RAW_DATA,
59 	TRACE_FUNC_REPEATS,
60 
61 	__TRACE_LAST_TYPE,
62 };
63 
64 
65 #undef __field
66 #define __field(type, item)		type	item;
67 
68 #undef __field_fn
69 #define __field_fn(type, item)		type	item;
70 
71 #undef __field_packed
72 #define __field_packed(type, item)	type	item;
73 
74 #undef __field_struct
75 #define __field_struct(type, item)	__field(type, item)
76 
77 #undef __field_desc
78 #define __field_desc(type, container, item)
79 
80 #undef __field_desc_packed
81 #define __field_desc_packed(type, container, item)
82 
83 #undef __array
84 #define __array(type, item, size)	type	item[size];
85 
86 /*
87  * For backward compatibility, older user space expects to see the
88  * kernel_stack event with a fixed size caller field. But today the fix
89  * size is ignored by the kernel, and the real structure is dynamic.
90  * Expose to user space: "unsigned long caller[8];" but the real structure
91  * will be "unsigned long caller[] __counted_by(size)"
92  */
93 #undef __stack_array
94 #define __stack_array(type, item, size, field)		type item[] __counted_by(field);
95 
96 #undef __array_desc
97 #define __array_desc(type, container, item, size)
98 
99 #undef __dynamic_array
100 #define __dynamic_array(type, item)	type	item[];
101 
102 #undef __rel_dynamic_array
103 #define __rel_dynamic_array(type, item)	type	item[];
104 
105 #undef F_STRUCT
106 #define F_STRUCT(args...)		args
107 
108 #undef FTRACE_ENTRY
109 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print)		\
110 	struct struct_name {						\
111 		struct trace_entry	ent;				\
112 		tstruct							\
113 	}
114 
115 #undef FTRACE_ENTRY_DUP
116 #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk)
117 
118 #undef FTRACE_ENTRY_REG
119 #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print,	regfn)	\
120 	FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
121 
122 #undef FTRACE_ENTRY_PACKED
123 #define FTRACE_ENTRY_PACKED(name, struct_name, id, tstruct, print)	\
124 	FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print)) __packed
125 
126 #include "trace_entries.h"
127 
128 /* Use this for memory failure errors */
129 #define MEM_FAIL(condition, fmt, ...)					\
130 	DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__)
131 
132 #define FAULT_STRING "(fault)"
133 
134 #define HIST_STACKTRACE_DEPTH	31
135 #define HIST_STACKTRACE_SIZE	(HIST_STACKTRACE_DEPTH * sizeof(unsigned long))
136 #define HIST_STACKTRACE_SKIP	5
137 
138 #define SYSCALL_FAULT_USER_MAX 165
139 
140 /*
141  * syscalls are special, and need special handling, this is why
142  * they are not included in trace_entries.h
143  */
144 struct syscall_trace_enter {
145 	struct trace_entry	ent;
146 	int			nr;
147 	unsigned long		args[];
148 };
149 
150 struct syscall_trace_exit {
151 	struct trace_entry	ent;
152 	int			nr;
153 	long			ret;
154 };
155 
156 struct kprobe_trace_entry_head {
157 	struct trace_entry	ent;
158 	unsigned long		ip;
159 };
160 
161 struct eprobe_trace_entry_head {
162 	struct trace_entry	ent;
163 };
164 
165 struct kretprobe_trace_entry_head {
166 	struct trace_entry	ent;
167 	unsigned long		func;
168 	unsigned long		ret_ip;
169 };
170 
171 struct fentry_trace_entry_head {
172 	struct trace_entry	ent;
173 	unsigned long		ip;
174 };
175 
176 struct fexit_trace_entry_head {
177 	struct trace_entry	ent;
178 	unsigned long		func;
179 	unsigned long		ret_ip;
180 };
181 
182 #define TRACE_BUF_SIZE		1024
183 
184 struct trace_array;
185 
186 /*
187  * The CPU trace array - it consists of thousands of trace entries
188  * plus some other descriptor data: (for example which task started
189  * the trace, etc.)
190  */
191 struct trace_array_cpu {
192 	local_t			disabled;
193 
194 	unsigned long		entries;
195 	unsigned long		saved_latency;
196 	unsigned long		critical_start;
197 	unsigned long		critical_end;
198 	unsigned long		critical_sequence;
199 	unsigned long		nice;
200 	unsigned long		policy;
201 	unsigned long		rt_priority;
202 	unsigned long		skipped_entries;
203 	u64			preempt_timestamp;
204 	pid_t			pid;
205 	kuid_t			uid;
206 	char			comm[TASK_COMM_LEN];
207 
208 #ifdef CONFIG_FUNCTION_TRACER
209 	int			ftrace_ignore_pid;
210 #endif
211 	bool			ignore_pid;
212 };
213 
214 struct tracer;
215 struct trace_option_dentry;
216 
217 struct array_buffer {
218 	struct trace_array		*tr;
219 	struct trace_buffer		*buffer;
220 	struct trace_array_cpu __percpu	*data;
221 	u64				time_start;
222 	int				cpu;
223 };
224 
225 #define TRACE_FLAGS_MAX_SIZE		64
226 
227 struct trace_options {
228 	struct tracer			*tracer;
229 	struct trace_option_dentry	*topts;
230 };
231 
232 struct trace_pid_list *trace_pid_list_alloc(void);
233 void trace_pid_list_free(struct trace_pid_list *pid_list);
234 bool trace_pid_list_is_set(struct trace_pid_list *pid_list, unsigned int pid);
235 int trace_pid_list_set(struct trace_pid_list *pid_list, unsigned int pid);
236 int trace_pid_list_clear(struct trace_pid_list *pid_list, unsigned int pid);
237 int trace_pid_list_first(struct trace_pid_list *pid_list, unsigned int *pid);
238 int trace_pid_list_next(struct trace_pid_list *pid_list, unsigned int pid,
239 			unsigned int *next);
240 
241 enum {
242 	TRACE_PIDS		= BIT(0),
243 	TRACE_NO_PIDS		= BIT(1),
244 };
245 
246 static inline bool pid_type_enabled(int type, struct trace_pid_list *pid_list,
247 				    struct trace_pid_list *no_pid_list)
248 {
249 	/* Return true if the pid list in type has pids */
250 	return ((type & TRACE_PIDS) && pid_list) ||
251 		((type & TRACE_NO_PIDS) && no_pid_list);
252 }
253 
254 static inline bool still_need_pid_events(int type, struct trace_pid_list *pid_list,
255 					 struct trace_pid_list *no_pid_list)
256 {
257 	/*
258 	 * Turning off what is in @type, return true if the "other"
259 	 * pid list, still has pids in it.
260 	 */
261 	return (!(type & TRACE_PIDS) && pid_list) ||
262 		(!(type & TRACE_NO_PIDS) && no_pid_list);
263 }
264 
265 typedef bool (*cond_update_fn_t)(struct trace_array *tr, void *cond_data);
266 
267 /**
268  * struct cond_snapshot - conditional snapshot data and callback
269  *
270  * The cond_snapshot structure encapsulates a callback function and
271  * data associated with the snapshot for a given tracing instance.
272  *
273  * When a snapshot is taken conditionally, by invoking
274  * tracing_snapshot_cond(tr, cond_data), the cond_data passed in is
275  * passed in turn to the cond_snapshot.update() function.  That data
276  * can be compared by the update() implementation with the cond_data
277  * contained within the struct cond_snapshot instance associated with
278  * the trace_array.  Because the tr->max_lock is held throughout the
279  * update() call, the update() function can directly retrieve the
280  * cond_snapshot and cond_data associated with the per-instance
281  * snapshot associated with the trace_array.
282  *
283  * The cond_snapshot.update() implementation can save data to be
284  * associated with the snapshot if it decides to, and returns 'true'
285  * in that case, or it returns 'false' if the conditional snapshot
286  * shouldn't be taken.
287  *
288  * The cond_snapshot instance is created and associated with the
289  * user-defined cond_data by tracing_cond_snapshot_enable().
290  * Likewise, the cond_snapshot instance is destroyed and is no longer
291  * associated with the trace instance by
292  * tracing_cond_snapshot_disable().
293  *
294  * The method below is required.
295  *
296  * @update: When a conditional snapshot is invoked, the update()
297  *	callback function is invoked with the tr->max_lock held.  The
298  *	update() implementation signals whether or not to actually
299  *	take the snapshot, by returning 'true' if so, 'false' if no
300  *	snapshot should be taken.  Because the max_lock is held for
301  *	the duration of update(), the implementation is safe to
302  *	directly retrieved and save any implementation data it needs
303  *	to in association with the snapshot.
304  */
305 struct cond_snapshot {
306 	void				*cond_data;
307 	cond_update_fn_t		update;
308 };
309 
310 /*
311  * struct trace_func_repeats - used to keep track of the consecutive
312  * (on the same CPU) calls of a single function.
313  */
314 struct trace_func_repeats {
315 	unsigned long	ip;
316 	unsigned long	parent_ip;
317 	unsigned long	count;
318 	u64		ts_last_call;
319 };
320 
321 struct trace_module_delta {
322 	struct rcu_head	rcu;
323 	long		delta[];
324 };
325 
326 /*
327  * The trace array - an array of per-CPU trace arrays. This is the
328  * highest level data structure that individual tracers deal with.
329  * They have on/off state as well:
330  */
331 struct trace_array {
332 	struct list_head	list;
333 	char			*name;
334 	struct array_buffer	array_buffer;
335 #ifdef CONFIG_TRACER_SNAPSHOT
336 	/*
337 	 * The snapshot_buffer is used to snapshot the trace when a maximum
338 	 * latency is reached, or when the user initiates a snapshot.
339 	 * Some tracers will use this to store a maximum trace while
340 	 * it continues examining live traces.
341 	 *
342 	 * The buffers for the snapshot_buffer are set up the same as the
343 	 * array_buffer. When a snapshot is taken, the buffer of the
344 	 * snapshot_buffer is swapped with the buffer of the array_buffer
345 	 * and the buffers are reset for the array_buffer so the tracing can
346 	 * continue.
347 	 */
348 	struct array_buffer	snapshot_buffer;
349 	bool			allocated_snapshot;
350 	spinlock_t		snapshot_trigger_lock;
351 	unsigned int		snapshot;
352 #ifdef CONFIG_TRACER_MAX_TRACE
353 	unsigned long		max_latency;
354 	struct dentry		*d_max_latency;
355 #ifdef CONFIG_FSNOTIFY
356 	struct work_struct	fsnotify_work;
357 	struct irq_work		fsnotify_irqwork;
358 #endif /* CONFIG_FSNOTIFY */
359 #endif /* CONFIG_TRACER_MAX_TRACE */
360 #endif /* CONFIG_TRACER_SNAPSHOT */
361 
362 	/* The below is for memory mapped ring buffer */
363 	unsigned int		mapped;
364 	unsigned long		range_addr_start;
365 	unsigned long		range_addr_size;
366 	char			*range_name;
367 	long			text_delta;
368 	struct trace_module_delta *module_delta;
369 	void			*scratch; /* pointer in persistent memory */
370 	int			scratch_size;
371 
372 	int			buffer_disabled;
373 
374 	struct trace_pid_list	__rcu *filtered_pids;
375 	struct trace_pid_list	__rcu *filtered_no_pids;
376 	/*
377 	 * max_lock is used to protect the swapping of buffers
378 	 * when taking a max snapshot. The buffers themselves are
379 	 * protected by per_cpu spinlocks. But the action of the swap
380 	 * needs its own lock.
381 	 *
382 	 * This is defined as a arch_spinlock_t in order to help
383 	 * with performance when lockdep debugging is enabled.
384 	 *
385 	 * It is also used in other places outside the update_max_tr
386 	 * so it needs to be defined outside of the
387 	 * CONFIG_TRACER_SNAPSHOT.
388 	 */
389 	arch_spinlock_t		max_lock;
390 #ifdef CONFIG_FTRACE_SYSCALLS
391 	int			sys_refcount_enter;
392 	int			sys_refcount_exit;
393 	struct trace_event_file	*enter_syscall_files[NR_syscalls];
394 	struct trace_event_file	*exit_syscall_files[NR_syscalls];
395 #endif
396 	int			stop_count;
397 	int			clock_id;
398 	int			nr_topts;
399 	bool			clear_trace;
400 	int			buffer_percent;
401 	unsigned int		n_err_log_entries;
402 	struct tracer		*current_trace;
403 	struct tracer_flags	*current_trace_flags;
404 	u64			trace_flags;
405 	unsigned char		trace_flags_index[TRACE_FLAGS_MAX_SIZE];
406 	unsigned int		flags;
407 	raw_spinlock_t		start_lock;
408 	const char		*system_names;
409 	struct list_head	err_log;
410 	struct dentry		*dir;
411 	struct dentry		*options;
412 	struct dentry		*percpu_dir;
413 	struct eventfs_inode	*event_dir;
414 	struct trace_options	*topts;
415 	struct list_head	systems;
416 	struct list_head	events;
417 	struct list_head	marker_list;
418 	struct list_head	tracers;
419 	struct trace_event_file *trace_marker_file;
420 	cpumask_var_t		tracing_cpumask; /* only trace on set CPUs */
421 	/* one per_cpu trace_pipe can be opened by only one user */
422 	cpumask_var_t		pipe_cpumask;
423 	int			ref;
424 	int			trace_ref;
425 #ifdef CONFIG_MODULES
426 	struct list_head	mod_events;
427 #endif
428 #ifdef CONFIG_FUNCTION_TRACER
429 	struct ftrace_ops	*ops;
430 	struct trace_pid_list	__rcu *function_pids;
431 	struct trace_pid_list	__rcu *function_no_pids;
432 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
433 	struct fgraph_ops	*gops;
434 #endif
435 #ifdef CONFIG_DYNAMIC_FTRACE
436 	/* All of these are protected by the ftrace_lock */
437 	struct list_head	func_probes;
438 	struct list_head	mod_trace;
439 	struct list_head	mod_notrace;
440 #endif
441 	/* function tracing enabled */
442 	int			function_enabled;
443 #endif
444 	int			no_filter_buffering_ref;
445 	unsigned int		syscall_buf_sz;
446 	struct list_head	hist_vars;
447 #ifdef CONFIG_TRACER_SNAPSHOT
448 	struct cond_snapshot	*cond_snapshot;
449 #endif
450 	struct trace_func_repeats	__percpu *last_func_repeats;
451 	/*
452 	 * On boot up, the ring buffer is set to the minimum size, so that
453 	 * we do not waste memory on systems that are not using tracing.
454 	 */
455 	bool ring_buffer_expanded;
456 };
457 
458 enum {
459 	TRACE_ARRAY_FL_GLOBAL		= BIT(0),
460 	TRACE_ARRAY_FL_BOOT		= BIT(1),
461 	TRACE_ARRAY_FL_LAST_BOOT	= BIT(2),
462 	TRACE_ARRAY_FL_MOD_INIT		= BIT(3),
463 	TRACE_ARRAY_FL_MEMMAP		= BIT(4),
464 	TRACE_ARRAY_FL_VMALLOC		= BIT(5),
465 };
466 
467 #ifdef CONFIG_MODULES
468 bool module_exists(const char *module);
469 #else
470 static inline bool module_exists(const char *module)
471 {
472 	return false;
473 }
474 #endif
475 
476 extern struct list_head ftrace_trace_arrays;
477 
478 extern struct mutex trace_types_lock;
479 
480 extern int trace_array_get(struct trace_array *tr);
481 extern int tracing_check_open_get_tr(struct trace_array *tr);
482 extern struct trace_array *trace_array_find(const char *instance);
483 extern struct trace_array *trace_array_find_get(const char *instance);
484 
485 extern u64 tracing_event_time_stamp(struct trace_buffer *buffer, struct ring_buffer_event *rbe);
486 extern int tracing_set_clock(struct trace_array *tr, const char *clockstr);
487 
488 extern bool trace_clock_in_ns(struct trace_array *tr);
489 
490 extern unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr);
491 
492 extern struct trace_array *printk_trace;
493 
494 /*
495  * The global tracer (top) should be the first trace array added,
496  * but we check the flag anyway.
497  */
498 static inline struct trace_array *top_trace_array(void)
499 {
500 	struct trace_array *tr;
501 
502 	if (list_empty(&ftrace_trace_arrays))
503 		return NULL;
504 
505 	tr = list_entry(ftrace_trace_arrays.prev,
506 			typeof(*tr), list);
507 	WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
508 	return tr;
509 }
510 
511 #define FTRACE_CMP_TYPE(var, type) \
512 	__builtin_types_compatible_p(typeof(var), type *)
513 
514 #undef IF_ASSIGN
515 #define IF_ASSIGN(var, entry, etype, id)			\
516 	if (FTRACE_CMP_TYPE(var, etype)) {			\
517 		var = (typeof(var))(entry);			\
518 		WARN_ON(id != 0 && (entry)->type != id);	\
519 		break;						\
520 	}
521 
522 /* Will cause compile errors if type is not found. */
523 extern void __ftrace_bad_type(void);
524 
525 /*
526  * The trace_assign_type is a verifier that the entry type is
527  * the same as the type being assigned. To add new types simply
528  * add a line with the following format:
529  *
530  * IF_ASSIGN(var, ent, type, id);
531  *
532  *  Where "type" is the trace type that includes the trace_entry
533  *  as the "ent" item. And "id" is the trace identifier that is
534  *  used in the trace_type enum.
535  *
536  *  If the type can have more than one id, then use zero.
537  */
538 #define trace_assign_type(var, ent)					\
539 	do {								\
540 		IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN);	\
541 		IF_ASSIGN(var, ent, struct ctx_switch_entry, 0);	\
542 		IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK);	\
543 		IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
544 		IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT);	\
545 		IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT);	\
546 		IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS);	\
547 		IF_ASSIGN(var, ent, struct hwlat_entry, TRACE_HWLAT);	\
548 		IF_ASSIGN(var, ent, struct osnoise_entry, TRACE_OSNOISE);\
549 		IF_ASSIGN(var, ent, struct timerlat_entry, TRACE_TIMERLAT);\
550 		IF_ASSIGN(var, ent, struct raw_data_entry, TRACE_RAW_DATA);\
551 		IF_ASSIGN(var, ent, struct trace_mmiotrace_rw,		\
552 			  TRACE_MMIO_RW);				\
553 		IF_ASSIGN(var, ent, struct trace_mmiotrace_map,		\
554 			  TRACE_MMIO_MAP);				\
555 		IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
556 		IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry,	\
557 			  TRACE_GRAPH_ENT);		\
558 		IF_ASSIGN(var, ent, struct fgraph_retaddr_ent_entry,\
559 			  TRACE_GRAPH_RETADDR_ENT);		\
560 		IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry,	\
561 			  TRACE_GRAPH_RET);		\
562 		IF_ASSIGN(var, ent, struct func_repeats_entry,		\
563 			  TRACE_FUNC_REPEATS);				\
564 		__ftrace_bad_type();					\
565 	} while (0)
566 
567 /*
568  * An option specific to a tracer. This is a boolean value.
569  * The bit is the bit index that sets its value on the
570  * flags value in struct tracer_flags.
571  */
572 struct tracer_opt {
573 	const char	*name; /* Will appear on the trace_options file */
574 	u32		bit; /* Mask assigned in val field in tracer_flags */
575 };
576 
577 /*
578  * The set of specific options for a tracer. Your tracer
579  * have to set the initial value of the flags val.
580  */
581 struct tracer_flags {
582 	u32			val;
583 	struct tracer_opt	*opts;
584 	struct tracer		*trace;
585 };
586 
587 /* Makes more easy to define a tracer opt */
588 #define TRACER_OPT(s, b)	.name = #s, .bit = b
589 
590 
591 struct trace_option_dentry {
592 	struct tracer_opt		*opt;
593 	struct tracer_flags		*flags;
594 	struct trace_array		*tr;
595 	struct dentry			*entry;
596 };
597 
598 /**
599  * struct tracer - a specific tracer and its callbacks to interact with tracefs
600  * @name: the name chosen to select it on the available_tracers file
601  * @init: called when one switches to this tracer (echo name > current_tracer)
602  * @reset: called when one switches to another tracer
603  * @start: called when tracing is unpaused (echo 1 > tracing_on)
604  * @stop: called when tracing is paused (echo 0 > tracing_on)
605  * @update_thresh: called when tracing_thresh is updated
606  * @open: called when the trace file is opened
607  * @pipe_open: called when the trace_pipe file is opened
608  * @close: called when the trace file is released
609  * @pipe_close: called when the trace_pipe file is released
610  * @read: override the default read callback on trace_pipe
611  * @splice_read: override the default splice_read callback on trace_pipe
612  * @selftest: selftest to run on boot (see trace_selftest.c)
613  * @print_headers: override the first lines that describe your columns
614  * @print_line: callback that prints a trace
615  * @set_flag: signals one of your private flags changed (trace_options file)
616  * @flags: your private flags
617  */
618 struct tracer {
619 	const char		*name;
620 	int			(*init)(struct trace_array *tr);
621 	void			(*reset)(struct trace_array *tr);
622 	void			(*start)(struct trace_array *tr);
623 	void			(*stop)(struct trace_array *tr);
624 	int			(*update_thresh)(struct trace_array *tr);
625 	void			(*open)(struct trace_iterator *iter);
626 	void			(*pipe_open)(struct trace_iterator *iter);
627 	void			(*close)(struct trace_iterator *iter);
628 	void			(*pipe_close)(struct trace_iterator *iter);
629 	ssize_t			(*read)(struct trace_iterator *iter,
630 					struct file *filp, char __user *ubuf,
631 					size_t cnt, loff_t *ppos);
632 	ssize_t			(*splice_read)(struct trace_iterator *iter,
633 					       struct file *filp,
634 					       loff_t *ppos,
635 					       struct pipe_inode_info *pipe,
636 					       size_t len,
637 					       unsigned int flags);
638 #ifdef CONFIG_FTRACE_STARTUP_TEST
639 	int			(*selftest)(struct tracer *trace,
640 					    struct trace_array *tr);
641 #endif
642 	void			(*print_header)(struct seq_file *m);
643 	enum print_line_t	(*print_line)(struct trace_iterator *iter);
644 	/* If you handled the flag setting, return 0 */
645 	int			(*set_flag)(struct trace_array *tr,
646 					    u32 old_flags, u32 bit, int set);
647 	/* Return 0 if OK with change, else return non-zero */
648 	int			(*flag_changed)(struct trace_array *tr,
649 						u64 mask, int set);
650 	struct tracer		*next;
651 	struct tracer_flags	*flags;
652 	struct tracer_flags	*default_flags;
653 	int			enabled;
654 	bool			print_max;
655 	bool			allow_instances;
656 #ifdef CONFIG_TRACER_MAX_TRACE
657 	bool			use_max_tr;
658 #endif
659 	/* True if tracer cannot be enabled in kernel param */
660 	bool			noboot;
661 };
662 
663 static inline struct ring_buffer_iter *
664 trace_buffer_iter(struct trace_iterator *iter, int cpu)
665 {
666 	return iter->buffer_iter ? iter->buffer_iter[cpu] : NULL;
667 }
668 
669 extern int tracing_disabled;
670 
671 int tracer_init(struct tracer *t, struct trace_array *tr);
672 int tracing_is_enabled(void);
673 void tracing_reset_online_cpus(struct array_buffer *buf);
674 void tracing_reset_all_online_cpus(void);
675 void tracing_reset_all_online_cpus_unlocked(void);
676 int tracing_open_generic(struct inode *inode, struct file *filp);
677 int tracing_open_generic_tr(struct inode *inode, struct file *filp);
678 int tracing_release_generic_tr(struct inode *inode, struct file *file);
679 int tracing_open_file_tr(struct inode *inode, struct file *filp);
680 int tracing_release_file_tr(struct inode *inode, struct file *filp);
681 int tracing_single_release_file_tr(struct inode *inode, struct file *filp);
682 bool tracer_tracing_is_on(struct trace_array *tr);
683 void tracer_tracing_on(struct trace_array *tr);
684 void tracer_tracing_off(struct trace_array *tr);
685 void tracer_tracing_disable(struct trace_array *tr);
686 void tracer_tracing_enable(struct trace_array *tr);
687 struct dentry *trace_create_file(const char *name,
688 				 umode_t mode,
689 				 struct dentry *parent,
690 				 void *data,
691 				 const struct file_operations *fops);
692 
693 
694 /**
695  * tracer_tracing_is_on_cpu - show real state of ring buffer enabled on for a cpu
696  * @tr : the trace array to know if ring buffer is enabled
697  * @cpu: The cpu buffer to check if enabled
698  *
699  * Shows real state of the per CPU buffer if it is enabled or not.
700  */
701 static inline bool tracer_tracing_is_on_cpu(struct trace_array *tr, int cpu)
702 {
703 	if (tr->array_buffer.buffer)
704 		return ring_buffer_record_is_on_cpu(tr->array_buffer.buffer, cpu);
705 	return false;
706 }
707 
708 int tracing_init_dentry(void);
709 
710 struct ring_buffer_event;
711 
712 struct ring_buffer_event *
713 trace_buffer_lock_reserve(struct trace_buffer *buffer,
714 			  int type,
715 			  unsigned long len,
716 			  unsigned int trace_ctx);
717 
718 int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, int cpu);
719 
720 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
721 						struct trace_array_cpu *data);
722 
723 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
724 					  int *ent_cpu, u64 *ent_ts);
725 
726 void trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
727 					struct ring_buffer_event *event);
728 
729 bool trace_is_tracepoint_string(const char *str);
730 const char *trace_event_format(struct trace_iterator *iter, const char *fmt);
731 char *trace_iter_expand_format(struct trace_iterator *iter);
732 bool ignore_event(struct trace_iterator *iter);
733 
734 int trace_empty(struct trace_iterator *iter);
735 
736 void *trace_find_next_entry_inc(struct trace_iterator *iter);
737 
738 void trace_init_global_iter(struct trace_iterator *iter);
739 
740 void tracing_iter_reset(struct trace_iterator *iter, int cpu);
741 
742 unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu);
743 unsigned long trace_total_entries(struct trace_array *tr);
744 
745 void trace_function(struct trace_array *tr,
746 		    unsigned long ip,
747 		    unsigned long parent_ip,
748 		    unsigned int trace_ctx,
749 		    struct ftrace_regs *regs);
750 void trace_graph_function(struct trace_array *tr,
751 		    unsigned long ip,
752 		    unsigned long parent_ip,
753 		    unsigned int trace_ctx);
754 void trace_latency_header(struct seq_file *m);
755 void trace_default_header(struct seq_file *m);
756 void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
757 
758 void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops,
759 			struct ftrace_regs *fregs);
760 int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
761 		      struct ftrace_regs *fregs);
762 
763 void tracing_start_cmdline_record(void);
764 void tracing_stop_cmdline_record(void);
765 void tracing_start_tgid_record(void);
766 void tracing_stop_tgid_record(void);
767 
768 int register_tracer(struct tracer *type);
769 int is_tracing_stopped(void);
770 
771 loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
772 
773 extern cpumask_var_t __read_mostly tracing_buffer_mask;
774 
775 #define for_each_tracing_cpu(cpu)	\
776 	for_each_cpu(cpu, tracing_buffer_mask)
777 
778 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
779 
780 extern unsigned long tracing_thresh;
781 extern struct workqueue_struct *trace_init_wq __initdata;
782 
783 /* PID filtering */
784 
785 bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids,
786 			     pid_t search_pid);
787 bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
788 			    struct trace_pid_list *filtered_no_pids,
789 			    struct task_struct *task);
790 void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
791 				  struct task_struct *self,
792 				  struct task_struct *task);
793 void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
794 void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
795 int trace_pid_show(struct seq_file *m, void *v);
796 int trace_pid_write(struct trace_pid_list *filtered_pids,
797 		    struct trace_pid_list **new_pid_list,
798 		    const char __user *ubuf, size_t cnt);
799 
800 #ifdef CONFIG_TRACER_SNAPSHOT
801 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
802 		   void *cond_data);
803 void update_max_tr_single(struct trace_array *tr,
804 			  struct task_struct *tsk, int cpu);
805 
806 #if defined(CONFIG_TRACER_MAX_TRACE) && defined(CONFIG_FSNOTIFY)
807 # define LATENCY_FS_NOTIFY
808 #endif
809 
810 #ifdef LATENCY_FS_NOTIFY
811 void latency_fsnotify(struct trace_array *tr);
812 #else
813 static inline void latency_fsnotify(struct trace_array *tr) { }
814 #endif
815 #endif /* CONFIG_TRACER_SNAPSHOT */
816 
817 #ifdef CONFIG_STACKTRACE
818 void __trace_stack(struct trace_array *tr, unsigned int trace_ctx, int skip);
819 #else
820 static inline void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,
821 				 int skip)
822 {
823 }
824 #endif /* CONFIG_STACKTRACE */
825 
826 #ifdef CONFIG_TRACER_MAX_TRACE
827 static inline bool tracer_uses_snapshot(struct tracer *tracer)
828 {
829 	return tracer->use_max_tr;
830 }
831 #else
832 static inline bool tracer_uses_snapshot(struct tracer *tracer)
833 {
834 	return false;
835 }
836 #endif
837 
838 void trace_last_func_repeats(struct trace_array *tr,
839 			     struct trace_func_repeats *last_info,
840 			     unsigned int trace_ctx);
841 
842 extern u64 ftrace_now(int cpu);
843 
844 extern void trace_find_cmdline(int pid, char comm[]);
845 extern int trace_find_tgid(int pid);
846 extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
847 
848 extern int trace_events_enabled(struct trace_array *tr, const char *system);
849 
850 #ifdef CONFIG_DYNAMIC_FTRACE
851 extern unsigned long ftrace_update_tot_cnt;
852 extern unsigned long ftrace_number_of_pages;
853 extern unsigned long ftrace_number_of_groups;
854 extern u64 ftrace_update_time;
855 extern u64 ftrace_total_mod_time;
856 void ftrace_init_trace_array(struct trace_array *tr);
857 #else
858 static inline void ftrace_init_trace_array(struct trace_array *tr) { }
859 #endif
860 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
861 extern int DYN_FTRACE_TEST_NAME(void);
862 #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
863 extern int DYN_FTRACE_TEST_NAME2(void);
864 
865 extern void trace_set_ring_buffer_expanded(struct trace_array *tr);
866 extern bool tracing_selftest_disabled;
867 
868 #ifdef CONFIG_FTRACE_STARTUP_TEST
869 extern void __init disable_tracing_selftest(const char *reason);
870 
871 extern int trace_selftest_startup_function(struct tracer *trace,
872 					   struct trace_array *tr);
873 extern int trace_selftest_startup_function_graph(struct tracer *trace,
874 						 struct trace_array *tr);
875 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
876 					  struct trace_array *tr);
877 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
878 					     struct trace_array *tr);
879 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
880 						 struct trace_array *tr);
881 extern int trace_selftest_startup_wakeup(struct tracer *trace,
882 					 struct trace_array *tr);
883 extern int trace_selftest_startup_nop(struct tracer *trace,
884 					 struct trace_array *tr);
885 extern int trace_selftest_startup_branch(struct tracer *trace,
886 					 struct trace_array *tr);
887 extern bool __read_mostly tracing_selftest_running;
888 /*
889  * Tracer data references selftest functions that only occur
890  * on boot up. These can be __init functions. Thus, when selftests
891  * are enabled, then the tracers need to reference __init functions.
892  */
893 #define __tracer_data		__refdata
894 #else
895 static inline void __init disable_tracing_selftest(const char *reason)
896 {
897 }
898 /* Tracers are seldom changed. Optimize when selftests are disabled. */
899 #define __tracer_data		__read_mostly
900 #define tracing_selftest_running	0
901 #endif /* CONFIG_FTRACE_STARTUP_TEST */
902 
903 extern void *head_page(struct trace_array_cpu *data);
904 extern unsigned long long ns2usecs(u64 nsec);
905 
906 __printf(2, 0)
907 int trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
908 __printf(2, 0)
909 int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
910 __printf(3, 0)
911 int trace_array_vprintk(struct trace_array *tr,
912 			unsigned long ip, const char *fmt, va_list args);
913 __printf(3, 4)
914 int trace_array_printk_buf(struct trace_buffer *buffer,
915 			   unsigned long ip, const char *fmt, ...);
916 void trace_printk_seq(struct trace_seq *s);
917 enum print_line_t print_trace_line(struct trace_iterator *iter);
918 
919 extern char trace_find_mark(unsigned long long duration);
920 
921 struct ftrace_hash;
922 
923 struct ftrace_mod_load {
924 	struct list_head	list;
925 	char			*func;
926 	char			*module;
927 	int			 enable;
928 };
929 
930 enum {
931 	FTRACE_HASH_FL_MOD	= (1 << 0),
932 };
933 
934 struct ftrace_hash {
935 	unsigned long		size_bits;
936 	struct hlist_head	*buckets;
937 	unsigned long		count;
938 	unsigned long		flags;
939 	struct rcu_head		rcu;
940 };
941 
942 struct ftrace_func_entry *
943 ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
944 
945 static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
946 {
947 	return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
948 }
949 
950 /* Standard output formatting function used for function return traces */
951 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
952 
953 /* Flag options */
954 #define TRACE_GRAPH_PRINT_OVERRUN       0x1
955 #define TRACE_GRAPH_PRINT_CPU           0x2
956 #define TRACE_GRAPH_PRINT_OVERHEAD      0x4
957 #define TRACE_GRAPH_PRINT_PROC          0x8
958 #define TRACE_GRAPH_PRINT_DURATION      0x10
959 #define TRACE_GRAPH_PRINT_ABS_TIME      0x20
960 #define TRACE_GRAPH_PRINT_REL_TIME      0x40
961 #define TRACE_GRAPH_PRINT_IRQS          0x80
962 #define TRACE_GRAPH_PRINT_TAIL          0x100
963 #define TRACE_GRAPH_SLEEP_TIME          0x200
964 #define TRACE_GRAPH_GRAPH_TIME          0x400
965 #define TRACE_GRAPH_PRINT_RETVAL        0x800
966 #define TRACE_GRAPH_PRINT_RETVAL_HEX    0x1000
967 #define TRACE_GRAPH_PRINT_RETADDR       0x2000
968 #define TRACE_GRAPH_ARGS		0x4000
969 #define TRACE_GRAPH_PRINT_FILL_SHIFT	28
970 #define TRACE_GRAPH_PRINT_FILL_MASK	(0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
971 
972 #ifdef CONFIG_FUNCTION_PROFILER
973 extern void ftrace_graph_graph_time_control(bool enable);
974 #else
975 static inline void ftrace_graph_graph_time_control(bool enable) { }
976 #endif
977 
978 extern enum print_line_t
979 print_graph_function_flags(struct trace_iterator *iter, u32 flags);
980 extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
981 extern void
982 trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
983 extern void graph_trace_open(struct trace_iterator *iter);
984 extern void graph_trace_close(struct trace_iterator *iter);
985 extern int __trace_graph_entry(struct trace_array *tr,
986 			       struct ftrace_graph_ent *trace,
987 			       unsigned int trace_ctx);
988 extern int __trace_graph_retaddr_entry(struct trace_array *tr,
989 				struct ftrace_graph_ent *trace,
990 				unsigned int trace_ctx,
991 				unsigned long retaddr,
992 				struct ftrace_regs *fregs);
993 extern void __trace_graph_return(struct trace_array *tr,
994 				 struct ftrace_graph_ret *trace,
995 				 unsigned int trace_ctx,
996 				 u64 calltime, u64 rettime);
997 
998 extern void init_array_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops);
999 extern int allocate_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops);
1000 extern void free_fgraph_ops(struct trace_array *tr);
1001 
1002 enum {
1003 	TRACE_GRAPH_FL		= 1,
1004 
1005 	/*
1006 	 * In the very unlikely case that an interrupt came in
1007 	 * at a start of graph tracing, and we want to trace
1008 	 * the function in that interrupt, the depth can be greater
1009 	 * than zero, because of the preempted start of a previous
1010 	 * trace. In an even more unlikely case, depth could be 2
1011 	 * if a softirq interrupted the start of graph tracing,
1012 	 * followed by an interrupt preempting a start of graph
1013 	 * tracing in the softirq, and depth can even be 3
1014 	 * if an NMI came in at the start of an interrupt function
1015 	 * that preempted a softirq start of a function that
1016 	 * preempted normal context!!!! Luckily, it can't be
1017 	 * greater than 3, so the next two bits are a mask
1018 	 * of what the depth is when we set TRACE_GRAPH_FL
1019 	 */
1020 
1021 	TRACE_GRAPH_DEPTH_START_BIT,
1022 	TRACE_GRAPH_DEPTH_END_BIT,
1023 
1024 	/*
1025 	 * To implement set_graph_notrace, if this bit is set, we ignore
1026 	 * function graph tracing of called functions, until the return
1027 	 * function is called to clear it.
1028 	 */
1029 	TRACE_GRAPH_NOTRACE_BIT,
1030 };
1031 
1032 #define TRACE_GRAPH_NOTRACE		(1 << TRACE_GRAPH_NOTRACE_BIT)
1033 
1034 static inline unsigned long ftrace_graph_depth(unsigned long *task_var)
1035 {
1036 	return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3;
1037 }
1038 
1039 static inline void ftrace_graph_set_depth(unsigned long *task_var, int depth)
1040 {
1041 	*task_var &= ~(3 << TRACE_GRAPH_DEPTH_START_BIT);
1042 	*task_var |= (depth & 3) << TRACE_GRAPH_DEPTH_START_BIT;
1043 }
1044 
1045 #ifdef CONFIG_DYNAMIC_FTRACE
1046 extern struct ftrace_hash __rcu *ftrace_graph_hash;
1047 extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash;
1048 
1049 static inline int
1050 ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace)
1051 {
1052 	unsigned long addr = trace->func;
1053 	int ret = 0;
1054 	struct ftrace_hash *hash;
1055 
1056 	preempt_disable_notrace();
1057 
1058 	/*
1059 	 * Have to open code "rcu_dereference_sched()" because the
1060 	 * function graph tracer can be called when RCU is not
1061 	 * "watching".
1062 	 * Protected with schedule_on_each_cpu(ftrace_sync)
1063 	 */
1064 	hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
1065 
1066 	if (ftrace_hash_empty(hash)) {
1067 		ret = 1;
1068 		goto out;
1069 	}
1070 
1071 	if (ftrace_lookup_ip(hash, addr)) {
1072 		/*
1073 		 * This needs to be cleared on the return functions
1074 		 * when the depth is zero.
1075 		 */
1076 		*task_var |= TRACE_GRAPH_FL;
1077 		ftrace_graph_set_depth(task_var, trace->depth);
1078 
1079 		/*
1080 		 * If no irqs are to be traced, but a set_graph_function
1081 		 * is set, and called by an interrupt handler, we still
1082 		 * want to trace it.
1083 		 */
1084 		if (in_hardirq())
1085 			trace_recursion_set(TRACE_IRQ_BIT);
1086 		else
1087 			trace_recursion_clear(TRACE_IRQ_BIT);
1088 		ret = 1;
1089 	}
1090 
1091 out:
1092 	preempt_enable_notrace();
1093 	return ret;
1094 }
1095 
1096 static inline void
1097 ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace)
1098 {
1099 	unsigned long *task_var = fgraph_get_task_var(gops);
1100 
1101 	if ((*task_var & TRACE_GRAPH_FL) &&
1102 	    trace->depth == ftrace_graph_depth(task_var))
1103 		*task_var &= ~TRACE_GRAPH_FL;
1104 }
1105 
1106 static inline int ftrace_graph_notrace_addr(unsigned long addr)
1107 {
1108 	int ret = 0;
1109 	struct ftrace_hash *notrace_hash;
1110 
1111 	preempt_disable_notrace();
1112 
1113 	/*
1114 	 * Have to open code "rcu_dereference_sched()" because the
1115 	 * function graph tracer can be called when RCU is not
1116 	 * "watching".
1117 	 * Protected with schedule_on_each_cpu(ftrace_sync)
1118 	 */
1119 	notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
1120 						 !preemptible());
1121 
1122 	if (ftrace_lookup_ip(notrace_hash, addr))
1123 		ret = 1;
1124 
1125 	preempt_enable_notrace();
1126 	return ret;
1127 }
1128 #else
1129 static inline int ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace)
1130 {
1131 	return 1;
1132 }
1133 
1134 static inline int ftrace_graph_notrace_addr(unsigned long addr)
1135 {
1136 	return 0;
1137 }
1138 static inline void ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace)
1139 { }
1140 #endif /* CONFIG_DYNAMIC_FTRACE */
1141 
1142 extern unsigned int fgraph_max_depth;
1143 extern int fgraph_no_sleep_time;
1144 extern bool fprofile_no_sleep_time;
1145 
1146 static inline bool
1147 ftrace_graph_ignore_func(struct fgraph_ops *gops, struct ftrace_graph_ent *trace)
1148 {
1149 	unsigned long *task_var = fgraph_get_task_var(gops);
1150 
1151 	/* trace it when it is-nested-in or is a function enabled. */
1152 	return !((*task_var & TRACE_GRAPH_FL) ||
1153 		 ftrace_graph_addr(task_var, trace)) ||
1154 		(trace->depth < 0) ||
1155 		(fgraph_max_depth && trace->depth >= fgraph_max_depth);
1156 }
1157 
1158 void fgraph_init_ops(struct ftrace_ops *dst_ops,
1159 		     struct ftrace_ops *src_ops);
1160 
1161 #else /* CONFIG_FUNCTION_GRAPH_TRACER */
1162 static inline enum print_line_t
1163 print_graph_function_flags(struct trace_iterator *iter, u32 flags)
1164 {
1165 	return TRACE_TYPE_UNHANDLED;
1166 }
1167 static inline void free_fgraph_ops(struct trace_array *tr) { }
1168 /* ftrace_ops may not be defined */
1169 #define init_array_fgraph_ops(tr, ops) do { } while (0)
1170 #define allocate_fgraph_ops(tr, ops) ({ 0; })
1171 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
1172 
1173 extern struct list_head ftrace_pids;
1174 
1175 #ifdef CONFIG_FUNCTION_TRACER
1176 
1177 #define FTRACE_PID_IGNORE	-1
1178 #define FTRACE_PID_TRACE	-2
1179 
1180 struct ftrace_func_command {
1181 	struct list_head	list;
1182 	char			*name;
1183 	int			(*func)(struct trace_array *tr,
1184 					struct ftrace_hash *hash,
1185 					char *func, char *cmd,
1186 					char *params, int enable);
1187 };
1188 extern bool ftrace_filter_param __initdata;
1189 extern int ftrace_is_dead(void);
1190 int ftrace_create_function_files(struct trace_array *tr,
1191 				 struct dentry *parent);
1192 void ftrace_destroy_function_files(struct trace_array *tr);
1193 int ftrace_allocate_ftrace_ops(struct trace_array *tr);
1194 void ftrace_free_ftrace_ops(struct trace_array *tr);
1195 void ftrace_init_global_array_ops(struct trace_array *tr);
1196 struct trace_array *trace_get_global_array(void);
1197 void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
1198 void ftrace_reset_array_ops(struct trace_array *tr);
1199 void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
1200 void ftrace_init_tracefs_toplevel(struct trace_array *tr,
1201 				  struct dentry *d_tracer);
1202 void ftrace_clear_pids(struct trace_array *tr);
1203 int init_function_trace(void);
1204 void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
1205 #else
1206 static inline int ftrace_is_dead(void) { return 0; }
1207 static inline int
1208 ftrace_create_function_files(struct trace_array *tr,
1209 			     struct dentry *parent)
1210 {
1211 	return 0;
1212 }
1213 static inline int ftrace_allocate_ftrace_ops(struct trace_array *tr)
1214 {
1215 	return 0;
1216 }
1217 static inline void ftrace_free_ftrace_ops(struct trace_array *tr) { }
1218 static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
1219 static inline __init void
1220 ftrace_init_global_array_ops(struct trace_array *tr) { }
1221 static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
1222 static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
1223 static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
1224 static inline void ftrace_clear_pids(struct trace_array *tr) { }
1225 static inline int init_function_trace(void) { return 0; }
1226 static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
1227 /* ftace_func_t type is not defined, use macro instead of static inline */
1228 #define ftrace_init_array_ops(tr, func) do { } while (0)
1229 #endif /* CONFIG_FUNCTION_TRACER */
1230 
1231 #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
1232 
1233 struct ftrace_probe_ops {
1234 	void			(*func)(unsigned long ip,
1235 					unsigned long parent_ip,
1236 					struct trace_array *tr,
1237 					struct ftrace_probe_ops *ops,
1238 					void *data);
1239 	int			(*init)(struct ftrace_probe_ops *ops,
1240 					struct trace_array *tr,
1241 					unsigned long ip, void *init_data,
1242 					void **data);
1243 	void			(*free)(struct ftrace_probe_ops *ops,
1244 					struct trace_array *tr,
1245 					unsigned long ip, void *data);
1246 	int			(*print)(struct seq_file *m,
1247 					 unsigned long ip,
1248 					 struct ftrace_probe_ops *ops,
1249 					 void *data);
1250 };
1251 
1252 struct ftrace_func_mapper;
1253 typedef int (*ftrace_mapper_func)(void *data);
1254 
1255 struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
1256 void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
1257 					   unsigned long ip);
1258 int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
1259 			       unsigned long ip, void *data);
1260 void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
1261 				   unsigned long ip);
1262 void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
1263 			     ftrace_mapper_func free_func);
1264 
1265 extern int
1266 register_ftrace_function_probe(char *glob, struct trace_array *tr,
1267 			       struct ftrace_probe_ops *ops, void *data);
1268 extern int
1269 unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
1270 				      struct ftrace_probe_ops *ops);
1271 extern void clear_ftrace_function_probes(struct trace_array *tr);
1272 
1273 int register_ftrace_command(struct ftrace_func_command *cmd);
1274 int unregister_ftrace_command(struct ftrace_func_command *cmd);
1275 
1276 void ftrace_create_filter_files(struct ftrace_ops *ops,
1277 				struct dentry *parent);
1278 void ftrace_destroy_filter_files(struct ftrace_ops *ops);
1279 
1280 extern int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
1281 			     int len, int reset);
1282 extern int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
1283 			      int len, int reset);
1284 #else
1285 struct ftrace_func_command;
1286 
1287 static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
1288 {
1289 	return -EINVAL;
1290 }
1291 static inline __init int unregister_ftrace_command(char *cmd_name)
1292 {
1293 	return -EINVAL;
1294 }
1295 static inline void clear_ftrace_function_probes(struct trace_array *tr)
1296 {
1297 }
1298 
1299 /*
1300  * The ops parameter passed in is usually undefined.
1301  * This must be a macro.
1302  */
1303 #define ftrace_create_filter_files(ops, parent) do { } while (0)
1304 #define ftrace_destroy_filter_files(ops) do { } while (0)
1305 #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
1306 
1307 bool ftrace_event_is_function(struct trace_event_call *call);
1308 
1309 /*
1310  * struct trace_parser - servers for reading the user input separated by spaces
1311  * @cont: set if the input is not complete - no final space char was found
1312  * @buffer: holds the parsed user input
1313  * @idx: user input length
1314  * @size: buffer size
1315  */
1316 struct trace_parser {
1317 	bool		cont;
1318 	bool		fail;
1319 	char		*buffer;
1320 	unsigned	idx;
1321 	unsigned	size;
1322 };
1323 
1324 static inline bool trace_parser_loaded(struct trace_parser *parser)
1325 {
1326 	return !parser->fail && parser->idx != 0;
1327 }
1328 
1329 static inline bool trace_parser_cont(struct trace_parser *parser)
1330 {
1331 	return parser->cont;
1332 }
1333 
1334 static inline void trace_parser_clear(struct trace_parser *parser)
1335 {
1336 	parser->cont = false;
1337 	parser->idx = 0;
1338 }
1339 
1340 static inline void trace_parser_fail(struct trace_parser *parser)
1341 {
1342 	parser->fail = true;
1343 }
1344 
1345 extern int trace_parser_get_init(struct trace_parser *parser, int size);
1346 extern void trace_parser_put(struct trace_parser *parser);
1347 extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
1348 	size_t cnt, loff_t *ppos);
1349 
1350 /*
1351  * Only create function graph options if function graph is configured.
1352  */
1353 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1354 # define FGRAPH_FLAGS						\
1355 		C(DISPLAY_GRAPH,	"display-graph"),
1356 #else
1357 # define FGRAPH_FLAGS
1358 #endif
1359 
1360 #ifdef CONFIG_BRANCH_TRACER
1361 # define BRANCH_FLAGS					\
1362 		C(BRANCH,		"branch"),
1363 #else
1364 # define BRANCH_FLAGS
1365 #endif
1366 
1367 #ifdef CONFIG_FUNCTION_TRACER
1368 # define FUNCTION_FLAGS						\
1369 		C(FUNCTION,		"function-trace"),	\
1370 		C(FUNC_FORK,		"function-fork"),
1371 # define FUNCTION_DEFAULT_FLAGS		TRACE_ITER(FUNCTION)
1372 #else
1373 # define FUNCTION_FLAGS
1374 # define FUNCTION_DEFAULT_FLAGS		0UL
1375 # define TRACE_ITER_FUNC_FORK_BIT	-1
1376 #endif
1377 
1378 #ifdef CONFIG_STACKTRACE
1379 # define STACK_FLAGS				\
1380 		C(STACKTRACE,		"stacktrace"),
1381 #else
1382 # define STACK_FLAGS
1383 #endif
1384 
1385 #ifdef CONFIG_FUNCTION_PROFILER
1386 # define PROFILER_FLAGS					\
1387 		C(PROF_TEXT_OFFSET,	"prof-text-offset"),
1388 # ifdef CONFIG_FUNCTION_GRAPH_TRACER
1389 #  define FPROFILE_FLAGS				\
1390 		C(GRAPH_TIME,		"graph-time"),
1391 #  define FPROFILE_DEFAULT_FLAGS	TRACE_ITER(GRAPH_TIME)
1392 # else
1393 #  define FPROFILE_FLAGS
1394 #  define FPROFILE_DEFAULT_FLAGS	0UL
1395 # endif
1396 #else
1397 # define PROFILER_FLAGS
1398 # define FPROFILE_FLAGS
1399 # define FPROFILE_DEFAULT_FLAGS			0UL
1400 # define TRACE_ITER_PROF_TEXT_OFFSET_BIT	-1
1401 #endif
1402 
1403 /*
1404  * trace_iterator_flags is an enumeration that defines bit
1405  * positions into trace_flags that controls the output.
1406  *
1407  * NOTE: These bits must match the trace_options array in
1408  *       trace.c (this macro guarantees it).
1409  */
1410 #define TRACE_FLAGS						\
1411 		C(PRINT_PARENT,		"print-parent"),	\
1412 		C(SYM_OFFSET,		"sym-offset"),		\
1413 		C(SYM_ADDR,		"sym-addr"),		\
1414 		C(VERBOSE,		"verbose"),		\
1415 		C(RAW,			"raw"),			\
1416 		C(HEX,			"hex"),			\
1417 		C(BIN,			"bin"),			\
1418 		C(BLOCK,		"block"),		\
1419 		C(FIELDS,		"fields"),		\
1420 		C(PRINTK,		"trace_printk"),	\
1421 		C(ANNOTATE,		"annotate"),		\
1422 		C(USERSTACKTRACE,	"userstacktrace"),	\
1423 		C(SYM_USEROBJ,		"sym-userobj"),		\
1424 		C(PRINTK_MSGONLY,	"printk-msg-only"),	\
1425 		C(CONTEXT_INFO,		"context-info"),   /* Print pid/cpu/time */ \
1426 		C(LATENCY_FMT,		"latency-format"),	\
1427 		C(RECORD_CMD,		"record-cmd"),		\
1428 		C(RECORD_TGID,		"record-tgid"),		\
1429 		C(OVERWRITE,		"overwrite"),		\
1430 		C(STOP_ON_FREE,		"disable_on_free"),	\
1431 		C(IRQ_INFO,		"irq-info"),		\
1432 		C(MARKERS,		"markers"),		\
1433 		C(EVENT_FORK,		"event-fork"),		\
1434 		C(TRACE_PRINTK,		"trace_printk_dest"),	\
1435 		C(COPY_MARKER,		"copy_trace_marker"),	\
1436 		C(PAUSE_ON_TRACE,	"pause-on-trace"),	\
1437 		C(HASH_PTR,		"hash-ptr"),	/* Print hashed pointer */ \
1438 		C(BITMASK_LIST,		"bitmask-list"),	\
1439 		FUNCTION_FLAGS					\
1440 		FGRAPH_FLAGS					\
1441 		STACK_FLAGS					\
1442 		BRANCH_FLAGS					\
1443 		PROFILER_FLAGS					\
1444 		FPROFILE_FLAGS
1445 
1446 /*
1447  * By defining C, we can make TRACE_FLAGS a list of bit names
1448  * that will define the bits for the flag masks.
1449  */
1450 #undef C
1451 #define C(a, b) TRACE_ITER_##a##_BIT
1452 
1453 enum trace_iterator_bits {
1454 	TRACE_FLAGS
1455 	/* Make sure we don't go more than we have bits for */
1456 	TRACE_ITER_LAST_BIT
1457 };
1458 
1459 /*
1460  * And use TRACE_ITER(flag) to define the bit masks.
1461  */
1462 #define TRACE_ITER(flag)		\
1463 	(TRACE_ITER_##flag##_BIT < 0 ? 0 : 1ULL << (TRACE_ITER_##flag##_BIT))
1464 
1465 /*
1466  * TRACE_ITER_SYM_MASK masks the options in trace_flags that
1467  * control the output of kernel symbols.
1468  */
1469 #define TRACE_ITER_SYM_MASK \
1470 	(TRACE_ITER(PRINT_PARENT)|TRACE_ITER(SYM_OFFSET)|TRACE_ITER(SYM_ADDR))
1471 
1472 extern struct tracer nop_trace;
1473 
1474 #ifdef CONFIG_BRANCH_TRACER
1475 extern int enable_branch_tracing(struct trace_array *tr);
1476 extern void disable_branch_tracing(void);
1477 static inline int trace_branch_enable(struct trace_array *tr)
1478 {
1479 	if (tr->trace_flags & TRACE_ITER(BRANCH))
1480 		return enable_branch_tracing(tr);
1481 	return 0;
1482 }
1483 static inline void trace_branch_disable(void)
1484 {
1485 	/* due to races, always disable */
1486 	disable_branch_tracing();
1487 }
1488 #else
1489 static inline int trace_branch_enable(struct trace_array *tr)
1490 {
1491 	return 0;
1492 }
1493 static inline void trace_branch_disable(void)
1494 {
1495 }
1496 #endif /* CONFIG_BRANCH_TRACER */
1497 
1498 /* set ring buffers to default size if not already done so */
1499 int tracing_update_buffers(struct trace_array *tr);
1500 
1501 union trace_synth_field {
1502 	u8				as_u8;
1503 	u16				as_u16;
1504 	u32				as_u32;
1505 	u64				as_u64;
1506 	struct trace_dynamic_info	as_dynamic;
1507 };
1508 
1509 struct ftrace_event_field {
1510 	struct list_head	link;
1511 	const char		*name;
1512 	const char		*type;
1513 	int			filter_type;
1514 	int			offset;
1515 	int			size;
1516 	unsigned int		is_signed:1;
1517 	unsigned int		needs_test:1;
1518 	int			len;
1519 };
1520 
1521 struct prog_entry;
1522 
1523 struct event_filter {
1524 	struct prog_entry __rcu	*prog;
1525 	char			*filter_string;
1526 };
1527 
1528 struct event_subsystem {
1529 	struct list_head	list;
1530 	const char		*name;
1531 	struct event_filter	*filter;
1532 	int			ref_count;
1533 };
1534 
1535 struct trace_subsystem_dir {
1536 	struct list_head		list;
1537 	struct event_subsystem		*subsystem;
1538 	struct trace_array		*tr;
1539 	struct eventfs_inode		*ei;
1540 	int				ref_count;
1541 	int				nr_events;
1542 };
1543 
1544 void trace_buffer_unlock_commit_regs(struct trace_array *tr,
1545 				     struct trace_buffer *buffer,
1546 				     struct ring_buffer_event *event,
1547 				     unsigned int trcace_ctx,
1548 				     struct pt_regs *regs);
1549 
1550 static inline void trace_buffer_unlock_commit(struct trace_array *tr,
1551 					      struct trace_buffer *buffer,
1552 					      struct ring_buffer_event *event,
1553 					      unsigned int trace_ctx)
1554 {
1555 	trace_buffer_unlock_commit_regs(tr, buffer, event, trace_ctx, NULL);
1556 }
1557 
1558 DECLARE_PER_CPU(bool, trace_taskinfo_save);
1559 int trace_save_cmdline(struct task_struct *tsk);
1560 int trace_create_savedcmd(void);
1561 int trace_alloc_tgid_map(void);
1562 void trace_free_saved_cmdlines_buffer(void);
1563 
1564 extern const struct file_operations tracing_saved_cmdlines_fops;
1565 extern const struct file_operations tracing_saved_tgids_fops;
1566 extern const struct file_operations tracing_saved_cmdlines_size_fops;
1567 
1568 DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
1569 DECLARE_PER_CPU(int, trace_buffered_event_cnt);
1570 void trace_buffered_event_disable(void);
1571 void trace_buffered_event_enable(void);
1572 
1573 void early_enable_events(struct trace_array *tr, char *buf, bool disable_first);
1574 
1575 struct trace_user_buf;
1576 struct trace_user_buf_info {
1577 	struct trace_user_buf __percpu	*tbuf;
1578 	size_t				size;
1579 	int				ref;
1580 };
1581 
1582 typedef int (*trace_user_buf_copy)(char *dst, const char __user *src,
1583 				  size_t size, void *data);
1584 int trace_user_fault_init(struct trace_user_buf_info *tinfo, size_t size);
1585 int trace_user_fault_get(struct trace_user_buf_info *tinfo);
1586 int trace_user_fault_put(struct trace_user_buf_info *tinfo);
1587 void trace_user_fault_destroy(struct trace_user_buf_info *tinfo);
1588 char *trace_user_fault_read(struct trace_user_buf_info *tinfo,
1589 			    const char __user *ptr, size_t size,
1590 			    trace_user_buf_copy copy_func, void *data);
1591 
1592 static __always_inline void
1593 trace_event_setup(struct ring_buffer_event *event,
1594 		  int type, unsigned int trace_ctx)
1595 {
1596 	struct trace_entry *ent = ring_buffer_event_data(event);
1597 
1598 	tracing_generic_entry_update(ent, type, trace_ctx);
1599 }
1600 
1601 static __always_inline struct ring_buffer_event *
1602 __trace_buffer_lock_reserve(struct trace_buffer *buffer,
1603 			  int type,
1604 			  unsigned long len,
1605 			  unsigned int trace_ctx)
1606 {
1607 	struct ring_buffer_event *event;
1608 
1609 	event = ring_buffer_lock_reserve(buffer, len);
1610 	if (event != NULL)
1611 		trace_event_setup(event, type, trace_ctx);
1612 
1613 	return event;
1614 }
1615 
1616 static __always_inline void
1617 __buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *event)
1618 {
1619 	__this_cpu_write(trace_taskinfo_save, true);
1620 
1621 	/* If this is the temp buffer, we need to commit fully */
1622 	if (this_cpu_read(trace_buffered_event) == event) {
1623 		/* Length is in event->array[0] */
1624 		ring_buffer_write(buffer, event->array[0], &event->array[1]);
1625 		/* Release the temp buffer */
1626 		this_cpu_dec(trace_buffered_event_cnt);
1627 		/* ring_buffer_unlock_commit() enables preemption */
1628 		preempt_enable_notrace();
1629 	} else
1630 		ring_buffer_unlock_commit(buffer);
1631 }
1632 
1633 static inline void
1634 __trace_event_discard_commit(struct trace_buffer *buffer,
1635 			     struct ring_buffer_event *event)
1636 {
1637 	if (this_cpu_read(trace_buffered_event) == event) {
1638 		/* Simply release the temp buffer and enable preemption */
1639 		this_cpu_dec(trace_buffered_event_cnt);
1640 		preempt_enable_notrace();
1641 		return;
1642 	}
1643 	/* ring_buffer_discard_commit() enables preemption */
1644 	ring_buffer_discard_commit(buffer, event);
1645 }
1646 
1647 /*
1648  * Helper function for event_trigger_unlock_commit{_regs}().
1649  * If there are event triggers attached to this event that requires
1650  * filtering against its fields, then they will be called as the
1651  * entry already holds the field information of the current event.
1652  *
1653  * It also checks if the event should be discarded or not.
1654  * It is to be discarded if the event is soft disabled and the
1655  * event was only recorded to process triggers, or if the event
1656  * filter is active and this event did not match the filters.
1657  *
1658  * Returns true if the event is discarded, false otherwise.
1659  */
1660 static inline bool
1661 __event_trigger_test_discard(struct trace_event_file *file,
1662 			     struct trace_buffer *buffer,
1663 			     struct ring_buffer_event *event,
1664 			     void *entry,
1665 			     enum event_trigger_type *tt)
1666 {
1667 	unsigned long eflags = file->flags;
1668 
1669 	if (eflags & EVENT_FILE_FL_TRIGGER_COND)
1670 		*tt = event_triggers_call(file, buffer, entry, event);
1671 
1672 	if (likely(!(file->flags & (EVENT_FILE_FL_SOFT_DISABLED |
1673 				    EVENT_FILE_FL_FILTERED |
1674 				    EVENT_FILE_FL_PID_FILTER))))
1675 		return false;
1676 
1677 	if (file->flags & EVENT_FILE_FL_SOFT_DISABLED)
1678 		goto discard;
1679 
1680 	if (file->flags & EVENT_FILE_FL_FILTERED &&
1681 	    !filter_match_preds(file->filter, entry))
1682 		goto discard;
1683 
1684 	if ((file->flags & EVENT_FILE_FL_PID_FILTER) &&
1685 	    trace_event_ignore_this_pid(file))
1686 		goto discard;
1687 
1688 	return false;
1689  discard:
1690 	__trace_event_discard_commit(buffer, event);
1691 	return true;
1692 }
1693 
1694 /**
1695  * event_trigger_unlock_commit - handle triggers and finish event commit
1696  * @file: The file pointer associated with the event
1697  * @buffer: The ring buffer that the event is being written to
1698  * @event: The event meta data in the ring buffer
1699  * @entry: The event itself
1700  * @trace_ctx: The tracing context flags.
1701  *
1702  * This is a helper function to handle triggers that require data
1703  * from the event itself. It also tests the event against filters and
1704  * if the event is soft disabled and should be discarded.
1705  */
1706 static inline void
1707 event_trigger_unlock_commit(struct trace_event_file *file,
1708 			    struct trace_buffer *buffer,
1709 			    struct ring_buffer_event *event,
1710 			    void *entry, unsigned int trace_ctx)
1711 {
1712 	enum event_trigger_type tt = ETT_NONE;
1713 
1714 	if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
1715 		trace_buffer_unlock_commit(file->tr, buffer, event, trace_ctx);
1716 
1717 	if (tt)
1718 		event_triggers_post_call(file, tt);
1719 }
1720 
1721 #define FILTER_PRED_INVALID	((unsigned short)-1)
1722 #define FILTER_PRED_IS_RIGHT	(1 << 15)
1723 #define FILTER_PRED_FOLD	(1 << 15)
1724 
1725 /*
1726  * The max preds is the size of unsigned short with
1727  * two flags at the MSBs. One bit is used for both the IS_RIGHT
1728  * and FOLD flags. The other is reserved.
1729  *
1730  * 2^14 preds is way more than enough.
1731  */
1732 #define MAX_FILTER_PRED		16384
1733 
1734 struct filter_pred;
1735 struct regex;
1736 
1737 typedef int (*regex_match_func)(char *str, struct regex *r, int len);
1738 
1739 enum regex_type {
1740 	MATCH_FULL = 0,
1741 	MATCH_FRONT_ONLY,
1742 	MATCH_MIDDLE_ONLY,
1743 	MATCH_END_ONLY,
1744 	MATCH_GLOB,
1745 	MATCH_INDEX,
1746 };
1747 
1748 struct regex {
1749 	char			pattern[MAX_FILTER_STR_VAL];
1750 	int			len;
1751 	int			field_len;
1752 	regex_match_func	match;
1753 };
1754 
1755 static inline bool is_string_field(struct ftrace_event_field *field)
1756 {
1757 	return field->filter_type == FILTER_DYN_STRING ||
1758 	       field->filter_type == FILTER_RDYN_STRING ||
1759 	       field->filter_type == FILTER_STATIC_STRING ||
1760 	       field->filter_type == FILTER_PTR_STRING ||
1761 	       field->filter_type == FILTER_COMM;
1762 }
1763 
1764 static inline bool is_function_field(struct ftrace_event_field *field)
1765 {
1766 	return field->filter_type == FILTER_TRACE_FN;
1767 }
1768 
1769 extern enum regex_type
1770 filter_parse_regex(char *buff, int len, char **search, int *not);
1771 extern void print_event_filter(struct trace_event_file *file,
1772 			       struct trace_seq *s);
1773 extern int apply_event_filter(struct trace_event_file *file,
1774 			      char *filter_string);
1775 extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
1776 					char *filter_string);
1777 extern void print_subsystem_event_filter(struct event_subsystem *system,
1778 					 struct trace_seq *s);
1779 extern int filter_assign_type(const char *type);
1780 extern int create_event_filter(struct trace_array *tr,
1781 			       struct trace_event_call *call,
1782 			       char *filter_str, bool set_str,
1783 			       struct event_filter **filterp);
1784 extern void free_event_filter(struct event_filter *filter);
1785 
1786 struct ftrace_event_field *
1787 trace_find_event_field(struct trace_event_call *call, char *name);
1788 
1789 extern void trace_event_enable_cmd_record(bool enable);
1790 extern void trace_event_enable_tgid_record(bool enable);
1791 
1792 extern int event_trace_init(void);
1793 extern int init_events(void);
1794 extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
1795 extern int event_trace_del_tracer(struct trace_array *tr);
1796 extern void __trace_early_add_events(struct trace_array *tr);
1797 
1798 extern struct trace_event_file *__find_event_file(struct trace_array *tr,
1799 						  const char *system,
1800 						  const char *event);
1801 extern struct trace_event_file *find_event_file(struct trace_array *tr,
1802 						const char *system,
1803 						const char *event);
1804 
1805 static inline void *event_file_data(struct file *filp)
1806 {
1807 	return READ_ONCE(file_inode(filp)->i_private);
1808 }
1809 
1810 extern struct mutex event_mutex;
1811 extern struct list_head ftrace_events;
1812 
1813 /*
1814  * When the trace_event_file is the filp->i_private pointer,
1815  * it must be taken under the event_mutex lock, and then checked
1816  * if the EVENT_FILE_FL_FREED flag is set. If it is, then the
1817  * data pointed to by the trace_event_file can not be trusted.
1818  *
1819  * Use the event_file_file() to access the trace_event_file from
1820  * the filp the first time under the event_mutex and check for
1821  * NULL. If it is needed to be retrieved again and the event_mutex
1822  * is still held, then the event_file_data() can be used and it
1823  * is guaranteed to be valid.
1824  */
1825 static inline struct trace_event_file *event_file_file(struct file *filp)
1826 {
1827 	struct trace_event_file *file;
1828 
1829 	lockdep_assert_held(&event_mutex);
1830 	file = READ_ONCE(file_inode(filp)->i_private);
1831 	if (!file || file->flags & EVENT_FILE_FL_FREED)
1832 		return NULL;
1833 	return file;
1834 }
1835 
1836 extern const struct file_operations event_trigger_fops;
1837 extern const struct file_operations event_hist_fops;
1838 extern const struct file_operations event_hist_debug_fops;
1839 extern const struct file_operations event_inject_fops;
1840 
1841 #ifdef CONFIG_HIST_TRIGGERS
1842 extern int register_trigger_hist_cmd(void);
1843 extern int register_trigger_hist_enable_disable_cmds(void);
1844 #else
1845 static inline int register_trigger_hist_cmd(void) { return 0; }
1846 static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
1847 #endif
1848 
1849 extern int register_trigger_cmds(void);
1850 extern void clear_event_triggers(struct trace_array *tr);
1851 
1852 enum {
1853 	EVENT_TRIGGER_FL_PROBE		= BIT(0),
1854 	EVENT_TRIGGER_FL_COUNT		= BIT(1),
1855 };
1856 
1857 struct event_trigger_data {
1858 	unsigned long			count;
1859 	int				ref;
1860 	int				flags;
1861 	struct event_command		*cmd_ops;
1862 	struct event_filter __rcu	*filter;
1863 	char				*filter_str;
1864 	void				*private_data;
1865 	bool				paused;
1866 	bool				paused_tmp;
1867 	struct list_head		list;
1868 	char				*name;
1869 	struct list_head		named_list;
1870 	struct event_trigger_data	*named_data;
1871 	struct llist_node		llist;
1872 };
1873 
1874 /* Avoid typos */
1875 #define ENABLE_EVENT_STR	"enable_event"
1876 #define DISABLE_EVENT_STR	"disable_event"
1877 #define ENABLE_HIST_STR		"enable_hist"
1878 #define DISABLE_HIST_STR	"disable_hist"
1879 
1880 struct enable_trigger_data {
1881 	struct trace_event_file		*file;
1882 	bool				enable;
1883 	bool				hist;
1884 };
1885 
1886 bool event_trigger_count(struct event_trigger_data *data,
1887 			 struct trace_buffer *buffer,  void *rec,
1888 			 struct ring_buffer_event *event);
1889 
1890 extern int event_enable_trigger_print(struct seq_file *m,
1891 				      struct event_trigger_data *data);
1892 extern void event_enable_trigger_free(struct event_trigger_data *data);
1893 extern int event_enable_trigger_parse(struct event_command *cmd_ops,
1894 				      struct trace_event_file *file,
1895 				      char *glob, char *cmd,
1896 				      char *param_and_filter);
1897 extern int event_enable_register_trigger(char *glob,
1898 					 struct event_trigger_data *data,
1899 					 struct trace_event_file *file);
1900 extern void event_enable_unregister_trigger(char *glob,
1901 					    struct event_trigger_data *test,
1902 					    struct trace_event_file *file);
1903 extern struct event_trigger_data *
1904 trigger_data_alloc(struct event_command *cmd_ops, char *cmd, char *param,
1905 		   void *private_data);
1906 extern void trigger_data_free(struct event_trigger_data *data);
1907 extern int event_trigger_init(struct event_trigger_data *data);
1908 extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
1909 					      int trigger_enable);
1910 extern void update_cond_flag(struct trace_event_file *file);
1911 extern int set_trigger_filter(char *filter_str,
1912 			      struct event_trigger_data *trigger_data,
1913 			      struct trace_event_file *file);
1914 extern struct event_trigger_data *find_named_trigger(const char *name);
1915 extern bool is_named_trigger(struct event_trigger_data *test);
1916 extern int save_named_trigger(const char *name,
1917 			      struct event_trigger_data *data);
1918 extern void del_named_trigger(struct event_trigger_data *data);
1919 extern void pause_named_trigger(struct event_trigger_data *data);
1920 extern void unpause_named_trigger(struct event_trigger_data *data);
1921 extern void set_named_trigger_data(struct event_trigger_data *data,
1922 				   struct event_trigger_data *named_data);
1923 extern struct event_trigger_data *
1924 get_named_trigger_data(struct event_trigger_data *data);
1925 extern int register_event_command(struct event_command *cmd);
1926 extern int unregister_event_command(struct event_command *cmd);
1927 extern int register_trigger_hist_enable_disable_cmds(void);
1928 extern bool event_trigger_check_remove(const char *glob);
1929 extern bool event_trigger_empty_param(const char *param);
1930 extern int event_trigger_separate_filter(char *param_and_filter, char **param,
1931 					 char **filter, bool param_required);
1932 extern int event_trigger_parse_num(char *trigger,
1933 				   struct event_trigger_data *trigger_data);
1934 extern int event_trigger_set_filter(struct event_command *cmd_ops,
1935 				    struct trace_event_file *file,
1936 				    char *param,
1937 				    struct event_trigger_data *trigger_data);
1938 extern void event_trigger_reset_filter(struct event_command *cmd_ops,
1939 				       struct event_trigger_data *trigger_data);
1940 extern int event_trigger_register(struct event_command *cmd_ops,
1941 				  struct trace_event_file *file,
1942 				  char *glob,
1943 				  struct event_trigger_data *trigger_data);
1944 extern void event_trigger_unregister(struct event_command *cmd_ops,
1945 				     struct trace_event_file *file,
1946 				     char *glob,
1947 				     struct event_trigger_data *trigger_data);
1948 
1949 extern void event_file_get(struct trace_event_file *file);
1950 extern void event_file_put(struct trace_event_file *file);
1951 
1952 /**
1953  * struct event_command - callbacks and data members for event commands
1954  *
1955  * Event commands are invoked by users by writing the command name
1956  * into the 'trigger' file associated with a trace event.  The
1957  * parameters associated with a specific invocation of an event
1958  * command are used to create an event trigger instance, which is
1959  * added to the list of trigger instances associated with that trace
1960  * event.  When the event is hit, the set of triggers associated with
1961  * that event is invoked.
1962  *
1963  * The data members in this structure provide per-event command data
1964  * for various event commands.
1965  *
1966  * All the data members below, except for @post_trigger, must be set
1967  * for each event command.
1968  *
1969  * @name: The unique name that identifies the event command.  This is
1970  *	the name used when setting triggers via trigger files.
1971  *
1972  * @trigger_type: A unique id that identifies the event command
1973  *	'type'.  This value has two purposes, the first to ensure that
1974  *	only one trigger of the same type can be set at a given time
1975  *	for a particular event e.g. it doesn't make sense to have both
1976  *	a traceon and traceoff trigger attached to a single event at
1977  *	the same time, so traceon and traceoff have the same type
1978  *	though they have different names.  The @trigger_type value is
1979  *	also used as a bit value for deferring the actual trigger
1980  *	action until after the current event is finished.  Some
1981  *	commands need to do this if they themselves log to the trace
1982  *	buffer (see the @post_trigger() member below).  @trigger_type
1983  *	values are defined by adding new values to the trigger_type
1984  *	enum in include/linux/trace_events.h.
1985  *
1986  * @flags: See the enum event_command_flags below.
1987  *
1988  * All the methods below, except for @set_filter() and @unreg_all(),
1989  * must be implemented.
1990  *
1991  * @parse: The callback function responsible for parsing and
1992  *	registering the trigger written to the 'trigger' file by the
1993  *	user.  It allocates the trigger instance and registers it with
1994  *	the appropriate trace event.  It makes use of the other
1995  *	event_command callback functions to orchestrate this, and is
1996  *	usually implemented by the generic utility function
1997  *	@event_trigger_callback() (see trace_event_triggers.c).
1998  *
1999  * @reg: Adds the trigger to the list of triggers associated with the
2000  *	event, and enables the event trigger itself, after
2001  *	initializing it (via the event_command @init() function).
2002  *	This is also where commands can use the @trigger_type value to
2003  *	make the decision as to whether or not multiple instances of
2004  *	the trigger should be allowed.  This is usually implemented by
2005  *	the generic utility function @register_trigger() (see
2006  *	trace_event_triggers.c).
2007  *
2008  * @unreg: Removes the trigger from the list of triggers associated
2009  *	with the event, and disables the event trigger itself, after
2010  *	initializing it (via the event_command @free() function).
2011  *	This is usually implemented by the generic utility function
2012  *	@unregister_trigger() (see trace_event_triggers.c).
2013  *
2014  * @unreg_all: An optional function called to remove all the triggers
2015  *	from the list of triggers associated with the event.  Called
2016  *	when a trigger file is opened in truncate mode.
2017  *
2018  * @set_filter: An optional function called to parse and set a filter
2019  *	for the trigger.  If no @set_filter() method is set for the
2020  *	event command, filters set by the user for the command will be
2021  *	ignored.  This is usually implemented by the generic utility
2022  *	function @set_trigger_filter() (see trace_event_triggers.c).
2023  *
2024  * All the methods below, except for @init() and @free(), must be
2025  * implemented.
2026  *
2027  * @trigger: The trigger 'probe' function called when the triggering
2028  *	event occurs.  The data passed into this callback is the data
2029  *	that was supplied to the event_command @reg() function that
2030  *	registered the trigger (see struct event_command) along with
2031  *	the trace record, rec.
2032  *
2033  * @count_func: If defined and a numeric parameter is passed to the
2034  *	trigger, then this function will be called before @trigger
2035  *	is called. If this function returns false, then @trigger is not
2036  *	executed.
2037  *
2038  * @init: An optional initialization function called for the trigger
2039  *	when the trigger is registered (via the event_command reg()
2040  *	function).  This can be used to perform per-trigger
2041  *	initialization such as incrementing a per-trigger reference
2042  *	count, for instance.  This is usually implemented by the
2043  *	generic utility function @event_trigger_init() (see
2044  *	trace_event_triggers.c).
2045  *
2046  * @free: An optional de-initialization function called for the
2047  *	trigger when the trigger is unregistered (via the
2048  *	event_command @reg() function).  This can be used to perform
2049  *	per-trigger de-initialization such as decrementing a
2050  *	per-trigger reference count and freeing corresponding trigger
2051  *	data, for instance.  This is usually implemented by the
2052  *	generic utility function @event_trigger_free() (see
2053  *	trace_event_triggers.c).
2054  *
2055  * @print: The callback function invoked to have the trigger print
2056  *	itself.  This is usually implemented by a wrapper function
2057  *	that calls the generic utility function @event_trigger_print()
2058  *	(see trace_event_triggers.c).
2059  */
2060 struct event_command {
2061 	struct list_head	list;
2062 	char			*name;
2063 	enum event_trigger_type	trigger_type;
2064 	int			flags;
2065 	int			(*parse)(struct event_command *cmd_ops,
2066 					 struct trace_event_file *file,
2067 					 char *glob, char *cmd,
2068 					 char *param_and_filter);
2069 	int			(*reg)(char *glob,
2070 				       struct event_trigger_data *data,
2071 				       struct trace_event_file *file);
2072 	void			(*unreg)(char *glob,
2073 					 struct event_trigger_data *data,
2074 					 struct trace_event_file *file);
2075 	void			(*unreg_all)(struct trace_event_file *file);
2076 	int			(*set_filter)(char *filter_str,
2077 					      struct event_trigger_data *data,
2078 					      struct trace_event_file *file);
2079 	void			(*trigger)(struct event_trigger_data *data,
2080 					   struct trace_buffer *buffer,
2081 					   void *rec,
2082 					   struct ring_buffer_event *rbe);
2083 	bool			(*count_func)(struct event_trigger_data *data,
2084 					      struct trace_buffer *buffer,
2085 					      void *rec,
2086 					      struct ring_buffer_event *rbe);
2087 	int			(*init)(struct event_trigger_data *data);
2088 	void			(*free)(struct event_trigger_data *data);
2089 	int			(*print)(struct seq_file *m,
2090 					 struct event_trigger_data *data);
2091 };
2092 
2093 /**
2094  * enum event_command_flags - flags for struct event_command
2095  *
2096  * @POST_TRIGGER: A flag that says whether or not this command needs
2097  *	to have its action delayed until after the current event has
2098  *	been closed.  Some triggers need to avoid being invoked while
2099  *	an event is currently in the process of being logged, since
2100  *	the trigger may itself log data into the trace buffer.  Thus
2101  *	we make sure the current event is committed before invoking
2102  *	those triggers.  To do that, the trigger invocation is split
2103  *	in two - the first part checks the filter using the current
2104  *	trace record; if a command has the @post_trigger flag set, it
2105  *	sets a bit for itself in the return value, otherwise it
2106  *	directly invokes the trigger.  Once all commands have been
2107  *	either invoked or set their return flag, the current record is
2108  *	either committed or discarded.  At that point, if any commands
2109  *	have deferred their triggers, those commands are finally
2110  *	invoked following the close of the current event.  In other
2111  *	words, if the event_command @func() probe implementation
2112  *	itself logs to the trace buffer, this flag should be set,
2113  *	otherwise it can be left unspecified.
2114  *
2115  * @NEEDS_REC: A flag that says whether or not this command needs
2116  *	access to the trace record in order to perform its function,
2117  *	regardless of whether or not it has a filter associated with
2118  *	it (filters make a trigger require access to the trace record
2119  *	but are not always present).
2120  */
2121 enum event_command_flags {
2122 	EVENT_CMD_FL_POST_TRIGGER	= 1,
2123 	EVENT_CMD_FL_NEEDS_REC		= 2,
2124 };
2125 
2126 static inline bool event_command_post_trigger(struct event_command *cmd_ops)
2127 {
2128 	return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
2129 }
2130 
2131 static inline bool event_command_needs_rec(struct event_command *cmd_ops)
2132 {
2133 	return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
2134 }
2135 
2136 extern int trace_event_enable_disable(struct trace_event_file *file,
2137 				      int enable, int soft_disable);
2138 extern int tracing_alloc_snapshot(void);
2139 extern void tracing_snapshot_cond(struct trace_array *tr, void *cond_data);
2140 extern int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update);
2141 
2142 extern int tracing_snapshot_cond_disable(struct trace_array *tr);
2143 extern void *tracing_cond_snapshot_data(struct trace_array *tr);
2144 
2145 extern const char *__start___trace_bprintk_fmt[];
2146 extern const char *__stop___trace_bprintk_fmt[];
2147 
2148 extern const char *__start___tracepoint_str[];
2149 extern const char *__stop___tracepoint_str[];
2150 
2151 void trace_printk_control(bool enabled);
2152 void trace_printk_start_comm(void);
2153 void trace_printk_start_stop_comm(int enabled);
2154 int trace_keep_overwrite(struct tracer *tracer, u64 mask, int set);
2155 int set_tracer_flag(struct trace_array *tr, u64 mask, int enabled);
2156 
2157 /* Used from boot time tracer */
2158 extern int trace_set_options(struct trace_array *tr, char *option);
2159 extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
2160 extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
2161 					  unsigned long size, int cpu_id);
2162 extern int tracing_set_cpumask(struct trace_array *tr,
2163 				cpumask_var_t tracing_cpumask_new);
2164 
2165 
2166 #define MAX_EVENT_NAME_LEN	64
2167 
2168 extern ssize_t trace_parse_run_command(struct file *file,
2169 		const char __user *buffer, size_t count, loff_t *ppos,
2170 		int (*createfn)(const char *));
2171 
2172 extern unsigned int err_pos(char *cmd, const char *str);
2173 extern void tracing_log_err(struct trace_array *tr,
2174 			    const char *loc, const char *cmd,
2175 			    const char **errs, u8 type, u16 pos);
2176 
2177 /*
2178  * Normal trace_printk() and friends allocates special buffers
2179  * to do the manipulation, as well as saves the print formats
2180  * into sections to display. But the trace infrastructure wants
2181  * to use these without the added overhead at the price of being
2182  * a bit slower (used mainly for warnings, where we don't care
2183  * about performance). The internal_trace_puts() is for such
2184  * a purpose.
2185  */
2186 #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str)
2187 
2188 #undef FTRACE_ENTRY
2189 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print)	\
2190 	extern struct trace_event_call					\
2191 	__aligned(4) event_##call;
2192 #undef FTRACE_ENTRY_DUP
2193 #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print)	\
2194 	FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
2195 #undef FTRACE_ENTRY_PACKED
2196 #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print) \
2197 	FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
2198 
2199 #include "trace_entries.h"
2200 
2201 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
2202 int perf_ftrace_event_register(struct trace_event_call *call,
2203 			       enum trace_reg type, void *data);
2204 #else
2205 #define perf_ftrace_event_register NULL
2206 #endif
2207 
2208 #ifdef CONFIG_FTRACE_SYSCALLS
2209 void init_ftrace_syscalls(void);
2210 const char *get_syscall_name(int syscall);
2211 #else
2212 static inline void init_ftrace_syscalls(void) { }
2213 static inline const char *get_syscall_name(int syscall)
2214 {
2215 	return NULL;
2216 }
2217 #endif
2218 
2219 #ifdef CONFIG_EVENT_TRACING
2220 void trace_event_init(void);
2221 void trace_event_update_all(struct trace_eval_map **map, int len);
2222 /* Used from boot time tracer */
2223 extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
2224 extern int trigger_process_regex(struct trace_event_file *file, char *buff);
2225 #else
2226 static inline void __init trace_event_init(void) { }
2227 static inline void trace_event_update_all(struct trace_eval_map **map, int len) { }
2228 #endif
2229 
2230 #ifdef CONFIG_TRACER_SNAPSHOT
2231 void tracing_snapshot_instance(struct trace_array *tr);
2232 int tracing_alloc_snapshot_instance(struct trace_array *tr);
2233 int tracing_arm_snapshot(struct trace_array *tr);
2234 void tracing_disarm_snapshot(struct trace_array *tr);
2235 #else
2236 static inline void tracing_snapshot_instance(struct trace_array *tr) { }
2237 static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
2238 {
2239 	return 0;
2240 }
2241 static inline int tracing_arm_snapshot(struct trace_array *tr) { return 0; }
2242 static inline void tracing_disarm_snapshot(struct trace_array *tr) { }
2243 #endif
2244 
2245 #ifdef CONFIG_PREEMPT_TRACER
2246 void tracer_preempt_on(unsigned long a0, unsigned long a1);
2247 void tracer_preempt_off(unsigned long a0, unsigned long a1);
2248 #else
2249 static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { }
2250 static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { }
2251 #endif
2252 #ifdef CONFIG_IRQSOFF_TRACER
2253 void tracer_hardirqs_on(unsigned long a0, unsigned long a1);
2254 void tracer_hardirqs_off(unsigned long a0, unsigned long a1);
2255 #else
2256 static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { }
2257 static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { }
2258 #endif
2259 
2260 /*
2261  * Reset the state of the trace_iterator so that it can read consumed data.
2262  * Normally, the trace_iterator is used for reading the data when it is not
2263  * consumed, and must retain state.
2264  */
2265 static __always_inline void trace_iterator_reset(struct trace_iterator *iter)
2266 {
2267 	memset_startat(iter, 0, seq);
2268 	iter->pos = -1;
2269 }
2270 
2271 /* Check the name is good for event/group/fields */
2272 static inline bool __is_good_name(const char *name, bool hash_ok)
2273 {
2274 	if (!isalpha(*name) && *name != '_' && (!hash_ok || *name != '-'))
2275 		return false;
2276 	while (*++name != '\0') {
2277 		if (!isalpha(*name) && !isdigit(*name) && *name != '_' &&
2278 		    (!hash_ok || *name != '-'))
2279 			return false;
2280 	}
2281 	return true;
2282 }
2283 
2284 /* Check the name is good for event/group/fields */
2285 static inline bool is_good_name(const char *name)
2286 {
2287 	return __is_good_name(name, false);
2288 }
2289 
2290 /* Check the name is good for system */
2291 static inline bool is_good_system_name(const char *name)
2292 {
2293 	return __is_good_name(name, true);
2294 }
2295 
2296 /* Convert certain expected symbols into '_' when generating event names */
2297 static inline void sanitize_event_name(char *name)
2298 {
2299 	while (*name++ != '\0')
2300 		if (*name == ':' || *name == '.' || *name == '*')
2301 			*name = '_';
2302 }
2303 
2304 #ifdef CONFIG_STACKTRACE
2305 void __ftrace_trace_stack(struct trace_array *tr,
2306 			  struct trace_buffer *buffer,
2307 			  unsigned int trace_ctx,
2308 			  int skip, struct pt_regs *regs);
2309 
2310 static __always_inline void ftrace_trace_stack(struct trace_array *tr,
2311 					       struct trace_buffer *buffer,
2312 					       unsigned int trace_ctx,
2313 					       int skip, struct pt_regs *regs)
2314 {
2315 	if (!(tr->trace_flags & TRACE_ITER(STACKTRACE)))
2316 		return;
2317 
2318 	__ftrace_trace_stack(tr, buffer, trace_ctx, skip, regs);
2319 }
2320 #else
2321 static inline void __ftrace_trace_stack(struct trace_array *tr,
2322 					struct trace_buffer *buffer,
2323 					unsigned int trace_ctx,
2324 					int skip, struct pt_regs *regs)
2325 {
2326 }
2327 static inline void ftrace_trace_stack(struct trace_array *tr,
2328 				      struct trace_buffer *buffer,
2329 				      unsigned long trace_ctx,
2330 				      int skip, struct pt_regs *regs)
2331 {
2332 }
2333 #endif
2334 
2335 /*
2336  * This is a generic way to read and write a u64 value from a file in tracefs.
2337  *
2338  * The value is stored on the variable pointed by *val. The value needs
2339  * to be at least *min and at most *max. The write is protected by an
2340  * existing *lock.
2341  */
2342 struct trace_min_max_param {
2343 	struct mutex	*lock;
2344 	u64		*val;
2345 	u64		*min;
2346 	u64		*max;
2347 };
2348 
2349 #define U64_STR_SIZE		24	/* 20 digits max */
2350 
2351 extern const struct file_operations trace_min_max_fops;
2352 
2353 #ifdef CONFIG_RV
2354 extern int rv_init_interface(void);
2355 #else
2356 static inline int rv_init_interface(void)
2357 {
2358 	return 0;
2359 }
2360 #endif
2361 
2362 /*
2363  * This is used only to distinguish
2364  * function address from trampoline code.
2365  * So this value has no meaning.
2366  */
2367 #define FTRACE_TRAMPOLINE_MARKER  ((unsigned long) INT_MAX)
2368 
2369 /*
2370  * This is used to get the address of the args array based on
2371  * the type of the entry.
2372  */
2373 #define FGRAPH_ENTRY_ARGS(e)						\
2374 	({								\
2375 		unsigned long *_args;					\
2376 		struct ftrace_graph_ent_entry *_e = e;			\
2377 									\
2378 		if (IS_ENABLED(CONFIG_FUNCTION_GRAPH_RETADDR) &&	\
2379 			e->ent.type == TRACE_GRAPH_RETADDR_ENT) {	\
2380 			struct fgraph_retaddr_ent_entry *_re;		\
2381 									\
2382 			_re = (typeof(_re))_e;				\
2383 			_args = _re->args;				\
2384 		} else {						\
2385 			_args = _e->args;				\
2386 		}							\
2387 		_args;							\
2388 	})
2389 
2390 #endif /* _LINUX_KERNEL_TRACE_H */
2391