1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
7 * - Added format output of fields of the trace point.
8 * This was based off of work by Tom Zanussi <tzanussi@gmail.com>.
12 #define pr_fmt(fmt) fmt
14 #include <linux/workqueue.h>
15 #include <linux/security.h>
16 #include <linux/spinlock.h>
17 #include <linux/kthread.h>
18 #include <linux/tracefs.h>
19 #include <linux/uaccess.h>
20 #include <linux/module.h>
21 #include <linux/ctype.h>
22 #include <linux/sort.h>
23 #include <linux/slab.h>
24 #include <linux/delay.h>
26 #include <trace/events/sched.h>
27 #include <trace/syscall.h>
29 #include <asm/setup.h>
31 #include "trace_output.h"
34 #define TRACE_SYSTEM "TRACE_SYSTEM"
36 DEFINE_MUTEX(event_mutex);
38 LIST_HEAD(ftrace_events);
39 static LIST_HEAD(ftrace_generic_fields);
40 static LIST_HEAD(ftrace_common_fields);
41 static bool eventdir_initialized;
43 static LIST_HEAD(module_strings);
45 struct module_string {
46 struct list_head next;
47 struct module *module;
51 #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO)
53 static struct kmem_cache *field_cachep;
54 static struct kmem_cache *file_cachep;
56 static inline int system_refcount(struct event_subsystem *system)
58 return system->ref_count;
61 static int system_refcount_inc(struct event_subsystem *system)
63 return system->ref_count++;
66 static int system_refcount_dec(struct event_subsystem *system)
68 return --system->ref_count;
71 /* Double loops, do not use break, only goto's work */
72 #define do_for_each_event_file(tr, file) \
73 list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
74 list_for_each_entry(file, &tr->events, list)
76 #define do_for_each_event_file_safe(tr, file) \
77 list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
78 struct trace_event_file *___n; \
79 list_for_each_entry_safe(file, ___n, &tr->events, list)
81 #define while_for_each_event_file() \
84 static struct ftrace_event_field *
85 __find_event_field(struct list_head *head, char *name)
87 struct ftrace_event_field *field;
89 list_for_each_entry(field, head, link) {
90 if (!strcmp(field->name, name))
97 struct ftrace_event_field *
98 trace_find_event_field(struct trace_event_call *call, char *name)
100 struct ftrace_event_field *field;
101 struct list_head *head;
103 head = trace_get_fields(call);
104 field = __find_event_field(head, name);
108 field = __find_event_field(&ftrace_generic_fields, name);
112 return __find_event_field(&ftrace_common_fields, name);
115 static int __trace_define_field(struct list_head *head, const char *type,
116 const char *name, int offset, int size,
117 int is_signed, int filter_type, int len)
119 struct ftrace_event_field *field;
121 field = kmem_cache_alloc(field_cachep, GFP_TRACE);
128 if (filter_type == FILTER_OTHER)
129 field->filter_type = filter_assign_type(type);
131 field->filter_type = filter_type;
133 field->offset = offset;
135 field->is_signed = is_signed;
138 list_add(&field->link, head);
143 int trace_define_field(struct trace_event_call *call, const char *type,
144 const char *name, int offset, int size, int is_signed,
147 struct list_head *head;
149 if (WARN_ON(!call->class))
152 head = trace_get_fields(call);
153 return __trace_define_field(head, type, name, offset, size,
154 is_signed, filter_type, 0);
156 EXPORT_SYMBOL_GPL(trace_define_field);
158 static int trace_define_field_ext(struct trace_event_call *call, const char *type,
159 const char *name, int offset, int size, int is_signed,
160 int filter_type, int len)
162 struct list_head *head;
164 if (WARN_ON(!call->class))
167 head = trace_get_fields(call);
168 return __trace_define_field(head, type, name, offset, size,
169 is_signed, filter_type, len);
172 #define __generic_field(type, item, filter_type) \
173 ret = __trace_define_field(&ftrace_generic_fields, #type, \
174 #item, 0, 0, is_signed_type(type), \
179 #define __common_field(type, item) \
180 ret = __trace_define_field(&ftrace_common_fields, #type, \
182 offsetof(typeof(ent), item), \
184 is_signed_type(type), FILTER_OTHER, 0); \
188 static int trace_define_generic_fields(void)
192 __generic_field(int, CPU, FILTER_CPU);
193 __generic_field(int, cpu, FILTER_CPU);
194 __generic_field(int, common_cpu, FILTER_CPU);
195 __generic_field(char *, COMM, FILTER_COMM);
196 __generic_field(char *, comm, FILTER_COMM);
197 __generic_field(char *, stacktrace, FILTER_STACKTRACE);
198 __generic_field(char *, STACKTRACE, FILTER_STACKTRACE);
203 static int trace_define_common_fields(void)
206 struct trace_entry ent;
208 __common_field(unsigned short, type);
209 __common_field(unsigned char, flags);
210 /* Holds both preempt_count and migrate_disable */
211 __common_field(unsigned char, preempt_count);
212 __common_field(int, pid);
217 static void trace_destroy_fields(struct trace_event_call *call)
219 struct ftrace_event_field *field, *next;
220 struct list_head *head;
222 head = trace_get_fields(call);
223 list_for_each_entry_safe(field, next, head, link) {
224 list_del(&field->link);
225 kmem_cache_free(field_cachep, field);
230 * run-time version of trace_event_get_offsets_<call>() that returns the last
231 * accessible offset of trace fields excluding __dynamic_array bytes
233 int trace_event_get_offsets(struct trace_event_call *call)
235 struct ftrace_event_field *tail;
236 struct list_head *head;
238 head = trace_get_fields(call);
240 * head->next points to the last field with the largest offset,
241 * since it was added last by trace_define_field()
243 tail = list_first_entry(head, struct ftrace_event_field, link);
244 return tail->offset + tail->size;
248 * Check if the referenced field is an array and return true,
249 * as arrays are OK to dereference.
251 static bool test_field(const char *fmt, struct trace_event_call *call)
253 struct trace_event_fields *field = call->class->fields_array;
254 const char *array_descriptor;
258 if (!(len = str_has_prefix(fmt, "REC->")))
261 for (p = fmt; *p; p++) {
262 if (!isalnum(*p) && *p != '_')
267 for (; field->type; field++) {
268 if (strncmp(field->name, fmt, len) ||
271 array_descriptor = strchr(field->type, '[');
272 /* This is an array and is OK to dereference. */
273 return array_descriptor != NULL;
279 * Examine the print fmt of the event looking for unsafe dereference
280 * pointers using %p* that could be recorded in the trace event and
281 * much later referenced after the pointer was freed. Dereferencing
282 * pointers are OK, if it is dereferenced into the event itself.
284 static void test_event_printk(struct trace_event_call *call)
286 u64 dereference_flags = 0;
288 const char *fmt, *c, *r, *a;
295 fmt = call->print_fmt;
300 for (i = 0; fmt[i]; i++) {
310 * The print fmt starts with a string that
311 * is processed first to find %p* usage,
312 * then after the first string, the print fmt
313 * contains arguments that are used to check
314 * if the dereferenced %p* usage is safe.
323 * If there was no %p* uses
326 if (!dereference_flags)
331 if (in_quote == fmt[i])
338 if (!first || !in_quote)
347 /* Find dereferencing fields */
348 switch (fmt[i + 1]) {
349 case 'B': case 'R': case 'r':
350 case 'b': case 'M': case 'm':
351 case 'I': case 'i': case 'E':
352 case 'U': case 'V': case 'N':
353 case 'a': case 'd': case 'D':
354 case 'g': case 't': case 'C':
356 if (WARN_ONCE(arg == 63,
357 "Too many args for event: %s",
358 trace_event_name(call)))
360 dereference_flags |= 1ULL << arg;
368 /* Increment arg if %*s exists. */
369 for (j = 0; fmt[i + j]; j++) {
370 if (isdigit(fmt[i + j]) ||
373 if (fmt[i + j] == '*') {
377 if ((fmt[i + j] == 's') && star)
396 if (WARN_ONCE(parens < 0,
397 "Paren mismatch for event: %s\narg='%s'\n%*s",
398 trace_event_name(call),
400 (i - start_arg) + 5, "^"))
404 if (in_quote || parens)
407 while (isspace(fmt[i]))
410 if (!(dereference_flags & (1ULL << arg)))
413 /* Find the REC-> in the argument */
414 c = strchr(fmt + i, ',');
415 r = strstr(fmt + i, "REC->");
416 if (r && (!c || r < c)) {
418 * Addresses of events on the buffer,
419 * or an array on the buffer is
421 * There's ways to fool this, but
422 * this is to catch common mistakes,
423 * not malicious code.
425 a = strchr(fmt + i, '&');
426 if ((a && (a < r)) || test_field(r, call))
427 dereference_flags &= ~(1ULL << arg);
428 } else if ((r = strstr(fmt + i, "__get_dynamic_array(")) &&
430 dereference_flags &= ~(1ULL << arg);
431 } else if ((r = strstr(fmt + i, "__get_sockaddr(")) &&
433 dereference_flags &= ~(1ULL << arg);
443 * If you triggered the below warning, the trace event reported
444 * uses an unsafe dereference pointer %p*. As the data stored
445 * at the trace event time may no longer exist when the trace
446 * event is printed, dereferencing to the original source is
447 * unsafe. The source of the dereference must be copied into the
448 * event itself, and the dereference must access the copy instead.
450 if (WARN_ON_ONCE(dereference_flags)) {
452 while (!(dereference_flags & 1)) {
453 dereference_flags >>= 1;
456 pr_warn("event %s has unsafe dereference of argument %d\n",
457 trace_event_name(call), arg);
458 pr_warn("print_fmt: %s\n", fmt);
462 int trace_event_raw_init(struct trace_event_call *call)
466 id = register_trace_event(&call->event);
470 test_event_printk(call);
474 EXPORT_SYMBOL_GPL(trace_event_raw_init);
476 bool trace_event_ignore_this_pid(struct trace_event_file *trace_file)
478 struct trace_array *tr = trace_file->tr;
479 struct trace_array_cpu *data;
480 struct trace_pid_list *no_pid_list;
481 struct trace_pid_list *pid_list;
483 pid_list = rcu_dereference_raw(tr->filtered_pids);
484 no_pid_list = rcu_dereference_raw(tr->filtered_no_pids);
486 if (!pid_list && !no_pid_list)
489 data = this_cpu_ptr(tr->array_buffer.data);
491 return data->ignore_pid;
493 EXPORT_SYMBOL_GPL(trace_event_ignore_this_pid);
495 void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
496 struct trace_event_file *trace_file,
499 struct trace_event_call *event_call = trace_file->event_call;
501 if ((trace_file->flags & EVENT_FILE_FL_PID_FILTER) &&
502 trace_event_ignore_this_pid(trace_file))
506 * If CONFIG_PREEMPTION is enabled, then the tracepoint itself disables
507 * preemption (adding one to the preempt_count). Since we are
508 * interested in the preempt_count at the time the tracepoint was
509 * hit, we need to subtract one to offset the increment.
511 fbuffer->trace_ctx = tracing_gen_ctx_dec();
512 fbuffer->trace_file = trace_file;
515 trace_event_buffer_lock_reserve(&fbuffer->buffer, trace_file,
516 event_call->event.type, len,
521 fbuffer->regs = NULL;
522 fbuffer->entry = ring_buffer_event_data(fbuffer->event);
523 return fbuffer->entry;
525 EXPORT_SYMBOL_GPL(trace_event_buffer_reserve);
527 int trace_event_reg(struct trace_event_call *call,
528 enum trace_reg type, void *data)
530 struct trace_event_file *file = data;
532 WARN_ON(!(call->flags & TRACE_EVENT_FL_TRACEPOINT));
534 case TRACE_REG_REGISTER:
535 return tracepoint_probe_register(call->tp,
538 case TRACE_REG_UNREGISTER:
539 tracepoint_probe_unregister(call->tp,
544 #ifdef CONFIG_PERF_EVENTS
545 case TRACE_REG_PERF_REGISTER:
546 return tracepoint_probe_register(call->tp,
547 call->class->perf_probe,
549 case TRACE_REG_PERF_UNREGISTER:
550 tracepoint_probe_unregister(call->tp,
551 call->class->perf_probe,
554 case TRACE_REG_PERF_OPEN:
555 case TRACE_REG_PERF_CLOSE:
556 case TRACE_REG_PERF_ADD:
557 case TRACE_REG_PERF_DEL:
563 EXPORT_SYMBOL_GPL(trace_event_reg);
565 void trace_event_enable_cmd_record(bool enable)
567 struct trace_event_file *file;
568 struct trace_array *tr;
570 lockdep_assert_held(&event_mutex);
572 do_for_each_event_file(tr, file) {
574 if (!(file->flags & EVENT_FILE_FL_ENABLED))
578 tracing_start_cmdline_record();
579 set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
581 tracing_stop_cmdline_record();
582 clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
584 } while_for_each_event_file();
587 void trace_event_enable_tgid_record(bool enable)
589 struct trace_event_file *file;
590 struct trace_array *tr;
592 lockdep_assert_held(&event_mutex);
594 do_for_each_event_file(tr, file) {
595 if (!(file->flags & EVENT_FILE_FL_ENABLED))
599 tracing_start_tgid_record();
600 set_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
602 tracing_stop_tgid_record();
603 clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT,
606 } while_for_each_event_file();
609 static int __ftrace_event_enable_disable(struct trace_event_file *file,
610 int enable, int soft_disable)
612 struct trace_event_call *call = file->event_call;
613 struct trace_array *tr = file->tr;
614 unsigned long file_flags = file->flags;
621 * When soft_disable is set and enable is cleared, the sm_ref
622 * reference counter is decremented. If it reaches 0, we want
623 * to clear the SOFT_DISABLED flag but leave the event in the
624 * state that it was. That is, if the event was enabled and
625 * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED
626 * is set we do not want the event to be enabled before we
629 * When soft_disable is not set but the SOFT_MODE flag is,
630 * we do nothing. Do not disable the tracepoint, otherwise
631 * "soft enable"s (clearing the SOFT_DISABLED bit) wont work.
634 if (atomic_dec_return(&file->sm_ref) > 0)
636 disable = file->flags & EVENT_FILE_FL_SOFT_DISABLED;
637 clear_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags);
639 disable = !(file->flags & EVENT_FILE_FL_SOFT_MODE);
641 if (disable && (file->flags & EVENT_FILE_FL_ENABLED)) {
642 clear_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);
643 if (file->flags & EVENT_FILE_FL_RECORDED_CMD) {
644 tracing_stop_cmdline_record();
645 clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
648 if (file->flags & EVENT_FILE_FL_RECORDED_TGID) {
649 tracing_stop_tgid_record();
650 clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
653 call->class->reg(call, TRACE_REG_UNREGISTER, file);
655 /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */
656 if (file->flags & EVENT_FILE_FL_SOFT_MODE)
657 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
659 clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
663 * When soft_disable is set and enable is set, we want to
664 * register the tracepoint for the event, but leave the event
665 * as is. That means, if the event was already enabled, we do
666 * nothing (but set SOFT_MODE). If the event is disabled, we
667 * set SOFT_DISABLED before enabling the event tracepoint, so
668 * it still seems to be disabled.
671 clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
673 if (atomic_inc_return(&file->sm_ref) > 1)
675 set_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags);
678 if (!(file->flags & EVENT_FILE_FL_ENABLED)) {
679 bool cmd = false, tgid = false;
681 /* Keep the event disabled, when going to SOFT_MODE. */
683 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
685 if (tr->trace_flags & TRACE_ITER_RECORD_CMD) {
687 tracing_start_cmdline_record();
688 set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
691 if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
693 tracing_start_tgid_record();
694 set_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
697 ret = call->class->reg(call, TRACE_REG_REGISTER, file);
700 tracing_stop_cmdline_record();
702 tracing_stop_tgid_record();
703 pr_info("event trace: Could not enable event "
704 "%s\n", trace_event_name(call));
707 set_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);
709 /* WAS_ENABLED gets set but never cleared. */
710 set_bit(EVENT_FILE_FL_WAS_ENABLED_BIT, &file->flags);
715 /* Enable or disable use of trace_buffered_event */
716 if ((file_flags & EVENT_FILE_FL_SOFT_DISABLED) !=
717 (file->flags & EVENT_FILE_FL_SOFT_DISABLED)) {
718 if (file->flags & EVENT_FILE_FL_SOFT_DISABLED)
719 trace_buffered_event_enable();
721 trace_buffered_event_disable();
727 int trace_event_enable_disable(struct trace_event_file *file,
728 int enable, int soft_disable)
730 return __ftrace_event_enable_disable(file, enable, soft_disable);
733 static int ftrace_event_enable_disable(struct trace_event_file *file,
736 return __ftrace_event_enable_disable(file, enable, 0);
739 static void ftrace_clear_events(struct trace_array *tr)
741 struct trace_event_file *file;
743 mutex_lock(&event_mutex);
744 list_for_each_entry(file, &tr->events, list) {
745 ftrace_event_enable_disable(file, 0);
747 mutex_unlock(&event_mutex);
751 event_filter_pid_sched_process_exit(void *data, struct task_struct *task)
753 struct trace_pid_list *pid_list;
754 struct trace_array *tr = data;
756 pid_list = rcu_dereference_raw(tr->filtered_pids);
757 trace_filter_add_remove_task(pid_list, NULL, task);
759 pid_list = rcu_dereference_raw(tr->filtered_no_pids);
760 trace_filter_add_remove_task(pid_list, NULL, task);
764 event_filter_pid_sched_process_fork(void *data,
765 struct task_struct *self,
766 struct task_struct *task)
768 struct trace_pid_list *pid_list;
769 struct trace_array *tr = data;
771 pid_list = rcu_dereference_sched(tr->filtered_pids);
772 trace_filter_add_remove_task(pid_list, self, task);
774 pid_list = rcu_dereference_sched(tr->filtered_no_pids);
775 trace_filter_add_remove_task(pid_list, self, task);
778 void trace_event_follow_fork(struct trace_array *tr, bool enable)
781 register_trace_prio_sched_process_fork(event_filter_pid_sched_process_fork,
783 register_trace_prio_sched_process_free(event_filter_pid_sched_process_exit,
786 unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
788 unregister_trace_sched_process_free(event_filter_pid_sched_process_exit,
794 event_filter_pid_sched_switch_probe_pre(void *data, bool preempt,
795 struct task_struct *prev,
796 struct task_struct *next,
797 unsigned int prev_state)
799 struct trace_array *tr = data;
800 struct trace_pid_list *no_pid_list;
801 struct trace_pid_list *pid_list;
804 pid_list = rcu_dereference_sched(tr->filtered_pids);
805 no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
808 * Sched switch is funny, as we only want to ignore it
809 * in the notrace case if both prev and next should be ignored.
811 ret = trace_ignore_this_task(NULL, no_pid_list, prev) &&
812 trace_ignore_this_task(NULL, no_pid_list, next);
814 this_cpu_write(tr->array_buffer.data->ignore_pid, ret ||
815 (trace_ignore_this_task(pid_list, NULL, prev) &&
816 trace_ignore_this_task(pid_list, NULL, next)));
820 event_filter_pid_sched_switch_probe_post(void *data, bool preempt,
821 struct task_struct *prev,
822 struct task_struct *next,
823 unsigned int prev_state)
825 struct trace_array *tr = data;
826 struct trace_pid_list *no_pid_list;
827 struct trace_pid_list *pid_list;
829 pid_list = rcu_dereference_sched(tr->filtered_pids);
830 no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
832 this_cpu_write(tr->array_buffer.data->ignore_pid,
833 trace_ignore_this_task(pid_list, no_pid_list, next));
837 event_filter_pid_sched_wakeup_probe_pre(void *data, struct task_struct *task)
839 struct trace_array *tr = data;
840 struct trace_pid_list *no_pid_list;
841 struct trace_pid_list *pid_list;
843 /* Nothing to do if we are already tracing */
844 if (!this_cpu_read(tr->array_buffer.data->ignore_pid))
847 pid_list = rcu_dereference_sched(tr->filtered_pids);
848 no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
850 this_cpu_write(tr->array_buffer.data->ignore_pid,
851 trace_ignore_this_task(pid_list, no_pid_list, task));
855 event_filter_pid_sched_wakeup_probe_post(void *data, struct task_struct *task)
857 struct trace_array *tr = data;
858 struct trace_pid_list *no_pid_list;
859 struct trace_pid_list *pid_list;
861 /* Nothing to do if we are not tracing */
862 if (this_cpu_read(tr->array_buffer.data->ignore_pid))
865 pid_list = rcu_dereference_sched(tr->filtered_pids);
866 no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
868 /* Set tracing if current is enabled */
869 this_cpu_write(tr->array_buffer.data->ignore_pid,
870 trace_ignore_this_task(pid_list, no_pid_list, current));
873 static void unregister_pid_events(struct trace_array *tr)
875 unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
876 unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
878 unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
879 unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
881 unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre, tr);
882 unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post, tr);
884 unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_pre, tr);
885 unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_post, tr);
888 static void __ftrace_clear_event_pids(struct trace_array *tr, int type)
890 struct trace_pid_list *pid_list;
891 struct trace_pid_list *no_pid_list;
892 struct trace_event_file *file;
895 pid_list = rcu_dereference_protected(tr->filtered_pids,
896 lockdep_is_held(&event_mutex));
897 no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
898 lockdep_is_held(&event_mutex));
900 /* Make sure there's something to do */
901 if (!pid_type_enabled(type, pid_list, no_pid_list))
904 if (!still_need_pid_events(type, pid_list, no_pid_list)) {
905 unregister_pid_events(tr);
907 list_for_each_entry(file, &tr->events, list) {
908 clear_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags);
911 for_each_possible_cpu(cpu)
912 per_cpu_ptr(tr->array_buffer.data, cpu)->ignore_pid = false;
915 if (type & TRACE_PIDS)
916 rcu_assign_pointer(tr->filtered_pids, NULL);
918 if (type & TRACE_NO_PIDS)
919 rcu_assign_pointer(tr->filtered_no_pids, NULL);
921 /* Wait till all users are no longer using pid filtering */
922 tracepoint_synchronize_unregister();
924 if ((type & TRACE_PIDS) && pid_list)
925 trace_pid_list_free(pid_list);
927 if ((type & TRACE_NO_PIDS) && no_pid_list)
928 trace_pid_list_free(no_pid_list);
931 static void ftrace_clear_event_pids(struct trace_array *tr, int type)
933 mutex_lock(&event_mutex);
934 __ftrace_clear_event_pids(tr, type);
935 mutex_unlock(&event_mutex);
938 static void __put_system(struct event_subsystem *system)
940 struct event_filter *filter = system->filter;
942 WARN_ON_ONCE(system_refcount(system) == 0);
943 if (system_refcount_dec(system))
946 list_del(&system->list);
949 kfree(filter->filter_string);
952 kfree_const(system->name);
956 static void __get_system(struct event_subsystem *system)
958 WARN_ON_ONCE(system_refcount(system) == 0);
959 system_refcount_inc(system);
962 static void __get_system_dir(struct trace_subsystem_dir *dir)
964 WARN_ON_ONCE(dir->ref_count == 0);
966 __get_system(dir->subsystem);
969 static void __put_system_dir(struct trace_subsystem_dir *dir)
971 WARN_ON_ONCE(dir->ref_count == 0);
972 /* If the subsystem is about to be freed, the dir must be too */
973 WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1);
975 __put_system(dir->subsystem);
976 if (!--dir->ref_count)
980 static void put_system(struct trace_subsystem_dir *dir)
982 mutex_lock(&event_mutex);
983 __put_system_dir(dir);
984 mutex_unlock(&event_mutex);
987 static void remove_subsystem(struct trace_subsystem_dir *dir)
992 if (!--dir->nr_events) {
993 tracefs_remove(dir->entry);
994 list_del(&dir->list);
995 __put_system_dir(dir);
999 static void remove_event_file_dir(struct trace_event_file *file)
1001 struct dentry *dir = file->dir;
1002 struct dentry *child;
1005 spin_lock(&dir->d_lock); /* probably unneeded */
1006 list_for_each_entry(child, &dir->d_subdirs, d_child) {
1007 if (d_really_is_positive(child)) /* probably unneeded */
1008 d_inode(child)->i_private = NULL;
1010 spin_unlock(&dir->d_lock);
1012 tracefs_remove(dir);
1015 list_del(&file->list);
1016 remove_subsystem(file->system);
1017 free_event_filter(file->filter);
1018 kmem_cache_free(file_cachep, file);
1022 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
1025 __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match,
1026 const char *sub, const char *event, int set)
1028 struct trace_event_file *file;
1029 struct trace_event_call *call;
1034 list_for_each_entry(file, &tr->events, list) {
1036 call = file->event_call;
1037 name = trace_event_name(call);
1039 if (!name || !call->class || !call->class->reg)
1042 if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
1046 strcmp(match, name) != 0 &&
1047 strcmp(match, call->class->system) != 0)
1050 if (sub && strcmp(sub, call->class->system) != 0)
1053 if (event && strcmp(event, name) != 0)
1056 ret = ftrace_event_enable_disable(file, set);
1059 * Save the first error and return that. Some events
1060 * may still have been enabled, but let the user
1061 * know that something went wrong.
1072 static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
1073 const char *sub, const char *event, int set)
1077 mutex_lock(&event_mutex);
1078 ret = __ftrace_set_clr_event_nolock(tr, match, sub, event, set);
1079 mutex_unlock(&event_mutex);
1084 int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
1086 char *event = NULL, *sub = NULL, *match;
1092 * The buf format can be <subsystem>:<event-name>
1093 * *:<event-name> means any event by that name.
1094 * :<event-name> is the same.
1096 * <subsystem>:* means all events in that subsystem
1097 * <subsystem>: means the same.
1099 * <name> (no ':') means all events in a subsystem with
1100 * the name <name> or any event that matches <name>
1103 match = strsep(&buf, ":");
1109 if (!strlen(sub) || strcmp(sub, "*") == 0)
1111 if (!strlen(event) || strcmp(event, "*") == 0)
1115 ret = __ftrace_set_clr_event(tr, match, sub, event, set);
1117 /* Put back the colon to allow this to be called again */
1125 * trace_set_clr_event - enable or disable an event
1126 * @system: system name to match (NULL for any system)
1127 * @event: event name to match (NULL for all events, within system)
1128 * @set: 1 to enable, 0 to disable
1130 * This is a way for other parts of the kernel to enable or disable
1133 * Returns 0 on success, -EINVAL if the parameters do not match any
1134 * registered events.
1136 int trace_set_clr_event(const char *system, const char *event, int set)
1138 struct trace_array *tr = top_trace_array();
1143 return __ftrace_set_clr_event(tr, NULL, system, event, set);
1145 EXPORT_SYMBOL_GPL(trace_set_clr_event);
1148 * trace_array_set_clr_event - enable or disable an event for a trace array.
1149 * @tr: concerned trace array.
1150 * @system: system name to match (NULL for any system)
1151 * @event: event name to match (NULL for all events, within system)
1152 * @enable: true to enable, false to disable
1154 * This is a way for other parts of the kernel to enable or disable
1157 * Returns 0 on success, -EINVAL if the parameters do not match any
1158 * registered events.
1160 int trace_array_set_clr_event(struct trace_array *tr, const char *system,
1161 const char *event, bool enable)
1168 set = (enable == true) ? 1 : 0;
1169 return __ftrace_set_clr_event(tr, NULL, system, event, set);
1171 EXPORT_SYMBOL_GPL(trace_array_set_clr_event);
1173 /* 128 should be much more than enough */
1174 #define EVENT_BUF_SIZE 127
1177 ftrace_event_write(struct file *file, const char __user *ubuf,
1178 size_t cnt, loff_t *ppos)
1180 struct trace_parser parser;
1181 struct seq_file *m = file->private_data;
1182 struct trace_array *tr = m->private;
1188 ret = tracing_update_buffers();
1192 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
1195 read = trace_get_user(&parser, ubuf, cnt, ppos);
1197 if (read >= 0 && trace_parser_loaded((&parser))) {
1200 if (*parser.buffer == '!')
1203 ret = ftrace_set_clr_event(tr, parser.buffer + !set, set);
1211 trace_parser_put(&parser);
1217 t_next(struct seq_file *m, void *v, loff_t *pos)
1219 struct trace_event_file *file = v;
1220 struct trace_event_call *call;
1221 struct trace_array *tr = m->private;
1225 list_for_each_entry_continue(file, &tr->events, list) {
1226 call = file->event_call;
1228 * The ftrace subsystem is for showing formats only.
1229 * They can not be enabled or disabled via the event files.
1231 if (call->class && call->class->reg &&
1232 !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
1239 static void *t_start(struct seq_file *m, loff_t *pos)
1241 struct trace_event_file *file;
1242 struct trace_array *tr = m->private;
1245 mutex_lock(&event_mutex);
1247 file = list_entry(&tr->events, struct trace_event_file, list);
1248 for (l = 0; l <= *pos; ) {
1249 file = t_next(m, file, &l);
1257 s_next(struct seq_file *m, void *v, loff_t *pos)
1259 struct trace_event_file *file = v;
1260 struct trace_array *tr = m->private;
1264 list_for_each_entry_continue(file, &tr->events, list) {
1265 if (file->flags & EVENT_FILE_FL_ENABLED)
1272 static void *s_start(struct seq_file *m, loff_t *pos)
1274 struct trace_event_file *file;
1275 struct trace_array *tr = m->private;
1278 mutex_lock(&event_mutex);
1280 file = list_entry(&tr->events, struct trace_event_file, list);
1281 for (l = 0; l <= *pos; ) {
1282 file = s_next(m, file, &l);
1289 static int t_show(struct seq_file *m, void *v)
1291 struct trace_event_file *file = v;
1292 struct trace_event_call *call = file->event_call;
1294 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
1295 seq_printf(m, "%s:", call->class->system);
1296 seq_printf(m, "%s\n", trace_event_name(call));
1301 static void t_stop(struct seq_file *m, void *p)
1303 mutex_unlock(&event_mutex);
1307 __next(struct seq_file *m, void *v, loff_t *pos, int type)
1309 struct trace_array *tr = m->private;
1310 struct trace_pid_list *pid_list;
1312 if (type == TRACE_PIDS)
1313 pid_list = rcu_dereference_sched(tr->filtered_pids);
1315 pid_list = rcu_dereference_sched(tr->filtered_no_pids);
1317 return trace_pid_next(pid_list, v, pos);
1321 p_next(struct seq_file *m, void *v, loff_t *pos)
1323 return __next(m, v, pos, TRACE_PIDS);
1327 np_next(struct seq_file *m, void *v, loff_t *pos)
1329 return __next(m, v, pos, TRACE_NO_PIDS);
1332 static void *__start(struct seq_file *m, loff_t *pos, int type)
1335 struct trace_pid_list *pid_list;
1336 struct trace_array *tr = m->private;
1339 * Grab the mutex, to keep calls to p_next() having the same
1340 * tr->filtered_pids as p_start() has.
1341 * If we just passed the tr->filtered_pids around, then RCU would
1342 * have been enough, but doing that makes things more complex.
1344 mutex_lock(&event_mutex);
1345 rcu_read_lock_sched();
1347 if (type == TRACE_PIDS)
1348 pid_list = rcu_dereference_sched(tr->filtered_pids);
1350 pid_list = rcu_dereference_sched(tr->filtered_no_pids);
1355 return trace_pid_start(pid_list, pos);
1358 static void *p_start(struct seq_file *m, loff_t *pos)
1361 return __start(m, pos, TRACE_PIDS);
1364 static void *np_start(struct seq_file *m, loff_t *pos)
1367 return __start(m, pos, TRACE_NO_PIDS);
1370 static void p_stop(struct seq_file *m, void *p)
1373 rcu_read_unlock_sched();
1374 mutex_unlock(&event_mutex);
1378 event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
1381 struct trace_event_file *file;
1382 unsigned long flags;
1385 mutex_lock(&event_mutex);
1386 file = event_file_data(filp);
1388 flags = file->flags;
1389 mutex_unlock(&event_mutex);
1394 if (flags & EVENT_FILE_FL_ENABLED &&
1395 !(flags & EVENT_FILE_FL_SOFT_DISABLED))
1398 if (flags & EVENT_FILE_FL_SOFT_DISABLED ||
1399 flags & EVENT_FILE_FL_SOFT_MODE)
1404 return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf));
1408 event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
1411 struct trace_event_file *file;
1415 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
1419 ret = tracing_update_buffers();
1427 mutex_lock(&event_mutex);
1428 file = event_file_data(filp);
1430 ret = ftrace_event_enable_disable(file, val);
1431 mutex_unlock(&event_mutex);
1440 return ret ? ret : cnt;
1444 system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
1447 const char set_to_char[4] = { '?', '0', '1', 'X' };
1448 struct trace_subsystem_dir *dir = filp->private_data;
1449 struct event_subsystem *system = dir->subsystem;
1450 struct trace_event_call *call;
1451 struct trace_event_file *file;
1452 struct trace_array *tr = dir->tr;
1457 mutex_lock(&event_mutex);
1458 list_for_each_entry(file, &tr->events, list) {
1459 call = file->event_call;
1460 if ((call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) ||
1461 !trace_event_name(call) || !call->class || !call->class->reg)
1464 if (system && strcmp(call->class->system, system->name) != 0)
1468 * We need to find out if all the events are set
1469 * or if all events or cleared, or if we have
1472 set |= (1 << !!(file->flags & EVENT_FILE_FL_ENABLED));
1475 * If we have a mixture, no need to look further.
1480 mutex_unlock(&event_mutex);
1482 buf[0] = set_to_char[set];
1485 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
1491 system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
1494 struct trace_subsystem_dir *dir = filp->private_data;
1495 struct event_subsystem *system = dir->subsystem;
1496 const char *name = NULL;
1500 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
1504 ret = tracing_update_buffers();
1508 if (val != 0 && val != 1)
1512 * Opening of "enable" adds a ref count to system,
1513 * so the name is safe to use.
1516 name = system->name;
1518 ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val);
1532 FORMAT_FIELD_SEPERATOR = 2,
1533 FORMAT_PRINTFMT = 3,
1536 static void *f_next(struct seq_file *m, void *v, loff_t *pos)
1538 struct trace_event_call *call = event_file_data(m->private);
1539 struct list_head *common_head = &ftrace_common_fields;
1540 struct list_head *head = trace_get_fields(call);
1541 struct list_head *node = v;
1545 switch ((unsigned long)v) {
1550 case FORMAT_FIELD_SEPERATOR:
1554 case FORMAT_PRINTFMT:
1560 if (node == common_head)
1561 return (void *)FORMAT_FIELD_SEPERATOR;
1562 else if (node == head)
1563 return (void *)FORMAT_PRINTFMT;
1568 static int f_show(struct seq_file *m, void *v)
1570 struct trace_event_call *call = event_file_data(m->private);
1571 struct ftrace_event_field *field;
1572 const char *array_descriptor;
1574 switch ((unsigned long)v) {
1576 seq_printf(m, "name: %s\n", trace_event_name(call));
1577 seq_printf(m, "ID: %d\n", call->event.type);
1578 seq_puts(m, "format:\n");
1581 case FORMAT_FIELD_SEPERATOR:
1585 case FORMAT_PRINTFMT:
1586 seq_printf(m, "\nprint fmt: %s\n",
1591 field = list_entry(v, struct ftrace_event_field, link);
1593 * Smartly shows the array type(except dynamic array).
1596 * If TYPE := TYPE[LEN], it is shown:
1597 * field:TYPE VAR[LEN]
1599 array_descriptor = strchr(field->type, '[');
1601 if (str_has_prefix(field->type, "__data_loc"))
1602 array_descriptor = NULL;
1604 if (!array_descriptor)
1605 seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
1606 field->type, field->name, field->offset,
1607 field->size, !!field->is_signed);
1608 else if (field->len)
1609 seq_printf(m, "\tfield:%.*s %s[%d];\toffset:%u;\tsize:%u;\tsigned:%d;\n",
1610 (int)(array_descriptor - field->type),
1611 field->type, field->name,
1612 field->len, field->offset,
1613 field->size, !!field->is_signed);
1615 seq_printf(m, "\tfield:%.*s %s[];\toffset:%u;\tsize:%u;\tsigned:%d;\n",
1616 (int)(array_descriptor - field->type),
1617 field->type, field->name,
1618 field->offset, field->size, !!field->is_signed);
1623 static void *f_start(struct seq_file *m, loff_t *pos)
1625 void *p = (void *)FORMAT_HEADER;
1628 /* ->stop() is called even if ->start() fails */
1629 mutex_lock(&event_mutex);
1630 if (!event_file_data(m->private))
1631 return ERR_PTR(-ENODEV);
1633 while (l < *pos && p)
1634 p = f_next(m, p, &l);
1639 static void f_stop(struct seq_file *m, void *p)
1641 mutex_unlock(&event_mutex);
1644 static const struct seq_operations trace_format_seq_ops = {
1651 static int trace_format_open(struct inode *inode, struct file *file)
1656 /* Do we want to hide event format files on tracefs lockdown? */
1658 ret = seq_open(file, &trace_format_seq_ops);
1662 m = file->private_data;
1669 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
1671 int id = (long)event_file_data(filp);
1678 len = sprintf(buf, "%d\n", id);
1680 return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
1684 event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
1687 struct trace_event_file *file;
1688 struct trace_seq *s;
1694 s = kmalloc(sizeof(*s), GFP_KERNEL);
1701 mutex_lock(&event_mutex);
1702 file = event_file_data(filp);
1704 print_event_filter(file, s);
1705 mutex_unlock(&event_mutex);
1708 r = simple_read_from_buffer(ubuf, cnt, ppos,
1709 s->buffer, trace_seq_used(s));
1717 event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
1720 struct trace_event_file *file;
1724 if (cnt >= PAGE_SIZE)
1727 buf = memdup_user_nul(ubuf, cnt);
1729 return PTR_ERR(buf);
1731 mutex_lock(&event_mutex);
1732 file = event_file_data(filp);
1734 err = apply_event_filter(file, buf);
1735 mutex_unlock(&event_mutex);
1746 static LIST_HEAD(event_subsystems);
1748 static int subsystem_open(struct inode *inode, struct file *filp)
1750 struct trace_subsystem_dir *dir = NULL, *iter_dir;
1751 struct trace_array *tr = NULL, *iter_tr;
1752 struct event_subsystem *system = NULL;
1755 if (tracing_is_disabled())
1758 /* Make sure the system still exists */
1759 mutex_lock(&event_mutex);
1760 mutex_lock(&trace_types_lock);
1761 list_for_each_entry(iter_tr, &ftrace_trace_arrays, list) {
1762 list_for_each_entry(iter_dir, &iter_tr->systems, list) {
1763 if (iter_dir == inode->i_private) {
1764 /* Don't open systems with no events */
1767 if (dir->nr_events) {
1768 __get_system_dir(dir);
1769 system = dir->subsystem;
1776 mutex_unlock(&trace_types_lock);
1777 mutex_unlock(&event_mutex);
1782 /* Still need to increment the ref count of the system */
1783 if (trace_array_get(tr) < 0) {
1788 ret = tracing_open_generic(inode, filp);
1790 trace_array_put(tr);
1797 static int system_tr_open(struct inode *inode, struct file *filp)
1799 struct trace_subsystem_dir *dir;
1800 struct trace_array *tr = inode->i_private;
1803 /* Make a temporary dir that has no system but points to tr */
1804 dir = kzalloc(sizeof(*dir), GFP_KERNEL);
1808 ret = tracing_open_generic_tr(inode, filp);
1814 filp->private_data = dir;
1819 static int subsystem_release(struct inode *inode, struct file *file)
1821 struct trace_subsystem_dir *dir = file->private_data;
1823 trace_array_put(dir->tr);
1826 * If dir->subsystem is NULL, then this is a temporary
1827 * descriptor that was made for a trace_array to enable
1839 subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
1842 struct trace_subsystem_dir *dir = filp->private_data;
1843 struct event_subsystem *system = dir->subsystem;
1844 struct trace_seq *s;
1850 s = kmalloc(sizeof(*s), GFP_KERNEL);
1856 print_subsystem_event_filter(system, s);
1857 r = simple_read_from_buffer(ubuf, cnt, ppos,
1858 s->buffer, trace_seq_used(s));
1866 subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
1869 struct trace_subsystem_dir *dir = filp->private_data;
1873 if (cnt >= PAGE_SIZE)
1876 buf = memdup_user_nul(ubuf, cnt);
1878 return PTR_ERR(buf);
1880 err = apply_subsystem_event_filter(dir, buf);
1891 show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
1893 int (*func)(struct trace_seq *s) = filp->private_data;
1894 struct trace_seq *s;
1900 s = kmalloc(sizeof(*s), GFP_KERNEL);
1907 r = simple_read_from_buffer(ubuf, cnt, ppos,
1908 s->buffer, trace_seq_used(s));
1915 static void ignore_task_cpu(void *data)
1917 struct trace_array *tr = data;
1918 struct trace_pid_list *pid_list;
1919 struct trace_pid_list *no_pid_list;
1922 * This function is called by on_each_cpu() while the
1923 * event_mutex is held.
1925 pid_list = rcu_dereference_protected(tr->filtered_pids,
1926 mutex_is_locked(&event_mutex));
1927 no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
1928 mutex_is_locked(&event_mutex));
1930 this_cpu_write(tr->array_buffer.data->ignore_pid,
1931 trace_ignore_this_task(pid_list, no_pid_list, current));
1934 static void register_pid_events(struct trace_array *tr)
1937 * Register a probe that is called before all other probes
1938 * to set ignore_pid if next or prev do not match.
1939 * Register a probe this is called after all other probes
1940 * to only keep ignore_pid set if next pid matches.
1942 register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre,
1944 register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post,
1947 register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre,
1949 register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
1952 register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre,
1954 register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post,
1957 register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_pre,
1959 register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_post,
1964 event_pid_write(struct file *filp, const char __user *ubuf,
1965 size_t cnt, loff_t *ppos, int type)
1967 struct seq_file *m = filp->private_data;
1968 struct trace_array *tr = m->private;
1969 struct trace_pid_list *filtered_pids = NULL;
1970 struct trace_pid_list *other_pids = NULL;
1971 struct trace_pid_list *pid_list;
1972 struct trace_event_file *file;
1978 ret = tracing_update_buffers();
1982 mutex_lock(&event_mutex);
1984 if (type == TRACE_PIDS) {
1985 filtered_pids = rcu_dereference_protected(tr->filtered_pids,
1986 lockdep_is_held(&event_mutex));
1987 other_pids = rcu_dereference_protected(tr->filtered_no_pids,
1988 lockdep_is_held(&event_mutex));
1990 filtered_pids = rcu_dereference_protected(tr->filtered_no_pids,
1991 lockdep_is_held(&event_mutex));
1992 other_pids = rcu_dereference_protected(tr->filtered_pids,
1993 lockdep_is_held(&event_mutex));
1996 ret = trace_pid_write(filtered_pids, &pid_list, ubuf, cnt);
2000 if (type == TRACE_PIDS)
2001 rcu_assign_pointer(tr->filtered_pids, pid_list);
2003 rcu_assign_pointer(tr->filtered_no_pids, pid_list);
2005 list_for_each_entry(file, &tr->events, list) {
2006 set_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags);
2009 if (filtered_pids) {
2010 tracepoint_synchronize_unregister();
2011 trace_pid_list_free(filtered_pids);
2012 } else if (pid_list && !other_pids) {
2013 register_pid_events(tr);
2017 * Ignoring of pids is done at task switch. But we have to
2018 * check for those tasks that are currently running.
2019 * Always do this in case a pid was appended or removed.
2021 on_each_cpu(ignore_task_cpu, tr, 1);
2024 mutex_unlock(&event_mutex);
2033 ftrace_event_pid_write(struct file *filp, const char __user *ubuf,
2034 size_t cnt, loff_t *ppos)
2036 return event_pid_write(filp, ubuf, cnt, ppos, TRACE_PIDS);
2040 ftrace_event_npid_write(struct file *filp, const char __user *ubuf,
2041 size_t cnt, loff_t *ppos)
2043 return event_pid_write(filp, ubuf, cnt, ppos, TRACE_NO_PIDS);
2046 static int ftrace_event_avail_open(struct inode *inode, struct file *file);
2047 static int ftrace_event_set_open(struct inode *inode, struct file *file);
2048 static int ftrace_event_set_pid_open(struct inode *inode, struct file *file);
2049 static int ftrace_event_set_npid_open(struct inode *inode, struct file *file);
2050 static int ftrace_event_release(struct inode *inode, struct file *file);
2052 static const struct seq_operations show_event_seq_ops = {
2059 static const struct seq_operations show_set_event_seq_ops = {
2066 static const struct seq_operations show_set_pid_seq_ops = {
2069 .show = trace_pid_show,
2073 static const struct seq_operations show_set_no_pid_seq_ops = {
2076 .show = trace_pid_show,
2080 static const struct file_operations ftrace_avail_fops = {
2081 .open = ftrace_event_avail_open,
2083 .llseek = seq_lseek,
2084 .release = seq_release,
2087 static const struct file_operations ftrace_set_event_fops = {
2088 .open = ftrace_event_set_open,
2090 .write = ftrace_event_write,
2091 .llseek = seq_lseek,
2092 .release = ftrace_event_release,
2095 static const struct file_operations ftrace_set_event_pid_fops = {
2096 .open = ftrace_event_set_pid_open,
2098 .write = ftrace_event_pid_write,
2099 .llseek = seq_lseek,
2100 .release = ftrace_event_release,
2103 static const struct file_operations ftrace_set_event_notrace_pid_fops = {
2104 .open = ftrace_event_set_npid_open,
2106 .write = ftrace_event_npid_write,
2107 .llseek = seq_lseek,
2108 .release = ftrace_event_release,
2111 static const struct file_operations ftrace_enable_fops = {
2112 .open = tracing_open_generic,
2113 .read = event_enable_read,
2114 .write = event_enable_write,
2115 .llseek = default_llseek,
2118 static const struct file_operations ftrace_event_format_fops = {
2119 .open = trace_format_open,
2121 .llseek = seq_lseek,
2122 .release = seq_release,
2125 static const struct file_operations ftrace_event_id_fops = {
2126 .read = event_id_read,
2127 .llseek = default_llseek,
2130 static const struct file_operations ftrace_event_filter_fops = {
2131 .open = tracing_open_generic,
2132 .read = event_filter_read,
2133 .write = event_filter_write,
2134 .llseek = default_llseek,
2137 static const struct file_operations ftrace_subsystem_filter_fops = {
2138 .open = subsystem_open,
2139 .read = subsystem_filter_read,
2140 .write = subsystem_filter_write,
2141 .llseek = default_llseek,
2142 .release = subsystem_release,
2145 static const struct file_operations ftrace_system_enable_fops = {
2146 .open = subsystem_open,
2147 .read = system_enable_read,
2148 .write = system_enable_write,
2149 .llseek = default_llseek,
2150 .release = subsystem_release,
2153 static const struct file_operations ftrace_tr_enable_fops = {
2154 .open = system_tr_open,
2155 .read = system_enable_read,
2156 .write = system_enable_write,
2157 .llseek = default_llseek,
2158 .release = subsystem_release,
2161 static const struct file_operations ftrace_show_header_fops = {
2162 .open = tracing_open_generic,
2163 .read = show_header,
2164 .llseek = default_llseek,
2168 ftrace_event_open(struct inode *inode, struct file *file,
2169 const struct seq_operations *seq_ops)
2174 ret = security_locked_down(LOCKDOWN_TRACEFS);
2178 ret = seq_open(file, seq_ops);
2181 m = file->private_data;
2182 /* copy tr over to seq ops */
2183 m->private = inode->i_private;
2188 static int ftrace_event_release(struct inode *inode, struct file *file)
2190 struct trace_array *tr = inode->i_private;
2192 trace_array_put(tr);
2194 return seq_release(inode, file);
2198 ftrace_event_avail_open(struct inode *inode, struct file *file)
2200 const struct seq_operations *seq_ops = &show_event_seq_ops;
2202 /* Checks for tracefs lockdown */
2203 return ftrace_event_open(inode, file, seq_ops);
2207 ftrace_event_set_open(struct inode *inode, struct file *file)
2209 const struct seq_operations *seq_ops = &show_set_event_seq_ops;
2210 struct trace_array *tr = inode->i_private;
2213 ret = tracing_check_open_get_tr(tr);
2217 if ((file->f_mode & FMODE_WRITE) &&
2218 (file->f_flags & O_TRUNC))
2219 ftrace_clear_events(tr);
2221 ret = ftrace_event_open(inode, file, seq_ops);
2223 trace_array_put(tr);
2228 ftrace_event_set_pid_open(struct inode *inode, struct file *file)
2230 const struct seq_operations *seq_ops = &show_set_pid_seq_ops;
2231 struct trace_array *tr = inode->i_private;
2234 ret = tracing_check_open_get_tr(tr);
2238 if ((file->f_mode & FMODE_WRITE) &&
2239 (file->f_flags & O_TRUNC))
2240 ftrace_clear_event_pids(tr, TRACE_PIDS);
2242 ret = ftrace_event_open(inode, file, seq_ops);
2244 trace_array_put(tr);
2249 ftrace_event_set_npid_open(struct inode *inode, struct file *file)
2251 const struct seq_operations *seq_ops = &show_set_no_pid_seq_ops;
2252 struct trace_array *tr = inode->i_private;
2255 ret = tracing_check_open_get_tr(tr);
2259 if ((file->f_mode & FMODE_WRITE) &&
2260 (file->f_flags & O_TRUNC))
2261 ftrace_clear_event_pids(tr, TRACE_NO_PIDS);
2263 ret = ftrace_event_open(inode, file, seq_ops);
2265 trace_array_put(tr);
2269 static struct event_subsystem *
2270 create_new_subsystem(const char *name)
2272 struct event_subsystem *system;
2274 /* need to create new entry */
2275 system = kmalloc(sizeof(*system), GFP_KERNEL);
2279 system->ref_count = 1;
2281 /* Only allocate if dynamic (kprobes and modules) */
2282 system->name = kstrdup_const(name, GFP_KERNEL);
2286 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
2287 if (!system->filter)
2290 list_add(&system->list, &event_subsystems);
2295 kfree_const(system->name);
2300 static struct dentry *
2301 event_subsystem_dir(struct trace_array *tr, const char *name,
2302 struct trace_event_file *file, struct dentry *parent)
2304 struct event_subsystem *system, *iter;
2305 struct trace_subsystem_dir *dir;
2306 struct dentry *entry;
2308 /* First see if we did not already create this dir */
2309 list_for_each_entry(dir, &tr->systems, list) {
2310 system = dir->subsystem;
2311 if (strcmp(system->name, name) == 0) {
2318 /* Now see if the system itself exists. */
2320 list_for_each_entry(iter, &event_subsystems, list) {
2321 if (strcmp(iter->name, name) == 0) {
2327 dir = kmalloc(sizeof(*dir), GFP_KERNEL);
2332 system = create_new_subsystem(name);
2336 __get_system(system);
2338 dir->entry = tracefs_create_dir(name, parent);
2340 pr_warn("Failed to create system directory %s\n", name);
2341 __put_system(system);
2348 dir->subsystem = system;
2351 /* the ftrace system is special, do not create enable or filter files */
2352 if (strcmp(name, "ftrace") != 0) {
2354 entry = tracefs_create_file("filter", TRACE_MODE_WRITE,
2356 &ftrace_subsystem_filter_fops);
2358 kfree(system->filter);
2359 system->filter = NULL;
2360 pr_warn("Could not create tracefs '%s/filter' entry\n", name);
2363 trace_create_file("enable", TRACE_MODE_WRITE, dir->entry, dir,
2364 &ftrace_system_enable_fops);
2367 list_add(&dir->list, &tr->systems);
2374 /* Only print this message if failed on memory allocation */
2375 if (!dir || !system)
2376 pr_warn("No memory to create event subsystem %s\n", name);
2381 event_define_fields(struct trace_event_call *call)
2383 struct list_head *head;
2387 * Other events may have the same class. Only update
2388 * the fields if they are not already defined.
2390 head = trace_get_fields(call);
2391 if (list_empty(head)) {
2392 struct trace_event_fields *field = call->class->fields_array;
2393 unsigned int offset = sizeof(struct trace_entry);
2395 for (; field->type; field++) {
2396 if (field->type == TRACE_FUNCTION_TYPE) {
2397 field->define_fields(call);
2401 offset = ALIGN(offset, field->align);
2402 ret = trace_define_field_ext(call, field->type, field->name,
2403 offset, field->size,
2404 field->is_signed, field->filter_type,
2406 if (WARN_ON_ONCE(ret)) {
2407 pr_err("error code is %d\n", ret);
2411 offset += field->size;
2419 event_create_dir(struct dentry *parent, struct trace_event_file *file)
2421 struct trace_event_call *call = file->event_call;
2422 struct trace_array *tr = file->tr;
2423 struct dentry *d_events;
2428 * If the trace point header did not define TRACE_SYSTEM
2429 * then the system would be called "TRACE_SYSTEM".
2431 if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
2432 d_events = event_subsystem_dir(tr, call->class->system, file, parent);
2438 name = trace_event_name(call);
2439 file->dir = tracefs_create_dir(name, d_events);
2441 pr_warn("Could not create tracefs '%s' directory\n", name);
2445 if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
2446 trace_create_file("enable", TRACE_MODE_WRITE, file->dir, file,
2447 &ftrace_enable_fops);
2449 #ifdef CONFIG_PERF_EVENTS
2450 if (call->event.type && call->class->reg)
2451 trace_create_file("id", TRACE_MODE_READ, file->dir,
2452 (void *)(long)call->event.type,
2453 &ftrace_event_id_fops);
2456 ret = event_define_fields(call);
2458 pr_warn("Could not initialize trace point events/%s\n", name);
2463 * Only event directories that can be enabled should have
2464 * triggers or filters.
2466 if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) {
2467 trace_create_file("filter", TRACE_MODE_WRITE, file->dir,
2468 file, &ftrace_event_filter_fops);
2470 trace_create_file("trigger", TRACE_MODE_WRITE, file->dir,
2471 file, &event_trigger_fops);
2474 #ifdef CONFIG_HIST_TRIGGERS
2475 trace_create_file("hist", TRACE_MODE_READ, file->dir, file,
2478 #ifdef CONFIG_HIST_TRIGGERS_DEBUG
2479 trace_create_file("hist_debug", TRACE_MODE_READ, file->dir, file,
2480 &event_hist_debug_fops);
2482 trace_create_file("format", TRACE_MODE_READ, file->dir, call,
2483 &ftrace_event_format_fops);
2485 #ifdef CONFIG_TRACE_EVENT_INJECT
2486 if (call->event.type && call->class->reg)
2487 trace_create_file("inject", 0200, file->dir, file,
2488 &event_inject_fops);
2494 static void remove_event_from_tracers(struct trace_event_call *call)
2496 struct trace_event_file *file;
2497 struct trace_array *tr;
2499 do_for_each_event_file_safe(tr, file) {
2500 if (file->event_call != call)
2503 remove_event_file_dir(file);
2505 * The do_for_each_event_file_safe() is
2506 * a double loop. After finding the call for this
2507 * trace_array, we use break to jump to the next
2511 } while_for_each_event_file();
2514 static void event_remove(struct trace_event_call *call)
2516 struct trace_array *tr;
2517 struct trace_event_file *file;
2519 do_for_each_event_file(tr, file) {
2520 if (file->event_call != call)
2523 if (file->flags & EVENT_FILE_FL_WAS_ENABLED)
2524 tr->clear_trace = true;
2526 ftrace_event_enable_disable(file, 0);
2528 * The do_for_each_event_file() is
2529 * a double loop. After finding the call for this
2530 * trace_array, we use break to jump to the next
2534 } while_for_each_event_file();
2536 if (call->event.funcs)
2537 __unregister_trace_event(&call->event);
2538 remove_event_from_tracers(call);
2539 list_del(&call->list);
2542 static int event_init(struct trace_event_call *call)
2547 name = trace_event_name(call);
2551 if (call->class->raw_init) {
2552 ret = call->class->raw_init(call);
2553 if (ret < 0 && ret != -ENOSYS)
2554 pr_warn("Could not initialize trace events/%s\n", name);
2561 __register_event(struct trace_event_call *call, struct module *mod)
2565 ret = event_init(call);
2569 list_add(&call->list, &ftrace_events);
2570 if (call->flags & TRACE_EVENT_FL_DYNAMIC)
2571 atomic_set(&call->refcnt, 0);
2578 static char *eval_replace(char *ptr, struct trace_eval_map *map, int len)
2583 /* Find the length of the eval value as a string */
2584 elen = snprintf(ptr, 0, "%ld", map->eval_value);
2585 /* Make sure there's enough room to replace the string with the value */
2589 snprintf(ptr, elen + 1, "%ld", map->eval_value);
2591 /* Get the rest of the string of ptr */
2592 rlen = strlen(ptr + len);
2593 memmove(ptr + elen, ptr + len, rlen);
2594 /* Make sure we end the new string */
2595 ptr[elen + rlen] = 0;
2600 static void update_event_printk(struct trace_event_call *call,
2601 struct trace_eval_map *map)
2605 int len = strlen(map->eval_string);
2607 for (ptr = call->print_fmt; *ptr; ptr++) {
2621 if (isdigit(*ptr)) {
2625 /* Check for alpha chars like ULL */
2626 } while (isalnum(*ptr));
2630 * A number must have some kind of delimiter after
2631 * it, and we can ignore that too.
2635 if (isalpha(*ptr) || *ptr == '_') {
2636 if (strncmp(map->eval_string, ptr, len) == 0 &&
2637 !isalnum(ptr[len]) && ptr[len] != '_') {
2638 ptr = eval_replace(ptr, map, len);
2639 /* enum/sizeof string smaller than value */
2640 if (WARN_ON_ONCE(!ptr))
2643 * No need to decrement here, as eval_replace()
2644 * returns the pointer to the character passed
2645 * the eval, and two evals can not be placed
2646 * back to back without something in between.
2647 * We can skip that something in between.
2654 } while (isalnum(*ptr) || *ptr == '_');
2658 * If what comes after this variable is a '.' or
2659 * '->' then we can continue to ignore that string.
2661 if (*ptr == '.' || (ptr[0] == '-' && ptr[1] == '>')) {
2662 ptr += *ptr == '.' ? 1 : 2;
2668 * Once again, we can skip the delimiter that came
2676 static void add_str_to_module(struct module *module, char *str)
2678 struct module_string *modstr;
2680 modstr = kmalloc(sizeof(*modstr), GFP_KERNEL);
2683 * If we failed to allocate memory here, then we'll just
2684 * let the str memory leak when the module is removed.
2685 * If this fails to allocate, there's worse problems than
2686 * a leaked string on module removal.
2688 if (WARN_ON_ONCE(!modstr))
2691 modstr->module = module;
2694 list_add(&modstr->next, &module_strings);
2697 static void update_event_fields(struct trace_event_call *call,
2698 struct trace_eval_map *map)
2700 struct ftrace_event_field *field;
2701 struct list_head *head;
2704 int len = strlen(map->eval_string);
2706 /* Dynamic events should never have field maps */
2707 if (WARN_ON_ONCE(call->flags & TRACE_EVENT_FL_DYNAMIC))
2710 head = trace_get_fields(call);
2711 list_for_each_entry(field, head, link) {
2712 ptr = strchr(field->type, '[');
2717 if (!isalpha(*ptr) && *ptr != '_')
2720 if (strncmp(map->eval_string, ptr, len) != 0)
2723 str = kstrdup(field->type, GFP_KERNEL);
2724 if (WARN_ON_ONCE(!str))
2726 ptr = str + (ptr - field->type);
2727 ptr = eval_replace(ptr, map, len);
2728 /* enum/sizeof string smaller than value */
2729 if (WARN_ON_ONCE(!ptr)) {
2735 * If the event is part of a module, then we need to free the string
2736 * when the module is removed. Otherwise, it will stay allocated
2740 add_str_to_module(call->module, str);
2746 void trace_event_eval_update(struct trace_eval_map **map, int len)
2748 struct trace_event_call *call, *p;
2749 const char *last_system = NULL;
2754 down_write(&trace_event_sem);
2755 list_for_each_entry_safe(call, p, &ftrace_events, list) {
2756 /* events are usually grouped together with systems */
2757 if (!last_system || call->class->system != last_system) {
2760 last_system = call->class->system;
2764 * Since calls are grouped by systems, the likelihood that the
2765 * next call in the iteration belongs to the same system as the
2766 * previous call is high. As an optimization, we skip searching
2767 * for a map[] that matches the call's system if the last call
2768 * was from the same system. That's what last_i is for. If the
2769 * call has the same system as the previous call, then last_i
2770 * will be the index of the first map[] that has a matching
2773 for (i = last_i; i < len; i++) {
2774 if (call->class->system == map[i]->system) {
2775 /* Save the first system if need be */
2780 update_event_printk(call, map[i]);
2781 update_event_fields(call, map[i]);
2785 up_write(&trace_event_sem);
2788 static struct trace_event_file *
2789 trace_create_new_event(struct trace_event_call *call,
2790 struct trace_array *tr)
2792 struct trace_pid_list *no_pid_list;
2793 struct trace_pid_list *pid_list;
2794 struct trace_event_file *file;
2797 file = kmem_cache_alloc(file_cachep, GFP_TRACE);
2801 pid_list = rcu_dereference_protected(tr->filtered_pids,
2802 lockdep_is_held(&event_mutex));
2803 no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
2804 lockdep_is_held(&event_mutex));
2806 if (!trace_pid_list_first(pid_list, &first) ||
2807 !trace_pid_list_first(no_pid_list, &first))
2808 file->flags |= EVENT_FILE_FL_PID_FILTER;
2810 file->event_call = call;
2812 atomic_set(&file->sm_ref, 0);
2813 atomic_set(&file->tm_ref, 0);
2814 INIT_LIST_HEAD(&file->triggers);
2815 list_add(&file->list, &tr->events);
2820 #define MAX_BOOT_TRIGGERS 32
2822 static struct boot_triggers {
2825 } bootup_triggers[MAX_BOOT_TRIGGERS];
2827 static char bootup_trigger_buf[COMMAND_LINE_SIZE];
2828 static int nr_boot_triggers;
2830 static __init int setup_trace_triggers(char *str)
2836 strscpy(bootup_trigger_buf, str, COMMAND_LINE_SIZE);
2837 ring_buffer_expanded = true;
2838 disable_tracing_selftest("running event triggers");
2840 buf = bootup_trigger_buf;
2841 for (i = 0; i < MAX_BOOT_TRIGGERS; i++) {
2842 trigger = strsep(&buf, ",");
2845 bootup_triggers[i].event = strsep(&trigger, ".");
2846 bootup_triggers[i].trigger = trigger;
2847 if (!bootup_triggers[i].trigger)
2851 nr_boot_triggers = i;
2854 __setup("trace_trigger=", setup_trace_triggers);
2856 /* Add an event to a trace directory */
2858 __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr)
2860 struct trace_event_file *file;
2862 file = trace_create_new_event(call, tr);
2866 if (eventdir_initialized)
2867 return event_create_dir(tr->event_dir, file);
2869 return event_define_fields(call);
2872 static void trace_early_triggers(struct trace_event_file *file, const char *name)
2877 for (i = 0; i < nr_boot_triggers; i++) {
2878 if (strcmp(name, bootup_triggers[i].event))
2880 mutex_lock(&event_mutex);
2881 ret = trigger_process_regex(file, bootup_triggers[i].trigger);
2882 mutex_unlock(&event_mutex);
2884 pr_err("Failed to register trigger '%s' on event %s\n",
2885 bootup_triggers[i].trigger,
2886 bootup_triggers[i].event);
2891 * Just create a descriptor for early init. A descriptor is required
2892 * for enabling events at boot. We want to enable events before
2893 * the filesystem is initialized.
2896 __trace_early_add_new_event(struct trace_event_call *call,
2897 struct trace_array *tr)
2899 struct trace_event_file *file;
2902 file = trace_create_new_event(call, tr);
2906 ret = event_define_fields(call);
2910 trace_early_triggers(file, trace_event_name(call));
2915 struct ftrace_module_file_ops;
2916 static void __add_event_to_tracers(struct trace_event_call *call);
2918 /* Add an additional event_call dynamically */
2919 int trace_add_event_call(struct trace_event_call *call)
2922 lockdep_assert_held(&event_mutex);
2924 mutex_lock(&trace_types_lock);
2926 ret = __register_event(call, NULL);
2928 __add_event_to_tracers(call);
2930 mutex_unlock(&trace_types_lock);
2933 EXPORT_SYMBOL_GPL(trace_add_event_call);
2936 * Must be called under locking of trace_types_lock, event_mutex and
2939 static void __trace_remove_event_call(struct trace_event_call *call)
2942 trace_destroy_fields(call);
2943 free_event_filter(call->filter);
2944 call->filter = NULL;
2947 static int probe_remove_event_call(struct trace_event_call *call)
2949 struct trace_array *tr;
2950 struct trace_event_file *file;
2952 #ifdef CONFIG_PERF_EVENTS
2953 if (call->perf_refcount)
2956 do_for_each_event_file(tr, file) {
2957 if (file->event_call != call)
2960 * We can't rely on ftrace_event_enable_disable(enable => 0)
2961 * we are going to do, EVENT_FILE_FL_SOFT_MODE can suppress
2962 * TRACE_REG_UNREGISTER.
2964 if (file->flags & EVENT_FILE_FL_ENABLED)
2967 if (file->flags & EVENT_FILE_FL_WAS_ENABLED)
2968 tr->clear_trace = true;
2970 * The do_for_each_event_file_safe() is
2971 * a double loop. After finding the call for this
2972 * trace_array, we use break to jump to the next
2976 } while_for_each_event_file();
2978 __trace_remove_event_call(call);
2982 /* No need to clear the trace now */
2983 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
2984 tr->clear_trace = false;
2989 /* Remove an event_call */
2990 int trace_remove_event_call(struct trace_event_call *call)
2994 lockdep_assert_held(&event_mutex);
2996 mutex_lock(&trace_types_lock);
2997 down_write(&trace_event_sem);
2998 ret = probe_remove_event_call(call);
2999 up_write(&trace_event_sem);
3000 mutex_unlock(&trace_types_lock);
3004 EXPORT_SYMBOL_GPL(trace_remove_event_call);
3006 #define for_each_event(event, start, end) \
3007 for (event = start; \
3008 (unsigned long)event < (unsigned long)end; \
3011 #ifdef CONFIG_MODULES
3013 static void trace_module_add_events(struct module *mod)
3015 struct trace_event_call **call, **start, **end;
3017 if (!mod->num_trace_events)
3020 /* Don't add infrastructure for mods without tracepoints */
3021 if (trace_module_has_bad_taint(mod)) {
3022 pr_err("%s: module has bad taint, not creating trace events\n",
3027 start = mod->trace_events;
3028 end = mod->trace_events + mod->num_trace_events;
3030 for_each_event(call, start, end) {
3031 __register_event(*call, mod);
3032 __add_event_to_tracers(*call);
3036 static void trace_module_remove_events(struct module *mod)
3038 struct trace_event_call *call, *p;
3039 struct module_string *modstr, *m;
3041 down_write(&trace_event_sem);
3042 list_for_each_entry_safe(call, p, &ftrace_events, list) {
3043 if ((call->flags & TRACE_EVENT_FL_DYNAMIC) || !call->module)
3045 if (call->module == mod)
3046 __trace_remove_event_call(call);
3048 /* Check for any strings allocade for this module */
3049 list_for_each_entry_safe(modstr, m, &module_strings, next) {
3050 if (modstr->module != mod)
3052 list_del(&modstr->next);
3056 up_write(&trace_event_sem);
3059 * It is safest to reset the ring buffer if the module being unloaded
3060 * registered any events that were used. The only worry is if
3061 * a new module gets loaded, and takes on the same id as the events
3062 * of this module. When printing out the buffer, traced events left
3063 * over from this module may be passed to the new module events and
3064 * unexpected results may occur.
3066 tracing_reset_all_online_cpus_unlocked();
3069 static int trace_module_notify(struct notifier_block *self,
3070 unsigned long val, void *data)
3072 struct module *mod = data;
3074 mutex_lock(&event_mutex);
3075 mutex_lock(&trace_types_lock);
3077 case MODULE_STATE_COMING:
3078 trace_module_add_events(mod);
3080 case MODULE_STATE_GOING:
3081 trace_module_remove_events(mod);
3084 mutex_unlock(&trace_types_lock);
3085 mutex_unlock(&event_mutex);
3090 static struct notifier_block trace_module_nb = {
3091 .notifier_call = trace_module_notify,
3092 .priority = 1, /* higher than trace.c module notify */
3094 #endif /* CONFIG_MODULES */
3096 /* Create a new event directory structure for a trace directory. */
3098 __trace_add_event_dirs(struct trace_array *tr)
3100 struct trace_event_call *call;
3103 list_for_each_entry(call, &ftrace_events, list) {
3104 ret = __trace_add_new_event(call, tr);
3106 pr_warn("Could not create directory for event %s\n",
3107 trace_event_name(call));
3111 /* Returns any file that matches the system and event */
3112 struct trace_event_file *
3113 __find_event_file(struct trace_array *tr, const char *system, const char *event)
3115 struct trace_event_file *file;
3116 struct trace_event_call *call;
3119 list_for_each_entry(file, &tr->events, list) {
3121 call = file->event_call;
3122 name = trace_event_name(call);
3124 if (!name || !call->class)
3127 if (strcmp(event, name) == 0 &&
3128 strcmp(system, call->class->system) == 0)
3134 /* Returns valid trace event files that match system and event */
3135 struct trace_event_file *
3136 find_event_file(struct trace_array *tr, const char *system, const char *event)
3138 struct trace_event_file *file;
3140 file = __find_event_file(tr, system, event);
3141 if (!file || !file->event_call->class->reg ||
3142 file->event_call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
3149 * trace_get_event_file - Find and return a trace event file
3150 * @instance: The name of the trace instance containing the event
3151 * @system: The name of the system containing the event
3152 * @event: The name of the event
3154 * Return a trace event file given the trace instance name, trace
3155 * system, and trace event name. If the instance name is NULL, it
3156 * refers to the top-level trace array.
3158 * This function will look it up and return it if found, after calling
3159 * trace_array_get() to prevent the instance from going away, and
3160 * increment the event's module refcount to prevent it from being
3163 * To release the file, call trace_put_event_file(), which will call
3164 * trace_array_put() and decrement the event's module refcount.
3166 * Return: The trace event on success, ERR_PTR otherwise.
3168 struct trace_event_file *trace_get_event_file(const char *instance,
3172 struct trace_array *tr = top_trace_array();
3173 struct trace_event_file *file = NULL;
3177 tr = trace_array_find_get(instance);
3179 return ERR_PTR(-ENOENT);
3181 ret = trace_array_get(tr);
3183 return ERR_PTR(ret);
3186 mutex_lock(&event_mutex);
3188 file = find_event_file(tr, system, event);
3190 trace_array_put(tr);
3195 /* Don't let event modules unload while in use */
3196 ret = trace_event_try_get_ref(file->event_call);
3198 trace_array_put(tr);
3205 mutex_unlock(&event_mutex);
3208 file = ERR_PTR(ret);
3212 EXPORT_SYMBOL_GPL(trace_get_event_file);
3215 * trace_put_event_file - Release a file from trace_get_event_file()
3216 * @file: The trace event file
3218 * If a file was retrieved using trace_get_event_file(), this should
3219 * be called when it's no longer needed. It will cancel the previous
3220 * trace_array_get() called by that function, and decrement the
3221 * event's module refcount.
3223 void trace_put_event_file(struct trace_event_file *file)
3225 mutex_lock(&event_mutex);
3226 trace_event_put_ref(file->event_call);
3227 mutex_unlock(&event_mutex);
3229 trace_array_put(file->tr);
3231 EXPORT_SYMBOL_GPL(trace_put_event_file);
3233 #ifdef CONFIG_DYNAMIC_FTRACE
3236 #define ENABLE_EVENT_STR "enable_event"
3237 #define DISABLE_EVENT_STR "disable_event"
3239 struct event_probe_data {
3240 struct trace_event_file *file;
3241 unsigned long count;
3246 static void update_event_probe(struct event_probe_data *data)
3249 clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
3251 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
3255 event_enable_probe(unsigned long ip, unsigned long parent_ip,
3256 struct trace_array *tr, struct ftrace_probe_ops *ops,
3259 struct ftrace_func_mapper *mapper = data;
3260 struct event_probe_data *edata;
3263 pdata = ftrace_func_mapper_find_ip(mapper, ip);
3264 if (!pdata || !*pdata)
3268 update_event_probe(edata);
3272 event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
3273 struct trace_array *tr, struct ftrace_probe_ops *ops,
3276 struct ftrace_func_mapper *mapper = data;
3277 struct event_probe_data *edata;
3280 pdata = ftrace_func_mapper_find_ip(mapper, ip);
3281 if (!pdata || !*pdata)
3289 /* Skip if the event is in a state we want to switch to */
3290 if (edata->enable == !(edata->file->flags & EVENT_FILE_FL_SOFT_DISABLED))
3293 if (edata->count != -1)
3296 update_event_probe(edata);
3300 event_enable_print(struct seq_file *m, unsigned long ip,
3301 struct ftrace_probe_ops *ops, void *data)
3303 struct ftrace_func_mapper *mapper = data;
3304 struct event_probe_data *edata;
3307 pdata = ftrace_func_mapper_find_ip(mapper, ip);
3309 if (WARN_ON_ONCE(!pdata || !*pdata))
3314 seq_printf(m, "%ps:", (void *)ip);
3316 seq_printf(m, "%s:%s:%s",
3317 edata->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
3318 edata->file->event_call->class->system,
3319 trace_event_name(edata->file->event_call));
3321 if (edata->count == -1)
3322 seq_puts(m, ":unlimited\n");
3324 seq_printf(m, ":count=%ld\n", edata->count);
3330 event_enable_init(struct ftrace_probe_ops *ops, struct trace_array *tr,
3331 unsigned long ip, void *init_data, void **data)
3333 struct ftrace_func_mapper *mapper = *data;
3334 struct event_probe_data *edata = init_data;
3338 mapper = allocate_ftrace_func_mapper();
3344 ret = ftrace_func_mapper_add_ip(mapper, ip, edata);
3353 static int free_probe_data(void *data)
3355 struct event_probe_data *edata = data;
3359 /* Remove the SOFT_MODE flag */
3360 __ftrace_event_enable_disable(edata->file, 0, 1);
3361 trace_event_put_ref(edata->file->event_call);
3368 event_enable_free(struct ftrace_probe_ops *ops, struct trace_array *tr,
3369 unsigned long ip, void *data)
3371 struct ftrace_func_mapper *mapper = data;
3372 struct event_probe_data *edata;
3377 free_ftrace_func_mapper(mapper, free_probe_data);
3381 edata = ftrace_func_mapper_remove_ip(mapper, ip);
3383 if (WARN_ON_ONCE(!edata))
3386 if (WARN_ON_ONCE(edata->ref <= 0))
3389 free_probe_data(edata);
3392 static struct ftrace_probe_ops event_enable_probe_ops = {
3393 .func = event_enable_probe,
3394 .print = event_enable_print,
3395 .init = event_enable_init,
3396 .free = event_enable_free,
3399 static struct ftrace_probe_ops event_enable_count_probe_ops = {
3400 .func = event_enable_count_probe,
3401 .print = event_enable_print,
3402 .init = event_enable_init,
3403 .free = event_enable_free,
3406 static struct ftrace_probe_ops event_disable_probe_ops = {
3407 .func = event_enable_probe,
3408 .print = event_enable_print,
3409 .init = event_enable_init,
3410 .free = event_enable_free,
3413 static struct ftrace_probe_ops event_disable_count_probe_ops = {
3414 .func = event_enable_count_probe,
3415 .print = event_enable_print,
3416 .init = event_enable_init,
3417 .free = event_enable_free,
3421 event_enable_func(struct trace_array *tr, struct ftrace_hash *hash,
3422 char *glob, char *cmd, char *param, int enabled)
3424 struct trace_event_file *file;
3425 struct ftrace_probe_ops *ops;
3426 struct event_probe_data *data;
3436 /* hash funcs only work with set_ftrace_filter */
3437 if (!enabled || !param)
3440 system = strsep(¶m, ":");
3444 event = strsep(¶m, ":");
3446 mutex_lock(&event_mutex);
3449 file = find_event_file(tr, system, event);
3453 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
3456 ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops;
3458 ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops;
3460 if (glob[0] == '!') {
3461 ret = unregister_ftrace_function_probe_func(glob+1, tr, ops);
3467 data = kzalloc(sizeof(*data), GFP_KERNEL);
3471 data->enable = enable;
3478 number = strsep(¶m, ":");
3481 if (!strlen(number))
3485 * We use the callback data field (which is a pointer)
3488 ret = kstrtoul(number, 0, &data->count);
3493 /* Don't let event modules unload while probe registered */
3494 ret = trace_event_try_get_ref(file->event_call);
3500 ret = __ftrace_event_enable_disable(file, 1, 1);
3504 ret = register_ftrace_function_probe(glob, tr, ops, data);
3506 * The above returns on success the # of functions enabled,
3507 * but if it didn't find any functions it returns zero.
3508 * Consider no functions a failure too.
3515 /* Just return zero, not the number of enabled functions */
3518 mutex_unlock(&event_mutex);
3522 __ftrace_event_enable_disable(file, 0, 1);
3524 trace_event_put_ref(file->event_call);
3530 static struct ftrace_func_command event_enable_cmd = {
3531 .name = ENABLE_EVENT_STR,
3532 .func = event_enable_func,
3535 static struct ftrace_func_command event_disable_cmd = {
3536 .name = DISABLE_EVENT_STR,
3537 .func = event_enable_func,
3540 static __init int register_event_cmds(void)
3544 ret = register_ftrace_command(&event_enable_cmd);
3545 if (WARN_ON(ret < 0))
3547 ret = register_ftrace_command(&event_disable_cmd);
3548 if (WARN_ON(ret < 0))
3549 unregister_ftrace_command(&event_enable_cmd);
3553 static inline int register_event_cmds(void) { return 0; }
3554 #endif /* CONFIG_DYNAMIC_FTRACE */
3557 * The top level array and trace arrays created by boot-time tracing
3558 * have already had its trace_event_file descriptors created in order
3559 * to allow for early events to be recorded.
3560 * This function is called after the tracefs has been initialized,
3561 * and we now have to create the files associated to the events.
3563 static void __trace_early_add_event_dirs(struct trace_array *tr)
3565 struct trace_event_file *file;
3569 list_for_each_entry(file, &tr->events, list) {
3570 ret = event_create_dir(tr->event_dir, file);
3572 pr_warn("Could not create directory for event %s\n",
3573 trace_event_name(file->event_call));
3578 * For early boot up, the top trace array and the trace arrays created
3579 * by boot-time tracing require to have a list of events that can be
3580 * enabled. This must be done before the filesystem is set up in order
3581 * to allow events to be traced early.
3583 void __trace_early_add_events(struct trace_array *tr)
3585 struct trace_event_call *call;
3588 list_for_each_entry(call, &ftrace_events, list) {
3589 /* Early boot up should not have any modules loaded */
3590 if (!(call->flags & TRACE_EVENT_FL_DYNAMIC) &&
3591 WARN_ON_ONCE(call->module))
3594 ret = __trace_early_add_new_event(call, tr);
3596 pr_warn("Could not create early event %s\n",
3597 trace_event_name(call));
3601 /* Remove the event directory structure for a trace directory. */
3603 __trace_remove_event_dirs(struct trace_array *tr)
3605 struct trace_event_file *file, *next;
3607 list_for_each_entry_safe(file, next, &tr->events, list)
3608 remove_event_file_dir(file);
3611 static void __add_event_to_tracers(struct trace_event_call *call)
3613 struct trace_array *tr;
3615 list_for_each_entry(tr, &ftrace_trace_arrays, list)
3616 __trace_add_new_event(call, tr);
3619 extern struct trace_event_call *__start_ftrace_events[];
3620 extern struct trace_event_call *__stop_ftrace_events[];
3622 static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
3624 static __init int setup_trace_event(char *str)
3626 strscpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
3627 ring_buffer_expanded = true;
3628 disable_tracing_selftest("running event tracing");
3632 __setup("trace_event=", setup_trace_event);
3634 /* Expects to have event_mutex held when called */
3636 create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
3638 struct dentry *d_events;
3639 struct dentry *entry;
3641 entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent,
3642 tr, &ftrace_set_event_fops);
3646 d_events = tracefs_create_dir("events", parent);
3648 pr_warn("Could not create tracefs 'events' directory\n");
3652 entry = trace_create_file("enable", TRACE_MODE_WRITE, d_events,
3653 tr, &ftrace_tr_enable_fops);
3657 /* There are not as crucial, just warn if they are not created */
3659 trace_create_file("set_event_pid", TRACE_MODE_WRITE, parent,
3660 tr, &ftrace_set_event_pid_fops);
3662 trace_create_file("set_event_notrace_pid",
3663 TRACE_MODE_WRITE, parent, tr,
3664 &ftrace_set_event_notrace_pid_fops);
3666 /* ring buffer internal formats */
3667 trace_create_file("header_page", TRACE_MODE_READ, d_events,
3668 ring_buffer_print_page_header,
3669 &ftrace_show_header_fops);
3671 trace_create_file("header_event", TRACE_MODE_READ, d_events,
3672 ring_buffer_print_entry_header,
3673 &ftrace_show_header_fops);
3675 tr->event_dir = d_events;
3681 * event_trace_add_tracer - add a instance of a trace_array to events
3682 * @parent: The parent dentry to place the files/directories for events in
3683 * @tr: The trace array associated with these events
3685 * When a new instance is created, it needs to set up its events
3686 * directory, as well as other files associated with events. It also
3687 * creates the event hierarchy in the @parent/events directory.
3689 * Returns 0 on success.
3691 * Must be called with event_mutex held.
3693 int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr)
3697 lockdep_assert_held(&event_mutex);
3699 ret = create_event_toplevel_files(parent, tr);
3703 down_write(&trace_event_sem);
3704 /* If tr already has the event list, it is initialized in early boot. */
3705 if (unlikely(!list_empty(&tr->events)))
3706 __trace_early_add_event_dirs(tr);
3708 __trace_add_event_dirs(tr);
3709 up_write(&trace_event_sem);
3716 * The top trace array already had its file descriptors created.
3717 * Now the files themselves need to be created.
3720 early_event_add_tracer(struct dentry *parent, struct trace_array *tr)
3724 mutex_lock(&event_mutex);
3726 ret = create_event_toplevel_files(parent, tr);
3730 down_write(&trace_event_sem);
3731 __trace_early_add_event_dirs(tr);
3732 up_write(&trace_event_sem);
3735 mutex_unlock(&event_mutex);
3740 /* Must be called with event_mutex held */
3741 int event_trace_del_tracer(struct trace_array *tr)
3743 lockdep_assert_held(&event_mutex);
3745 /* Disable any event triggers and associated soft-disabled events */
3746 clear_event_triggers(tr);
3748 /* Clear the pid list */
3749 __ftrace_clear_event_pids(tr, TRACE_PIDS | TRACE_NO_PIDS);
3751 /* Disable any running events */
3752 __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0);
3754 /* Make sure no more events are being executed */
3755 tracepoint_synchronize_unregister();
3757 down_write(&trace_event_sem);
3758 __trace_remove_event_dirs(tr);
3759 tracefs_remove(tr->event_dir);
3760 up_write(&trace_event_sem);
3762 tr->event_dir = NULL;
3767 static __init int event_trace_memsetup(void)
3769 field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC);
3770 file_cachep = KMEM_CACHE(trace_event_file, SLAB_PANIC);
3775 early_enable_events(struct trace_array *tr, char *buf, bool disable_first)
3781 token = strsep(&buf, ",");
3787 /* Restarting syscalls requires that we stop them first */
3789 ftrace_set_clr_event(tr, token, 0);
3791 ret = ftrace_set_clr_event(tr, token, 1);
3793 pr_warn("Failed to enable trace event: %s\n", token);
3796 /* Put back the comma to allow this to be called again */
3802 static __init int event_trace_enable(void)
3804 struct trace_array *tr = top_trace_array();
3805 struct trace_event_call **iter, *call;
3811 for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
3814 ret = event_init(call);
3816 list_add(&call->list, &ftrace_events);
3819 register_trigger_cmds();
3822 * We need the top trace array to have a working set of trace
3823 * points at early init, before the debug files and directories
3824 * are created. Create the file entries now, and attach them
3825 * to the actual file dentries later.
3827 __trace_early_add_events(tr);
3829 early_enable_events(tr, bootup_event_buf, false);
3831 trace_printk_start_comm();
3833 register_event_cmds();
3840 * event_trace_enable() is called from trace_event_init() first to
3841 * initialize events and perhaps start any events that are on the
3842 * command line. Unfortunately, there are some events that will not
3843 * start this early, like the system call tracepoints that need
3844 * to set the %SYSCALL_WORK_SYSCALL_TRACEPOINT flag of pid 1. But
3845 * event_trace_enable() is called before pid 1 starts, and this flag
3846 * is never set, making the syscall tracepoint never get reached, but
3847 * the event is enabled regardless (and not doing anything).
3849 static __init int event_trace_enable_again(void)
3851 struct trace_array *tr;
3853 tr = top_trace_array();
3857 early_enable_events(tr, bootup_event_buf, true);
3862 early_initcall(event_trace_enable_again);
3864 /* Init fields which doesn't related to the tracefs */
3865 static __init int event_trace_init_fields(void)
3867 if (trace_define_generic_fields())
3868 pr_warn("tracing: Failed to allocated generic fields");
3870 if (trace_define_common_fields())
3871 pr_warn("tracing: Failed to allocate common fields");
3876 __init int event_trace_init(void)
3878 struct trace_array *tr;
3881 tr = top_trace_array();
3885 trace_create_file("available_events", TRACE_MODE_READ,
3886 NULL, tr, &ftrace_avail_fops);
3888 ret = early_event_add_tracer(NULL, tr);
3892 #ifdef CONFIG_MODULES
3893 ret = register_module_notifier(&trace_module_nb);
3895 pr_warn("Failed to register trace events module notifier\n");
3898 eventdir_initialized = true;
3903 void __init trace_event_init(void)
3905 event_trace_memsetup();
3906 init_ftrace_syscalls();
3907 event_trace_enable();
3908 event_trace_init_fields();
3911 #ifdef CONFIG_EVENT_TRACE_STARTUP_TEST
3913 static DEFINE_SPINLOCK(test_spinlock);
3914 static DEFINE_SPINLOCK(test_spinlock_irq);
3915 static DEFINE_MUTEX(test_mutex);
3917 static __init void test_work(struct work_struct *dummy)
3919 spin_lock(&test_spinlock);
3920 spin_lock_irq(&test_spinlock_irq);
3922 spin_unlock_irq(&test_spinlock_irq);
3923 spin_unlock(&test_spinlock);
3925 mutex_lock(&test_mutex);
3927 mutex_unlock(&test_mutex);
3930 static __init int event_test_thread(void *unused)
3934 test_malloc = kmalloc(1234, GFP_KERNEL);
3936 pr_info("failed to kmalloc\n");
3938 schedule_on_each_cpu(test_work);
3942 set_current_state(TASK_INTERRUPTIBLE);
3943 while (!kthread_should_stop()) {
3945 set_current_state(TASK_INTERRUPTIBLE);
3947 __set_current_state(TASK_RUNNING);
3953 * Do various things that may trigger events.
3955 static __init void event_test_stuff(void)
3957 struct task_struct *test_thread;
3959 test_thread = kthread_run(event_test_thread, NULL, "test-events");
3961 kthread_stop(test_thread);
3965 * For every trace event defined, we will test each trace point separately,
3966 * and then by groups, and finally all trace points.
3968 static __init void event_trace_self_tests(void)
3970 struct trace_subsystem_dir *dir;
3971 struct trace_event_file *file;
3972 struct trace_event_call *call;
3973 struct event_subsystem *system;
3974 struct trace_array *tr;
3977 tr = top_trace_array();
3981 pr_info("Running tests on trace events:\n");
3983 list_for_each_entry(file, &tr->events, list) {
3985 call = file->event_call;
3987 /* Only test those that have a probe */
3988 if (!call->class || !call->class->probe)
3992 * Testing syscall events here is pretty useless, but
3993 * we still do it if configured. But this is time consuming.
3994 * What we really need is a user thread to perform the
3995 * syscalls as we test.
3997 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
3998 if (call->class->system &&
3999 strcmp(call->class->system, "syscalls") == 0)
4003 pr_info("Testing event %s: ", trace_event_name(call));
4006 * If an event is already enabled, someone is using
4007 * it and the self test should not be on.
4009 if (file->flags & EVENT_FILE_FL_ENABLED) {
4010 pr_warn("Enabled event during self test!\n");
4015 ftrace_event_enable_disable(file, 1);
4017 ftrace_event_enable_disable(file, 0);
4022 /* Now test at the sub system level */
4024 pr_info("Running tests on trace event systems:\n");
4026 list_for_each_entry(dir, &tr->systems, list) {
4028 system = dir->subsystem;
4030 /* the ftrace system is special, skip it */
4031 if (strcmp(system->name, "ftrace") == 0)
4034 pr_info("Testing event system %s: ", system->name);
4036 ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1);
4037 if (WARN_ON_ONCE(ret)) {
4038 pr_warn("error enabling system %s\n",
4045 ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0);
4046 if (WARN_ON_ONCE(ret)) {
4047 pr_warn("error disabling system %s\n",
4055 /* Test with all events enabled */
4057 pr_info("Running tests on all trace events:\n");
4058 pr_info("Testing all events: ");
4060 ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1);
4061 if (WARN_ON_ONCE(ret)) {
4062 pr_warn("error enabling all events\n");
4069 ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
4070 if (WARN_ON_ONCE(ret)) {
4071 pr_warn("error disabling all events\n");
4078 #ifdef CONFIG_FUNCTION_TRACER
4080 static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
4082 static struct trace_event_file event_trace_file __initdata;
4085 function_test_events_call(unsigned long ip, unsigned long parent_ip,
4086 struct ftrace_ops *op, struct ftrace_regs *regs)
4088 struct trace_buffer *buffer;
4089 struct ring_buffer_event *event;
4090 struct ftrace_entry *entry;
4091 unsigned int trace_ctx;
4095 trace_ctx = tracing_gen_ctx();
4096 preempt_disable_notrace();
4097 cpu = raw_smp_processor_id();
4098 disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
4103 event = trace_event_buffer_lock_reserve(&buffer, &event_trace_file,
4104 TRACE_FN, sizeof(*entry),
4108 entry = ring_buffer_event_data(event);
4110 entry->parent_ip = parent_ip;
4112 event_trigger_unlock_commit(&event_trace_file, buffer, event,
4115 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
4116 preempt_enable_notrace();
4119 static struct ftrace_ops trace_ops __initdata =
4121 .func = function_test_events_call,
4124 static __init void event_trace_self_test_with_function(void)
4128 event_trace_file.tr = top_trace_array();
4129 if (WARN_ON(!event_trace_file.tr))
4132 ret = register_ftrace_function(&trace_ops);
4133 if (WARN_ON(ret < 0)) {
4134 pr_info("Failed to enable function tracer for event tests\n");
4137 pr_info("Running tests again, along with the function tracer\n");
4138 event_trace_self_tests();
4139 unregister_ftrace_function(&trace_ops);
4142 static __init void event_trace_self_test_with_function(void)
4147 static __init int event_trace_self_tests_init(void)
4149 if (!tracing_selftest_disabled) {
4150 event_trace_self_tests();
4151 event_trace_self_test_with_function();
4157 late_initcall(event_trace_self_tests_init);