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