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