Steven Rostedt (VMware) | bcea3f9 | 2018-08-16 11:23:53 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 2 | /* |
| 3 | * trace_events_trigger - trace event triggers |
| 4 | * |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 5 | * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com> |
| 6 | */ |
| 7 | |
Steven Rostedt (VMware) | 17911ff | 2019-10-11 17:22:50 -0400 | [diff] [blame] | 8 | #include <linux/security.h> |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 9 | #include <linux/module.h> |
| 10 | #include <linux/ctype.h> |
| 11 | #include <linux/mutex.h> |
| 12 | #include <linux/slab.h> |
Ingo Molnar | b2d0910 | 2017-02-04 01:27:20 +0100 | [diff] [blame] | 13 | #include <linux/rculist.h> |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 14 | |
| 15 | #include "trace.h" |
| 16 | |
| 17 | static LIST_HEAD(trigger_commands); |
| 18 | static DEFINE_MUTEX(trigger_cmd_mutex); |
| 19 | |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame] | 20 | void trigger_data_free(struct event_trigger_data *data) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 21 | { |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 22 | if (data->cmd_ops->set_filter) |
| 23 | data->cmd_ops->set_filter(NULL, data, NULL); |
| 24 | |
Steven Rostedt (VMware) | e0a568d | 2018-08-09 15:31:48 -0400 | [diff] [blame] | 25 | /* make sure current triggers exit before free */ |
| 26 | tracepoint_synchronize_unregister(); |
| 27 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 28 | kfree(data); |
| 29 | } |
| 30 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 31 | /** |
| 32 | * event_triggers_call - Call triggers associated with a trace event |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 33 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 34 | * @rec: The trace entry for the event, NULL for unconditional invocation |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 35 | * |
| 36 | * For each trigger associated with an event, invoke the trigger |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 37 | * function registered with the associated trigger command. If rec is |
| 38 | * non-NULL, it means that the trigger requires further processing and |
| 39 | * shouldn't be unconditionally invoked. If rec is non-NULL and the |
| 40 | * trigger has a filter associated with it, rec will checked against |
| 41 | * the filter and if the record matches the trigger will be invoked. |
| 42 | * If the trigger is a 'post_trigger', meaning it shouldn't be invoked |
| 43 | * in any case until the current event is written, the trigger |
| 44 | * function isn't invoked but the bit associated with the deferred |
| 45 | * trigger is set in the return value. |
| 46 | * |
| 47 | * Returns an enum event_trigger_type value containing a set bit for |
| 48 | * any trigger that should be deferred, ETT_NONE if nothing to defer. |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 49 | * |
| 50 | * Called from tracepoint handlers (with rcu_read_lock_sched() held). |
| 51 | * |
| 52 | * Return: an enum event_trigger_type value containing a set bit for |
| 53 | * any trigger that should be deferred, ETT_NONE if nothing to defer. |
| 54 | */ |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 55 | enum event_trigger_type |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 56 | event_triggers_call(struct trace_event_file *file, |
| 57 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 58 | struct ring_buffer_event *event) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 59 | { |
| 60 | struct event_trigger_data *data; |
| 61 | enum event_trigger_type tt = ETT_NONE; |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 62 | struct event_filter *filter; |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 63 | |
| 64 | if (list_empty(&file->triggers)) |
| 65 | return tt; |
| 66 | |
| 67 | list_for_each_entry_rcu(data, &file->triggers, list) { |
Tom Zanussi | 104f281 | 2015-12-10 12:50:47 -0600 | [diff] [blame] | 68 | if (data->paused) |
| 69 | continue; |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 70 | if (!rec) { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 71 | data->ops->trigger(data, buffer, rec, event); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 72 | continue; |
| 73 | } |
Steven Rostedt (Red Hat) | 561a4fe | 2014-05-02 13:30:04 -0400 | [diff] [blame] | 74 | filter = rcu_dereference_sched(data->filter); |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 75 | if (filter && !filter_match_preds(filter, rec)) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 76 | continue; |
Steven Rostedt (Red Hat) | 353206f | 2016-02-22 15:55:09 -0500 | [diff] [blame] | 77 | if (event_command_post_trigger(data->cmd_ops)) { |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 78 | tt |= data->cmd_ops->trigger_type; |
| 79 | continue; |
| 80 | } |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 81 | data->ops->trigger(data, buffer, rec, event); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 82 | } |
| 83 | return tt; |
| 84 | } |
| 85 | EXPORT_SYMBOL_GPL(event_triggers_call); |
| 86 | |
| 87 | /** |
| 88 | * event_triggers_post_call - Call 'post_triggers' for a trace event |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 89 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 90 | * @tt: enum event_trigger_type containing a set bit for each trigger to invoke |
| 91 | * |
| 92 | * For each trigger associated with an event, invoke the trigger |
| 93 | * function registered with the associated trigger command, if the |
| 94 | * corresponding bit is set in the tt enum passed into this function. |
| 95 | * See @event_triggers_call for details on how those bits are set. |
| 96 | * |
| 97 | * Called from tracepoint handlers (with rcu_read_lock_sched() held). |
| 98 | */ |
| 99 | void |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 100 | event_triggers_post_call(struct trace_event_file *file, |
Steven Rostedt (VMware) | c94e45b | 2018-05-07 16:02:14 -0400 | [diff] [blame] | 101 | enum event_trigger_type tt) |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 102 | { |
| 103 | struct event_trigger_data *data; |
| 104 | |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 105 | list_for_each_entry_rcu(data, &file->triggers, list) { |
Tom Zanussi | 104f281 | 2015-12-10 12:50:47 -0600 | [diff] [blame] | 106 | if (data->paused) |
| 107 | continue; |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 108 | if (data->cmd_ops->trigger_type & tt) |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 109 | data->ops->trigger(data, NULL, NULL, NULL); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 110 | } |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 111 | } |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 112 | EXPORT_SYMBOL_GPL(event_triggers_post_call); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 113 | |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 114 | #define SHOW_AVAILABLE_TRIGGERS (void *)(1UL) |
| 115 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 116 | static void *trigger_next(struct seq_file *m, void *t, loff_t *pos) |
| 117 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 118 | struct trace_event_file *event_file = event_file_data(m->private); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 119 | |
Vasily Averin | 6722b23 | 2020-01-24 10:03:06 +0300 | [diff] [blame] | 120 | if (t == SHOW_AVAILABLE_TRIGGERS) { |
| 121 | (*pos)++; |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 122 | return NULL; |
Vasily Averin | 6722b23 | 2020-01-24 10:03:06 +0300 | [diff] [blame] | 123 | } |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 124 | return seq_list_next(t, &event_file->triggers, pos); |
| 125 | } |
| 126 | |
Tzvetomir Stoyanov (VMware) | 7491e2c | 2021-08-19 11:26:06 -0400 | [diff] [blame] | 127 | static bool check_user_trigger(struct trace_event_file *file) |
| 128 | { |
| 129 | struct event_trigger_data *data; |
| 130 | |
| 131 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 132 | if (data->flags & EVENT_TRIGGER_FL_PROBE) |
| 133 | continue; |
| 134 | return true; |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 139 | static void *trigger_start(struct seq_file *m, loff_t *pos) |
| 140 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 141 | struct trace_event_file *event_file; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 142 | |
| 143 | /* ->stop() is called even if ->start() fails */ |
| 144 | mutex_lock(&event_mutex); |
| 145 | event_file = event_file_data(m->private); |
| 146 | if (unlikely(!event_file)) |
| 147 | return ERR_PTR(-ENODEV); |
| 148 | |
Tzvetomir Stoyanov (VMware) | 7491e2c | 2021-08-19 11:26:06 -0400 | [diff] [blame] | 149 | if (list_empty(&event_file->triggers) || !check_user_trigger(event_file)) |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 150 | return *pos == 0 ? SHOW_AVAILABLE_TRIGGERS : NULL; |
| 151 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 152 | return seq_list_start(&event_file->triggers, *pos); |
| 153 | } |
| 154 | |
| 155 | static void trigger_stop(struct seq_file *m, void *t) |
| 156 | { |
| 157 | mutex_unlock(&event_mutex); |
| 158 | } |
| 159 | |
| 160 | static int trigger_show(struct seq_file *m, void *v) |
| 161 | { |
| 162 | struct event_trigger_data *data; |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 163 | struct event_command *p; |
| 164 | |
| 165 | if (v == SHOW_AVAILABLE_TRIGGERS) { |
| 166 | seq_puts(m, "# Available triggers:\n"); |
| 167 | seq_putc(m, '#'); |
| 168 | mutex_lock(&trigger_cmd_mutex); |
| 169 | list_for_each_entry_reverse(p, &trigger_commands, list) |
| 170 | seq_printf(m, " %s", p->name); |
| 171 | seq_putc(m, '\n'); |
| 172 | mutex_unlock(&trigger_cmd_mutex); |
| 173 | return 0; |
| 174 | } |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 175 | |
| 176 | data = list_entry(v, struct event_trigger_data, list); |
| 177 | data->ops->print(m, data->ops, data); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static const struct seq_operations event_triggers_seq_ops = { |
| 183 | .start = trigger_start, |
| 184 | .next = trigger_next, |
| 185 | .stop = trigger_stop, |
| 186 | .show = trigger_show, |
| 187 | }; |
| 188 | |
| 189 | static int event_trigger_regex_open(struct inode *inode, struct file *file) |
| 190 | { |
Steven Rostedt (VMware) | 17911ff | 2019-10-11 17:22:50 -0400 | [diff] [blame] | 191 | int ret; |
| 192 | |
| 193 | ret = security_locked_down(LOCKDOWN_TRACEFS); |
| 194 | if (ret) |
| 195 | return ret; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 196 | |
| 197 | mutex_lock(&event_mutex); |
| 198 | |
| 199 | if (unlikely(!event_file_data(file))) { |
| 200 | mutex_unlock(&event_mutex); |
| 201 | return -ENODEV; |
| 202 | } |
| 203 | |
Tom Zanussi | a88e1cf | 2015-12-10 12:50:49 -0600 | [diff] [blame] | 204 | if ((file->f_mode & FMODE_WRITE) && |
| 205 | (file->f_flags & O_TRUNC)) { |
| 206 | struct trace_event_file *event_file; |
| 207 | struct event_command *p; |
| 208 | |
| 209 | event_file = event_file_data(file); |
| 210 | |
| 211 | list_for_each_entry(p, &trigger_commands, list) { |
| 212 | if (p->unreg_all) |
| 213 | p->unreg_all(event_file); |
| 214 | } |
| 215 | } |
| 216 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 217 | if (file->f_mode & FMODE_READ) { |
| 218 | ret = seq_open(file, &event_triggers_seq_ops); |
| 219 | if (!ret) { |
| 220 | struct seq_file *m = file->private_data; |
| 221 | m->private = file; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | mutex_unlock(&event_mutex); |
| 226 | |
| 227 | return ret; |
| 228 | } |
| 229 | |
Masami Hiramatsu | 81a5955 | 2020-01-11 01:06:29 +0900 | [diff] [blame] | 230 | int trigger_process_regex(struct trace_event_file *file, char *buff) |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 231 | { |
Masami Hiramatsu | 6784bea | 2020-06-20 12:46:03 +0900 | [diff] [blame] | 232 | char *command, *next; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 233 | struct event_command *p; |
| 234 | int ret = -EINVAL; |
| 235 | |
Masami Hiramatsu | 6784bea | 2020-06-20 12:46:03 +0900 | [diff] [blame] | 236 | next = buff = skip_spaces(buff); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 237 | command = strsep(&next, ": \t"); |
Masami Hiramatsu | 6784bea | 2020-06-20 12:46:03 +0900 | [diff] [blame] | 238 | if (next) { |
| 239 | next = skip_spaces(next); |
| 240 | if (!*next) |
| 241 | next = NULL; |
| 242 | } |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 243 | command = (command[0] != '!') ? command : command + 1; |
| 244 | |
| 245 | mutex_lock(&trigger_cmd_mutex); |
| 246 | list_for_each_entry(p, &trigger_commands, list) { |
| 247 | if (strcmp(p->name, command) == 0) { |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 248 | ret = p->parse(p, file, buff, command, next); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 249 | goto out_unlock; |
| 250 | } |
| 251 | } |
| 252 | out_unlock: |
| 253 | mutex_unlock(&trigger_cmd_mutex); |
| 254 | |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | static ssize_t event_trigger_regex_write(struct file *file, |
| 259 | const char __user *ubuf, |
| 260 | size_t cnt, loff_t *ppos) |
| 261 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 262 | struct trace_event_file *event_file; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 263 | ssize_t ret; |
| 264 | char *buf; |
| 265 | |
| 266 | if (!cnt) |
| 267 | return 0; |
| 268 | |
| 269 | if (cnt >= PAGE_SIZE) |
| 270 | return -EINVAL; |
| 271 | |
Al Viro | 70f6cbb | 2015-12-24 00:13:10 -0500 | [diff] [blame] | 272 | buf = memdup_user_nul(ubuf, cnt); |
| 273 | if (IS_ERR(buf)) |
| 274 | return PTR_ERR(buf); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 275 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 276 | strim(buf); |
| 277 | |
| 278 | mutex_lock(&event_mutex); |
| 279 | event_file = event_file_data(file); |
| 280 | if (unlikely(!event_file)) { |
| 281 | mutex_unlock(&event_mutex); |
Al Viro | 70f6cbb | 2015-12-24 00:13:10 -0500 | [diff] [blame] | 282 | kfree(buf); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 283 | return -ENODEV; |
| 284 | } |
| 285 | ret = trigger_process_regex(event_file, buf); |
| 286 | mutex_unlock(&event_mutex); |
| 287 | |
Al Viro | 70f6cbb | 2015-12-24 00:13:10 -0500 | [diff] [blame] | 288 | kfree(buf); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 289 | if (ret < 0) |
| 290 | goto out; |
| 291 | |
| 292 | *ppos += cnt; |
| 293 | ret = cnt; |
| 294 | out: |
| 295 | return ret; |
| 296 | } |
| 297 | |
| 298 | static int event_trigger_regex_release(struct inode *inode, struct file *file) |
| 299 | { |
| 300 | mutex_lock(&event_mutex); |
| 301 | |
| 302 | if (file->f_mode & FMODE_READ) |
| 303 | seq_release(inode, file); |
| 304 | |
| 305 | mutex_unlock(&event_mutex); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static ssize_t |
| 311 | event_trigger_write(struct file *filp, const char __user *ubuf, |
| 312 | size_t cnt, loff_t *ppos) |
| 313 | { |
| 314 | return event_trigger_regex_write(filp, ubuf, cnt, ppos); |
| 315 | } |
| 316 | |
| 317 | static int |
| 318 | event_trigger_open(struct inode *inode, struct file *filp) |
| 319 | { |
Steven Rostedt (VMware) | 17911ff | 2019-10-11 17:22:50 -0400 | [diff] [blame] | 320 | /* Checks for tracefs lockdown */ |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 321 | return event_trigger_regex_open(inode, filp); |
| 322 | } |
| 323 | |
| 324 | static int |
| 325 | event_trigger_release(struct inode *inode, struct file *file) |
| 326 | { |
| 327 | return event_trigger_regex_release(inode, file); |
| 328 | } |
| 329 | |
| 330 | const struct file_operations event_trigger_fops = { |
| 331 | .open = event_trigger_open, |
| 332 | .read = seq_read, |
| 333 | .write = event_trigger_write, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 334 | .llseek = tracing_lseek, |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 335 | .release = event_trigger_release, |
| 336 | }; |
| 337 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 338 | /* |
| 339 | * Currently we only register event commands from __init, so mark this |
| 340 | * __init too. |
| 341 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame] | 342 | __init int register_event_command(struct event_command *cmd) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 343 | { |
| 344 | struct event_command *p; |
| 345 | int ret = 0; |
| 346 | |
| 347 | mutex_lock(&trigger_cmd_mutex); |
| 348 | list_for_each_entry(p, &trigger_commands, list) { |
| 349 | if (strcmp(cmd->name, p->name) == 0) { |
| 350 | ret = -EBUSY; |
| 351 | goto out_unlock; |
| 352 | } |
| 353 | } |
| 354 | list_add(&cmd->list, &trigger_commands); |
| 355 | out_unlock: |
| 356 | mutex_unlock(&trigger_cmd_mutex); |
| 357 | |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Currently we only unregister event commands from __init, so mark |
| 363 | * this __init too. |
| 364 | */ |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 365 | __init int unregister_event_command(struct event_command *cmd) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 366 | { |
| 367 | struct event_command *p, *n; |
| 368 | int ret = -ENODEV; |
| 369 | |
| 370 | mutex_lock(&trigger_cmd_mutex); |
| 371 | list_for_each_entry_safe(p, n, &trigger_commands, list) { |
| 372 | if (strcmp(cmd->name, p->name) == 0) { |
| 373 | ret = 0; |
| 374 | list_del_init(&p->list); |
| 375 | goto out_unlock; |
| 376 | } |
| 377 | } |
| 378 | out_unlock: |
| 379 | mutex_unlock(&trigger_cmd_mutex); |
| 380 | |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * event_trigger_print - Generic event_trigger_ops @print implementation |
| 386 | * @name: The name of the event trigger |
| 387 | * @m: The seq_file being printed to |
| 388 | * @data: Trigger-specific data |
| 389 | * @filter_str: filter_str to print, if present |
| 390 | * |
| 391 | * Common implementation for event triggers to print themselves. |
| 392 | * |
| 393 | * Usually wrapped by a function that simply sets the @name of the |
| 394 | * trigger command and then invokes this. |
| 395 | * |
| 396 | * Return: 0 on success, errno otherwise |
| 397 | */ |
| 398 | static int |
| 399 | event_trigger_print(const char *name, struct seq_file *m, |
| 400 | void *data, char *filter_str) |
| 401 | { |
| 402 | long count = (long)data; |
| 403 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 404 | seq_puts(m, name); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 405 | |
| 406 | if (count == -1) |
| 407 | seq_puts(m, ":unlimited"); |
| 408 | else |
| 409 | seq_printf(m, ":count=%ld", count); |
| 410 | |
| 411 | if (filter_str) |
| 412 | seq_printf(m, " if %s\n", filter_str); |
| 413 | else |
Rasmus Villemoes | 1177e43 | 2014-11-08 21:42:12 +0100 | [diff] [blame] | 414 | seq_putc(m, '\n'); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * event_trigger_init - Generic event_trigger_ops @init implementation |
| 421 | * @ops: The trigger ops associated with the trigger |
| 422 | * @data: Trigger-specific data |
| 423 | * |
| 424 | * Common implementation of event trigger initialization. |
| 425 | * |
| 426 | * Usually used directly as the @init method in event trigger |
| 427 | * implementations. |
| 428 | * |
| 429 | * Return: 0 on success, errno otherwise |
| 430 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame] | 431 | int event_trigger_init(struct event_trigger_ops *ops, |
| 432 | struct event_trigger_data *data) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 433 | { |
| 434 | data->ref++; |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * event_trigger_free - Generic event_trigger_ops @free implementation |
| 440 | * @ops: The trigger ops associated with the trigger |
| 441 | * @data: Trigger-specific data |
| 442 | * |
| 443 | * Common implementation of event trigger de-initialization. |
| 444 | * |
| 445 | * Usually used directly as the @free method in event trigger |
| 446 | * implementations. |
| 447 | */ |
| 448 | static void |
| 449 | event_trigger_free(struct event_trigger_ops *ops, |
| 450 | struct event_trigger_data *data) |
| 451 | { |
| 452 | if (WARN_ON_ONCE(data->ref <= 0)) |
| 453 | return; |
| 454 | |
| 455 | data->ref--; |
| 456 | if (!data->ref) |
| 457 | trigger_data_free(data); |
| 458 | } |
| 459 | |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame] | 460 | int trace_event_trigger_enable_disable(struct trace_event_file *file, |
| 461 | int trigger_enable) |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 462 | { |
| 463 | int ret = 0; |
| 464 | |
| 465 | if (trigger_enable) { |
| 466 | if (atomic_inc_return(&file->tm_ref) > 1) |
| 467 | return ret; |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 468 | set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 469 | ret = trace_event_enable_disable(file, 1, 1); |
| 470 | } else { |
| 471 | if (atomic_dec_return(&file->tm_ref) > 0) |
| 472 | return ret; |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 473 | clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 474 | ret = trace_event_enable_disable(file, 0, 1); |
| 475 | } |
| 476 | |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * clear_event_triggers - Clear all triggers associated with a trace array |
| 482 | * @tr: The trace array to clear |
| 483 | * |
| 484 | * For each trigger, the triggering event has its tm_ref decremented |
| 485 | * via trace_event_trigger_enable_disable(), and any associated event |
| 486 | * (in the case of enable/disable_event triggers) will have its sm_ref |
| 487 | * decremented via free()->trace_event_enable_disable(). That |
| 488 | * combination effectively reverses the soft-mode/trigger state added |
| 489 | * by trigger registration. |
| 490 | * |
| 491 | * Must be called with event_mutex held. |
| 492 | */ |
| 493 | void |
| 494 | clear_event_triggers(struct trace_array *tr) |
| 495 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 496 | struct trace_event_file *file; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 497 | |
| 498 | list_for_each_entry(file, &tr->events, list) { |
Steven Rostedt (VMware) | 86b389f | 2018-05-27 20:54:44 -0400 | [diff] [blame] | 499 | struct event_trigger_data *data, *n; |
| 500 | list_for_each_entry_safe(data, n, &file->triggers, list) { |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 501 | trace_event_trigger_enable_disable(file, 0); |
Steven Rostedt (VMware) | 86b389f | 2018-05-27 20:54:44 -0400 | [diff] [blame] | 502 | list_del_rcu(&data->list); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 503 | if (data->ops->free) |
| 504 | data->ops->free(data->ops, data); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 509 | /** |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 510 | * update_cond_flag - Set or reset the TRIGGER_COND bit |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 511 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 512 | * |
| 513 | * If an event has triggers and any of those triggers has a filter or |
| 514 | * a post_trigger, trigger invocation needs to be deferred until after |
| 515 | * the current event has logged its data, and the event should have |
| 516 | * its TRIGGER_COND bit set, otherwise the TRIGGER_COND bit should be |
| 517 | * cleared. |
| 518 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame] | 519 | void update_cond_flag(struct trace_event_file *file) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 520 | { |
| 521 | struct event_trigger_data *data; |
| 522 | bool set_cond = false; |
| 523 | |
Masami Hiramatsu | 3b42a4c | 2019-12-20 11:31:43 +0900 | [diff] [blame] | 524 | lockdep_assert_held(&event_mutex); |
| 525 | |
| 526 | list_for_each_entry(data, &file->triggers, list) { |
Steven Rostedt (Red Hat) | 353206f | 2016-02-22 15:55:09 -0500 | [diff] [blame] | 527 | if (data->filter || event_command_post_trigger(data->cmd_ops) || |
| 528 | event_command_needs_rec(data->cmd_ops)) { |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 529 | set_cond = true; |
| 530 | break; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | if (set_cond) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 535 | set_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 536 | else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 537 | clear_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /** |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 541 | * register_trigger - Generic event_command @reg implementation |
| 542 | * @glob: The raw string used to register the trigger |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 543 | * @data: Trigger-specific data to associate with the trigger |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 544 | * @file: The trace_event_file associated with the event |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 545 | * |
| 546 | * Common implementation for event trigger registration. |
| 547 | * |
| 548 | * Usually used directly as the @reg method in event command |
| 549 | * implementations. |
| 550 | * |
| 551 | * Return: 0 on success, errno otherwise |
| 552 | */ |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 553 | static int register_trigger(char *glob, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 554 | struct event_trigger_data *data, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 555 | struct trace_event_file *file) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 556 | { |
| 557 | struct event_trigger_data *test; |
| 558 | int ret = 0; |
| 559 | |
Masami Hiramatsu | 3b42a4c | 2019-12-20 11:31:43 +0900 | [diff] [blame] | 560 | lockdep_assert_held(&event_mutex); |
| 561 | |
| 562 | list_for_each_entry(test, &file->triggers, list) { |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 563 | if (test->cmd_ops->trigger_type == data->cmd_ops->trigger_type) { |
| 564 | ret = -EEXIST; |
| 565 | goto out; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if (data->ops->init) { |
| 570 | ret = data->ops->init(data->ops, data); |
| 571 | if (ret < 0) |
| 572 | goto out; |
| 573 | } |
| 574 | |
| 575 | list_add_rcu(&data->list, &file->triggers); |
| 576 | ret++; |
| 577 | |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 578 | update_cond_flag(file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 579 | if (trace_event_trigger_enable_disable(file, 1) < 0) { |
| 580 | list_del_rcu(&data->list); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 581 | update_cond_flag(file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 582 | ret--; |
| 583 | } |
| 584 | out: |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * unregister_trigger - Generic event_command @unreg implementation |
| 590 | * @glob: The raw string used to register the trigger |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 591 | * @test: Trigger-specific data used to find the trigger to remove |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 592 | * @file: The trace_event_file associated with the event |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 593 | * |
| 594 | * Common implementation for event trigger unregistration. |
| 595 | * |
| 596 | * Usually used directly as the @unreg method in event command |
| 597 | * implementations. |
| 598 | */ |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 599 | static void unregister_trigger(char *glob, |
Steven Rostedt (VMware) | f6b7425 | 2018-07-24 18:55:58 -0400 | [diff] [blame] | 600 | struct event_trigger_data *test, |
| 601 | struct trace_event_file *file) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 602 | { |
| 603 | struct event_trigger_data *data; |
| 604 | bool unregistered = false; |
| 605 | |
Masami Hiramatsu | 3b42a4c | 2019-12-20 11:31:43 +0900 | [diff] [blame] | 606 | lockdep_assert_held(&event_mutex); |
| 607 | |
| 608 | list_for_each_entry(data, &file->triggers, list) { |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 609 | if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) { |
| 610 | unregistered = true; |
| 611 | list_del_rcu(&data->list); |
| 612 | trace_event_trigger_enable_disable(file, 0); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 613 | update_cond_flag(file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 614 | break; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | if (unregistered && data->ops->free) |
| 619 | data->ops->free(data->ops, data); |
| 620 | } |
| 621 | |
Tom Zanussi | 86599db | 2022-01-10 08:04:14 -0600 | [diff] [blame] | 622 | /* |
| 623 | * Event trigger parsing helper functions. |
| 624 | * |
| 625 | * These functions help make it easier to write an event trigger |
| 626 | * parsing function i.e. the struct event_command.parse() callback |
| 627 | * function responsible for parsing and registering a trigger command |
| 628 | * written to the 'trigger' file. |
| 629 | * |
| 630 | * A trigger command (or just 'trigger' for short) takes the form: |
| 631 | * [trigger] [if filter] |
| 632 | * |
| 633 | * The struct event_command.parse() callback (and other struct |
| 634 | * event_command functions) refer to several components of a trigger |
| 635 | * command. Those same components are referenced by the event trigger |
| 636 | * parsing helper functions defined below. These components are: |
| 637 | * |
| 638 | * cmd - the trigger command name |
| 639 | * glob - the trigger command name optionally prefaced with '!' |
| 640 | * param_and_filter - text following cmd and ':' |
| 641 | * param - text following cmd and ':' and stripped of filter |
| 642 | * filter - the optional filter text following (and including) 'if' |
| 643 | * |
| 644 | * To illustrate the use of these componenents, here are some concrete |
| 645 | * examples. For the following triggers: |
| 646 | * |
| 647 | * echo 'traceon:5 if pid == 0' > trigger |
| 648 | * - 'traceon' is both cmd and glob |
| 649 | * - '5 if pid == 0' is the param_and_filter |
| 650 | * - '5' is the param |
| 651 | * - 'if pid == 0' is the filter |
| 652 | * |
| 653 | * echo 'enable_event:sys:event:n' > trigger |
| 654 | * - 'enable_event' is both cmd and glob |
| 655 | * - 'sys:event:n' is the param_and_filter |
| 656 | * - 'sys:event:n' is the param |
| 657 | * - there is no filter |
| 658 | * |
| 659 | * echo 'hist:keys=pid if prio > 50' > trigger |
| 660 | * - 'hist' is both cmd and glob |
| 661 | * - 'keys=pid if prio > 50' is the param_and_filter |
| 662 | * - 'keys=pid' is the param |
| 663 | * - 'if prio > 50' is the filter |
| 664 | * |
| 665 | * echo '!enable_event:sys:event:n' > trigger |
| 666 | * - 'enable_event' the cmd |
| 667 | * - '!enable_event' is the glob |
| 668 | * - 'sys:event:n' is the param_and_filter |
| 669 | * - 'sys:event:n' is the param |
| 670 | * - there is no filter |
| 671 | * |
| 672 | * echo 'traceoff' > trigger |
| 673 | * - 'traceoff' is both cmd and glob |
| 674 | * - there is no param_and_filter |
| 675 | * - there is no param |
| 676 | * - there is no filter |
| 677 | * |
| 678 | * There are a few different categories of event trigger covered by |
| 679 | * these helpers: |
| 680 | * |
| 681 | * - triggers that don't require a parameter e.g. traceon |
| 682 | * - triggers that do require a parameter e.g. enable_event and hist |
| 683 | * - triggers that though they may not require a param may support an |
| 684 | * optional 'n' param (n = number of times the trigger should fire) |
| 685 | * e.g.: traceon:5 or enable_event:sys:event:n |
| 686 | * - triggers that do not support an 'n' param e.g. hist |
| 687 | * |
| 688 | * These functions can be used or ignored as necessary - it all |
| 689 | * depends on the complexity of the trigger, and the granularity of |
| 690 | * the functions supported reflects the fact that some implementations |
| 691 | * may need to customize certain aspects of their implementations and |
| 692 | * won't need certain functions. For instance, the hist trigger |
| 693 | * implementation doesn't use event_trigger_separate_filter() because |
| 694 | * it has special requirements for handling the filter. |
| 695 | */ |
| 696 | |
| 697 | /** |
| 698 | * event_trigger_check_remove - check whether an event trigger specifies remove |
| 699 | * @glob: The trigger command string, with optional remove(!) operator |
| 700 | * |
| 701 | * The event trigger callback implementations pass in 'glob' as a |
| 702 | * parameter. This is the command name either with or without a |
| 703 | * remove(!) operator. This function simply parses the glob and |
| 704 | * determines whether the command corresponds to a trigger removal or |
| 705 | * a trigger addition. |
| 706 | * |
| 707 | * Return: true if this is a remove command, false otherwise |
| 708 | */ |
| 709 | bool event_trigger_check_remove(const char *glob) |
| 710 | { |
| 711 | return (glob && glob[0] == '!') ? true : false; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * event_trigger_empty_param - check whether the param is empty |
| 716 | * @param: The trigger param string |
| 717 | * |
| 718 | * The event trigger callback implementations pass in 'param' as a |
| 719 | * parameter. This corresponds to the string following the command |
| 720 | * name minus the command name. This function can be called by a |
| 721 | * callback implementation for any command that requires a param; a |
| 722 | * callback that doesn't require a param can ignore it. |
| 723 | * |
| 724 | * Return: true if this is an empty param, false otherwise |
| 725 | */ |
| 726 | bool event_trigger_empty_param(const char *param) |
| 727 | { |
| 728 | return !param; |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * event_trigger_separate_filter - separate an event trigger from a filter |
| 733 | * @param: The param string containing trigger and possibly filter |
| 734 | * @trigger: outparam, will be filled with a pointer to the trigger |
| 735 | * @filter: outparam, will be filled with a pointer to the filter |
| 736 | * @param_required: Specifies whether or not the param string is required |
| 737 | * |
| 738 | * Given a param string of the form '[trigger] [if filter]', this |
| 739 | * function separates the filter from the trigger and returns the |
| 740 | * trigger in *trigger and the filter in *filter. Either the *trigger |
| 741 | * or the *filter may be set to NULL by this function - if not set to |
| 742 | * NULL, they will contain strings corresponding to the trigger and |
| 743 | * filter. |
| 744 | * |
| 745 | * There are two cases that need to be handled with respect to the |
| 746 | * passed-in param: either the param is required, or it is not |
| 747 | * required. If @param_required is set, and there's no param, it will |
| 748 | * return -EINVAL. If @param_required is not set and there's a param |
| 749 | * that starts with a number, that corresponds to the case of a |
| 750 | * trigger with :n (n = number of times the trigger should fire) and |
| 751 | * the parsing continues normally; otherwise the function just returns |
| 752 | * and assumes param just contains a filter and there's nothing else |
| 753 | * to do. |
| 754 | * |
| 755 | * Return: 0 on success, errno otherwise |
| 756 | */ |
| 757 | int event_trigger_separate_filter(char *param_and_filter, char **param, |
| 758 | char **filter, bool param_required) |
| 759 | { |
| 760 | int ret = 0; |
| 761 | |
| 762 | *param = *filter = NULL; |
| 763 | |
| 764 | if (!param_and_filter) { |
| 765 | if (param_required) |
| 766 | ret = -EINVAL; |
| 767 | goto out; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * Here we check for an optional param. The only legal |
| 772 | * optional param is :n, and if that's the case, continue |
| 773 | * below. Otherwise we assume what's left is a filter and |
| 774 | * return it as the filter string for the caller to deal with. |
| 775 | */ |
| 776 | if (!param_required && param_and_filter && !isdigit(param_and_filter[0])) { |
| 777 | *filter = param_and_filter; |
| 778 | goto out; |
| 779 | } |
| 780 | |
| 781 | /* |
| 782 | * Separate the param from the filter (param [if filter]). |
| 783 | * Here we have either an optional :n param or a required |
| 784 | * param and an optional filter. |
| 785 | */ |
| 786 | *param = strsep(¶m_and_filter, " \t"); |
| 787 | |
| 788 | /* |
| 789 | * Here we have a filter, though it may be empty. |
| 790 | */ |
| 791 | if (param_and_filter) { |
| 792 | *filter = skip_spaces(param_and_filter); |
| 793 | if (!**filter) |
| 794 | *filter = NULL; |
| 795 | } |
| 796 | out: |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * event_trigger_alloc - allocate and init event_trigger_data for a trigger |
| 802 | * @cmd_ops: The event_command operations for the trigger |
| 803 | * @cmd: The cmd string |
| 804 | * @param: The param string |
| 805 | * @private_data: User data to associate with the event trigger |
| 806 | * |
| 807 | * Allocate an event_trigger_data instance and initialize it. The |
| 808 | * @cmd_ops are used along with the @cmd and @param to get the |
| 809 | * trigger_ops to assign to the event_trigger_data. @private_data can |
| 810 | * also be passed in and associated with the event_trigger_data. |
| 811 | * |
| 812 | * Use event_trigger_free() to free an event_trigger_data object. |
| 813 | * |
| 814 | * Return: The trigger_data object success, NULL otherwise |
| 815 | */ |
| 816 | struct event_trigger_data *event_trigger_alloc(struct event_command *cmd_ops, |
| 817 | char *cmd, |
| 818 | char *param, |
| 819 | void *private_data) |
| 820 | { |
| 821 | struct event_trigger_data *trigger_data; |
| 822 | struct event_trigger_ops *trigger_ops; |
| 823 | |
| 824 | trigger_ops = cmd_ops->get_trigger_ops(cmd, param); |
| 825 | |
| 826 | trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL); |
| 827 | if (!trigger_data) |
| 828 | return NULL; |
| 829 | |
| 830 | trigger_data->count = -1; |
| 831 | trigger_data->ops = trigger_ops; |
| 832 | trigger_data->cmd_ops = cmd_ops; |
| 833 | trigger_data->private_data = private_data; |
| 834 | |
| 835 | INIT_LIST_HEAD(&trigger_data->list); |
| 836 | INIT_LIST_HEAD(&trigger_data->named_list); |
| 837 | RCU_INIT_POINTER(trigger_data->filter, NULL); |
| 838 | |
| 839 | return trigger_data; |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * event_trigger_parse_num - parse and return the number param for a trigger |
| 844 | * @param: The param string |
| 845 | * @trigger_data: The trigger_data for the trigger |
| 846 | * |
| 847 | * Parse the :n (n = number of times the trigger should fire) param |
| 848 | * and set the count variable in the trigger_data to the parsed count. |
| 849 | * |
| 850 | * Return: 0 on success, errno otherwise |
| 851 | */ |
| 852 | int event_trigger_parse_num(char *param, |
| 853 | struct event_trigger_data *trigger_data) |
| 854 | { |
| 855 | char *number; |
| 856 | int ret = 0; |
| 857 | |
| 858 | if (param) { |
| 859 | number = strsep(¶m, ":"); |
| 860 | |
| 861 | if (!strlen(number)) |
| 862 | return -EINVAL; |
| 863 | |
| 864 | /* |
| 865 | * We use the callback data field (which is a pointer) |
| 866 | * as our counter. |
| 867 | */ |
| 868 | ret = kstrtoul(number, 0, &trigger_data->count); |
| 869 | } |
| 870 | |
| 871 | return ret; |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * event_trigger_set_filter - set an event trigger's filter |
| 876 | * @cmd_ops: The event_command operations for the trigger |
| 877 | * @file: The event file for the trigger's event |
| 878 | * @param: The string containing the filter |
| 879 | * @trigger_data: The trigger_data for the trigger |
| 880 | * |
| 881 | * Set the filter for the trigger. If the filter is NULL, just return |
| 882 | * without error. |
| 883 | * |
| 884 | * Return: 0 on success, errno otherwise |
| 885 | */ |
| 886 | int event_trigger_set_filter(struct event_command *cmd_ops, |
| 887 | struct trace_event_file *file, |
| 888 | char *param, |
| 889 | struct event_trigger_data *trigger_data) |
| 890 | { |
| 891 | if (param && cmd_ops->set_filter) |
| 892 | return cmd_ops->set_filter(param, trigger_data, file); |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * event_trigger_reset_filter - reset an event trigger's filter |
| 899 | * @cmd_ops: The event_command operations for the trigger |
| 900 | * @trigger_data: The trigger_data for the trigger |
| 901 | * |
| 902 | * Reset the filter for the trigger to no filter. |
| 903 | */ |
| 904 | void event_trigger_reset_filter(struct event_command *cmd_ops, |
| 905 | struct event_trigger_data *trigger_data) |
| 906 | { |
| 907 | if (cmd_ops->set_filter) |
| 908 | cmd_ops->set_filter(NULL, trigger_data, NULL); |
| 909 | } |
| 910 | |
| 911 | /** |
| 912 | * event_trigger_register - register an event trigger |
| 913 | * @cmd_ops: The event_command operations for the trigger |
| 914 | * @file: The event file for the trigger's event |
| 915 | * @glob: The trigger command string, with optional remove(!) operator |
| 916 | * @cmd: The cmd string |
| 917 | * @param: The param string |
| 918 | * @trigger_data: The trigger_data for the trigger |
| 919 | * @n_registered: optional outparam, the number of triggers registered |
| 920 | * |
| 921 | * Register an event trigger. The @cmd_ops are used to call the |
| 922 | * cmd_ops->reg() function which actually does the registration. The |
| 923 | * cmd_ops->reg() function returns the number of triggers registered, |
| 924 | * which is assigned to n_registered, if n_registered is non-NULL. |
| 925 | * |
| 926 | * Return: 0 on success, errno otherwise |
| 927 | */ |
| 928 | int event_trigger_register(struct event_command *cmd_ops, |
| 929 | struct trace_event_file *file, |
| 930 | char *glob, |
| 931 | char *cmd, |
| 932 | char *param, |
| 933 | struct event_trigger_data *trigger_data, |
| 934 | int *n_registered) |
| 935 | { |
| 936 | int ret; |
| 937 | |
| 938 | if (n_registered) |
| 939 | *n_registered = 0; |
| 940 | |
| 941 | ret = cmd_ops->reg(glob, trigger_data, file); |
| 942 | /* |
| 943 | * The above returns on success the # of functions enabled, |
| 944 | * but if it didn't find any functions it returns zero. |
| 945 | * Consider no functions a failure too. |
| 946 | */ |
| 947 | if (!ret) { |
| 948 | cmd_ops->unreg(glob, trigger_data, file); |
| 949 | ret = -ENOENT; |
| 950 | } else if (ret > 0) { |
| 951 | if (n_registered) |
| 952 | *n_registered = ret; |
| 953 | /* Just return zero, not the number of enabled functions */ |
| 954 | ret = 0; |
| 955 | } |
| 956 | |
| 957 | return ret; |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | * End event trigger parsing helper functions. |
| 962 | */ |
| 963 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 964 | /** |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 965 | * event_trigger_parse - Generic event_command @parse implementation |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 966 | * @cmd_ops: The command ops, used for trigger registration |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 967 | * @file: The trace_event_file associated with the event |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 968 | * @glob: The raw string used to register the trigger |
| 969 | * @cmd: The cmd portion of the string used to register the trigger |
| 970 | * @param: The params portion of the string used to register the trigger |
| 971 | * |
| 972 | * Common implementation for event command parsing and trigger |
| 973 | * instantiation. |
| 974 | * |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 975 | * Usually used directly as the @parse method in event command |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 976 | * implementations. |
| 977 | * |
| 978 | * Return: 0 on success, errno otherwise |
| 979 | */ |
| 980 | static int |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 981 | event_trigger_parse(struct event_command *cmd_ops, |
| 982 | struct trace_event_file *file, |
| 983 | char *glob, char *cmd, char *param) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 984 | { |
| 985 | struct event_trigger_data *trigger_data; |
| 986 | struct event_trigger_ops *trigger_ops; |
| 987 | char *trigger = NULL; |
| 988 | char *number; |
| 989 | int ret; |
| 990 | |
| 991 | /* separate the trigger from the filter (t:n [if filter]) */ |
Masami Hiramatsu | 6784bea | 2020-06-20 12:46:03 +0900 | [diff] [blame] | 992 | if (param && isdigit(param[0])) { |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 993 | trigger = strsep(¶m, " \t"); |
Masami Hiramatsu | 6784bea | 2020-06-20 12:46:03 +0900 | [diff] [blame] | 994 | if (param) { |
| 995 | param = skip_spaces(param); |
| 996 | if (!*param) |
| 997 | param = NULL; |
| 998 | } |
| 999 | } |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1000 | |
| 1001 | trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger); |
| 1002 | |
| 1003 | ret = -ENOMEM; |
| 1004 | trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL); |
| 1005 | if (!trigger_data) |
| 1006 | goto out; |
| 1007 | |
| 1008 | trigger_data->count = -1; |
| 1009 | trigger_data->ops = trigger_ops; |
| 1010 | trigger_data->cmd_ops = cmd_ops; |
Steven Rostedt (VMware) | 2824f50 | 2018-05-28 10:56:36 -0400 | [diff] [blame] | 1011 | trigger_data->private_data = file; |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1012 | INIT_LIST_HEAD(&trigger_data->list); |
Tom Zanussi | db1388b | 2016-03-03 12:54:58 -0600 | [diff] [blame] | 1013 | INIT_LIST_HEAD(&trigger_data->named_list); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1014 | |
| 1015 | if (glob[0] == '!') { |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1016 | cmd_ops->unreg(glob+1, trigger_data, file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1017 | kfree(trigger_data); |
| 1018 | ret = 0; |
| 1019 | goto out; |
| 1020 | } |
| 1021 | |
| 1022 | if (trigger) { |
| 1023 | number = strsep(&trigger, ":"); |
| 1024 | |
| 1025 | ret = -EINVAL; |
| 1026 | if (!strlen(number)) |
| 1027 | goto out_free; |
| 1028 | |
| 1029 | /* |
| 1030 | * We use the callback data field (which is a pointer) |
| 1031 | * as our counter. |
| 1032 | */ |
| 1033 | ret = kstrtoul(number, 0, &trigger_data->count); |
| 1034 | if (ret) |
| 1035 | goto out_free; |
| 1036 | } |
| 1037 | |
| 1038 | if (!param) /* if param is non-empty, it's supposed to be a filter */ |
| 1039 | goto out_reg; |
| 1040 | |
| 1041 | if (!cmd_ops->set_filter) |
| 1042 | goto out_reg; |
| 1043 | |
| 1044 | ret = cmd_ops->set_filter(param, trigger_data, file); |
| 1045 | if (ret < 0) |
| 1046 | goto out_free; |
| 1047 | |
| 1048 | out_reg: |
Steven Rostedt (VMware) | 1863c38 | 2018-07-24 19:13:31 -0400 | [diff] [blame] | 1049 | /* Up the trigger_data count to make sure reg doesn't free it on failure */ |
| 1050 | event_trigger_init(trigger_ops, trigger_data); |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1051 | ret = cmd_ops->reg(glob, trigger_data, file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1052 | /* |
| 1053 | * The above returns on success the # of functions enabled, |
| 1054 | * but if it didn't find any functions it returns zero. |
| 1055 | * Consider no functions a failure too. |
| 1056 | */ |
| 1057 | if (!ret) { |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1058 | cmd_ops->unreg(glob, trigger_data, file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1059 | ret = -ENOENT; |
Steven Rostedt (VMware) | 1863c38 | 2018-07-24 19:13:31 -0400 | [diff] [blame] | 1060 | } else if (ret > 0) |
| 1061 | ret = 0; |
| 1062 | |
| 1063 | /* Down the counter of trigger_data or free it if not used anymore */ |
| 1064 | event_trigger_free(trigger_ops, trigger_data); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1065 | out: |
| 1066 | return ret; |
| 1067 | |
| 1068 | out_free: |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1069 | if (cmd_ops->set_filter) |
| 1070 | cmd_ops->set_filter(NULL, trigger_data, NULL); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1071 | kfree(trigger_data); |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1075 | /** |
| 1076 | * set_trigger_filter - Generic event_command @set_filter implementation |
| 1077 | * @filter_str: The filter string for the trigger, NULL to remove filter |
| 1078 | * @trigger_data: Trigger-specific data |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1079 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1080 | * |
| 1081 | * Common implementation for event command filter parsing and filter |
| 1082 | * instantiation. |
| 1083 | * |
| 1084 | * Usually used directly as the @set_filter method in event command |
| 1085 | * implementations. |
| 1086 | * |
| 1087 | * Also used to remove a filter (if filter_str = NULL). |
| 1088 | * |
| 1089 | * Return: 0 on success, errno otherwise |
| 1090 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame] | 1091 | int set_trigger_filter(char *filter_str, |
| 1092 | struct event_trigger_data *trigger_data, |
| 1093 | struct trace_event_file *file) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1094 | { |
| 1095 | struct event_trigger_data *data = trigger_data; |
| 1096 | struct event_filter *filter = NULL, *tmp; |
| 1097 | int ret = -EINVAL; |
| 1098 | char *s; |
| 1099 | |
| 1100 | if (!filter_str) /* clear the current filter */ |
| 1101 | goto assign; |
| 1102 | |
| 1103 | s = strsep(&filter_str, " \t"); |
| 1104 | |
| 1105 | if (!strlen(s) || strcmp(s, "if") != 0) |
| 1106 | goto out; |
| 1107 | |
| 1108 | if (!filter_str) |
| 1109 | goto out; |
| 1110 | |
| 1111 | /* The filter is for the 'trigger' event, not the triggered event */ |
Steven Rostedt (VMware) | 1e144d7 | 2019-04-01 16:07:48 -0400 | [diff] [blame] | 1112 | ret = create_event_filter(file->tr, file->event_call, |
| 1113 | filter_str, false, &filter); |
Steven Rostedt (VMware) | 3cec638 | 2018-12-09 21:17:30 -0500 | [diff] [blame] | 1114 | /* |
| 1115 | * If create_event_filter() fails, filter still needs to be freed. |
| 1116 | * Which the calling code will do with data->filter. |
| 1117 | */ |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1118 | assign: |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 1119 | tmp = rcu_access_pointer(data->filter); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1120 | |
| 1121 | rcu_assign_pointer(data->filter, filter); |
| 1122 | |
| 1123 | if (tmp) { |
| 1124 | /* Make sure the call is done with the filter */ |
Steven Rostedt (VMware) | e0a568d | 2018-08-09 15:31:48 -0400 | [diff] [blame] | 1125 | tracepoint_synchronize_unregister(); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1126 | free_event_filter(tmp); |
| 1127 | } |
| 1128 | |
| 1129 | kfree(data->filter_str); |
| 1130 | data->filter_str = NULL; |
| 1131 | |
| 1132 | if (filter_str) { |
| 1133 | data->filter_str = kstrdup(filter_str, GFP_KERNEL); |
| 1134 | if (!data->filter_str) { |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 1135 | free_event_filter(rcu_access_pointer(data->filter)); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1136 | data->filter = NULL; |
| 1137 | ret = -ENOMEM; |
| 1138 | } |
| 1139 | } |
| 1140 | out: |
| 1141 | return ret; |
| 1142 | } |
| 1143 | |
Tom Zanussi | db1388b | 2016-03-03 12:54:58 -0600 | [diff] [blame] | 1144 | static LIST_HEAD(named_triggers); |
| 1145 | |
| 1146 | /** |
| 1147 | * find_named_trigger - Find the common named trigger associated with @name |
| 1148 | * @name: The name of the set of named triggers to find the common data for |
| 1149 | * |
| 1150 | * Named triggers are sets of triggers that share a common set of |
| 1151 | * trigger data. The first named trigger registered with a given name |
| 1152 | * owns the common trigger data that the others subsequently |
| 1153 | * registered with the same name will reference. This function |
| 1154 | * returns the common trigger data associated with that first |
| 1155 | * registered instance. |
| 1156 | * |
| 1157 | * Return: the common trigger data for the given named trigger on |
| 1158 | * success, NULL otherwise. |
| 1159 | */ |
| 1160 | struct event_trigger_data *find_named_trigger(const char *name) |
| 1161 | { |
| 1162 | struct event_trigger_data *data; |
| 1163 | |
| 1164 | if (!name) |
| 1165 | return NULL; |
| 1166 | |
| 1167 | list_for_each_entry(data, &named_triggers, named_list) { |
| 1168 | if (data->named_data) |
| 1169 | continue; |
| 1170 | if (strcmp(data->name, name) == 0) |
| 1171 | return data; |
| 1172 | } |
| 1173 | |
| 1174 | return NULL; |
| 1175 | } |
| 1176 | |
| 1177 | /** |
| 1178 | * is_named_trigger - determine if a given trigger is a named trigger |
| 1179 | * @test: The trigger data to test |
| 1180 | * |
| 1181 | * Return: true if 'test' is a named trigger, false otherwise. |
| 1182 | */ |
| 1183 | bool is_named_trigger(struct event_trigger_data *test) |
| 1184 | { |
| 1185 | struct event_trigger_data *data; |
| 1186 | |
| 1187 | list_for_each_entry(data, &named_triggers, named_list) { |
| 1188 | if (test == data) |
| 1189 | return true; |
| 1190 | } |
| 1191 | |
| 1192 | return false; |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * save_named_trigger - save the trigger in the named trigger list |
| 1197 | * @name: The name of the named trigger set |
| 1198 | * @data: The trigger data to save |
| 1199 | * |
| 1200 | * Return: 0 if successful, negative error otherwise. |
| 1201 | */ |
| 1202 | int save_named_trigger(const char *name, struct event_trigger_data *data) |
| 1203 | { |
| 1204 | data->name = kstrdup(name, GFP_KERNEL); |
| 1205 | if (!data->name) |
| 1206 | return -ENOMEM; |
| 1207 | |
| 1208 | list_add(&data->named_list, &named_triggers); |
| 1209 | |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * del_named_trigger - delete a trigger from the named trigger list |
| 1215 | * @data: The trigger data to delete |
| 1216 | */ |
| 1217 | void del_named_trigger(struct event_trigger_data *data) |
| 1218 | { |
| 1219 | kfree(data->name); |
| 1220 | data->name = NULL; |
| 1221 | |
| 1222 | list_del(&data->named_list); |
| 1223 | } |
| 1224 | |
| 1225 | static void __pause_named_trigger(struct event_trigger_data *data, bool pause) |
| 1226 | { |
| 1227 | struct event_trigger_data *test; |
| 1228 | |
| 1229 | list_for_each_entry(test, &named_triggers, named_list) { |
| 1230 | if (strcmp(test->name, data->name) == 0) { |
| 1231 | if (pause) { |
| 1232 | test->paused_tmp = test->paused; |
| 1233 | test->paused = true; |
| 1234 | } else { |
| 1235 | test->paused = test->paused_tmp; |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * pause_named_trigger - Pause all named triggers with the same name |
| 1243 | * @data: The trigger data of a named trigger to pause |
| 1244 | * |
| 1245 | * Pauses a named trigger along with all other triggers having the |
| 1246 | * same name. Because named triggers share a common set of data, |
| 1247 | * pausing only one is meaningless, so pausing one named trigger needs |
| 1248 | * to pause all triggers with the same name. |
| 1249 | */ |
| 1250 | void pause_named_trigger(struct event_trigger_data *data) |
| 1251 | { |
| 1252 | __pause_named_trigger(data, true); |
| 1253 | } |
| 1254 | |
| 1255 | /** |
| 1256 | * unpause_named_trigger - Un-pause all named triggers with the same name |
| 1257 | * @data: The trigger data of a named trigger to unpause |
| 1258 | * |
| 1259 | * Un-pauses a named trigger along with all other triggers having the |
| 1260 | * same name. Because named triggers share a common set of data, |
| 1261 | * unpausing only one is meaningless, so unpausing one named trigger |
| 1262 | * needs to unpause all triggers with the same name. |
| 1263 | */ |
| 1264 | void unpause_named_trigger(struct event_trigger_data *data) |
| 1265 | { |
| 1266 | __pause_named_trigger(data, false); |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * set_named_trigger_data - Associate common named trigger data |
Qiujun Huang | 099dcc1 | 2021-05-15 10:57:35 +0000 | [diff] [blame] | 1271 | * @data: The trigger data to associate |
| 1272 | * @named_data: The common named trigger to be associated |
Tom Zanussi | db1388b | 2016-03-03 12:54:58 -0600 | [diff] [blame] | 1273 | * |
| 1274 | * Named triggers are sets of triggers that share a common set of |
| 1275 | * trigger data. The first named trigger registered with a given name |
| 1276 | * owns the common trigger data that the others subsequently |
| 1277 | * registered with the same name will reference. This function |
| 1278 | * associates the common trigger data from the first trigger with the |
| 1279 | * given trigger. |
| 1280 | */ |
| 1281 | void set_named_trigger_data(struct event_trigger_data *data, |
| 1282 | struct event_trigger_data *named_data) |
| 1283 | { |
| 1284 | data->named_data = named_data; |
| 1285 | } |
| 1286 | |
Tom Zanussi | 067fe03 | 2018-01-15 20:51:56 -0600 | [diff] [blame] | 1287 | struct event_trigger_data * |
| 1288 | get_named_trigger_data(struct event_trigger_data *data) |
| 1289 | { |
| 1290 | return data->named_data; |
| 1291 | } |
| 1292 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1293 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1294 | traceon_trigger(struct event_trigger_data *data, |
| 1295 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1296 | struct ring_buffer_event *event) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1297 | { |
| 1298 | if (tracing_is_on()) |
| 1299 | return; |
| 1300 | |
| 1301 | tracing_on(); |
| 1302 | } |
| 1303 | |
| 1304 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1305 | traceon_count_trigger(struct event_trigger_data *data, |
| 1306 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1307 | struct ring_buffer_event *event) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1308 | { |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 1309 | if (tracing_is_on()) |
| 1310 | return; |
| 1311 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1312 | if (!data->count) |
| 1313 | return; |
| 1314 | |
| 1315 | if (data->count != -1) |
| 1316 | (data->count)--; |
| 1317 | |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 1318 | tracing_on(); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1322 | traceoff_trigger(struct event_trigger_data *data, |
| 1323 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1324 | struct ring_buffer_event *event) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1325 | { |
| 1326 | if (!tracing_is_on()) |
| 1327 | return; |
| 1328 | |
| 1329 | tracing_off(); |
| 1330 | } |
| 1331 | |
| 1332 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1333 | traceoff_count_trigger(struct event_trigger_data *data, |
| 1334 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1335 | struct ring_buffer_event *event) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1336 | { |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 1337 | if (!tracing_is_on()) |
| 1338 | return; |
| 1339 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1340 | if (!data->count) |
| 1341 | return; |
| 1342 | |
| 1343 | if (data->count != -1) |
| 1344 | (data->count)--; |
| 1345 | |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 1346 | tracing_off(); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static int |
| 1350 | traceon_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 1351 | struct event_trigger_data *data) |
| 1352 | { |
| 1353 | return event_trigger_print("traceon", m, (void *)data->count, |
| 1354 | data->filter_str); |
| 1355 | } |
| 1356 | |
| 1357 | static int |
| 1358 | traceoff_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 1359 | struct event_trigger_data *data) |
| 1360 | { |
| 1361 | return event_trigger_print("traceoff", m, (void *)data->count, |
| 1362 | data->filter_str); |
| 1363 | } |
| 1364 | |
| 1365 | static struct event_trigger_ops traceon_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1366 | .trigger = traceon_trigger, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1367 | .print = traceon_trigger_print, |
| 1368 | .init = event_trigger_init, |
| 1369 | .free = event_trigger_free, |
| 1370 | }; |
| 1371 | |
| 1372 | static struct event_trigger_ops traceon_count_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1373 | .trigger = traceon_count_trigger, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1374 | .print = traceon_trigger_print, |
| 1375 | .init = event_trigger_init, |
| 1376 | .free = event_trigger_free, |
| 1377 | }; |
| 1378 | |
| 1379 | static struct event_trigger_ops traceoff_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1380 | .trigger = traceoff_trigger, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1381 | .print = traceoff_trigger_print, |
| 1382 | .init = event_trigger_init, |
| 1383 | .free = event_trigger_free, |
| 1384 | }; |
| 1385 | |
| 1386 | static struct event_trigger_ops traceoff_count_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1387 | .trigger = traceoff_count_trigger, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1388 | .print = traceoff_trigger_print, |
| 1389 | .init = event_trigger_init, |
| 1390 | .free = event_trigger_free, |
| 1391 | }; |
| 1392 | |
| 1393 | static struct event_trigger_ops * |
| 1394 | onoff_get_trigger_ops(char *cmd, char *param) |
| 1395 | { |
| 1396 | struct event_trigger_ops *ops; |
| 1397 | |
| 1398 | /* we register both traceon and traceoff to this callback */ |
| 1399 | if (strcmp(cmd, "traceon") == 0) |
| 1400 | ops = param ? &traceon_count_trigger_ops : |
| 1401 | &traceon_trigger_ops; |
| 1402 | else |
| 1403 | ops = param ? &traceoff_count_trigger_ops : |
| 1404 | &traceoff_trigger_ops; |
| 1405 | |
| 1406 | return ops; |
| 1407 | } |
| 1408 | |
| 1409 | static struct event_command trigger_traceon_cmd = { |
| 1410 | .name = "traceon", |
| 1411 | .trigger_type = ETT_TRACE_ONOFF, |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1412 | .parse = event_trigger_parse, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1413 | .reg = register_trigger, |
| 1414 | .unreg = unregister_trigger, |
| 1415 | .get_trigger_ops = onoff_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1416 | .set_filter = set_trigger_filter, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1417 | }; |
| 1418 | |
| 1419 | static struct event_command trigger_traceoff_cmd = { |
| 1420 | .name = "traceoff", |
| 1421 | .trigger_type = ETT_TRACE_ONOFF, |
Masami Hiramatsu | a0d0c62 | 2016-09-09 01:05:45 +0900 | [diff] [blame] | 1422 | .flags = EVENT_CMD_FL_POST_TRIGGER, |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1423 | .parse = event_trigger_parse, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1424 | .reg = register_trigger, |
| 1425 | .unreg = unregister_trigger, |
| 1426 | .get_trigger_ops = onoff_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1427 | .set_filter = set_trigger_filter, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1428 | }; |
| 1429 | |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1430 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 1431 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1432 | snapshot_trigger(struct event_trigger_data *data, |
| 1433 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1434 | struct ring_buffer_event *event) |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1435 | { |
Steven Rostedt (VMware) | 2824f50 | 2018-05-28 10:56:36 -0400 | [diff] [blame] | 1436 | struct trace_event_file *file = data->private_data; |
| 1437 | |
| 1438 | if (file) |
| 1439 | tracing_snapshot_instance(file->tr); |
| 1440 | else |
| 1441 | tracing_snapshot(); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1445 | snapshot_count_trigger(struct event_trigger_data *data, |
| 1446 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1447 | struct ring_buffer_event *event) |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1448 | { |
| 1449 | if (!data->count) |
| 1450 | return; |
| 1451 | |
| 1452 | if (data->count != -1) |
| 1453 | (data->count)--; |
| 1454 | |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1455 | snapshot_trigger(data, buffer, rec, event); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | static int |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1459 | register_snapshot_trigger(char *glob, |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1460 | struct event_trigger_data *data, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1461 | struct trace_event_file *file) |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1462 | { |
Xiao Yang | 0bbe7f7 | 2020-04-14 09:51:45 +0800 | [diff] [blame] | 1463 | if (tracing_alloc_snapshot_instance(file->tr) != 0) |
| 1464 | return 0; |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1465 | |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1466 | return register_trigger(glob, data, file); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static int |
| 1470 | snapshot_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 1471 | struct event_trigger_data *data) |
| 1472 | { |
| 1473 | return event_trigger_print("snapshot", m, (void *)data->count, |
| 1474 | data->filter_str); |
| 1475 | } |
| 1476 | |
| 1477 | static struct event_trigger_ops snapshot_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1478 | .trigger = snapshot_trigger, |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1479 | .print = snapshot_trigger_print, |
| 1480 | .init = event_trigger_init, |
| 1481 | .free = event_trigger_free, |
| 1482 | }; |
| 1483 | |
| 1484 | static struct event_trigger_ops snapshot_count_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1485 | .trigger = snapshot_count_trigger, |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1486 | .print = snapshot_trigger_print, |
| 1487 | .init = event_trigger_init, |
| 1488 | .free = event_trigger_free, |
| 1489 | }; |
| 1490 | |
| 1491 | static struct event_trigger_ops * |
| 1492 | snapshot_get_trigger_ops(char *cmd, char *param) |
| 1493 | { |
| 1494 | return param ? &snapshot_count_trigger_ops : &snapshot_trigger_ops; |
| 1495 | } |
| 1496 | |
| 1497 | static struct event_command trigger_snapshot_cmd = { |
| 1498 | .name = "snapshot", |
| 1499 | .trigger_type = ETT_SNAPSHOT, |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1500 | .parse = event_trigger_parse, |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1501 | .reg = register_snapshot_trigger, |
| 1502 | .unreg = unregister_trigger, |
| 1503 | .get_trigger_ops = snapshot_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1504 | .set_filter = set_trigger_filter, |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1505 | }; |
| 1506 | |
| 1507 | static __init int register_trigger_snapshot_cmd(void) |
| 1508 | { |
| 1509 | int ret; |
| 1510 | |
| 1511 | ret = register_event_command(&trigger_snapshot_cmd); |
| 1512 | WARN_ON(ret < 0); |
| 1513 | |
| 1514 | return ret; |
| 1515 | } |
| 1516 | #else |
| 1517 | static __init int register_trigger_snapshot_cmd(void) { return 0; } |
| 1518 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 1519 | |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1520 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (VMware) | 2ee5b92 | 2018-01-23 13:25:04 -0500 | [diff] [blame] | 1521 | #ifdef CONFIG_UNWINDER_ORC |
| 1522 | /* Skip 2: |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1523 | * event_triggers_post_call() |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 1524 | * trace_event_raw_event_xxx() |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1525 | */ |
Steven Rostedt (VMware) | 2ee5b92 | 2018-01-23 13:25:04 -0500 | [diff] [blame] | 1526 | # define STACK_SKIP 2 |
| 1527 | #else |
| 1528 | /* |
| 1529 | * Skip 4: |
| 1530 | * stacktrace_trigger() |
| 1531 | * event_triggers_post_call() |
| 1532 | * trace_event_buffer_commit() |
| 1533 | * trace_event_raw_event_xxx() |
| 1534 | */ |
| 1535 | #define STACK_SKIP 4 |
| 1536 | #endif |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1537 | |
| 1538 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1539 | stacktrace_trigger(struct event_trigger_data *data, |
| 1540 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1541 | struct ring_buffer_event *event) |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1542 | { |
| 1543 | trace_dump_stack(STACK_SKIP); |
| 1544 | } |
| 1545 | |
| 1546 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1547 | stacktrace_count_trigger(struct event_trigger_data *data, |
| 1548 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1549 | struct ring_buffer_event *event) |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1550 | { |
| 1551 | if (!data->count) |
| 1552 | return; |
| 1553 | |
| 1554 | if (data->count != -1) |
| 1555 | (data->count)--; |
| 1556 | |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1557 | stacktrace_trigger(data, buffer, rec, event); |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static int |
| 1561 | stacktrace_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 1562 | struct event_trigger_data *data) |
| 1563 | { |
| 1564 | return event_trigger_print("stacktrace", m, (void *)data->count, |
| 1565 | data->filter_str); |
| 1566 | } |
| 1567 | |
| 1568 | static struct event_trigger_ops stacktrace_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1569 | .trigger = stacktrace_trigger, |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1570 | .print = stacktrace_trigger_print, |
| 1571 | .init = event_trigger_init, |
| 1572 | .free = event_trigger_free, |
| 1573 | }; |
| 1574 | |
| 1575 | static struct event_trigger_ops stacktrace_count_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1576 | .trigger = stacktrace_count_trigger, |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1577 | .print = stacktrace_trigger_print, |
| 1578 | .init = event_trigger_init, |
| 1579 | .free = event_trigger_free, |
| 1580 | }; |
| 1581 | |
| 1582 | static struct event_trigger_ops * |
| 1583 | stacktrace_get_trigger_ops(char *cmd, char *param) |
| 1584 | { |
| 1585 | return param ? &stacktrace_count_trigger_ops : &stacktrace_trigger_ops; |
| 1586 | } |
| 1587 | |
| 1588 | static struct event_command trigger_stacktrace_cmd = { |
| 1589 | .name = "stacktrace", |
| 1590 | .trigger_type = ETT_STACKTRACE, |
Steven Rostedt (Red Hat) | 353206f | 2016-02-22 15:55:09 -0500 | [diff] [blame] | 1591 | .flags = EVENT_CMD_FL_POST_TRIGGER, |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1592 | .parse = event_trigger_parse, |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1593 | .reg = register_trigger, |
| 1594 | .unreg = unregister_trigger, |
| 1595 | .get_trigger_ops = stacktrace_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1596 | .set_filter = set_trigger_filter, |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1597 | }; |
| 1598 | |
| 1599 | static __init int register_trigger_stacktrace_cmd(void) |
| 1600 | { |
| 1601 | int ret; |
| 1602 | |
| 1603 | ret = register_event_command(&trigger_stacktrace_cmd); |
| 1604 | WARN_ON(ret < 0); |
| 1605 | |
| 1606 | return ret; |
| 1607 | } |
| 1608 | #else |
| 1609 | static __init int register_trigger_stacktrace_cmd(void) { return 0; } |
| 1610 | #endif /* CONFIG_STACKTRACE */ |
| 1611 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1612 | static __init void unregister_trigger_traceon_traceoff_cmds(void) |
| 1613 | { |
| 1614 | unregister_event_command(&trigger_traceon_cmd); |
| 1615 | unregister_event_command(&trigger_traceoff_cmd); |
| 1616 | } |
| 1617 | |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1618 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1619 | event_enable_trigger(struct event_trigger_data *data, |
| 1620 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1621 | struct ring_buffer_event *event) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1622 | { |
| 1623 | struct enable_trigger_data *enable_data = data->private_data; |
| 1624 | |
| 1625 | if (enable_data->enable) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1626 | clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1627 | else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1628 | set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | static void |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1632 | event_enable_count_trigger(struct event_trigger_data *data, |
| 1633 | struct trace_buffer *buffer, void *rec, |
Tom Zanussi | 1ac4f51 | 2018-01-15 20:51:42 -0600 | [diff] [blame] | 1634 | struct ring_buffer_event *event) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1635 | { |
| 1636 | struct enable_trigger_data *enable_data = data->private_data; |
| 1637 | |
| 1638 | if (!data->count) |
| 1639 | return; |
| 1640 | |
| 1641 | /* Skip if the event is in a state we want to switch to */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1642 | if (enable_data->enable == !(enable_data->file->flags & EVENT_FILE_FL_SOFT_DISABLED)) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1643 | return; |
| 1644 | |
| 1645 | if (data->count != -1) |
| 1646 | (data->count)--; |
| 1647 | |
Steven Rostedt (VMware) | b47e330 | 2021-03-16 12:41:03 -0400 | [diff] [blame] | 1648 | event_enable_trigger(data, buffer, rec, event); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1649 | } |
| 1650 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1651 | int event_enable_trigger_print(struct seq_file *m, |
| 1652 | struct event_trigger_ops *ops, |
| 1653 | struct event_trigger_data *data) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1654 | { |
| 1655 | struct enable_trigger_data *enable_data = data->private_data; |
| 1656 | |
| 1657 | seq_printf(m, "%s:%s:%s", |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1658 | enable_data->hist ? |
| 1659 | (enable_data->enable ? ENABLE_HIST_STR : DISABLE_HIST_STR) : |
| 1660 | (enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR), |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1661 | enable_data->file->event_call->class->system, |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1662 | trace_event_name(enable_data->file->event_call)); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1663 | |
| 1664 | if (data->count == -1) |
| 1665 | seq_puts(m, ":unlimited"); |
| 1666 | else |
| 1667 | seq_printf(m, ":count=%ld", data->count); |
| 1668 | |
| 1669 | if (data->filter_str) |
| 1670 | seq_printf(m, " if %s\n", data->filter_str); |
| 1671 | else |
Rasmus Villemoes | 1177e43 | 2014-11-08 21:42:12 +0100 | [diff] [blame] | 1672 | seq_putc(m, '\n'); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1673 | |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1677 | void event_enable_trigger_free(struct event_trigger_ops *ops, |
| 1678 | struct event_trigger_data *data) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1679 | { |
| 1680 | struct enable_trigger_data *enable_data = data->private_data; |
| 1681 | |
| 1682 | if (WARN_ON_ONCE(data->ref <= 0)) |
| 1683 | return; |
| 1684 | |
| 1685 | data->ref--; |
| 1686 | if (!data->ref) { |
| 1687 | /* Remove the SOFT_MODE flag */ |
| 1688 | trace_event_enable_disable(enable_data->file, 0, 1); |
Steven Rostedt (VMware) | 1d18538 | 2021-08-16 23:42:57 -0400 | [diff] [blame] | 1689 | trace_event_put_ref(enable_data->file->event_call); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1690 | trigger_data_free(data); |
| 1691 | kfree(enable_data); |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | static struct event_trigger_ops event_enable_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1696 | .trigger = event_enable_trigger, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1697 | .print = event_enable_trigger_print, |
| 1698 | .init = event_trigger_init, |
| 1699 | .free = event_enable_trigger_free, |
| 1700 | }; |
| 1701 | |
| 1702 | static struct event_trigger_ops event_enable_count_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1703 | .trigger = event_enable_count_trigger, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1704 | .print = event_enable_trigger_print, |
| 1705 | .init = event_trigger_init, |
| 1706 | .free = event_enable_trigger_free, |
| 1707 | }; |
| 1708 | |
| 1709 | static struct event_trigger_ops event_disable_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1710 | .trigger = event_enable_trigger, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1711 | .print = event_enable_trigger_print, |
| 1712 | .init = event_trigger_init, |
| 1713 | .free = event_enable_trigger_free, |
| 1714 | }; |
| 1715 | |
| 1716 | static struct event_trigger_ops event_disable_count_trigger_ops = { |
Tom Zanussi | fb339e5 | 2022-01-10 08:04:12 -0600 | [diff] [blame] | 1717 | .trigger = event_enable_count_trigger, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1718 | .print = event_enable_trigger_print, |
| 1719 | .init = event_trigger_init, |
| 1720 | .free = event_enable_trigger_free, |
| 1721 | }; |
| 1722 | |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1723 | int event_enable_trigger_parse(struct event_command *cmd_ops, |
| 1724 | struct trace_event_file *file, |
| 1725 | char *glob, char *cmd, char *param) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1726 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1727 | struct trace_event_file *event_enable_file; |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1728 | struct enable_trigger_data *enable_data; |
| 1729 | struct event_trigger_data *trigger_data; |
| 1730 | struct event_trigger_ops *trigger_ops; |
| 1731 | struct trace_array *tr = file->tr; |
| 1732 | const char *system; |
| 1733 | const char *event; |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1734 | bool hist = false; |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1735 | char *trigger; |
| 1736 | char *number; |
| 1737 | bool enable; |
| 1738 | int ret; |
| 1739 | |
| 1740 | if (!param) |
| 1741 | return -EINVAL; |
| 1742 | |
| 1743 | /* separate the trigger from the filter (s:e:n [if filter]) */ |
| 1744 | trigger = strsep(¶m, " \t"); |
| 1745 | if (!trigger) |
| 1746 | return -EINVAL; |
Masami Hiramatsu | 6784bea | 2020-06-20 12:46:03 +0900 | [diff] [blame] | 1747 | if (param) { |
| 1748 | param = skip_spaces(param); |
| 1749 | if (!*param) |
| 1750 | param = NULL; |
| 1751 | } |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1752 | |
| 1753 | system = strsep(&trigger, ":"); |
| 1754 | if (!trigger) |
| 1755 | return -EINVAL; |
| 1756 | |
| 1757 | event = strsep(&trigger, ":"); |
| 1758 | |
| 1759 | ret = -EINVAL; |
| 1760 | event_enable_file = find_event_file(tr, system, event); |
| 1761 | if (!event_enable_file) |
| 1762 | goto out; |
| 1763 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1764 | #ifdef CONFIG_HIST_TRIGGERS |
| 1765 | hist = ((strcmp(cmd, ENABLE_HIST_STR) == 0) || |
| 1766 | (strcmp(cmd, DISABLE_HIST_STR) == 0)); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1767 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1768 | enable = ((strcmp(cmd, ENABLE_EVENT_STR) == 0) || |
| 1769 | (strcmp(cmd, ENABLE_HIST_STR) == 0)); |
| 1770 | #else |
| 1771 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; |
| 1772 | #endif |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1773 | trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger); |
| 1774 | |
| 1775 | ret = -ENOMEM; |
| 1776 | trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL); |
| 1777 | if (!trigger_data) |
| 1778 | goto out; |
| 1779 | |
| 1780 | enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL); |
| 1781 | if (!enable_data) { |
| 1782 | kfree(trigger_data); |
| 1783 | goto out; |
| 1784 | } |
| 1785 | |
| 1786 | trigger_data->count = -1; |
| 1787 | trigger_data->ops = trigger_ops; |
| 1788 | trigger_data->cmd_ops = cmd_ops; |
| 1789 | INIT_LIST_HEAD(&trigger_data->list); |
| 1790 | RCU_INIT_POINTER(trigger_data->filter, NULL); |
| 1791 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1792 | enable_data->hist = hist; |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1793 | enable_data->enable = enable; |
| 1794 | enable_data->file = event_enable_file; |
| 1795 | trigger_data->private_data = enable_data; |
| 1796 | |
| 1797 | if (glob[0] == '!') { |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1798 | cmd_ops->unreg(glob+1, trigger_data, file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1799 | kfree(trigger_data); |
| 1800 | kfree(enable_data); |
| 1801 | ret = 0; |
| 1802 | goto out; |
| 1803 | } |
| 1804 | |
Steven Rostedt (VMware) | 15cc786 | 2018-07-25 16:02:06 -0400 | [diff] [blame] | 1805 | /* Up the trigger_data count to make sure nothing frees it on failure */ |
| 1806 | event_trigger_init(trigger_ops, trigger_data); |
| 1807 | |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1808 | if (trigger) { |
| 1809 | number = strsep(&trigger, ":"); |
| 1810 | |
| 1811 | ret = -EINVAL; |
| 1812 | if (!strlen(number)) |
| 1813 | goto out_free; |
| 1814 | |
| 1815 | /* |
| 1816 | * We use the callback data field (which is a pointer) |
| 1817 | * as our counter. |
| 1818 | */ |
| 1819 | ret = kstrtoul(number, 0, &trigger_data->count); |
| 1820 | if (ret) |
| 1821 | goto out_free; |
| 1822 | } |
| 1823 | |
| 1824 | if (!param) /* if param is non-empty, it's supposed to be a filter */ |
| 1825 | goto out_reg; |
| 1826 | |
| 1827 | if (!cmd_ops->set_filter) |
| 1828 | goto out_reg; |
| 1829 | |
| 1830 | ret = cmd_ops->set_filter(param, trigger_data, file); |
| 1831 | if (ret < 0) |
| 1832 | goto out_free; |
| 1833 | |
| 1834 | out_reg: |
| 1835 | /* Don't let event modules unload while probe registered */ |
Steven Rostedt (VMware) | 1d18538 | 2021-08-16 23:42:57 -0400 | [diff] [blame] | 1836 | ret = trace_event_try_get_ref(event_enable_file->event_call); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1837 | if (!ret) { |
| 1838 | ret = -EBUSY; |
| 1839 | goto out_free; |
| 1840 | } |
| 1841 | |
| 1842 | ret = trace_event_enable_disable(event_enable_file, 1, 1); |
| 1843 | if (ret < 0) |
| 1844 | goto out_put; |
Tom Zanussi | 2378a2d | 2022-01-10 08:04:13 -0600 | [diff] [blame] | 1845 | ret = cmd_ops->reg(glob, trigger_data, file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1846 | /* |
| 1847 | * The above returns on success the # of functions enabled, |
| 1848 | * but if it didn't find any functions it returns zero. |
| 1849 | * Consider no functions a failure too. |
| 1850 | */ |
| 1851 | if (!ret) { |
| 1852 | ret = -ENOENT; |
| 1853 | goto out_disable; |
| 1854 | } else if (ret < 0) |
| 1855 | goto out_disable; |
| 1856 | /* Just return zero, not the number of enabled functions */ |
| 1857 | ret = 0; |
Steven Rostedt (VMware) | 15cc786 | 2018-07-25 16:02:06 -0400 | [diff] [blame] | 1858 | event_trigger_free(trigger_ops, trigger_data); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1859 | out: |
| 1860 | return ret; |
| 1861 | |
| 1862 | out_disable: |
| 1863 | trace_event_enable_disable(event_enable_file, 0, 1); |
| 1864 | out_put: |
Steven Rostedt (VMware) | 1d18538 | 2021-08-16 23:42:57 -0400 | [diff] [blame] | 1865 | trace_event_put_ref(event_enable_file->event_call); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1866 | out_free: |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1867 | if (cmd_ops->set_filter) |
| 1868 | cmd_ops->set_filter(NULL, trigger_data, NULL); |
Steven Rostedt (VMware) | 15cc786 | 2018-07-25 16:02:06 -0400 | [diff] [blame] | 1869 | event_trigger_free(trigger_ops, trigger_data); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1870 | kfree(enable_data); |
| 1871 | goto out; |
| 1872 | } |
| 1873 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1874 | int event_enable_register_trigger(char *glob, |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1875 | struct event_trigger_data *data, |
| 1876 | struct trace_event_file *file) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1877 | { |
| 1878 | struct enable_trigger_data *enable_data = data->private_data; |
| 1879 | struct enable_trigger_data *test_enable_data; |
| 1880 | struct event_trigger_data *test; |
| 1881 | int ret = 0; |
| 1882 | |
Masami Hiramatsu | 3b42a4c | 2019-12-20 11:31:43 +0900 | [diff] [blame] | 1883 | lockdep_assert_held(&event_mutex); |
| 1884 | |
| 1885 | list_for_each_entry(test, &file->triggers, list) { |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1886 | test_enable_data = test->private_data; |
| 1887 | if (test_enable_data && |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1888 | (test->cmd_ops->trigger_type == |
| 1889 | data->cmd_ops->trigger_type) && |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1890 | (test_enable_data->file == enable_data->file)) { |
| 1891 | ret = -EEXIST; |
| 1892 | goto out; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | if (data->ops->init) { |
| 1897 | ret = data->ops->init(data->ops, data); |
| 1898 | if (ret < 0) |
| 1899 | goto out; |
| 1900 | } |
| 1901 | |
| 1902 | list_add_rcu(&data->list, &file->triggers); |
| 1903 | ret++; |
| 1904 | |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 1905 | update_cond_flag(file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1906 | if (trace_event_trigger_enable_disable(file, 1) < 0) { |
| 1907 | list_del_rcu(&data->list); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 1908 | update_cond_flag(file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1909 | ret--; |
| 1910 | } |
| 1911 | out: |
| 1912 | return ret; |
| 1913 | } |
| 1914 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1915 | void event_enable_unregister_trigger(char *glob, |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1916 | struct event_trigger_data *test, |
| 1917 | struct trace_event_file *file) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1918 | { |
| 1919 | struct enable_trigger_data *test_enable_data = test->private_data; |
| 1920 | struct enable_trigger_data *enable_data; |
| 1921 | struct event_trigger_data *data; |
| 1922 | bool unregistered = false; |
| 1923 | |
Masami Hiramatsu | 3b42a4c | 2019-12-20 11:31:43 +0900 | [diff] [blame] | 1924 | lockdep_assert_held(&event_mutex); |
| 1925 | |
| 1926 | list_for_each_entry(data, &file->triggers, list) { |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1927 | enable_data = data->private_data; |
| 1928 | if (enable_data && |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1929 | (data->cmd_ops->trigger_type == |
| 1930 | test->cmd_ops->trigger_type) && |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1931 | (enable_data->file == test_enable_data->file)) { |
| 1932 | unregistered = true; |
| 1933 | list_del_rcu(&data->list); |
| 1934 | trace_event_trigger_enable_disable(file, 0); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 1935 | update_cond_flag(file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1936 | break; |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | if (unregistered && data->ops->free) |
| 1941 | data->ops->free(data->ops, data); |
| 1942 | } |
| 1943 | |
| 1944 | static struct event_trigger_ops * |
| 1945 | event_enable_get_trigger_ops(char *cmd, char *param) |
| 1946 | { |
| 1947 | struct event_trigger_ops *ops; |
| 1948 | bool enable; |
| 1949 | |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1950 | #ifdef CONFIG_HIST_TRIGGERS |
| 1951 | enable = ((strcmp(cmd, ENABLE_EVENT_STR) == 0) || |
| 1952 | (strcmp(cmd, ENABLE_HIST_STR) == 0)); |
| 1953 | #else |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1954 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 1955 | #endif |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1956 | if (enable) |
| 1957 | ops = param ? &event_enable_count_trigger_ops : |
| 1958 | &event_enable_trigger_ops; |
| 1959 | else |
| 1960 | ops = param ? &event_disable_count_trigger_ops : |
| 1961 | &event_disable_trigger_ops; |
| 1962 | |
| 1963 | return ops; |
| 1964 | } |
| 1965 | |
| 1966 | static struct event_command trigger_enable_cmd = { |
| 1967 | .name = ENABLE_EVENT_STR, |
| 1968 | .trigger_type = ETT_EVENT_ENABLE, |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1969 | .parse = event_enable_trigger_parse, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1970 | .reg = event_enable_register_trigger, |
| 1971 | .unreg = event_enable_unregister_trigger, |
| 1972 | .get_trigger_ops = event_enable_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1973 | .set_filter = set_trigger_filter, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1974 | }; |
| 1975 | |
| 1976 | static struct event_command trigger_disable_cmd = { |
| 1977 | .name = DISABLE_EVENT_STR, |
| 1978 | .trigger_type = ETT_EVENT_ENABLE, |
Tom Zanussi | 9ec5a7d | 2022-01-10 08:04:11 -0600 | [diff] [blame] | 1979 | .parse = event_enable_trigger_parse, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1980 | .reg = event_enable_register_trigger, |
| 1981 | .unreg = event_enable_unregister_trigger, |
| 1982 | .get_trigger_ops = event_enable_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1983 | .set_filter = set_trigger_filter, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1984 | }; |
| 1985 | |
| 1986 | static __init void unregister_trigger_enable_disable_cmds(void) |
| 1987 | { |
| 1988 | unregister_event_command(&trigger_enable_cmd); |
| 1989 | unregister_event_command(&trigger_disable_cmd); |
| 1990 | } |
| 1991 | |
| 1992 | static __init int register_trigger_enable_disable_cmds(void) |
| 1993 | { |
| 1994 | int ret; |
| 1995 | |
| 1996 | ret = register_event_command(&trigger_enable_cmd); |
| 1997 | if (WARN_ON(ret < 0)) |
| 1998 | return ret; |
| 1999 | ret = register_event_command(&trigger_disable_cmd); |
| 2000 | if (WARN_ON(ret < 0)) |
| 2001 | unregister_trigger_enable_disable_cmds(); |
| 2002 | |
| 2003 | return ret; |
| 2004 | } |
| 2005 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 2006 | static __init int register_trigger_traceon_traceoff_cmds(void) |
| 2007 | { |
| 2008 | int ret; |
| 2009 | |
| 2010 | ret = register_event_command(&trigger_traceon_cmd); |
| 2011 | if (WARN_ON(ret < 0)) |
| 2012 | return ret; |
| 2013 | ret = register_event_command(&trigger_traceoff_cmd); |
| 2014 | if (WARN_ON(ret < 0)) |
| 2015 | unregister_trigger_traceon_traceoff_cmds(); |
| 2016 | |
| 2017 | return ret; |
| 2018 | } |
| 2019 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 2020 | __init int register_trigger_cmds(void) |
| 2021 | { |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 2022 | register_trigger_traceon_traceoff_cmds(); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 2023 | register_trigger_snapshot_cmd(); |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 2024 | register_trigger_stacktrace_cmd(); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 2025 | register_trigger_enable_disable_cmds(); |
Tom Zanussi | d0bad49 | 2016-03-03 12:54:55 -0600 | [diff] [blame] | 2026 | register_trigger_hist_enable_disable_cmds(); |
Tom Zanussi | 7ef224d | 2016-03-03 12:54:42 -0600 | [diff] [blame] | 2027 | register_trigger_hist_cmd(); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 2028 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 2029 | return 0; |
| 2030 | } |