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