^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * event tracer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * - Added format output of fields of the trace point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This was based off of work by Tom Zanussi <tzanussi@gmail.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define pr_fmt(fmt) fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/tracefs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <trace/events/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <trace/syscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "trace_output.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #undef TRACE_SYSTEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define TRACE_SYSTEM "TRACE_SYSTEM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) DEFINE_MUTEX(event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) LIST_HEAD(ftrace_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static LIST_HEAD(ftrace_generic_fields);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static LIST_HEAD(ftrace_common_fields);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static bool eventdir_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct kmem_cache *field_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct kmem_cache *file_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static inline int system_refcount(struct event_subsystem *system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return system->ref_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static int system_refcount_inc(struct event_subsystem *system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return system->ref_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int system_refcount_dec(struct event_subsystem *system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return --system->ref_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Double loops, do not use break, only goto's work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define do_for_each_event_file(tr, file) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) list_for_each_entry(file, &tr->events, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define do_for_each_event_file_safe(tr, file) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct trace_event_file *___n; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) list_for_each_entry_safe(file, ___n, &tr->events, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define while_for_each_event_file() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static struct ftrace_event_field *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) __find_event_field(struct list_head *head, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct ftrace_event_field *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) list_for_each_entry(field, head, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (!strcmp(field->name, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct ftrace_event_field *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) trace_find_event_field(struct trace_event_call *call, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct ftrace_event_field *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) head = trace_get_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) field = __find_event_field(head, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) field = __find_event_field(&ftrace_generic_fields, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return __find_event_field(&ftrace_common_fields, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int __trace_define_field(struct list_head *head, const char *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) const char *name, int offset, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int is_signed, int filter_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct ftrace_event_field *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) field = kmem_cache_alloc(field_cachep, GFP_TRACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) field->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) field->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (filter_type == FILTER_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) field->filter_type = filter_assign_type(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) field->filter_type = filter_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) field->offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) field->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) field->is_signed = is_signed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) list_add(&field->link, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int trace_define_field(struct trace_event_call *call, const char *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) const char *name, int offset, int size, int is_signed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int filter_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (WARN_ON(!call->class))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) head = trace_get_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return __trace_define_field(head, type, name, offset, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) is_signed, filter_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) EXPORT_SYMBOL_GPL(trace_define_field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define __generic_field(type, item, filter_type) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret = __trace_define_field(&ftrace_generic_fields, #type, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #item, 0, 0, is_signed_type(type), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) filter_type); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (ret) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define __common_field(type, item) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ret = __trace_define_field(&ftrace_common_fields, #type, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) "common_" #item, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) offsetof(typeof(ent), item), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) sizeof(ent.item), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) is_signed_type(type), FILTER_OTHER); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ret) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int trace_define_generic_fields(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) __generic_field(int, CPU, FILTER_CPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) __generic_field(int, cpu, FILTER_CPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) __generic_field(char *, COMM, FILTER_COMM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) __generic_field(char *, comm, FILTER_COMM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int trace_define_common_fields(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct trace_entry ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) __common_field(unsigned short, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) __common_field(unsigned char, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) __common_field(unsigned char, preempt_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) __common_field(int, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void trace_destroy_fields(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct ftrace_event_field *field, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) head = trace_get_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) list_for_each_entry_safe(field, next, head, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) list_del(&field->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) kmem_cache_free(field_cachep, field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * run-time version of trace_event_get_offsets_<call>() that returns the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * accessible offset of trace fields excluding __dynamic_array bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int trace_event_get_offsets(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct ftrace_event_field *tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) head = trace_get_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * head->next points to the last field with the largest offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * since it was added last by trace_define_field()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) tail = list_first_entry(head, struct ftrace_event_field, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return tail->offset + tail->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int trace_event_raw_init(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) id = register_trace_event(&call->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) EXPORT_SYMBOL_GPL(trace_event_raw_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) bool trace_event_ignore_this_pid(struct trace_event_file *trace_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct trace_array *tr = trace_file->tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct trace_array_cpu *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) pid_list = rcu_dereference_raw(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) no_pid_list = rcu_dereference_raw(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!pid_list && !no_pid_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) data = this_cpu_ptr(tr->array_buffer.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return data->ignore_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) EXPORT_SYMBOL_GPL(trace_event_ignore_this_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct trace_event_file *trace_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned long len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct trace_event_call *event_call = trace_file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if ((trace_file->flags & EVENT_FILE_FL_PID_FILTER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) trace_event_ignore_this_pid(trace_file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) local_save_flags(fbuffer->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) fbuffer->pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * If CONFIG_PREEMPTION is enabled, then the tracepoint itself disables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * preemption (adding one to the preempt_count). Since we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * interested in the preempt_count at the time the tracepoint was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * hit, we need to subtract one to offset the increment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (IS_ENABLED(CONFIG_PREEMPTION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) fbuffer->pc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) fbuffer->trace_file = trace_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) fbuffer->event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) trace_event_buffer_lock_reserve(&fbuffer->buffer, trace_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) event_call->event.type, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) fbuffer->flags, fbuffer->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (!fbuffer->event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) fbuffer->regs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) fbuffer->entry = ring_buffer_event_data(fbuffer->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return fbuffer->entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) EXPORT_SYMBOL_GPL(trace_event_buffer_reserve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int trace_event_reg(struct trace_event_call *call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) enum trace_reg type, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct trace_event_file *file = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) WARN_ON(!(call->flags & TRACE_EVENT_FL_TRACEPOINT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) case TRACE_REG_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return tracepoint_probe_register(call->tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) call->class->probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) case TRACE_REG_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) tracepoint_probe_unregister(call->tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) call->class->probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #ifdef CONFIG_PERF_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) case TRACE_REG_PERF_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return tracepoint_probe_register(call->tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) call->class->perf_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) case TRACE_REG_PERF_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) tracepoint_probe_unregister(call->tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) call->class->perf_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) case TRACE_REG_PERF_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) case TRACE_REG_PERF_CLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) case TRACE_REG_PERF_ADD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) case TRACE_REG_PERF_DEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) EXPORT_SYMBOL_GPL(trace_event_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) void trace_event_enable_cmd_record(bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) do_for_each_event_file(tr, file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (!(file->flags & EVENT_FILE_FL_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) tracing_start_cmdline_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) tracing_stop_cmdline_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) } while_for_each_event_file();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) void trace_event_enable_tgid_record(bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) do_for_each_event_file(tr, file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (!(file->flags & EVENT_FILE_FL_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) tracing_start_tgid_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) set_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) tracing_stop_tgid_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) } while_for_each_event_file();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static int __ftrace_event_enable_disable(struct trace_event_file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) int enable, int soft_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct trace_event_call *call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct trace_array *tr = file->tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned long file_flags = file->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) int disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) switch (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * When soft_disable is set and enable is cleared, the sm_ref
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * reference counter is decremented. If it reaches 0, we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * to clear the SOFT_DISABLED flag but leave the event in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * state that it was. That is, if the event was enabled and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * is set we do not want the event to be enabled before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * clear the bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * When soft_disable is not set but the SOFT_MODE flag is,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * we do nothing. Do not disable the tracepoint, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * "soft enable"s (clearing the SOFT_DISABLED bit) wont work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (soft_disable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (atomic_dec_return(&file->sm_ref) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) disable = file->flags & EVENT_FILE_FL_SOFT_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) clear_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) disable = !(file->flags & EVENT_FILE_FL_SOFT_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (disable && (file->flags & EVENT_FILE_FL_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) clear_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (file->flags & EVENT_FILE_FL_RECORDED_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) tracing_stop_cmdline_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (file->flags & EVENT_FILE_FL_RECORDED_TGID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) tracing_stop_tgid_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) call->class->reg(call, TRACE_REG_UNREGISTER, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (file->flags & EVENT_FILE_FL_SOFT_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * When soft_disable is set and enable is set, we want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * register the tracepoint for the event, but leave the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * as is. That means, if the event was already enabled, we do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * nothing (but set SOFT_MODE). If the event is disabled, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * set SOFT_DISABLED before enabling the event tracepoint, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * it still seems to be disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (!soft_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (atomic_inc_return(&file->sm_ref) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) set_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (!(file->flags & EVENT_FILE_FL_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) bool cmd = false, tgid = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* Keep the event disabled, when going to SOFT_MODE. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (soft_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (tr->trace_flags & TRACE_ITER_RECORD_CMD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) cmd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) tracing_start_cmdline_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) set_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) tgid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) tracing_start_tgid_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) set_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) ret = call->class->reg(call, TRACE_REG_REGISTER, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) tracing_stop_cmdline_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (tgid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) tracing_stop_tgid_record();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) pr_info("event trace: Could not enable event "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) "%s\n", trace_event_name(call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) set_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /* WAS_ENABLED gets set but never cleared. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) set_bit(EVENT_FILE_FL_WAS_ENABLED_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /* Enable or disable use of trace_buffered_event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if ((file_flags & EVENT_FILE_FL_SOFT_DISABLED) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) (file->flags & EVENT_FILE_FL_SOFT_DISABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (file->flags & EVENT_FILE_FL_SOFT_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) trace_buffered_event_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) trace_buffered_event_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int trace_event_enable_disable(struct trace_event_file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) int enable, int soft_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return __ftrace_event_enable_disable(file, enable, soft_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static int ftrace_event_enable_disable(struct trace_event_file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return __ftrace_event_enable_disable(file, enable, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static void ftrace_clear_events(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) ftrace_event_enable_disable(file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) event_filter_pid_sched_process_exit(void *data, struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) pid_list = rcu_dereference_raw(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) trace_filter_add_remove_task(pid_list, NULL, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) pid_list = rcu_dereference_raw(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) trace_filter_add_remove_task(pid_list, NULL, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) event_filter_pid_sched_process_fork(void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct task_struct *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) trace_filter_add_remove_task(pid_list, self, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) trace_filter_add_remove_task(pid_list, self, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) void trace_event_follow_fork(struct trace_array *tr, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) register_trace_prio_sched_process_fork(event_filter_pid_sched_process_fork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) tr, INT_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) register_trace_prio_sched_process_free(event_filter_pid_sched_process_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) tr, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) unregister_trace_sched_process_free(event_filter_pid_sched_process_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) event_filter_pid_sched_switch_probe_pre(void *data, bool preempt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct task_struct *prev, struct task_struct *next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * Sched switch is funny, as we only want to ignore it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * in the notrace case if both prev and next should be ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ret = trace_ignore_this_task(NULL, no_pid_list, prev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) trace_ignore_this_task(NULL, no_pid_list, next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) this_cpu_write(tr->array_buffer.data->ignore_pid, ret ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) (trace_ignore_this_task(pid_list, NULL, prev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) trace_ignore_this_task(pid_list, NULL, next)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) event_filter_pid_sched_switch_probe_post(void *data, bool preempt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct task_struct *prev, struct task_struct *next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) this_cpu_write(tr->array_buffer.data->ignore_pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) trace_ignore_this_task(pid_list, no_pid_list, next));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) event_filter_pid_sched_wakeup_probe_pre(void *data, struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* Nothing to do if we are already tracing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (!this_cpu_read(tr->array_buffer.data->ignore_pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) this_cpu_write(tr->array_buffer.data->ignore_pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) trace_ignore_this_task(pid_list, no_pid_list, task));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) event_filter_pid_sched_wakeup_probe_post(void *data, struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) /* Nothing to do if we are not tracing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (this_cpu_read(tr->array_buffer.data->ignore_pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) no_pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* Set tracing if current is enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) this_cpu_write(tr->array_buffer.data->ignore_pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) trace_ignore_this_task(pid_list, no_pid_list, current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static void unregister_pid_events(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_pre, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_post, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) static void __ftrace_clear_event_pids(struct trace_array *tr, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) pid_list = rcu_dereference_protected(tr->filtered_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Make sure there's something to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (!pid_type_enabled(type, pid_list, no_pid_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!still_need_pid_events(type, pid_list, no_pid_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) unregister_pid_events(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) clear_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) per_cpu_ptr(tr->array_buffer.data, cpu)->ignore_pid = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (type & TRACE_PIDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) rcu_assign_pointer(tr->filtered_pids, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (type & TRACE_NO_PIDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) rcu_assign_pointer(tr->filtered_no_pids, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) /* Wait till all users are no longer using pid filtering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) tracepoint_synchronize_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if ((type & TRACE_PIDS) && pid_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) trace_free_pid_list(pid_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if ((type & TRACE_NO_PIDS) && no_pid_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) trace_free_pid_list(no_pid_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static void ftrace_clear_event_pids(struct trace_array *tr, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) __ftrace_clear_event_pids(tr, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static void __put_system(struct event_subsystem *system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) struct event_filter *filter = system->filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) WARN_ON_ONCE(system_refcount(system) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (system_refcount_dec(system))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) list_del(&system->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) kfree(filter->filter_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) kfree(filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) kfree_const(system->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) kfree(system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static void __get_system(struct event_subsystem *system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) WARN_ON_ONCE(system_refcount(system) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) system_refcount_inc(system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) static void __get_system_dir(struct trace_subsystem_dir *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) WARN_ON_ONCE(dir->ref_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) dir->ref_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) __get_system(dir->subsystem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) static void __put_system_dir(struct trace_subsystem_dir *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) WARN_ON_ONCE(dir->ref_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /* If the subsystem is about to be freed, the dir must be too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) __put_system(dir->subsystem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (!--dir->ref_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) kfree(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) static void put_system(struct trace_subsystem_dir *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) __put_system_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static void remove_subsystem(struct trace_subsystem_dir *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (!dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (!--dir->nr_events) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) tracefs_remove(dir->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) list_del(&dir->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) __put_system_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static void remove_event_file_dir(struct trace_event_file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) struct dentry *dir = file->dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) struct dentry *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) spin_lock(&dir->d_lock); /* probably unneeded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) list_for_each_entry(child, &dir->d_subdirs, d_child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (d_really_is_positive(child)) /* probably unneeded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) d_inode(child)->i_private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) spin_unlock(&dir->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) tracefs_remove(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) list_del(&file->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) remove_subsystem(file->system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) free_event_filter(file->filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) kmem_cache_free(file_cachep, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) const char *sub, const char *event, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) int eret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) name = trace_event_name(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (!name || !call->class || !call->class->reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (match &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) strcmp(match, name) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) strcmp(match, call->class->system) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (sub && strcmp(sub, call->class->system) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) if (event && strcmp(event, name) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) ret = ftrace_event_enable_disable(file, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) * Save the first error and return that. Some events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * may still have been enabled, but let the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * know that something went wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (ret && !eret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) eret = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) ret = eret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) const char *sub, const char *event, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) ret = __ftrace_set_clr_event_nolock(tr, match, sub, event, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) char *event = NULL, *sub = NULL, *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * The buf format can be <subsystem>:<event-name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * *:<event-name> means any event by that name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * :<event-name> is the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * <subsystem>:* means all events in that subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * <subsystem>: means the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * <name> (no ':') means all events in a subsystem with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * the name <name> or any event that matches <name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) match = strsep(&buf, ":");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) sub = match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) event = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) match = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (!strlen(sub) || strcmp(sub, "*") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) sub = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (!strlen(event) || strcmp(event, "*") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ret = __ftrace_set_clr_event(tr, match, sub, event, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) /* Put back the colon to allow this to be called again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) *(buf - 1) = ':';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * trace_set_clr_event - enable or disable an event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * @system: system name to match (NULL for any system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * @event: event name to match (NULL for all events, within system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) * @set: 1 to enable, 0 to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * This is a way for other parts of the kernel to enable or disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) * event recording.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) * Returns 0 on success, -EINVAL if the parameters do not match any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * registered events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) int trace_set_clr_event(const char *system, const char *event, int set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct trace_array *tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return __ftrace_set_clr_event(tr, NULL, system, event, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) EXPORT_SYMBOL_GPL(trace_set_clr_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * trace_array_set_clr_event - enable or disable an event for a trace array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * @tr: concerned trace array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) * @system: system name to match (NULL for any system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) * @event: event name to match (NULL for all events, within system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * @enable: true to enable, false to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * This is a way for other parts of the kernel to enable or disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * event recording.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * Returns 0 on success, -EINVAL if the parameters do not match any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * registered events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) int trace_array_set_clr_event(struct trace_array *tr, const char *system,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) const char *event, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) int set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) set = (enable == true) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return __ftrace_set_clr_event(tr, NULL, system, event, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) EXPORT_SYMBOL_GPL(trace_array_set_clr_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) /* 128 should be much more than enough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) #define EVENT_BUF_SIZE 127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) ftrace_event_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct trace_parser parser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) struct seq_file *m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) ssize_t read, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) ret = tracing_update_buffers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) read = trace_get_user(&parser, ubuf, cnt, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) if (read >= 0 && trace_parser_loaded((&parser))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) int set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (*parser.buffer == '!')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) ret = ftrace_set_clr_event(tr, parser.buffer + !set, set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) ret = read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) trace_parser_put(&parser);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) t_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) struct trace_event_file *file = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) (*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) list_for_each_entry_continue(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) * The ftrace subsystem is for showing formats only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * They can not be enabled or disabled via the event files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (call->class && call->class->reg &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) static void *t_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) loff_t l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) file = list_entry(&tr->events, struct trace_event_file, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) for (l = 0; l <= *pos; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) file = t_next(m, file, &l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) s_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) struct trace_event_file *file = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) (*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) list_for_each_entry_continue(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (file->flags & EVENT_FILE_FL_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) static void *s_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) loff_t l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) file = list_entry(&tr->events, struct trace_event_file, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) for (l = 0; l <= *pos; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) file = s_next(m, file, &l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static int t_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) struct trace_event_file *file = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) struct trace_event_call *call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) seq_printf(m, "%s:", call->class->system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) seq_printf(m, "%s\n", trace_event_name(call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) static void t_stop(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) __next(struct seq_file *m, void *v, loff_t *pos, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (type == TRACE_PIDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) return trace_pid_next(pid_list, v, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) p_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) return __next(m, v, pos, TRACE_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) np_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return __next(m, v, pos, TRACE_NO_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) static void *__start(struct seq_file *m, loff_t *pos, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) __acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) * Grab the mutex, to keep calls to p_next() having the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) * tr->filtered_pids as p_start() has.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) * If we just passed the tr->filtered_pids around, then RCU would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) * have been enough, but doing that makes things more complex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) rcu_read_lock_sched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (type == TRACE_PIDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) pid_list = rcu_dereference_sched(tr->filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) pid_list = rcu_dereference_sched(tr->filtered_no_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!pid_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) return trace_pid_start(pid_list, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) static void *p_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) __acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) return __start(m, pos, TRACE_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) static void *np_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) __acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) return __start(m, pos, TRACE_NO_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static void p_stop(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) __releases(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) rcu_read_unlock_sched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) char buf[4] = "0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) file = event_file_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) if (likely(file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) flags = file->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (flags & EVENT_FILE_FL_ENABLED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) !(flags & EVENT_FILE_FL_SOFT_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) strcpy(buf, "1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (flags & EVENT_FILE_FL_SOFT_DISABLED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) flags & EVENT_FILE_FL_SOFT_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) strcat(buf, "*");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) strcat(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) ret = tracing_update_buffers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) file = event_file_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (likely(file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) ret = ftrace_event_enable_disable(file, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) *ppos += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return ret ? ret : cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) const char set_to_char[4] = { '?', '0', '1', 'X' };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct trace_subsystem_dir *dir = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) struct event_subsystem *system = dir->subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) struct trace_array *tr = dir->tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) char buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) int set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if ((call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) !trace_event_name(call) || !call->class || !call->class->reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (system && strcmp(call->class->system, system->name) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) * We need to find out if all the events are set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * or if all events or cleared, or if we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * a mixture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) set |= (1 << !!(file->flags & EVENT_FILE_FL_ENABLED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) * If we have a mixture, no need to look further.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if (set == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) buf[0] = set_to_char[set];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) buf[1] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) struct trace_subsystem_dir *dir = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) struct event_subsystem *system = dir->subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) const char *name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) ret = tracing_update_buffers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) if (val != 0 && val != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) * Opening of "enable" adds a ref count to system,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) * so the name is safe to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) if (system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) name = system->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) ret = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) *ppos += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) FORMAT_HEADER = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) FORMAT_FIELD_SEPERATOR = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) FORMAT_PRINTFMT = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) static void *f_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct trace_event_call *call = event_file_data(m->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) struct list_head *common_head = &ftrace_common_fields;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) struct list_head *head = trace_get_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct list_head *node = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) (*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) switch ((unsigned long)v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) case FORMAT_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) node = common_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) case FORMAT_FIELD_SEPERATOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) node = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) case FORMAT_PRINTFMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) /* all done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) node = node->prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (node == common_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) return (void *)FORMAT_FIELD_SEPERATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) else if (node == head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) return (void *)FORMAT_PRINTFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) static int f_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) struct trace_event_call *call = event_file_data(m->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) struct ftrace_event_field *field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) const char *array_descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) switch ((unsigned long)v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) case FORMAT_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) seq_printf(m, "name: %s\n", trace_event_name(call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) seq_printf(m, "ID: %d\n", call->event.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) seq_puts(m, "format:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) case FORMAT_FIELD_SEPERATOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) case FORMAT_PRINTFMT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) seq_printf(m, "\nprint fmt: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) call->print_fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) field = list_entry(v, struct ftrace_event_field, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) * Smartly shows the array type(except dynamic array).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) * Normal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) * field:TYPE VAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) * If TYPE := TYPE[LEN], it is shown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) * field:TYPE VAR[LEN]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) array_descriptor = strchr(field->type, '[');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) if (str_has_prefix(field->type, "__data_loc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) array_descriptor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (!array_descriptor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) field->type, field->name, field->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) field->size, !!field->is_signed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) (int)(array_descriptor - field->type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) field->type, field->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) array_descriptor, field->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) field->size, !!field->is_signed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) static void *f_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) void *p = (void *)FORMAT_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) loff_t l = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) /* ->stop() is called even if ->start() fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (!event_file_data(m->private))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) while (l < *pos && p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) p = f_next(m, p, &l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) static void f_stop(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) static const struct seq_operations trace_format_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) .start = f_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) .next = f_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) .stop = f_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) .show = f_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) static int trace_format_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) struct seq_file *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) /* Do we want to hide event format files on tracefs lockdown? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) ret = seq_open(file, &trace_format_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) m->private = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) int id = (long)event_file_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) if (unlikely(!id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) len = sprintf(buf, "%d\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) struct trace_seq *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) int r = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) if (*ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) s = kmalloc(sizeof(*s), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) trace_seq_init(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) file = event_file_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) if (file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) print_event_filter(file, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) if (file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) r = simple_read_from_buffer(ubuf, cnt, ppos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) s->buffer, trace_seq_used(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) int err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) if (cnt >= PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) buf = memdup_user_nul(ubuf, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) if (IS_ERR(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) return PTR_ERR(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) file = event_file_data(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) if (file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) err = apply_event_filter(file, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) *ppos += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) static LIST_HEAD(event_subsystems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) static int subsystem_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) struct event_subsystem *system = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) struct trace_subsystem_dir *dir = NULL; /* Initialize for gcc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) if (tracing_is_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) /* Make sure the system still exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) mutex_lock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) list_for_each_entry(tr, &ftrace_trace_arrays, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) list_for_each_entry(dir, &tr->systems, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (dir == inode->i_private) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) /* Don't open systems with no events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) if (dir->nr_events) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) __get_system_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) system = dir->subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) goto exit_loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) exit_loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) mutex_unlock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (!system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) /* Some versions of gcc think dir can be uninitialized here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) WARN_ON(!dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) /* Still need to increment the ref count of the system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) if (trace_array_get(tr) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) put_system(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) ret = tracing_open_generic(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) put_system(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) static int system_tr_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) struct trace_subsystem_dir *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) struct trace_array *tr = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) /* Make a temporary dir that has no system but points to tr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) dir = kzalloc(sizeof(*dir), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) if (!dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) ret = tracing_open_generic_tr(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) kfree(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) dir->tr = tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) filp->private_data = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) static int subsystem_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) struct trace_subsystem_dir *dir = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) trace_array_put(dir->tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) * If dir->subsystem is NULL, then this is a temporary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) * descriptor that was made for a trace_array to enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) * all subsystems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) if (dir->subsystem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) put_system(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) kfree(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) struct trace_subsystem_dir *dir = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) struct event_subsystem *system = dir->subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) struct trace_seq *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) if (*ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) s = kmalloc(sizeof(*s), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) trace_seq_init(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) print_subsystem_event_filter(system, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) r = simple_read_from_buffer(ubuf, cnt, ppos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) s->buffer, trace_seq_used(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct trace_subsystem_dir *dir = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) if (cnt >= PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) buf = memdup_user_nul(ubuf, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (IS_ERR(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) return PTR_ERR(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) err = apply_subsystem_event_filter(dir, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) *ppos += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) int (*func)(struct trace_seq *s) = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) struct trace_seq *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) if (*ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) s = kmalloc(sizeof(*s), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) trace_seq_init(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) func(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) r = simple_read_from_buffer(ubuf, cnt, ppos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) s->buffer, trace_seq_used(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) static void ignore_task_cpu(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) struct trace_array *tr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) * This function is called by on_each_cpu() while the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) * event_mutex is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) pid_list = rcu_dereference_protected(tr->filtered_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) mutex_is_locked(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) mutex_is_locked(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) this_cpu_write(tr->array_buffer.data->ignore_pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) trace_ignore_this_task(pid_list, no_pid_list, current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) static void register_pid_events(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * Register a probe that is called before all other probes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * to set ignore_pid if next or prev do not match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) * Register a probe this is called after all other probes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) * to only keep ignore_pid set if next pid matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) tr, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) tr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) tr, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) tr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) tr, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) tr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_pre,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) tr, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_post,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) tr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) event_pid_write(struct file *filp, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) size_t cnt, loff_t *ppos, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) struct seq_file *m = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) struct trace_array *tr = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) struct trace_pid_list *filtered_pids = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) struct trace_pid_list *other_pids = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) ret = tracing_update_buffers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) if (type == TRACE_PIDS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) filtered_pids = rcu_dereference_protected(tr->filtered_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) other_pids = rcu_dereference_protected(tr->filtered_no_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) filtered_pids = rcu_dereference_protected(tr->filtered_no_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) other_pids = rcu_dereference_protected(tr->filtered_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) ret = trace_pid_write(filtered_pids, &pid_list, ubuf, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) if (type == TRACE_PIDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) rcu_assign_pointer(tr->filtered_pids, pid_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) rcu_assign_pointer(tr->filtered_no_pids, pid_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) set_bit(EVENT_FILE_FL_PID_FILTER_BIT, &file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if (filtered_pids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) tracepoint_synchronize_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) trace_free_pid_list(filtered_pids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) } else if (pid_list && !other_pids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) register_pid_events(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) * Ignoring of pids is done at task switch. But we have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) * check for those tasks that are currently running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) * Always do this in case a pid was appended or removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) on_each_cpu(ignore_task_cpu, tr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) *ppos += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) ftrace_event_pid_write(struct file *filp, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) return event_pid_write(filp, ubuf, cnt, ppos, TRACE_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) ftrace_event_npid_write(struct file *filp, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) size_t cnt, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) return event_pid_write(filp, ubuf, cnt, ppos, TRACE_NO_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) static int ftrace_event_avail_open(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) static int ftrace_event_set_open(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) static int ftrace_event_set_pid_open(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) static int ftrace_event_set_npid_open(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) static int ftrace_event_release(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) static const struct seq_operations show_event_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) .start = t_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) .next = t_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) .show = t_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) .stop = t_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) static const struct seq_operations show_set_event_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) .start = s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) .next = s_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) .show = t_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) .stop = t_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) static const struct seq_operations show_set_pid_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) .start = p_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) .next = p_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) .show = trace_pid_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) .stop = p_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) static const struct seq_operations show_set_no_pid_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) .start = np_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) .next = np_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) .show = trace_pid_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) .stop = p_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) static const struct file_operations ftrace_avail_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) .open = ftrace_event_avail_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) .release = seq_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) static const struct file_operations ftrace_set_event_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) .open = ftrace_event_set_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) .write = ftrace_event_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) .release = ftrace_event_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) static const struct file_operations ftrace_set_event_pid_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) .open = ftrace_event_set_pid_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) .write = ftrace_event_pid_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) .release = ftrace_event_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) static const struct file_operations ftrace_set_event_notrace_pid_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) .open = ftrace_event_set_npid_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) .write = ftrace_event_npid_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) .release = ftrace_event_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) static const struct file_operations ftrace_enable_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) .open = tracing_open_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) .read = event_enable_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) .write = event_enable_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) static const struct file_operations ftrace_event_format_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) .open = trace_format_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) .release = seq_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) static const struct file_operations ftrace_event_id_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) .read = event_id_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) static const struct file_operations ftrace_event_filter_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) .open = tracing_open_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) .read = event_filter_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) .write = event_filter_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) static const struct file_operations ftrace_subsystem_filter_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) .open = subsystem_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) .read = subsystem_filter_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) .write = subsystem_filter_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) .release = subsystem_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) static const struct file_operations ftrace_system_enable_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) .open = subsystem_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) .read = system_enable_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) .write = system_enable_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) .release = subsystem_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) static const struct file_operations ftrace_tr_enable_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) .open = system_tr_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) .read = system_enable_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) .write = system_enable_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) .release = subsystem_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) static const struct file_operations ftrace_show_header_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) .open = tracing_open_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) .read = show_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) ftrace_event_open(struct inode *inode, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) const struct seq_operations *seq_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) struct seq_file *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) ret = security_locked_down(LOCKDOWN_TRACEFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) ret = seq_open(file, seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) /* copy tr over to seq ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) m->private = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) static int ftrace_event_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) struct trace_array *tr = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) return seq_release(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) ftrace_event_avail_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) const struct seq_operations *seq_ops = &show_event_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) /* Checks for tracefs lockdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) return ftrace_event_open(inode, file, seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) ftrace_event_set_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) const struct seq_operations *seq_ops = &show_set_event_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) struct trace_array *tr = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) ret = tracing_check_open_get_tr(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) if ((file->f_mode & FMODE_WRITE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) (file->f_flags & O_TRUNC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) ftrace_clear_events(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) ret = ftrace_event_open(inode, file, seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) ftrace_event_set_pid_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) const struct seq_operations *seq_ops = &show_set_pid_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) struct trace_array *tr = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) ret = tracing_check_open_get_tr(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) if ((file->f_mode & FMODE_WRITE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) (file->f_flags & O_TRUNC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) ftrace_clear_event_pids(tr, TRACE_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) ret = ftrace_event_open(inode, file, seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) ftrace_event_set_npid_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) const struct seq_operations *seq_ops = &show_set_no_pid_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) struct trace_array *tr = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) ret = tracing_check_open_get_tr(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) if ((file->f_mode & FMODE_WRITE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) (file->f_flags & O_TRUNC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) ftrace_clear_event_pids(tr, TRACE_NO_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) ret = ftrace_event_open(inode, file, seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) static struct event_subsystem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) create_new_subsystem(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) struct event_subsystem *system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) /* need to create new entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) system = kmalloc(sizeof(*system), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) if (!system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) system->ref_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) /* Only allocate if dynamic (kprobes and modules) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) system->name = kstrdup_const(name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) if (!system->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) system->filter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) if (!system->filter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) list_add(&system->list, &event_subsystems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) return system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) kfree_const(system->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) kfree(system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) static struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) event_subsystem_dir(struct trace_array *tr, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) struct trace_event_file *file, struct dentry *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) struct trace_subsystem_dir *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) struct event_subsystem *system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) struct dentry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) /* First see if we did not already create this dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) list_for_each_entry(dir, &tr->systems, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) system = dir->subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) if (strcmp(system->name, name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) dir->nr_events++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) file->system = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) return dir->entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) /* Now see if the system itself exists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) list_for_each_entry(system, &event_subsystems, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) if (strcmp(system->name, name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) /* Reset system variable when not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) if (&system->list == &event_subsystems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) system = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) dir = kmalloc(sizeof(*dir), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (!dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (!system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) system = create_new_subsystem(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) if (!system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) __get_system(system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) dir->entry = tracefs_create_dir(name, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) if (!dir->entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) pr_warn("Failed to create system directory %s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) __put_system(system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) dir->tr = tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) dir->ref_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) dir->nr_events = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) dir->subsystem = system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) file->system = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) entry = tracefs_create_file("filter", 0644, dir->entry, dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) &ftrace_subsystem_filter_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) kfree(system->filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) system->filter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) pr_warn("Could not create tracefs '%s/filter' entry\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) trace_create_file("enable", 0644, dir->entry, dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) &ftrace_system_enable_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) list_add(&dir->list, &tr->systems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) return dir->entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) kfree(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) /* Only print this message if failed on memory allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) if (!dir || !system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) pr_warn("No memory to create event subsystem %s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) event_define_fields(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) * Other events may have the same class. Only update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) * the fields if they are not already defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) head = trace_get_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) if (list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) struct trace_event_fields *field = call->class->fields_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) unsigned int offset = sizeof(struct trace_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) for (; field->type; field++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) if (field->type == TRACE_FUNCTION_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) field->define_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) offset = ALIGN(offset, field->align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) ret = trace_define_field(call, field->type, field->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) offset, field->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) field->is_signed, field->filter_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) if (WARN_ON_ONCE(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) pr_err("error code is %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) offset += field->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) event_create_dir(struct dentry *parent, struct trace_event_file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) struct trace_event_call *call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) struct trace_array *tr = file->tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) struct dentry *d_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) * If the trace point header did not define TRACE_SYSTEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) * then the system would be called "TRACE_SYSTEM".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) d_events = event_subsystem_dir(tr, call->class->system, file, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) if (!d_events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) d_events = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) name = trace_event_name(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) file->dir = tracefs_create_dir(name, d_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) if (!file->dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) pr_warn("Could not create tracefs '%s' directory\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) trace_create_file("enable", 0644, file->dir, file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) &ftrace_enable_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) #ifdef CONFIG_PERF_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) if (call->event.type && call->class->reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) trace_create_file("id", 0444, file->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) (void *)(long)call->event.type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) &ftrace_event_id_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) ret = event_define_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) pr_warn("Could not initialize trace point events/%s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) * Only event directories that can be enabled should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) * triggers or filters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) trace_create_file("filter", 0644, file->dir, file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) &ftrace_event_filter_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) trace_create_file("trigger", 0644, file->dir, file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) &event_trigger_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) #ifdef CONFIG_HIST_TRIGGERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) trace_create_file("hist", 0444, file->dir, file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) &event_hist_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) #ifdef CONFIG_HIST_TRIGGERS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) trace_create_file("hist_debug", 0444, file->dir, file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) &event_hist_debug_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) trace_create_file("format", 0444, file->dir, call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) &ftrace_event_format_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) #ifdef CONFIG_TRACE_EVENT_INJECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) if (call->event.type && call->class->reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) trace_create_file("inject", 0200, file->dir, file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) &event_inject_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) static void remove_event_from_tracers(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) do_for_each_event_file_safe(tr, file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) if (file->event_call != call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) remove_event_file_dir(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) * The do_for_each_event_file_safe() is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) * a double loop. After finding the call for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) * trace_array, we use break to jump to the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) * trace_array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) } while_for_each_event_file();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) static void event_remove(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) do_for_each_event_file(tr, file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) if (file->event_call != call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) if (file->flags & EVENT_FILE_FL_WAS_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) tr->clear_trace = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) ftrace_event_enable_disable(file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) * The do_for_each_event_file() is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) * a double loop. After finding the call for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) * trace_array, we use break to jump to the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) * trace_array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) } while_for_each_event_file();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) if (call->event.funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) __unregister_trace_event(&call->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) remove_event_from_tracers(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) list_del(&call->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) static int event_init(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) name = trace_event_name(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) if (WARN_ON(!name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) if (call->class->raw_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) ret = call->class->raw_init(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) if (ret < 0 && ret != -ENOSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) pr_warn("Could not initialize trace events/%s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) __register_event(struct trace_event_call *call, struct module *mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) ret = event_init(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) list_add(&call->list, &ftrace_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) call->mod = mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) static char *eval_replace(char *ptr, struct trace_eval_map *map, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) int rlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) int elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) /* Find the length of the eval value as a string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) elen = snprintf(ptr, 0, "%ld", map->eval_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) /* Make sure there's enough room to replace the string with the value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) if (len < elen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) snprintf(ptr, elen + 1, "%ld", map->eval_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) /* Get the rest of the string of ptr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) rlen = strlen(ptr + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) memmove(ptr + elen, ptr + len, rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) /* Make sure we end the new string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) ptr[elen + rlen] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) return ptr + elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) static void update_event_printk(struct trace_event_call *call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) struct trace_eval_map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) int quote = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) int len = strlen(map->eval_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) for (ptr = call->print_fmt; *ptr; ptr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) if (*ptr == '\\') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) /* paranoid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) if (!*ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) if (*ptr == '"') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) quote ^= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) if (quote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) if (isdigit(*ptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) /* skip numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) /* Check for alpha chars like ULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) } while (isalnum(*ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) if (!*ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) * A number must have some kind of delimiter after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) * it, and we can ignore that too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) if (isalpha(*ptr) || *ptr == '_') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) if (strncmp(map->eval_string, ptr, len) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) !isalnum(ptr[len]) && ptr[len] != '_') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) ptr = eval_replace(ptr, map, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) /* enum/sizeof string smaller than value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) if (WARN_ON_ONCE(!ptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) * No need to decrement here, as eval_replace()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) * returns the pointer to the character passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) * the eval, and two evals can not be placed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) * back to back without something in between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) * We can skip that something in between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) skip_more:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) } while (isalnum(*ptr) || *ptr == '_');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) if (!*ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) * If what comes after this variable is a '.' or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) * '->' then we can continue to ignore that string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (*ptr == '.' || (ptr[0] == '-' && ptr[1] == '>')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) ptr += *ptr == '.' ? 1 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) if (!*ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) goto skip_more;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) * Once again, we can skip the delimiter that came
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) * after the string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) void trace_event_eval_update(struct trace_eval_map **map, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) struct trace_event_call *call, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) const char *last_system = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) bool first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) int last_i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) down_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) list_for_each_entry_safe(call, p, &ftrace_events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) /* events are usually grouped together with systems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) if (!last_system || call->class->system != last_system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) last_i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) last_system = call->class->system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) * Since calls are grouped by systems, the likelyhood that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) * next call in the iteration belongs to the same system as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) * previous call is high. As an optimization, we skip seaching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) * for a map[] that matches the call's system if the last call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) * was from the same system. That's what last_i is for. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) * call has the same system as the previous call, then last_i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) * will be the index of the first map[] that has a matching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) * system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) for (i = last_i; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) if (call->class->system == map[i]->system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) /* Save the first system if need be */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) last_i = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) update_event_printk(call, map[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) up_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) static struct trace_event_file *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) trace_create_new_event(struct trace_event_call *call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) struct trace_pid_list *no_pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) struct trace_pid_list *pid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) file = kmem_cache_alloc(file_cachep, GFP_TRACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) pid_list = rcu_dereference_protected(tr->filtered_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) lockdep_is_held(&event_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) if (pid_list || no_pid_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) file->flags |= EVENT_FILE_FL_PID_FILTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) file->event_call = call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) file->tr = tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) atomic_set(&file->sm_ref, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) atomic_set(&file->tm_ref, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) INIT_LIST_HEAD(&file->triggers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) list_add(&file->list, &tr->events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) /* Add an event to a trace directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) file = trace_create_new_event(call, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) if (eventdir_initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) return event_create_dir(tr->event_dir, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) return event_define_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) * Just create a decriptor for early init. A descriptor is required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) * for enabling events at boot. We want to enable events before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) * the filesystem is initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) __trace_early_add_new_event(struct trace_event_call *call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) file = trace_create_new_event(call, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) return event_define_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) struct ftrace_module_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) static void __add_event_to_tracers(struct trace_event_call *call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) /* Add an additional event_call dynamically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) int trace_add_event_call(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) mutex_lock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) ret = __register_event(call, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) __add_event_to_tracers(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) mutex_unlock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) * Must be called under locking of trace_types_lock, event_mutex and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) * trace_event_sem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) static void __trace_remove_event_call(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) event_remove(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) trace_destroy_fields(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) free_event_filter(call->filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) call->filter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) static int probe_remove_event_call(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) #ifdef CONFIG_PERF_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) if (call->perf_refcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) do_for_each_event_file(tr, file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) if (file->event_call != call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) * We can't rely on ftrace_event_enable_disable(enable => 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) * we are going to do, EVENT_FILE_FL_SOFT_MODE can suppress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) * TRACE_REG_UNREGISTER.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) if (file->flags & EVENT_FILE_FL_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) * The do_for_each_event_file_safe() is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) * a double loop. After finding the call for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) * trace_array, we use break to jump to the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) * trace_array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) } while_for_each_event_file();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) __trace_remove_event_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) /* Remove an event_call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) int trace_remove_event_call(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) mutex_lock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) down_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) ret = probe_remove_event_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) up_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) mutex_unlock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) #define for_each_event(event, start, end) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) for (event = start; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) (unsigned long)event < (unsigned long)end; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) event++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) #ifdef CONFIG_MODULES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) static void trace_module_add_events(struct module *mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) struct trace_event_call **call, **start, **end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) if (!mod->num_trace_events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) /* Don't add infrastructure for mods without tracepoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) if (trace_module_has_bad_taint(mod)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) pr_err("%s: module has bad taint, not creating trace events\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) mod->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) start = mod->trace_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) end = mod->trace_events + mod->num_trace_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) for_each_event(call, start, end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) __register_event(*call, mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) __add_event_to_tracers(*call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) static void trace_module_remove_events(struct module *mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) struct trace_event_call *call, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) down_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) list_for_each_entry_safe(call, p, &ftrace_events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) if (call->mod == mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) __trace_remove_event_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) up_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) * It is safest to reset the ring buffer if the module being unloaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) * registered any events that were used. The only worry is if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) * a new module gets loaded, and takes on the same id as the events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) * of this module. When printing out the buffer, traced events left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) * over from this module may be passed to the new module events and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) * unexpected results may occur.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) tracing_reset_all_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) static int trace_module_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) unsigned long val, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) struct module *mod = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) mutex_lock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) case MODULE_STATE_COMING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) trace_module_add_events(mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) case MODULE_STATE_GOING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) trace_module_remove_events(mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) mutex_unlock(&trace_types_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) static struct notifier_block trace_module_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) .notifier_call = trace_module_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) .priority = 1, /* higher than trace.c module notify */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) #endif /* CONFIG_MODULES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) /* Create a new event directory structure for a trace directory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) __trace_add_event_dirs(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) list_for_each_entry(call, &ftrace_events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) ret = __trace_add_new_event(call, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) pr_warn("Could not create directory for event %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) trace_event_name(call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) /* Returns any file that matches the system and event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) struct trace_event_file *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) __find_event_file(struct trace_array *tr, const char *system, const char *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) name = trace_event_name(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) if (!name || !call->class)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) if (strcmp(event, name) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) strcmp(system, call->class->system) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) /* Returns valid trace event files that match system and event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) struct trace_event_file *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) find_event_file(struct trace_array *tr, const char *system, const char *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) file = __find_event_file(tr, system, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) if (!file || !file->event_call->class->reg ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) file->event_call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) * trace_get_event_file - Find and return a trace event file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) * @instance: The name of the trace instance containing the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) * @system: The name of the system containing the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) * @event: The name of the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) * Return a trace event file given the trace instance name, trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) * system, and trace event name. If the instance name is NULL, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) * refers to the top-level trace array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) * This function will look it up and return it if found, after calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) * trace_array_get() to prevent the instance from going away, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) * increment the event's module refcount to prevent it from being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) * removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) * To release the file, call trace_put_event_file(), which will call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) * trace_array_put() and decrement the event's module refcount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) * Return: The trace event on success, ERR_PTR otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) struct trace_event_file *trace_get_event_file(const char *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) const char *system,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) const char *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) struct trace_array *tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) struct trace_event_file *file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) if (instance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) tr = trace_array_find_get(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) ret = trace_array_get(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) file = find_event_file(tr, system, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) if (!file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) /* Don't let event modules unload while in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) ret = try_module_get(file->event_call->mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) trace_array_put(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) file = ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) EXPORT_SYMBOL_GPL(trace_get_event_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) * trace_put_event_file - Release a file from trace_get_event_file()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) * @file: The trace event file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) * If a file was retrieved using trace_get_event_file(), this should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) * be called when it's no longer needed. It will cancel the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) * trace_array_get() called by that function, and decrement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) * event's module refcount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) void trace_put_event_file(struct trace_event_file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) module_put(file->event_call->mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) trace_array_put(file->tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) EXPORT_SYMBOL_GPL(trace_put_event_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) #ifdef CONFIG_DYNAMIC_FTRACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) /* Avoid typos */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) #define ENABLE_EVENT_STR "enable_event"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) #define DISABLE_EVENT_STR "disable_event"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) struct event_probe_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) unsigned long count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) int ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) bool enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) static void update_event_probe(struct event_probe_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) if (data->enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) event_enable_probe(unsigned long ip, unsigned long parent_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) struct trace_array *tr, struct ftrace_probe_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) struct ftrace_func_mapper *mapper = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) struct event_probe_data *edata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) void **pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) pdata = ftrace_func_mapper_find_ip(mapper, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) if (!pdata || !*pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) edata = *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) update_event_probe(edata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) struct trace_array *tr, struct ftrace_probe_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) struct ftrace_func_mapper *mapper = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) struct event_probe_data *edata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) void **pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) pdata = ftrace_func_mapper_find_ip(mapper, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) if (!pdata || !*pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) edata = *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) if (!edata->count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) /* Skip if the event is in a state we want to switch to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) if (edata->enable == !(edata->file->flags & EVENT_FILE_FL_SOFT_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) if (edata->count != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) (edata->count)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) update_event_probe(edata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) event_enable_print(struct seq_file *m, unsigned long ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) struct ftrace_probe_ops *ops, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) struct ftrace_func_mapper *mapper = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) struct event_probe_data *edata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) void **pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) pdata = ftrace_func_mapper_find_ip(mapper, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) if (WARN_ON_ONCE(!pdata || !*pdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) edata = *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) seq_printf(m, "%ps:", (void *)ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) seq_printf(m, "%s:%s:%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) edata->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) edata->file->event_call->class->system,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) trace_event_name(edata->file->event_call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) if (edata->count == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) seq_puts(m, ":unlimited\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) seq_printf(m, ":count=%ld\n", edata->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) event_enable_init(struct ftrace_probe_ops *ops, struct trace_array *tr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) unsigned long ip, void *init_data, void **data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) struct ftrace_func_mapper *mapper = *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) struct event_probe_data *edata = init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) if (!mapper) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) mapper = allocate_ftrace_func_mapper();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) if (!mapper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) *data = mapper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) ret = ftrace_func_mapper_add_ip(mapper, ip, edata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) edata->ref++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) static int free_probe_data(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) struct event_probe_data *edata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) edata->ref--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) if (!edata->ref) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) /* Remove the SOFT_MODE flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) __ftrace_event_enable_disable(edata->file, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) module_put(edata->file->event_call->mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) kfree(edata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) event_enable_free(struct ftrace_probe_ops *ops, struct trace_array *tr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) unsigned long ip, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) struct ftrace_func_mapper *mapper = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) struct event_probe_data *edata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) if (!ip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) if (!mapper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) free_ftrace_func_mapper(mapper, free_probe_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) edata = ftrace_func_mapper_remove_ip(mapper, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) if (WARN_ON_ONCE(!edata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) if (WARN_ON_ONCE(edata->ref <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) free_probe_data(edata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) static struct ftrace_probe_ops event_enable_probe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) .func = event_enable_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) .print = event_enable_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) .init = event_enable_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) .free = event_enable_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) static struct ftrace_probe_ops event_enable_count_probe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) .func = event_enable_count_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) .print = event_enable_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) .init = event_enable_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) .free = event_enable_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) static struct ftrace_probe_ops event_disable_probe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) .func = event_enable_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) .print = event_enable_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) .init = event_enable_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) .free = event_enable_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) static struct ftrace_probe_ops event_disable_count_probe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) .func = event_enable_count_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) .print = event_enable_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) .init = event_enable_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) .free = event_enable_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) event_enable_func(struct trace_array *tr, struct ftrace_hash *hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) char *glob, char *cmd, char *param, int enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) struct ftrace_probe_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) struct event_probe_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) const char *system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) const char *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) char *number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) bool enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) /* hash funcs only work with set_ftrace_filter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) if (!enabled || !param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) system = strsep(¶m, ":");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) if (!param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) event = strsep(¶m, ":");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) file = find_event_file(tr, system, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) if (glob[0] == '!') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) ret = unregister_ftrace_function_probe_func(glob+1, tr, ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) data->enable = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) data->count = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) data->file = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) if (!param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) goto out_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) number = strsep(¶m, ":");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) if (!strlen(number))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) * We use the callback data field (which is a pointer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) * as our counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) ret = kstrtoul(number, 0, &data->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) out_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) /* Don't let event modules unload while probe registered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) ret = try_module_get(file->event_call->mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) ret = __ftrace_event_enable_disable(file, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) ret = register_ftrace_function_probe(glob, tr, ops, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) * The above returns on success the # of functions enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) * but if it didn't find any functions it returns zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) * Consider no functions a failure too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) goto out_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) } else if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) goto out_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) /* Just return zero, not the number of enabled functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) out_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) __ftrace_event_enable_disable(file, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) module_put(file->event_call->mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) static struct ftrace_func_command event_enable_cmd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) .name = ENABLE_EVENT_STR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) .func = event_enable_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) static struct ftrace_func_command event_disable_cmd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) .name = DISABLE_EVENT_STR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) .func = event_enable_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) static __init int register_event_cmds(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) ret = register_ftrace_command(&event_enable_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) if (WARN_ON(ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) ret = register_ftrace_command(&event_disable_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) if (WARN_ON(ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) unregister_ftrace_command(&event_enable_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) static inline int register_event_cmds(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) #endif /* CONFIG_DYNAMIC_FTRACE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) * The top level array and trace arrays created by boot-time tracing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) * have already had its trace_event_file descriptors created in order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) * to allow for early events to be recorded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) * This function is called after the tracefs has been initialized,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) * and we now have to create the files associated to the events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) static void __trace_early_add_event_dirs(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) ret = event_create_dir(tr->event_dir, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) pr_warn("Could not create directory for event %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) trace_event_name(file->event_call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) * For early boot up, the top trace array and the trace arrays created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) * by boot-time tracing require to have a list of events that can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) * enabled. This must be done before the filesystem is set up in order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) * to allow events to be traced early.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) void __trace_early_add_events(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) list_for_each_entry(call, &ftrace_events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) /* Early boot up should not have any modules loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) if (WARN_ON_ONCE(call->mod))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) ret = __trace_early_add_new_event(call, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) pr_warn("Could not create early event %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) trace_event_name(call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) /* Remove the event directory structure for a trace directory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) __trace_remove_event_dirs(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) struct trace_event_file *file, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) list_for_each_entry_safe(file, next, &tr->events, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) remove_event_file_dir(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) static void __add_event_to_tracers(struct trace_event_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) list_for_each_entry(tr, &ftrace_trace_arrays, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) __trace_add_new_event(call, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) extern struct trace_event_call *__start_ftrace_events[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) extern struct trace_event_call *__stop_ftrace_events[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) static __init int setup_trace_event(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) ring_buffer_expanded = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) disable_tracing_selftest("running event tracing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) __setup("trace_event=", setup_trace_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) /* Expects to have event_mutex held when called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) struct dentry *d_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) struct dentry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) entry = tracefs_create_file("set_event", 0644, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) tr, &ftrace_set_event_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) pr_warn("Could not create tracefs 'set_event' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) d_events = tracefs_create_dir("events", parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) if (!d_events) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) pr_warn("Could not create tracefs 'events' directory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) entry = trace_create_file("enable", 0644, d_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) tr, &ftrace_tr_enable_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) pr_warn("Could not create tracefs 'enable' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) /* There are not as crucial, just warn if they are not created */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) entry = tracefs_create_file("set_event_pid", 0644, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) tr, &ftrace_set_event_pid_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) pr_warn("Could not create tracefs 'set_event_pid' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) entry = tracefs_create_file("set_event_notrace_pid", 0644, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) tr, &ftrace_set_event_notrace_pid_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) pr_warn("Could not create tracefs 'set_event_notrace_pid' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) /* ring buffer internal formats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) entry = trace_create_file("header_page", 0444, d_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) ring_buffer_print_page_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) &ftrace_show_header_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) pr_warn("Could not create tracefs 'header_page' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) entry = trace_create_file("header_event", 0444, d_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) ring_buffer_print_entry_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) &ftrace_show_header_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) pr_warn("Could not create tracefs 'header_event' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) tr->event_dir = d_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) * event_trace_add_tracer - add a instance of a trace_array to events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) * @parent: The parent dentry to place the files/directories for events in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) * @tr: The trace array associated with these events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) * When a new instance is created, it needs to set up its events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) * directory, as well as other files associated with events. It also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) * creates the event hierachry in the @parent/events directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) * Returns 0 on success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) * Must be called with event_mutex held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) ret = create_event_toplevel_files(parent, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) down_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) /* If tr already has the event list, it is initialized in early boot. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) if (unlikely(!list_empty(&tr->events)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) __trace_early_add_event_dirs(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) __trace_add_event_dirs(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) up_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) * The top trace array already had its file descriptors created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) * Now the files themselves need to be created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) static __init int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) early_event_add_tracer(struct dentry *parent, struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) mutex_lock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) ret = create_event_toplevel_files(parent, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) down_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) __trace_early_add_event_dirs(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) up_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) mutex_unlock(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) /* Must be called with event_mutex held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) int event_trace_del_tracer(struct trace_array *tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) /* Disable any event triggers and associated soft-disabled events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) clear_event_triggers(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) /* Clear the pid list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) __ftrace_clear_event_pids(tr, TRACE_PIDS | TRACE_NO_PIDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) /* Disable any running events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) /* Make sure no more events are being executed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) tracepoint_synchronize_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) down_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) __trace_remove_event_dirs(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) tracefs_remove(tr->event_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) up_write(&trace_event_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) tr->event_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) static __init int event_trace_memsetup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) file_cachep = KMEM_CACHE(trace_event_file, SLAB_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) static __init void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) early_enable_events(struct trace_array *tr, bool disable_first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) char *buf = bootup_event_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) char *token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) while (true) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) token = strsep(&buf, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) if (!token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) if (*token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) /* Restarting syscalls requires that we stop them first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) if (disable_first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) ftrace_set_clr_event(tr, token, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) ret = ftrace_set_clr_event(tr, token, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) pr_warn("Failed to enable trace event: %s\n", token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) /* Put back the comma to allow this to be called again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) if (buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) *(buf - 1) = ',';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) static __init int event_trace_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) struct trace_array *tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) struct trace_event_call **iter, *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) call = *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) ret = event_init(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) list_add(&call->list, &ftrace_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) * We need the top trace array to have a working set of trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) * points at early init, before the debug files and directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) * are created. Create the file entries now, and attach them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) * to the actual file dentries later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) __trace_early_add_events(tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) early_enable_events(tr, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) trace_printk_start_comm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) register_event_cmds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) register_trigger_cmds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) * event_trace_enable() is called from trace_event_init() first to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) * initialize events and perhaps start any events that are on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) * command line. Unfortunately, there are some events that will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) * start this early, like the system call tracepoints that need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) * to set the TIF_SYSCALL_TRACEPOINT flag of pid 1. But event_trace_enable()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) * is called before pid 1 starts, and this flag is never set, making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) * the syscall tracepoint never get reached, but the event is enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) * regardless (and not doing anything).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) static __init int event_trace_enable_again(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) early_enable_events(tr, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) early_initcall(event_trace_enable_again);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) /* Init fields which doesn't related to the tracefs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) static __init int event_trace_init_fields(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) if (trace_define_generic_fields())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) pr_warn("tracing: Failed to allocated generic fields");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) if (trace_define_common_fields())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) pr_warn("tracing: Failed to allocate common fields");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) __init int event_trace_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) struct dentry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) entry = tracefs_create_file("available_events", 0444, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) tr, &ftrace_avail_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) pr_warn("Could not create tracefs 'available_events' entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) ret = early_event_add_tracer(NULL, tr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) #ifdef CONFIG_MODULES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) ret = register_module_notifier(&trace_module_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) pr_warn("Failed to register trace events module notifier\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) eventdir_initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) void __init trace_event_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) event_trace_memsetup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) init_ftrace_syscalls();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) event_trace_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) event_trace_init_fields();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) #ifdef CONFIG_EVENT_TRACE_STARTUP_TEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) static DEFINE_SPINLOCK(test_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) static DEFINE_SPINLOCK(test_spinlock_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) static DEFINE_MUTEX(test_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) static __init void test_work(struct work_struct *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) spin_lock(&test_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) spin_lock_irq(&test_spinlock_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) spin_unlock_irq(&test_spinlock_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) spin_unlock(&test_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) mutex_lock(&test_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) mutex_unlock(&test_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) static __init int event_test_thread(void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) void *test_malloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) test_malloc = kmalloc(1234, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) if (!test_malloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) pr_info("failed to kmalloc\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) schedule_on_each_cpu(test_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) kfree(test_malloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) __set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) * Do various things that may trigger events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) static __init void event_test_stuff(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) struct task_struct *test_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) test_thread = kthread_run(event_test_thread, NULL, "test-events");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) kthread_stop(test_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) * For every trace event defined, we will test each trace point separately,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) * and then by groups, and finally all trace points.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) static __init void event_trace_self_tests(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) struct trace_subsystem_dir *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) struct trace_event_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) struct event_subsystem *system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) struct trace_array *tr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) if (!tr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) pr_info("Running tests on trace events:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) list_for_each_entry(file, &tr->events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) call = file->event_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) /* Only test those that have a probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) if (!call->class || !call->class->probe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) * Testing syscall events here is pretty useless, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) * we still do it if configured. But this is time consuming.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) * What we really need is a user thread to perform the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) * syscalls as we test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) if (call->class->system &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) strcmp(call->class->system, "syscalls") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) pr_info("Testing event %s: ", trace_event_name(call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) * If an event is already enabled, someone is using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) * it and the self test should not be on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) if (file->flags & EVENT_FILE_FL_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) pr_warn("Enabled event during self test!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) ftrace_event_enable_disable(file, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) event_test_stuff();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) ftrace_event_enable_disable(file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) pr_cont("OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) /* Now test at the sub system level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) pr_info("Running tests on trace event systems:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) list_for_each_entry(dir, &tr->systems, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) system = dir->subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) /* the ftrace system is special, skip it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) if (strcmp(system->name, "ftrace") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) pr_info("Testing event system %s: ", system->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) if (WARN_ON_ONCE(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) pr_warn("error enabling system %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) system->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) event_test_stuff();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) if (WARN_ON_ONCE(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) pr_warn("error disabling system %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) system->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) pr_cont("OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) /* Test with all events enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) pr_info("Running tests on all trace events:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) pr_info("Testing all events: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) if (WARN_ON_ONCE(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) pr_warn("error enabling all events\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) event_test_stuff();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) /* reset sysname */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) if (WARN_ON_ONCE(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) pr_warn("error disabling all events\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) pr_cont("OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) #ifdef CONFIG_FUNCTION_TRACER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) static struct trace_event_file event_trace_file __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) function_test_events_call(unsigned long ip, unsigned long parent_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) struct ftrace_ops *op, struct pt_regs *pt_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) struct trace_buffer *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) struct ring_buffer_event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) struct ftrace_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) long disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) int pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) pc = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) preempt_disable_notrace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) if (disabled != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) local_save_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) event = trace_event_buffer_lock_reserve(&buffer, &event_trace_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) TRACE_FN, sizeof(*entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) entry = ring_buffer_event_data(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) entry->ip = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) entry->parent_ip = parent_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) event_trigger_unlock_commit(&event_trace_file, buffer, event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) entry, flags, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) preempt_enable_notrace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) static struct ftrace_ops trace_ops __initdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) .func = function_test_events_call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) .flags = FTRACE_OPS_FL_RECURSION_SAFE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) static __init void event_trace_self_test_with_function(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) event_trace_file.tr = top_trace_array();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) if (WARN_ON(!event_trace_file.tr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) ret = register_ftrace_function(&trace_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) if (WARN_ON(ret < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) pr_info("Failed to enable function tracer for event tests\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) pr_info("Running tests again, along with the function tracer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) event_trace_self_tests();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) unregister_ftrace_function(&trace_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) static __init void event_trace_self_test_with_function(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) static __init int event_trace_self_tests_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) if (!tracing_selftest_disabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) event_trace_self_tests();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) event_trace_self_test_with_function();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) late_initcall(event_trace_self_tests_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) #endif