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 struct ftrace_func_entry * 1010 ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip); 1011 1012 static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash) 1013 { 1014 return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD)); 1015 } 1016 1017 /* Standard output formatting function used for function return traces */ 1018 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 1019 1020 /* Flag options */ 1021 #define TRACE_GRAPH_PRINT_OVERRUN 0x1 1022 #define TRACE_GRAPH_PRINT_CPU 0x2 1023 #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 1024 #define TRACE_GRAPH_PRINT_PROC 0x8 1025 #define TRACE_GRAPH_PRINT_DURATION 0x10 1026 #define TRACE_GRAPH_PRINT_ABS_TIME 0x20 1027 #define TRACE_GRAPH_PRINT_REL_TIME 0x40 1028 #define TRACE_GRAPH_PRINT_IRQS 0x80 1029 #define TRACE_GRAPH_PRINT_TAIL 0x100 1030 #define TRACE_GRAPH_SLEEP_TIME 0x200 1031 #define TRACE_GRAPH_GRAPH_TIME 0x400 1032 #define TRACE_GRAPH_PRINT_RETVAL 0x800 1033 #define TRACE_GRAPH_PRINT_RETVAL_HEX 0x1000 1034 #define TRACE_GRAPH_PRINT_RETADDR 0x2000 1035 #define TRACE_GRAPH_ARGS 0x4000 1036 #define TRACE_GRAPH_PRINT_FILL_SHIFT 28 1037 #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT) 1038 1039 #ifdef CONFIG_FUNCTION_PROFILER 1040 extern void ftrace_graph_graph_time_control(bool enable); 1041 #else 1042 static inline void ftrace_graph_graph_time_control(bool enable) { } 1043 #endif 1044 1045 extern enum print_line_t 1046 print_graph_function_flags(struct trace_iterator *iter, u32 flags); 1047 extern void print_graph_headers_flags(struct seq_file *s, u32 flags); 1048 extern void 1049 trace_print_graph_duration(unsigned long long duration, struct trace_seq *s); 1050 extern void graph_trace_open(struct trace_iterator *iter); 1051 extern void graph_trace_close(struct trace_iterator *iter); 1052 extern int __trace_graph_entry(struct trace_array *tr, 1053 struct ftrace_graph_ent *trace, 1054 unsigned int trace_ctx); 1055 extern int __trace_graph_retaddr_entry(struct trace_array *tr, 1056 struct ftrace_graph_ent *trace, 1057 unsigned int trace_ctx, 1058 unsigned long retaddr, 1059 struct ftrace_regs *fregs); 1060 extern void __trace_graph_return(struct trace_array *tr, 1061 struct ftrace_graph_ret *trace, 1062 unsigned int trace_ctx, 1063 u64 calltime, u64 rettime); 1064 1065 extern void init_array_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops); 1066 extern int allocate_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops); 1067 extern void free_fgraph_ops(struct trace_array *tr); 1068 1069 enum { 1070 TRACE_GRAPH_FL = 1, 1071 1072 /* 1073 * In the very unlikely case that an interrupt came in 1074 * at a start of graph tracing, and we want to trace 1075 * the function in that interrupt, the depth can be greater 1076 * than zero, because of the preempted start of a previous 1077 * trace. In an even more unlikely case, depth could be 2 1078 * if a softirq interrupted the start of graph tracing, 1079 * followed by an interrupt preempting a start of graph 1080 * tracing in the softirq, and depth can even be 3 1081 * if an NMI came in at the start of an interrupt function 1082 * that preempted a softirq start of a function that 1083 * preempted normal context!!!! Luckily, it can't be 1084 * greater than 3, so the next two bits are a mask 1085 * of what the depth is when we set TRACE_GRAPH_FL 1086 */ 1087 1088 TRACE_GRAPH_DEPTH_START_BIT, 1089 TRACE_GRAPH_DEPTH_END_BIT, 1090 1091 /* 1092 * To implement set_graph_notrace, if this bit is set, we ignore 1093 * function graph tracing of called functions, until the return 1094 * function is called to clear it. 1095 */ 1096 TRACE_GRAPH_NOTRACE_BIT, 1097 }; 1098 1099 #define TRACE_GRAPH_NOTRACE (1 << TRACE_GRAPH_NOTRACE_BIT) 1100 1101 static inline unsigned long ftrace_graph_depth(unsigned long *task_var) 1102 { 1103 return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3; 1104 } 1105 1106 static inline void ftrace_graph_set_depth(unsigned long *task_var, int depth) 1107 { 1108 *task_var &= ~(3 << TRACE_GRAPH_DEPTH_START_BIT); 1109 *task_var |= (depth & 3) << TRACE_GRAPH_DEPTH_START_BIT; 1110 } 1111 1112 #ifdef CONFIG_DYNAMIC_FTRACE 1113 extern struct ftrace_hash __rcu *ftrace_graph_hash; 1114 extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash; 1115 1116 static inline int 1117 ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace) 1118 { 1119 unsigned long addr = trace->func; 1120 int ret = 0; 1121 struct ftrace_hash *hash; 1122 1123 preempt_disable_notrace(); 1124 1125 /* 1126 * Have to open code "rcu_dereference_sched()" because the 1127 * function graph tracer can be called when RCU is not 1128 * "watching". 1129 * Protected with schedule_on_each_cpu(ftrace_sync) 1130 */ 1131 hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible()); 1132 1133 if (ftrace_hash_empty(hash)) { 1134 ret = 1; 1135 goto out; 1136 } 1137 1138 if (ftrace_lookup_ip(hash, addr)) { 1139 /* 1140 * This needs to be cleared on the return functions 1141 * when the depth is zero. 1142 */ 1143 *task_var |= TRACE_GRAPH_FL; 1144 ftrace_graph_set_depth(task_var, trace->depth); 1145 1146 /* 1147 * If no irqs are to be traced, but a set_graph_function 1148 * is set, and called by an interrupt handler, we still 1149 * want to trace it. 1150 */ 1151 if (in_hardirq()) 1152 trace_recursion_set(TRACE_IRQ_BIT); 1153 else 1154 trace_recursion_clear(TRACE_IRQ_BIT); 1155 ret = 1; 1156 } 1157 1158 out: 1159 preempt_enable_notrace(); 1160 return ret; 1161 } 1162 1163 static inline void 1164 ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace) 1165 { 1166 unsigned long *task_var = fgraph_get_task_var(gops); 1167 1168 if ((*task_var & TRACE_GRAPH_FL) && 1169 trace->depth == ftrace_graph_depth(task_var)) 1170 *task_var &= ~TRACE_GRAPH_FL; 1171 } 1172 1173 static inline int ftrace_graph_notrace_addr(unsigned long addr) 1174 { 1175 int ret = 0; 1176 struct ftrace_hash *notrace_hash; 1177 1178 preempt_disable_notrace(); 1179 1180 /* 1181 * Have to open code "rcu_dereference_sched()" because the 1182 * function graph tracer can be called when RCU is not 1183 * "watching". 1184 * Protected with schedule_on_each_cpu(ftrace_sync) 1185 */ 1186 notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash, 1187 !preemptible()); 1188 1189 if (ftrace_lookup_ip(notrace_hash, addr)) 1190 ret = 1; 1191 1192 preempt_enable_notrace(); 1193 return ret; 1194 } 1195 #else 1196 static inline int ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace) 1197 { 1198 return 1; 1199 } 1200 1201 static inline int ftrace_graph_notrace_addr(unsigned long addr) 1202 { 1203 return 0; 1204 } 1205 static inline void ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace) 1206 { } 1207 #endif /* CONFIG_DYNAMIC_FTRACE */ 1208 1209 extern unsigned int fgraph_max_depth; 1210 extern int fgraph_no_sleep_time; 1211 extern bool fprofile_no_sleep_time; 1212 1213 static inline bool 1214 ftrace_graph_ignore_func(struct fgraph_ops *gops, struct ftrace_graph_ent *trace) 1215 { 1216 unsigned long *task_var = fgraph_get_task_var(gops); 1217 1218 /* trace it when it is-nested-in or is a function enabled. */ 1219 return !((*task_var & TRACE_GRAPH_FL) || 1220 ftrace_graph_addr(task_var, trace)) || 1221 (trace->depth < 0) || 1222 (fgraph_max_depth && trace->depth >= fgraph_max_depth); 1223 } 1224 1225 void fgraph_init_ops(struct ftrace_ops *dst_ops, 1226 struct ftrace_ops *src_ops); 1227 1228 #else /* CONFIG_FUNCTION_GRAPH_TRACER */ 1229 static inline enum print_line_t 1230 print_graph_function_flags(struct trace_iterator *iter, u32 flags) 1231 { 1232 return TRACE_TYPE_UNHANDLED; 1233 } 1234 static inline void free_fgraph_ops(struct trace_array *tr) { } 1235 /* ftrace_ops may not be defined */ 1236 #define init_array_fgraph_ops(tr, ops) do { } while (0) 1237 #define allocate_fgraph_ops(tr, ops) ({ 0; }) 1238 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ 1239 1240 extern struct list_head ftrace_pids; 1241 1242 #ifdef CONFIG_FUNCTION_TRACER 1243 1244 #define FTRACE_PID_IGNORE -1 1245 #define FTRACE_PID_TRACE -2 1246 1247 struct ftrace_func_command { 1248 struct list_head list; 1249 char *name; 1250 int (*func)(struct trace_array *tr, 1251 struct ftrace_hash *hash, 1252 char *func, char *cmd, 1253 char *params, int enable); 1254 }; 1255 extern bool ftrace_filter_param __initdata; 1256 extern int ftrace_is_dead(void); 1257 int ftrace_create_function_files(struct trace_array *tr, 1258 struct dentry *parent); 1259 void ftrace_destroy_function_files(struct trace_array *tr); 1260 int ftrace_allocate_ftrace_ops(struct trace_array *tr); 1261 void ftrace_free_ftrace_ops(struct trace_array *tr); 1262 void ftrace_init_global_array_ops(struct trace_array *tr); 1263 struct trace_array *trace_get_global_array(void); 1264 void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func); 1265 void ftrace_reset_array_ops(struct trace_array *tr); 1266 void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer); 1267 void ftrace_init_tracefs_toplevel(struct trace_array *tr, 1268 struct dentry *d_tracer); 1269 void ftrace_clear_pids(struct trace_array *tr); 1270 int init_function_trace(void); 1271 void ftrace_pid_follow_fork(struct trace_array *tr, bool enable); 1272 #else 1273 static inline int ftrace_is_dead(void) { return 0; } 1274 static inline int 1275 ftrace_create_function_files(struct trace_array *tr, 1276 struct dentry *parent) 1277 { 1278 return 0; 1279 } 1280 static inline int ftrace_allocate_ftrace_ops(struct trace_array *tr) 1281 { 1282 return 0; 1283 } 1284 static inline void ftrace_free_ftrace_ops(struct trace_array *tr) { } 1285 static inline void ftrace_destroy_function_files(struct trace_array *tr) { } 1286 static inline __init void 1287 ftrace_init_global_array_ops(struct trace_array *tr) { } 1288 static inline void ftrace_reset_array_ops(struct trace_array *tr) { } 1289 static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { } 1290 static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { } 1291 static inline void ftrace_clear_pids(struct trace_array *tr) { } 1292 static inline int init_function_trace(void) { return 0; } 1293 static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { } 1294 /* ftace_func_t type is not defined, use macro instead of static inline */ 1295 #define ftrace_init_array_ops(tr, func) do { } while (0) 1296 #endif /* CONFIG_FUNCTION_TRACER */ 1297 1298 #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE) 1299 1300 struct ftrace_probe_ops { 1301 void (*func)(unsigned long ip, 1302 unsigned long parent_ip, 1303 struct trace_array *tr, 1304 struct ftrace_probe_ops *ops, 1305 void *data); 1306 int (*init)(struct ftrace_probe_ops *ops, 1307 struct trace_array *tr, 1308 unsigned long ip, void *init_data, 1309 void **data); 1310 void (*free)(struct ftrace_probe_ops *ops, 1311 struct trace_array *tr, 1312 unsigned long ip, void *data); 1313 int (*print)(struct seq_file *m, 1314 unsigned long ip, 1315 struct ftrace_probe_ops *ops, 1316 void *data); 1317 }; 1318 1319 struct ftrace_func_mapper; 1320 typedef int (*ftrace_mapper_func)(void *data); 1321 1322 struct ftrace_func_mapper *allocate_ftrace_func_mapper(void); 1323 void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper, 1324 unsigned long ip); 1325 int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper, 1326 unsigned long ip, void *data); 1327 void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper, 1328 unsigned long ip); 1329 void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper, 1330 ftrace_mapper_func free_func); 1331 1332 extern int 1333 register_ftrace_function_probe(char *glob, struct trace_array *tr, 1334 struct ftrace_probe_ops *ops, void *data); 1335 extern int 1336 unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr, 1337 struct ftrace_probe_ops *ops); 1338 extern void clear_ftrace_function_probes(struct trace_array *tr); 1339 1340 int register_ftrace_command(struct ftrace_func_command *cmd); 1341 int unregister_ftrace_command(struct ftrace_func_command *cmd); 1342 1343 void ftrace_create_filter_files(struct trace_array *tr, 1344 struct dentry *parent); 1345 void ftrace_destroy_filter_files(struct ftrace_ops *ops); 1346 1347 extern int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf, 1348 int len, int reset); 1349 extern int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf, 1350 int len, int reset); 1351 #else 1352 struct ftrace_func_command; 1353 1354 static inline __init int register_ftrace_command(struct ftrace_func_command *cmd) 1355 { 1356 return -EINVAL; 1357 } 1358 static inline __init int unregister_ftrace_command(char *cmd_name) 1359 { 1360 return -EINVAL; 1361 } 1362 static inline void clear_ftrace_function_probes(struct trace_array *tr) 1363 { 1364 } 1365 1366 static inline void ftrace_create_filter_files(struct trace_array *tr, 1367 struct dentry *parent) { } 1368 /* 1369 * The ops parameter passed in is usually undefined. 1370 * This must be a macro. 1371 */ 1372 #define ftrace_destroy_filter_files(ops) do { } while (0) 1373 #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */ 1374 1375 bool ftrace_event_is_function(struct trace_event_call *call); 1376 1377 /* 1378 * struct trace_parser - servers for reading the user input separated by spaces 1379 * @cont: set if the input is not complete - no final space char was found 1380 * @buffer: holds the parsed user input 1381 * @idx: user input length 1382 * @size: buffer size 1383 */ 1384 struct trace_parser { 1385 bool cont; 1386 bool fail; 1387 char *buffer; 1388 unsigned idx; 1389 unsigned size; 1390 }; 1391 1392 static inline bool trace_parser_loaded(struct trace_parser *parser) 1393 { 1394 return !parser->fail && parser->idx != 0; 1395 } 1396 1397 static inline bool trace_parser_cont(struct trace_parser *parser) 1398 { 1399 return parser->cont; 1400 } 1401 1402 static inline void trace_parser_clear(struct trace_parser *parser) 1403 { 1404 parser->cont = false; 1405 parser->idx = 0; 1406 } 1407 1408 static inline void trace_parser_fail(struct trace_parser *parser) 1409 { 1410 parser->fail = true; 1411 } 1412 1413 extern int trace_parser_get_init(struct trace_parser *parser, int size); 1414 extern void trace_parser_put(struct trace_parser *parser); 1415 extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf, 1416 size_t cnt, loff_t *ppos); 1417 1418 /* 1419 * Only create function graph options if function graph is configured. 1420 */ 1421 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 1422 # define FGRAPH_FLAGS \ 1423 C(DISPLAY_GRAPH, "display-graph"), 1424 #else 1425 # define FGRAPH_FLAGS 1426 #endif 1427 1428 #ifdef CONFIG_BRANCH_TRACER 1429 # define BRANCH_FLAGS \ 1430 C(BRANCH, "branch"), 1431 #else 1432 # define BRANCH_FLAGS 1433 #endif 1434 1435 #ifdef CONFIG_FUNCTION_TRACER 1436 # define FUNCTION_FLAGS \ 1437 C(FUNCTION, "function-trace"), \ 1438 C(FUNC_FORK, "function-fork"), 1439 # define FUNCTION_DEFAULT_FLAGS TRACE_ITER(FUNCTION) 1440 #else 1441 # define FUNCTION_FLAGS 1442 # define FUNCTION_DEFAULT_FLAGS 0UL 1443 # define TRACE_ITER_FUNC_FORK_BIT -1 1444 #endif 1445 1446 #ifdef CONFIG_STACKTRACE 1447 # define STACK_FLAGS \ 1448 C(STACKTRACE, "stacktrace"), 1449 #else 1450 # define STACK_FLAGS 1451 #endif 1452 1453 #ifdef CONFIG_FUNCTION_PROFILER 1454 # define PROFILER_FLAGS \ 1455 C(PROF_TEXT_OFFSET, "prof-text-offset"), 1456 # ifdef CONFIG_FUNCTION_GRAPH_TRACER 1457 # define FPROFILE_FLAGS \ 1458 C(GRAPH_TIME, "graph-time"), 1459 # define FPROFILE_DEFAULT_FLAGS TRACE_ITER(GRAPH_TIME) 1460 # else 1461 # define FPROFILE_FLAGS 1462 # define FPROFILE_DEFAULT_FLAGS 0UL 1463 # endif 1464 #else 1465 # define PROFILER_FLAGS 1466 # define FPROFILE_FLAGS 1467 # define FPROFILE_DEFAULT_FLAGS 0UL 1468 # define TRACE_ITER_PROF_TEXT_OFFSET_BIT -1 1469 #endif 1470 1471 /* 1472 * trace_iterator_flags is an enumeration that defines bit 1473 * positions into trace_flags that controls the output. 1474 * 1475 * NOTE: These bits must match the trace_options array in 1476 * trace.c (this macro guarantees it). 1477 */ 1478 #define TRACE_FLAGS \ 1479 C(PRINT_PARENT, "print-parent"), \ 1480 C(SYM_OFFSET, "sym-offset"), \ 1481 C(SYM_ADDR, "sym-addr"), \ 1482 C(VERBOSE, "verbose"), \ 1483 C(RAW, "raw"), \ 1484 C(HEX, "hex"), \ 1485 C(BIN, "bin"), \ 1486 C(BLOCK, "block"), \ 1487 C(FIELDS, "fields"), \ 1488 C(PRINTK, "trace_printk"), \ 1489 C(ANNOTATE, "annotate"), \ 1490 C(USERSTACKTRACE, "userstacktrace"), \ 1491 C(SYM_USEROBJ, "sym-userobj"), \ 1492 C(PRINTK_MSGONLY, "printk-msg-only"), \ 1493 C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \ 1494 C(LATENCY_FMT, "latency-format"), \ 1495 C(RECORD_CMD, "record-cmd"), \ 1496 C(RECORD_TGID, "record-tgid"), \ 1497 C(OVERWRITE, "overwrite"), \ 1498 C(STOP_ON_FREE, "disable_on_free"), \ 1499 C(IRQ_INFO, "irq-info"), \ 1500 C(MARKERS, "markers"), \ 1501 C(EVENT_FORK, "event-fork"), \ 1502 C(TRACE_PRINTK, "trace_printk_dest"), \ 1503 C(COPY_MARKER, "copy_trace_marker"), \ 1504 C(PAUSE_ON_TRACE, "pause-on-trace"), \ 1505 C(HASH_PTR, "hash-ptr"), /* Print hashed pointer */ \ 1506 C(BITMASK_LIST, "bitmask-list"), \ 1507 FUNCTION_FLAGS \ 1508 FGRAPH_FLAGS \ 1509 STACK_FLAGS \ 1510 BRANCH_FLAGS \ 1511 PROFILER_FLAGS \ 1512 FPROFILE_FLAGS 1513 1514 /* 1515 * By defining C, we can make TRACE_FLAGS a list of bit names 1516 * that will define the bits for the flag masks. 1517 */ 1518 #undef C 1519 #define C(a, b) TRACE_ITER_##a##_BIT 1520 1521 enum trace_iterator_bits { 1522 TRACE_FLAGS 1523 /* Make sure we don't go more than we have bits for */ 1524 TRACE_ITER_LAST_BIT 1525 }; 1526 1527 /* 1528 * And use TRACE_ITER(flag) to define the bit masks. 1529 */ 1530 #define TRACE_ITER(flag) \ 1531 (TRACE_ITER_##flag##_BIT < 0 ? 0 : 1ULL << (TRACE_ITER_##flag##_BIT)) 1532 1533 /* 1534 * TRACE_ITER_SYM_MASK masks the options in trace_flags that 1535 * control the output of kernel symbols. 1536 */ 1537 #define TRACE_ITER_SYM_MASK \ 1538 (TRACE_ITER(PRINT_PARENT)|TRACE_ITER(SYM_OFFSET)|TRACE_ITER(SYM_ADDR)) 1539 1540 extern struct tracer nop_trace; 1541 1542 #ifdef CONFIG_BRANCH_TRACER 1543 extern int enable_branch_tracing(struct trace_array *tr); 1544 extern void disable_branch_tracing(void); 1545 static inline int trace_branch_enable(struct trace_array *tr) 1546 { 1547 if (tr->trace_flags & TRACE_ITER(BRANCH)) 1548 return enable_branch_tracing(tr); 1549 return 0; 1550 } 1551 static inline void trace_branch_disable(void) 1552 { 1553 /* due to races, always disable */ 1554 disable_branch_tracing(); 1555 } 1556 #else 1557 static inline int trace_branch_enable(struct trace_array *tr) 1558 { 1559 return 0; 1560 } 1561 static inline void trace_branch_disable(void) 1562 { 1563 } 1564 #endif /* CONFIG_BRANCH_TRACER */ 1565 1566 /* set ring buffers to default size if not already done so */ 1567 int tracing_update_buffers(struct trace_array *tr); 1568 1569 union trace_synth_field { 1570 u8 as_u8; 1571 u16 as_u16; 1572 u32 as_u32; 1573 u64 as_u64; 1574 struct trace_dynamic_info as_dynamic; 1575 }; 1576 1577 struct ftrace_event_field { 1578 struct list_head link; 1579 const char *name; 1580 const char *type; 1581 int filter_type; 1582 int offset; 1583 int size; 1584 unsigned int is_signed:1; 1585 unsigned int needs_test:1; 1586 int len; 1587 }; 1588 1589 struct prog_entry; 1590 1591 struct event_filter { 1592 struct prog_entry __rcu *prog; 1593 char *filter_string; 1594 }; 1595 1596 struct event_subsystem { 1597 struct list_head list; 1598 const char *name; 1599 struct event_filter *filter; 1600 int ref_count; 1601 }; 1602 1603 struct trace_subsystem_dir { 1604 struct list_head list; 1605 struct event_subsystem *subsystem; 1606 struct trace_array *tr; 1607 struct eventfs_inode *ei; 1608 int ref_count; 1609 int nr_events; 1610 }; 1611 1612 void trace_buffer_unlock_commit_regs(struct trace_array *tr, 1613 struct trace_buffer *buffer, 1614 struct ring_buffer_event *event, 1615 unsigned int trcace_ctx, 1616 struct pt_regs *regs); 1617 1618 static inline void trace_buffer_unlock_commit(struct trace_array *tr, 1619 struct trace_buffer *buffer, 1620 struct ring_buffer_event *event, 1621 unsigned int trace_ctx) 1622 { 1623 trace_buffer_unlock_commit_regs(tr, buffer, event, trace_ctx, NULL); 1624 } 1625 1626 DECLARE_PER_CPU(bool, trace_taskinfo_save); 1627 int trace_save_cmdline(struct task_struct *tsk); 1628 int trace_create_savedcmd(void); 1629 int trace_alloc_tgid_map(void); 1630 void trace_free_saved_cmdlines_buffer(void); 1631 1632 extern const struct file_operations tracing_saved_cmdlines_fops; 1633 extern const struct file_operations tracing_saved_tgids_fops; 1634 extern const struct file_operations tracing_saved_cmdlines_size_fops; 1635 1636 DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event); 1637 DECLARE_PER_CPU(int, trace_buffered_event_cnt); 1638 void trace_buffered_event_disable(void); 1639 void trace_buffered_event_enable(void); 1640 1641 void early_enable_events(struct trace_array *tr, char *buf, bool disable_first); 1642 1643 struct trace_user_buf; 1644 struct trace_user_buf_info { 1645 struct trace_user_buf __percpu *tbuf; 1646 size_t size; 1647 int ref; 1648 }; 1649 1650 typedef int (*trace_user_buf_copy)(char *dst, const char __user *src, 1651 size_t size, void *data); 1652 int trace_user_fault_init(struct trace_user_buf_info *tinfo, size_t size); 1653 int trace_user_fault_get(struct trace_user_buf_info *tinfo); 1654 int trace_user_fault_put(struct trace_user_buf_info *tinfo); 1655 void trace_user_fault_destroy(struct trace_user_buf_info *tinfo); 1656 char *trace_user_fault_read(struct trace_user_buf_info *tinfo, 1657 const char __user *ptr, size_t size, 1658 trace_user_buf_copy copy_func, void *data); 1659 1660 static __always_inline void 1661 trace_event_setup(struct ring_buffer_event *event, 1662 int type, unsigned int trace_ctx) 1663 { 1664 struct trace_entry *ent = ring_buffer_event_data(event); 1665 1666 tracing_generic_entry_update(ent, type, trace_ctx); 1667 } 1668 1669 static __always_inline struct ring_buffer_event * 1670 __trace_buffer_lock_reserve(struct trace_buffer *buffer, 1671 int type, 1672 unsigned long len, 1673 unsigned int trace_ctx) 1674 { 1675 struct ring_buffer_event *event; 1676 1677 event = ring_buffer_lock_reserve(buffer, len); 1678 if (event != NULL) 1679 trace_event_setup(event, type, trace_ctx); 1680 1681 return event; 1682 } 1683 1684 static __always_inline void 1685 __buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *event) 1686 { 1687 __this_cpu_write(trace_taskinfo_save, true); 1688 1689 /* If this is the temp buffer, we need to commit fully */ 1690 if (this_cpu_read(trace_buffered_event) == event) { 1691 /* Length is in event->array[0] */ 1692 ring_buffer_write(buffer, event->array[0], &event->array[1]); 1693 /* Release the temp buffer */ 1694 this_cpu_dec(trace_buffered_event_cnt); 1695 /* ring_buffer_unlock_commit() enables preemption */ 1696 preempt_enable_notrace(); 1697 } else 1698 ring_buffer_unlock_commit(buffer); 1699 } 1700 1701 static inline void 1702 __trace_event_discard_commit(struct trace_buffer *buffer, 1703 struct ring_buffer_event *event) 1704 { 1705 if (this_cpu_read(trace_buffered_event) == event) { 1706 /* Simply release the temp buffer and enable preemption */ 1707 this_cpu_dec(trace_buffered_event_cnt); 1708 preempt_enable_notrace(); 1709 return; 1710 } 1711 /* ring_buffer_discard_commit() enables preemption */ 1712 ring_buffer_discard_commit(buffer, event); 1713 } 1714 1715 /* 1716 * Helper function for event_trigger_unlock_commit{_regs}(). 1717 * If there are event triggers attached to this event that requires 1718 * filtering against its fields, then they will be called as the 1719 * entry already holds the field information of the current event. 1720 * 1721 * It also checks if the event should be discarded or not. 1722 * It is to be discarded if the event is soft disabled and the 1723 * event was only recorded to process triggers, or if the event 1724 * filter is active and this event did not match the filters. 1725 * 1726 * Returns true if the event is discarded, false otherwise. 1727 */ 1728 static inline bool 1729 __event_trigger_test_discard(struct trace_event_file *file, 1730 struct trace_buffer *buffer, 1731 struct ring_buffer_event *event, 1732 void *entry, 1733 enum event_trigger_type *tt) 1734 { 1735 unsigned long eflags = file->flags; 1736 1737 if (eflags & EVENT_FILE_FL_TRIGGER_COND) 1738 *tt = event_triggers_call(file, buffer, entry, event); 1739 1740 if (likely(!(file->flags & (EVENT_FILE_FL_SOFT_DISABLED | 1741 EVENT_FILE_FL_FILTERED | 1742 EVENT_FILE_FL_PID_FILTER)))) 1743 return false; 1744 1745 if (file->flags & EVENT_FILE_FL_SOFT_DISABLED) 1746 goto discard; 1747 1748 if (file->flags & EVENT_FILE_FL_FILTERED && 1749 !filter_match_preds(file->filter, entry)) 1750 goto discard; 1751 1752 if ((file->flags & EVENT_FILE_FL_PID_FILTER) && 1753 trace_event_ignore_this_pid(file)) 1754 goto discard; 1755 1756 return false; 1757 discard: 1758 __trace_event_discard_commit(buffer, event); 1759 return true; 1760 } 1761 1762 /** 1763 * event_trigger_unlock_commit - handle triggers and finish event commit 1764 * @file: The file pointer associated with the event 1765 * @buffer: The ring buffer that the event is being written to 1766 * @event: The event meta data in the ring buffer 1767 * @entry: The event itself 1768 * @trace_ctx: The tracing context flags. 1769 * 1770 * This is a helper function to handle triggers that require data 1771 * from the event itself. It also tests the event against filters and 1772 * if the event is soft disabled and should be discarded. 1773 */ 1774 static inline void 1775 event_trigger_unlock_commit(struct trace_event_file *file, 1776 struct trace_buffer *buffer, 1777 struct ring_buffer_event *event, 1778 void *entry, unsigned int trace_ctx) 1779 { 1780 enum event_trigger_type tt = ETT_NONE; 1781 1782 if (!__event_trigger_test_discard(file, buffer, event, entry, &tt)) 1783 trace_buffer_unlock_commit(file->tr, buffer, event, trace_ctx); 1784 1785 if (tt) 1786 event_triggers_post_call(file, tt); 1787 } 1788 1789 #define FILTER_PRED_INVALID ((unsigned short)-1) 1790 #define FILTER_PRED_IS_RIGHT (1 << 15) 1791 #define FILTER_PRED_FOLD (1 << 15) 1792 1793 /* 1794 * The max preds is the size of unsigned short with 1795 * two flags at the MSBs. One bit is used for both the IS_RIGHT 1796 * and FOLD flags. The other is reserved. 1797 * 1798 * 2^14 preds is way more than enough. 1799 */ 1800 #define MAX_FILTER_PRED 16384 1801 1802 struct filter_pred; 1803 struct regex; 1804 1805 typedef int (*regex_match_func)(char *str, struct regex *r, int len); 1806 1807 enum regex_type { 1808 MATCH_FULL = 0, 1809 MATCH_FRONT_ONLY, 1810 MATCH_MIDDLE_ONLY, 1811 MATCH_END_ONLY, 1812 MATCH_GLOB, 1813 MATCH_INDEX, 1814 }; 1815 1816 struct regex { 1817 char pattern[MAX_FILTER_STR_VAL]; 1818 int len; 1819 int field_len; 1820 regex_match_func match; 1821 }; 1822 1823 static inline bool is_string_field(struct ftrace_event_field *field) 1824 { 1825 return field->filter_type == FILTER_DYN_STRING || 1826 field->filter_type == FILTER_RDYN_STRING || 1827 field->filter_type == FILTER_STATIC_STRING || 1828 field->filter_type == FILTER_PTR_STRING || 1829 field->filter_type == FILTER_COMM; 1830 } 1831 1832 static inline bool is_function_field(struct ftrace_event_field *field) 1833 { 1834 return field->filter_type == FILTER_TRACE_FN; 1835 } 1836 1837 extern enum regex_type 1838 filter_parse_regex(char *buff, int len, char **search, int *not); 1839 extern void print_event_filter(struct trace_event_file *file, 1840 struct trace_seq *s); 1841 extern int apply_event_filter(struct trace_event_file *file, 1842 char *filter_string); 1843 extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir, 1844 char *filter_string); 1845 extern void print_subsystem_event_filter(struct event_subsystem *system, 1846 struct trace_seq *s); 1847 extern int filter_assign_type(const char *type); 1848 extern int create_event_filter(struct trace_array *tr, 1849 struct trace_event_call *call, 1850 char *filter_str, bool set_str, 1851 struct event_filter **filterp); 1852 extern void free_event_filter(struct event_filter *filter); 1853 1854 struct ftrace_event_field * 1855 trace_find_event_field(struct trace_event_call *call, char *name); 1856 1857 extern void trace_event_enable_cmd_record(bool enable); 1858 extern void trace_event_enable_tgid_record(bool enable); 1859 1860 extern int event_trace_init(void); 1861 extern int init_events(void); 1862 extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr); 1863 extern int event_trace_del_tracer(struct trace_array *tr); 1864 extern void __trace_early_add_events(struct trace_array *tr); 1865 1866 extern struct trace_event_file *__find_event_file(struct trace_array *tr, 1867 const char *system, 1868 const char *event); 1869 extern struct trace_event_file *find_event_file(struct trace_array *tr, 1870 const char *system, 1871 const char *event); 1872 1873 extern struct mutex event_mutex; 1874 extern struct list_head ftrace_events; 1875 1876 /* 1877 * When the trace_event_file is the filp->i_private pointer, 1878 * it must be taken under the event_mutex lock, and then checked 1879 * if the EVENT_FILE_FL_FREED flag is set. If it is, then the 1880 * data pointed to by the trace_event_file can not be trusted. 1881 * 1882 * Use the event_file_file() to access the trace_event_file from 1883 * the filp the first time under the event_mutex and check for 1884 * NULL. If it is needed to be retrieved again and the event_mutex 1885 * is still held, then the event_file_data() can be used and it 1886 * is guaranteed to be valid. 1887 */ 1888 static inline struct trace_event_file *event_file_file(struct file *filp) 1889 { 1890 struct trace_event_file *file; 1891 1892 lockdep_assert_held(&event_mutex); 1893 file = file_inode(filp)->i_private; 1894 if (!file || file->flags & EVENT_FILE_FL_FREED) 1895 return NULL; 1896 return file; 1897 } 1898 1899 static inline void *event_file_data(struct file *filp) 1900 { 1901 struct trace_event_file *file; 1902 1903 lockdep_assert_held(&event_mutex); 1904 file = file_inode(filp)->i_private; 1905 WARN_ON(!file || file->flags & EVENT_FILE_FL_FREED); 1906 return file; 1907 } 1908 1909 extern const struct file_operations event_trigger_fops; 1910 extern const struct file_operations event_hist_fops; 1911 extern const struct file_operations event_hist_debug_fops; 1912 extern const struct file_operations event_inject_fops; 1913 1914 #ifdef CONFIG_HIST_TRIGGERS 1915 extern int register_trigger_hist_cmd(void); 1916 extern int register_trigger_hist_enable_disable_cmds(void); 1917 #else 1918 static inline int register_trigger_hist_cmd(void) { return 0; } 1919 static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; } 1920 #endif 1921 1922 extern int register_trigger_cmds(void); 1923 extern void clear_event_triggers(struct trace_array *tr); 1924 1925 enum { 1926 EVENT_TRIGGER_FL_PROBE = BIT(0), 1927 EVENT_TRIGGER_FL_COUNT = BIT(1), 1928 }; 1929 1930 struct event_trigger_data { 1931 unsigned long count; 1932 int ref; 1933 int flags; 1934 struct event_command *cmd_ops; 1935 struct event_filter __rcu *filter; 1936 char *filter_str; 1937 void *private_data; 1938 bool paused; 1939 bool paused_tmp; 1940 struct list_head list; 1941 char *name; 1942 struct list_head named_list; 1943 struct event_trigger_data *named_data; 1944 struct llist_node llist; 1945 void (*private_data_free)(struct event_trigger_data *data); 1946 }; 1947 1948 /* Avoid typos */ 1949 #define ENABLE_EVENT_STR "enable_event" 1950 #define DISABLE_EVENT_STR "disable_event" 1951 #define ENABLE_HIST_STR "enable_hist" 1952 #define DISABLE_HIST_STR "disable_hist" 1953 1954 struct enable_trigger_data { 1955 struct trace_event_file *file; 1956 struct trace_event_call *call; 1957 bool enable; 1958 bool hist; 1959 }; 1960 1961 bool event_trigger_count(struct event_trigger_data *data, 1962 struct trace_buffer *buffer, void *rec, 1963 struct ring_buffer_event *event); 1964 1965 extern int event_enable_trigger_print(struct seq_file *m, 1966 struct event_trigger_data *data); 1967 extern void event_enable_trigger_free(struct event_trigger_data *data); 1968 extern int event_enable_trigger_parse(struct event_command *cmd_ops, 1969 struct trace_event_file *file, 1970 char *glob, char *cmd, 1971 char *param_and_filter); 1972 extern int event_enable_register_trigger(char *glob, 1973 struct event_trigger_data *data, 1974 struct trace_event_file *file); 1975 extern void event_enable_unregister_trigger(char *glob, 1976 struct event_trigger_data *test, 1977 struct trace_event_file *file); 1978 extern struct event_trigger_data * 1979 trigger_data_alloc(struct event_command *cmd_ops, char *cmd, char *param, 1980 void *private_data); 1981 extern void trigger_data_free(struct event_trigger_data *data); 1982 extern int event_trigger_init(struct event_trigger_data *data); 1983 extern int trace_event_trigger_enable_disable(struct trace_event_file *file, 1984 int trigger_enable); 1985 extern void update_cond_flag(struct trace_event_file *file); 1986 extern int set_trigger_filter(char *filter_str, 1987 struct event_trigger_data *trigger_data, 1988 struct trace_event_file *file); 1989 extern struct event_trigger_data *find_named_trigger(const char *name); 1990 extern bool is_named_trigger(struct event_trigger_data *test); 1991 extern int save_named_trigger(const char *name, 1992 struct event_trigger_data *data); 1993 extern void del_named_trigger(struct event_trigger_data *data); 1994 extern void pause_named_trigger(struct event_trigger_data *data); 1995 extern void unpause_named_trigger(struct event_trigger_data *data); 1996 extern void set_named_trigger_data(struct event_trigger_data *data, 1997 struct event_trigger_data *named_data); 1998 extern struct event_trigger_data * 1999 get_named_trigger_data(struct event_trigger_data *data); 2000 extern int register_event_command(struct event_command *cmd); 2001 extern int unregister_event_command(struct event_command *cmd); 2002 extern int register_trigger_hist_enable_disable_cmds(void); 2003 extern bool event_trigger_check_remove(const char *glob); 2004 extern bool event_trigger_empty_param(const char *param); 2005 extern int event_trigger_separate_filter(char *param_and_filter, char **param, 2006 char **filter, bool param_required); 2007 extern int event_trigger_parse_num(char *trigger, 2008 struct event_trigger_data *trigger_data); 2009 extern int event_trigger_set_filter(struct event_command *cmd_ops, 2010 struct trace_event_file *file, 2011 char *param, 2012 struct event_trigger_data *trigger_data); 2013 extern void event_trigger_reset_filter(struct event_command *cmd_ops, 2014 struct event_trigger_data *trigger_data); 2015 extern int event_trigger_register(struct event_command *cmd_ops, 2016 struct trace_event_file *file, 2017 char *glob, 2018 struct event_trigger_data *trigger_data); 2019 extern void event_trigger_unregister(struct event_command *cmd_ops, 2020 struct trace_event_file *file, 2021 char *glob, 2022 struct event_trigger_data *trigger_data); 2023 2024 extern void event_file_get(struct trace_event_file *file); 2025 extern void event_file_put(struct trace_event_file *file); 2026 2027 /** 2028 * struct event_command - callbacks and data members for event commands 2029 * 2030 * Event commands are invoked by users by writing the command name 2031 * into the 'trigger' file associated with a trace event. The 2032 * parameters associated with a specific invocation of an event 2033 * command are used to create an event trigger instance, which is 2034 * added to the list of trigger instances associated with that trace 2035 * event. When the event is hit, the set of triggers associated with 2036 * that event is invoked. 2037 * 2038 * The data members in this structure provide per-event command data 2039 * for various event commands. 2040 * 2041 * All the data members below, except for @post_trigger, must be set 2042 * for each event command. 2043 * 2044 * @name: The unique name that identifies the event command. This is 2045 * the name used when setting triggers via trigger files. 2046 * 2047 * @trigger_type: A unique id that identifies the event command 2048 * 'type'. This value has two purposes, the first to ensure that 2049 * only one trigger of the same type can be set at a given time 2050 * for a particular event e.g. it doesn't make sense to have both 2051 * a traceon and traceoff trigger attached to a single event at 2052 * the same time, so traceon and traceoff have the same type 2053 * though they have different names. The @trigger_type value is 2054 * also used as a bit value for deferring the actual trigger 2055 * action until after the current event is finished. Some 2056 * commands need to do this if they themselves log to the trace 2057 * buffer (see the @post_trigger() member below). @trigger_type 2058 * values are defined by adding new values to the trigger_type 2059 * enum in include/linux/trace_events.h. 2060 * 2061 * @flags: See the enum event_command_flags below. 2062 * 2063 * All the methods below, except for @set_filter() and @unreg_all(), 2064 * must be implemented. 2065 * 2066 * @parse: The callback function responsible for parsing and 2067 * registering the trigger written to the 'trigger' file by the 2068 * user. It allocates the trigger instance and registers it with 2069 * the appropriate trace event. It makes use of the other 2070 * event_command callback functions to orchestrate this, and is 2071 * usually implemented by the generic utility function 2072 * @event_trigger_callback() (see trace_event_triggers.c). 2073 * 2074 * @reg: Adds the trigger to the list of triggers associated with the 2075 * event, and enables the event trigger itself, after 2076 * initializing it (via the event_command @init() function). 2077 * This is also where commands can use the @trigger_type value to 2078 * make the decision as to whether or not multiple instances of 2079 * the trigger should be allowed. This is usually implemented by 2080 * the generic utility function @register_trigger() (see 2081 * trace_event_triggers.c). 2082 * 2083 * @unreg: Removes the trigger from the list of triggers associated 2084 * with the event, and disables the event trigger itself, after 2085 * initializing it (via the event_command @free() function). 2086 * This is usually implemented by the generic utility function 2087 * @unregister_trigger() (see trace_event_triggers.c). 2088 * 2089 * @unreg_all: An optional function called to remove all the triggers 2090 * from the list of triggers associated with the event. Called 2091 * when a trigger file is opened in truncate mode. 2092 * 2093 * @set_filter: An optional function called to parse and set a filter 2094 * for the trigger. If no @set_filter() method is set for the 2095 * event command, filters set by the user for the command will be 2096 * ignored. This is usually implemented by the generic utility 2097 * function @set_trigger_filter() (see trace_event_triggers.c). 2098 * 2099 * All the methods below, except for @init() and @free(), must be 2100 * implemented. 2101 * 2102 * @trigger: The trigger 'probe' function called when the triggering 2103 * event occurs. The data passed into this callback is the data 2104 * that was supplied to the event_command @reg() function that 2105 * registered the trigger (see struct event_command) along with 2106 * the trace record, rec. 2107 * 2108 * @count_func: If defined and a numeric parameter is passed to the 2109 * trigger, then this function will be called before @trigger 2110 * is called. If this function returns false, then @trigger is not 2111 * executed. 2112 * 2113 * @init: An optional initialization function called for the trigger 2114 * when the trigger is registered (via the event_command reg() 2115 * function). This can be used to perform per-trigger 2116 * initialization such as incrementing a per-trigger reference 2117 * count, for instance. This is usually implemented by the 2118 * generic utility function @event_trigger_init() (see 2119 * trace_event_triggers.c). 2120 * 2121 * @free: An optional de-initialization function called for the 2122 * trigger when the trigger is unregistered (via the 2123 * event_command @reg() function). This can be used to perform 2124 * per-trigger de-initialization such as decrementing a 2125 * per-trigger reference count and freeing corresponding trigger 2126 * data, for instance. This is usually implemented by the 2127 * generic utility function @event_trigger_free() (see 2128 * trace_event_triggers.c). 2129 * 2130 * @print: The callback function invoked to have the trigger print 2131 * itself. This is usually implemented by a wrapper function 2132 * that calls the generic utility function @event_trigger_print() 2133 * (see trace_event_triggers.c). 2134 */ 2135 struct event_command { 2136 struct list_head list; 2137 char *name; 2138 enum event_trigger_type trigger_type; 2139 int flags; 2140 int (*parse)(struct event_command *cmd_ops, 2141 struct trace_event_file *file, 2142 char *glob, char *cmd, 2143 char *param_and_filter); 2144 int (*reg)(char *glob, 2145 struct event_trigger_data *data, 2146 struct trace_event_file *file); 2147 void (*unreg)(char *glob, 2148 struct event_trigger_data *data, 2149 struct trace_event_file *file); 2150 void (*unreg_all)(struct trace_event_file *file); 2151 int (*set_filter)(char *filter_str, 2152 struct event_trigger_data *data, 2153 struct trace_event_file *file); 2154 void (*trigger)(struct event_trigger_data *data, 2155 struct trace_buffer *buffer, 2156 void *rec, 2157 struct ring_buffer_event *rbe); 2158 bool (*count_func)(struct event_trigger_data *data, 2159 struct trace_buffer *buffer, 2160 void *rec, 2161 struct ring_buffer_event *rbe); 2162 int (*init)(struct event_trigger_data *data); 2163 void (*free)(struct event_trigger_data *data); 2164 int (*print)(struct seq_file *m, 2165 struct event_trigger_data *data); 2166 }; 2167 2168 /** 2169 * enum event_command_flags - flags for struct event_command 2170 * 2171 * @POST_TRIGGER: A flag that says whether or not this command needs 2172 * to have its action delayed until after the current event has 2173 * been closed. Some triggers need to avoid being invoked while 2174 * an event is currently in the process of being logged, since 2175 * the trigger may itself log data into the trace buffer. Thus 2176 * we make sure the current event is committed before invoking 2177 * those triggers. To do that, the trigger invocation is split 2178 * in two - the first part checks the filter using the current 2179 * trace record; if a command has the @post_trigger flag set, it 2180 * sets a bit for itself in the return value, otherwise it 2181 * directly invokes the trigger. Once all commands have been 2182 * either invoked or set their return flag, the current record is 2183 * either committed or discarded. At that point, if any commands 2184 * have deferred their triggers, those commands are finally 2185 * invoked following the close of the current event. In other 2186 * words, if the event_command @func() probe implementation 2187 * itself logs to the trace buffer, this flag should be set, 2188 * otherwise it can be left unspecified. 2189 * 2190 * @NEEDS_REC: A flag that says whether or not this command needs 2191 * access to the trace record in order to perform its function, 2192 * regardless of whether or not it has a filter associated with 2193 * it (filters make a trigger require access to the trace record 2194 * but are not always present). 2195 */ 2196 enum event_command_flags { 2197 EVENT_CMD_FL_POST_TRIGGER = 1, 2198 EVENT_CMD_FL_NEEDS_REC = 2, 2199 }; 2200 2201 static inline bool event_command_post_trigger(struct event_command *cmd_ops) 2202 { 2203 return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER; 2204 } 2205 2206 static inline bool event_command_needs_rec(struct event_command *cmd_ops) 2207 { 2208 return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC; 2209 } 2210 2211 extern int trace_event_enable_disable(struct trace_event_file *file, 2212 int enable, int soft_disable); 2213 2214 extern const char *__start___trace_bprintk_fmt[]; 2215 extern const char *__stop___trace_bprintk_fmt[]; 2216 2217 extern const char *__start___tracepoint_str[]; 2218 extern const char *__stop___tracepoint_str[]; 2219 2220 void trace_printk_control(bool enabled); 2221 void trace_printk_start_comm(void); 2222 void trace_printk_start_stop_comm(int enabled); 2223 int trace_keep_overwrite(struct tracer *tracer, u64 mask, int set); 2224 int set_tracer_flag(struct trace_array *tr, u64 mask, int enabled); 2225 2226 /* Used from boot time tracer */ 2227 extern int trace_set_options(struct trace_array *tr, char *option); 2228 extern int tracing_set_tracer(struct trace_array *tr, const char *buf); 2229 extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr, 2230 unsigned long size, int cpu_id); 2231 extern int tracing_set_cpumask(struct trace_array *tr, 2232 cpumask_var_t tracing_cpumask_new); 2233 2234 2235 #define MAX_EVENT_NAME_LEN 64 2236 2237 extern ssize_t trace_parse_run_command(struct file *file, 2238 const char __user *buffer, size_t count, loff_t *ppos, 2239 int (*createfn)(const char *)); 2240 2241 extern unsigned int err_pos(char *cmd, const char *str); 2242 extern void tracing_log_err(struct trace_array *tr, 2243 const char *loc, const char *cmd, 2244 const char **errs, u8 type, u16 pos); 2245 2246 /* 2247 * Normal trace_printk() and friends allocates special buffers 2248 * to do the manipulation, as well as saves the print formats 2249 * into sections to display. But the trace infrastructure wants 2250 * to use these without the added overhead at the price of being 2251 * a bit slower (used mainly for warnings, where we don't care 2252 * about performance). The internal_trace_puts() is for such 2253 * a purpose. 2254 */ 2255 #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str) 2256 2257 #undef FTRACE_ENTRY 2258 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print) \ 2259 extern struct trace_event_call \ 2260 __aligned(4) event_##call; 2261 #undef FTRACE_ENTRY_DUP 2262 #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print) \ 2263 FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print)) 2264 #undef FTRACE_ENTRY_PACKED 2265 #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print) \ 2266 FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print)) 2267 2268 #include "trace_entries.h" 2269 2270 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER) 2271 int perf_ftrace_event_register(struct trace_event_call *call, 2272 enum trace_reg type, void *data); 2273 #else 2274 #define perf_ftrace_event_register NULL 2275 #endif 2276 2277 #ifdef CONFIG_FTRACE_SYSCALLS 2278 void init_ftrace_syscalls(void); 2279 const char *get_syscall_name(int syscall); 2280 #else 2281 static inline void init_ftrace_syscalls(void) { } 2282 static inline const char *get_syscall_name(int syscall) 2283 { 2284 return NULL; 2285 } 2286 #endif 2287 2288 #ifdef CONFIG_EVENT_TRACING 2289 void trace_event_init(void); 2290 void trace_event_update_all(struct trace_eval_map **map, int len, struct module *mod); 2291 /* Used from boot time tracer */ 2292 extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set); 2293 extern int trigger_process_regex(struct trace_event_file *file, char *buff); 2294 #else 2295 static inline void __init trace_event_init(void) { } 2296 static inline void trace_event_update_all(struct trace_eval_map **map, int len, struct module *mod) { } 2297 #endif 2298 2299 #ifdef CONFIG_TRACER_SNAPSHOT 2300 extern const struct file_operations snapshot_fops; 2301 extern const struct file_operations snapshot_raw_fops; 2302 2303 /* Used when creating instances */ 2304 int trace_allocate_snapshot(struct trace_array *tr, int size); 2305 2306 int tracing_alloc_snapshot(void); 2307 void tracing_snapshot_cond(struct trace_array *tr, void *cond_data); 2308 int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update); 2309 int tracing_snapshot_cond_disable(struct trace_array *tr); 2310 void *tracing_cond_snapshot_data(struct trace_array *tr); 2311 void tracing_snapshot_instance(struct trace_array *tr); 2312 int tracing_alloc_snapshot_instance(struct trace_array *tr); 2313 int tracing_arm_snapshot_locked(struct trace_array *tr); 2314 int tracing_arm_snapshot(struct trace_array *tr); 2315 void tracing_disarm_snapshot(struct trace_array *tr); 2316 void free_snapshot(struct trace_array *tr); 2317 void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter); 2318 int get_snapshot_map(struct trace_array *tr); 2319 void put_snapshot_map(struct trace_array *tr); 2320 int resize_buffer_duplicate_size(struct array_buffer *trace_buf, 2321 struct array_buffer *size_buf, int cpu_id); 2322 __init void do_allocate_snapshot(const char *name); 2323 # ifdef CONFIG_DYNAMIC_FTRACE 2324 __init int register_snapshot_cmd(void); 2325 # else 2326 static inline int register_snapshot_cmd(void) { return 0; } 2327 # endif 2328 #else /* !CONFIG_TRACER_SNAPSHOT */ 2329 static inline int trace_allocate_snapshot(struct trace_array *tr, int size) { return 0; } 2330 static inline void tracing_snapshot_instance(struct trace_array *tr) { } 2331 static inline int tracing_alloc_snapshot_instance(struct trace_array *tr) 2332 { 2333 return 0; 2334 } 2335 static inline int tracing_arm_snapshot_locked(struct trace_array *tr) { return -EBUSY; } 2336 static inline int tracing_arm_snapshot(struct trace_array *tr) { return 0; } 2337 static inline void tracing_disarm_snapshot(struct trace_array *tr) { } 2338 static inline void free_snapshot(struct trace_array *tr) {} 2339 static inline void tracing_snapshot_cond(struct trace_array *tr, void *cond_data) 2340 { 2341 WARN_ONCE(1, "Snapshot feature not enabled, but internal conditional snapshot used"); 2342 } 2343 static inline void *tracing_cond_snapshot_data(struct trace_array *tr) 2344 { 2345 return NULL; 2346 } 2347 static inline int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update) 2348 { 2349 return -ENODEV; 2350 } 2351 static inline int tracing_snapshot_cond_disable(struct trace_array *tr) 2352 { 2353 return false; 2354 } 2355 static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) 2356 { 2357 /* Should never be called */ 2358 WARN_ONCE(1, "Snapshot print function called without snapshot configured"); 2359 } 2360 static inline int get_snapshot_map(struct trace_array *tr) { return 0; } 2361 static inline void put_snapshot_map(struct trace_array *tr) { } 2362 static inline void do_allocate_snapshot(const char *name) { } 2363 static inline int register_snapshot_cmd(void) { return 0; } 2364 #endif /* CONFIG_TRACER_SNAPSHOT */ 2365 2366 #ifdef CONFIG_PREEMPT_TRACER 2367 void tracer_preempt_on(unsigned long a0, unsigned long a1); 2368 void tracer_preempt_off(unsigned long a0, unsigned long a1); 2369 #else 2370 static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { } 2371 static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { } 2372 #endif 2373 #ifdef CONFIG_IRQSOFF_TRACER 2374 void tracer_hardirqs_on(unsigned long a0, unsigned long a1); 2375 void tracer_hardirqs_off(unsigned long a0, unsigned long a1); 2376 #else 2377 static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { } 2378 static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { } 2379 #endif 2380 2381 /* 2382 * Reset the state of the trace_iterator so that it can read consumed data. 2383 * Normally, the trace_iterator is used for reading the data when it is not 2384 * consumed, and must retain state. 2385 */ 2386 static __always_inline void trace_iterator_reset(struct trace_iterator *iter) 2387 { 2388 memset_startat(iter, 0, seq); 2389 iter->pos = -1; 2390 } 2391 2392 /* Check the name is good for event/group/fields */ 2393 static inline bool __is_good_name(const char *name, bool hash_ok) 2394 { 2395 if (!isalpha(*name) && *name != '_' && (!hash_ok || *name != '-')) 2396 return false; 2397 while (*++name != '\0') { 2398 if (!isalpha(*name) && !isdigit(*name) && *name != '_' && 2399 (!hash_ok || *name != '-')) 2400 return false; 2401 } 2402 return true; 2403 } 2404 2405 /* Check the name is good for event/group/fields */ 2406 static inline bool is_good_name(const char *name) 2407 { 2408 return __is_good_name(name, false); 2409 } 2410 2411 /* Check the name is good for system */ 2412 static inline bool is_good_system_name(const char *name) 2413 { 2414 return __is_good_name(name, true); 2415 } 2416 2417 /* Convert certain expected symbols into '_' when generating event names */ 2418 static inline void sanitize_event_name(char *name) 2419 { 2420 while (*name++ != '\0') 2421 if (*name == ':' || *name == '.' || *name == '*') 2422 *name = '_'; 2423 } 2424 2425 #ifdef CONFIG_STACKTRACE 2426 void __ftrace_trace_stack(struct trace_array *tr, 2427 struct trace_buffer *buffer, 2428 unsigned int trace_ctx, 2429 int skip, struct pt_regs *regs); 2430 2431 static __always_inline void ftrace_trace_stack(struct trace_array *tr, 2432 struct trace_buffer *buffer, 2433 unsigned int trace_ctx, 2434 int skip, struct pt_regs *regs) 2435 { 2436 if (!(tr->trace_flags & TRACE_ITER(STACKTRACE))) 2437 return; 2438 2439 __ftrace_trace_stack(tr, buffer, trace_ctx, skip, regs); 2440 } 2441 #else 2442 static inline void __ftrace_trace_stack(struct trace_array *tr, 2443 struct trace_buffer *buffer, 2444 unsigned int trace_ctx, 2445 int skip, struct pt_regs *regs) 2446 { 2447 } 2448 static inline void ftrace_trace_stack(struct trace_array *tr, 2449 struct trace_buffer *buffer, 2450 unsigned long trace_ctx, 2451 int skip, struct pt_regs *regs) 2452 { 2453 } 2454 #endif 2455 2456 /* 2457 * This is a generic way to read and write a u64 value from a file in tracefs. 2458 * 2459 * The value is stored on the variable pointed by *val. The value needs 2460 * to be at least *min and at most *max. The write is protected by an 2461 * existing *lock. 2462 */ 2463 struct trace_min_max_param { 2464 struct mutex *lock; 2465 u64 *val; 2466 u64 *min; 2467 u64 *max; 2468 }; 2469 2470 #define U64_STR_SIZE 24 /* 20 digits max */ 2471 2472 extern const struct file_operations trace_min_max_fops; 2473 2474 #ifdef CONFIG_RV 2475 extern int rv_init_interface(void); 2476 #else 2477 static inline int rv_init_interface(void) 2478 { 2479 return 0; 2480 } 2481 #endif 2482 2483 /* 2484 * This is used only to distinguish 2485 * function address from trampoline code. 2486 * So this value has no meaning. 2487 */ 2488 #define FTRACE_TRAMPOLINE_MARKER ((unsigned long) INT_MAX) 2489 2490 /* 2491 * This is used to get the address of the args array based on 2492 * the type of the entry. 2493 */ 2494 #define FGRAPH_ENTRY_ARGS(e) \ 2495 ({ \ 2496 unsigned long *_args; \ 2497 struct ftrace_graph_ent_entry *_e = e; \ 2498 \ 2499 if (IS_ENABLED(CONFIG_FUNCTION_GRAPH_RETADDR) && \ 2500 e->ent.type == TRACE_GRAPH_RETADDR_ENT) { \ 2501 struct fgraph_retaddr_ent_entry *_re; \ 2502 \ 2503 _re = (typeof(_re))_e; \ 2504 _args = _re->args; \ 2505 } else { \ 2506 _args = _e->args; \ 2507 } \ 2508 _args; \ 2509 }) 2510 2511 #endif /* _LINUX_KERNEL_TRACE_H */ 2512