Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Frederic Weisbecker | 47788c5 | 2009-04-08 20:40:59 +0200 | [diff] [blame] | 2 | #include <trace/syscall.h> |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 3 | #include <trace/events/syscalls.h> |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 4 | #include <linux/syscalls.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 5 | #include <linux/slab.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 6 | #include <linux/kernel.h> |
Paul Gortmaker | 56d82e0 | 2011-05-26 17:53:52 -0400 | [diff] [blame] | 7 | #include <linux/module.h> /* for MODULE_NAME_LEN via KSYM_SYMBOL_LEN */ |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 8 | #include <linux/ftrace.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 9 | #include <linux/perf_event.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 10 | #include <asm/syscall.h> |
| 11 | |
| 12 | #include "trace_output.h" |
| 13 | #include "trace.h" |
| 14 | |
Frederic Weisbecker | 5be71b6 | 2009-03-15 22:10:37 +0100 | [diff] [blame] | 15 | static DEFINE_MUTEX(syscall_trace_lock); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 16 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 17 | static int syscall_enter_register(struct trace_event_call *event, |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 18 | enum trace_reg type, void *data); |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 19 | static int syscall_exit_register(struct trace_event_call *event, |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 20 | enum trace_reg type, void *data); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 21 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 22 | static struct list_head * |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 23 | syscall_get_enter_fields(struct trace_event_call *call) |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 24 | { |
| 25 | struct syscall_metadata *entry = call->data; |
| 26 | |
| 27 | return &entry->enter_fields; |
| 28 | } |
| 29 | |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 30 | extern struct syscall_metadata *__start_syscalls_metadata[]; |
| 31 | extern struct syscall_metadata *__stop_syscalls_metadata[]; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 32 | |
| 33 | static struct syscall_metadata **syscalls_metadata; |
| 34 | |
Ian Munsie | b2d5549 | 2011-02-03 14:27:23 +1100 | [diff] [blame] | 35 | #ifndef ARCH_HAS_SYSCALL_MATCH_SYM_NAME |
| 36 | static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) |
| 37 | { |
| 38 | /* |
| 39 | * Only compare after the "sys" prefix. Archs that use |
| 40 | * syscall wrappers may have syscalls symbols aliases prefixed |
zhangwei(Jovi) | 36a78e9 | 2013-03-11 15:13:51 +0800 | [diff] [blame] | 41 | * with ".SyS" or ".sys" instead of "sys", leading to an unwanted |
Ian Munsie | b2d5549 | 2011-02-03 14:27:23 +1100 | [diff] [blame] | 42 | * mismatch. |
| 43 | */ |
| 44 | return !strcmp(sym + 3, name + 3); |
| 45 | } |
| 46 | #endif |
| 47 | |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 48 | #ifdef ARCH_TRACE_IGNORE_COMPAT_SYSCALLS |
| 49 | /* |
| 50 | * Some architectures that allow for 32bit applications |
| 51 | * to run on a 64bit kernel, do not map the syscalls for |
| 52 | * the 32bit tasks the same as they do for 64bit tasks. |
| 53 | * |
| 54 | * *cough*x86*cough* |
| 55 | * |
| 56 | * In such a case, instead of reporting the wrong syscalls, |
| 57 | * simply ignore them. |
| 58 | * |
| 59 | * For an arch to ignore the compat syscalls it needs to |
| 60 | * define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS as well as |
| 61 | * define the function arch_trace_is_compat_syscall() to let |
| 62 | * the tracing system know that it should ignore it. |
| 63 | */ |
| 64 | static int |
| 65 | trace_get_syscall_nr(struct task_struct *task, struct pt_regs *regs) |
| 66 | { |
| 67 | if (unlikely(arch_trace_is_compat_syscall(regs))) |
| 68 | return -1; |
| 69 | |
| 70 | return syscall_get_nr(task, regs); |
| 71 | } |
| 72 | #else |
| 73 | static inline int |
| 74 | trace_get_syscall_nr(struct task_struct *task, struct pt_regs *regs) |
| 75 | { |
| 76 | return syscall_get_nr(task, regs); |
| 77 | } |
| 78 | #endif /* ARCH_TRACE_IGNORE_COMPAT_SYSCALLS */ |
| 79 | |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 80 | static __init struct syscall_metadata * |
| 81 | find_syscall_meta(unsigned long syscall) |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 82 | { |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 83 | struct syscall_metadata **start; |
| 84 | struct syscall_metadata **stop; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 85 | char str[KSYM_SYMBOL_LEN]; |
| 86 | |
| 87 | |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 88 | start = __start_syscalls_metadata; |
| 89 | stop = __stop_syscalls_metadata; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 90 | kallsyms_lookup(syscall, NULL, NULL, NULL, str); |
| 91 | |
Ian Munsie | ae07f55 | 2011-02-03 14:27:25 +1100 | [diff] [blame] | 92 | if (arch_syscall_match_sym_name(str, "sys_ni_syscall")) |
| 93 | return NULL; |
| 94 | |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 95 | for ( ; start < stop; start++) { |
Ian Munsie | b2d5549 | 2011-02-03 14:27:23 +1100 | [diff] [blame] | 96 | if ((*start)->name && arch_syscall_match_sym_name(str, (*start)->name)) |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 97 | return *start; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 98 | } |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | static struct syscall_metadata *syscall_nr_to_meta(int nr) |
| 103 | { |
| 104 | if (!syscalls_metadata || nr >= NR_syscalls || nr < 0) |
| 105 | return NULL; |
| 106 | |
| 107 | return syscalls_metadata[nr]; |
| 108 | } |
| 109 | |
Tom Zanussi | dbfeaa7 | 2015-12-10 12:50:46 -0600 | [diff] [blame] | 110 | const char *get_syscall_name(int syscall) |
| 111 | { |
| 112 | struct syscall_metadata *entry; |
| 113 | |
| 114 | entry = syscall_nr_to_meta(syscall); |
| 115 | if (!entry) |
| 116 | return NULL; |
| 117 | |
| 118 | return entry->name; |
| 119 | } |
| 120 | |
Fengguang Wu | 6aea49c | 2012-11-21 15:13:47 +0800 | [diff] [blame] | 121 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 122 | print_syscall_enter(struct trace_iterator *iter, int flags, |
| 123 | struct trace_event *event) |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 124 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 125 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 126 | struct trace_seq *s = &iter->seq; |
| 127 | struct trace_entry *ent = iter->ent; |
| 128 | struct syscall_trace_enter *trace; |
| 129 | struct syscall_metadata *entry; |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 130 | int i, syscall; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 131 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 132 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 133 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 134 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 135 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 136 | if (!entry) |
| 137 | goto end; |
| 138 | |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 139 | if (entry->enter_event->event.type != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 140 | WARN_ON_ONCE(1); |
| 141 | goto end; |
| 142 | } |
| 143 | |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 144 | trace_seq_printf(s, "%s(", entry->name); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 145 | |
| 146 | for (i = 0; i < entry->nb_args; i++) { |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 147 | |
| 148 | if (trace_seq_has_overflowed(s)) |
| 149 | goto end; |
| 150 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 151 | /* parameter types */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 152 | if (tr->trace_flags & TRACE_ITER_VERBOSE) |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 153 | trace_seq_printf(s, "%s ", entry->types[i]); |
| 154 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 155 | /* parameter values */ |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 156 | trace_seq_printf(s, "%s: %lx%s", entry->args[i], |
| 157 | trace->args[i], |
| 158 | i == entry->nb_args - 1 ? "" : ", "); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 161 | trace_seq_putc(s, ')'); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 162 | end: |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 163 | trace_seq_putc(s, '\n'); |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 164 | |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 165 | return trace_handle_return(s); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Fengguang Wu | 6aea49c | 2012-11-21 15:13:47 +0800 | [diff] [blame] | 168 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 169 | print_syscall_exit(struct trace_iterator *iter, int flags, |
| 170 | struct trace_event *event) |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 171 | { |
| 172 | struct trace_seq *s = &iter->seq; |
| 173 | struct trace_entry *ent = iter->ent; |
| 174 | struct syscall_trace_exit *trace; |
| 175 | int syscall; |
| 176 | struct syscall_metadata *entry; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 177 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 178 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 179 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 180 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 181 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 182 | if (!entry) { |
zhangwei(Jovi) | 146c344 | 2013-07-15 16:32:44 +0800 | [diff] [blame] | 183 | trace_seq_putc(s, '\n'); |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 184 | goto out; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 187 | if (entry->exit_event->event.type != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 188 | WARN_ON_ONCE(1); |
| 189 | return TRACE_TYPE_UNHANDLED; |
| 190 | } |
| 191 | |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 192 | trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 193 | trace->ret); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 194 | |
Steven Rostedt (Red Hat) | 183742f | 2014-11-12 17:41:33 -0500 | [diff] [blame] | 195 | out: |
| 196 | return trace_handle_return(s); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 199 | extern char *__bad_type_size(void); |
| 200 | |
Taeung Song | 026842d | 2016-02-26 13:23:01 -0500 | [diff] [blame] | 201 | #define SYSCALL_FIELD(type, field, name) \ |
| 202 | sizeof(type) != sizeof(trace.field) ? \ |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 203 | __bad_type_size() : \ |
Taeung Song | 026842d | 2016-02-26 13:23:01 -0500 | [diff] [blame] | 204 | #type, #name, offsetof(typeof(trace), field), \ |
| 205 | sizeof(trace.field), is_signed_type(type) |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 206 | |
Li Zefan | 3ddc77f | 2013-03-27 14:15:37 +0800 | [diff] [blame] | 207 | static int __init |
| 208 | __set_enter_print_fmt(struct syscall_metadata *entry, char *buf, int len) |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 209 | { |
| 210 | int i; |
| 211 | int pos = 0; |
| 212 | |
| 213 | /* When len=0, we just calculate the needed length */ |
| 214 | #define LEN_OR_ZERO (len ? len - pos : 0) |
| 215 | |
| 216 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); |
| 217 | for (i = 0; i < entry->nb_args; i++) { |
| 218 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s: 0x%%0%zulx%s", |
| 219 | entry->args[i], sizeof(unsigned long), |
| 220 | i == entry->nb_args - 1 ? "" : ", "); |
| 221 | } |
| 222 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); |
| 223 | |
| 224 | for (i = 0; i < entry->nb_args; i++) { |
| 225 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
| 226 | ", ((unsigned long)(REC->%s))", entry->args[i]); |
| 227 | } |
| 228 | |
| 229 | #undef LEN_OR_ZERO |
| 230 | |
| 231 | /* return the length of print_fmt */ |
| 232 | return pos; |
| 233 | } |
| 234 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 235 | static int __init set_syscall_print_fmt(struct trace_event_call *call) |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 236 | { |
| 237 | char *print_fmt; |
| 238 | int len; |
| 239 | struct syscall_metadata *entry = call->data; |
| 240 | |
| 241 | if (entry->enter_event != call) { |
| 242 | call->print_fmt = "\"0x%lx\", REC->ret"; |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | /* First: called with 0 length to calculate the needed length */ |
| 247 | len = __set_enter_print_fmt(entry, NULL, 0); |
| 248 | |
| 249 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
| 250 | if (!print_fmt) |
| 251 | return -ENOMEM; |
| 252 | |
| 253 | /* Second: actually write the @print_fmt */ |
| 254 | __set_enter_print_fmt(entry, print_fmt, len + 1); |
| 255 | call->print_fmt = print_fmt; |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 260 | static void __init free_syscall_print_fmt(struct trace_event_call *call) |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 261 | { |
| 262 | struct syscall_metadata *entry = call->data; |
| 263 | |
| 264 | if (entry->enter_event == call) |
| 265 | kfree(call->print_fmt); |
| 266 | } |
| 267 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 268 | static int __init syscall_enter_define_fields(struct trace_event_call *call) |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 269 | { |
| 270 | struct syscall_trace_enter trace; |
Lai Jiangshan | 31c16b1 | 2009-12-01 16:23:30 +0800 | [diff] [blame] | 271 | struct syscall_metadata *meta = call->data; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 272 | int ret; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 273 | int i; |
| 274 | int offset = offsetof(typeof(trace), args); |
| 275 | |
Taeung Song | 026842d | 2016-02-26 13:23:01 -0500 | [diff] [blame] | 276 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr, __syscall_nr), |
| 277 | FILTER_OTHER); |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 278 | if (ret) |
| 279 | return ret; |
| 280 | |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 281 | for (i = 0; i < meta->nb_args; i++) { |
Frederic Weisbecker | aeaeae1 | 2009-08-27 05:09:51 +0200 | [diff] [blame] | 282 | ret = trace_define_field(call, meta->types[i], |
| 283 | meta->args[i], offset, |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 284 | sizeof(unsigned long), 0, |
| 285 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 286 | offset += sizeof(unsigned long); |
| 287 | } |
| 288 | |
| 289 | return ret; |
| 290 | } |
| 291 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 292 | static int __init syscall_exit_define_fields(struct trace_event_call *call) |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 293 | { |
| 294 | struct syscall_trace_exit trace; |
| 295 | int ret; |
| 296 | |
Taeung Song | 026842d | 2016-02-26 13:23:01 -0500 | [diff] [blame] | 297 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr, __syscall_nr), |
| 298 | FILTER_OTHER); |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 299 | if (ret) |
| 300 | return ret; |
| 301 | |
Taeung Song | 026842d | 2016-02-26 13:23:01 -0500 | [diff] [blame] | 302 | ret = trace_define_field(call, SYSCALL_FIELD(long, ret, ret), |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 303 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 304 | |
| 305 | return ret; |
| 306 | } |
| 307 | |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 308 | static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 309 | { |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 310 | struct trace_array *tr = data; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 311 | struct trace_event_file *trace_file; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 312 | struct syscall_trace_enter *entry; |
| 313 | struct syscall_metadata *sys_data; |
| 314 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 315 | struct ring_buffer *buffer; |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 316 | unsigned long irq_flags; |
Steven Rostedt (Red Hat) | d08e411 | 2016-11-07 16:26:36 -0500 | [diff] [blame] | 317 | unsigned long args[6]; |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 318 | int pc; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 319 | int syscall_nr; |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 320 | int size; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 321 | |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 322 | syscall_nr = trace_get_syscall_nr(current, regs); |
Rabin Vincent | 086ba77 | 2014-10-29 23:06:58 +0100 | [diff] [blame] | 323 | if (syscall_nr < 0 || syscall_nr >= NR_syscalls) |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 324 | return; |
Tom Zanussi | d562aff | 2013-10-24 08:34:19 -0500 | [diff] [blame] | 325 | |
| 326 | /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE) */ |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 327 | trace_file = rcu_dereference_sched(tr->enter_syscall_files[syscall_nr]); |
| 328 | if (!trace_file) |
Tom Zanussi | d562aff | 2013-10-24 08:34:19 -0500 | [diff] [blame] | 329 | return; |
| 330 | |
Steven Rostedt (Red Hat) | 09a5059 | 2015-05-13 15:21:25 -0400 | [diff] [blame] | 331 | if (trace_trigger_soft_disabled(trace_file)) |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 332 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 333 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 334 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 335 | if (!sys_data) |
| 336 | return; |
| 337 | |
| 338 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
| 339 | |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 340 | local_save_flags(irq_flags); |
| 341 | pc = preempt_count(); |
| 342 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 343 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 344 | event = trace_buffer_lock_reserve(buffer, |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 345 | sys_data->enter_event->event.type, size, irq_flags, pc); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 346 | if (!event) |
| 347 | return; |
| 348 | |
| 349 | entry = ring_buffer_event_data(event); |
| 350 | entry->nr = syscall_nr; |
Steven Rostedt (Red Hat) | b35f549 | 2016-11-07 16:26:37 -0500 | [diff] [blame] | 351 | syscall_get_arguments(current, regs, args); |
Steven Rostedt (Red Hat) | d08e411 | 2016-11-07 16:26:36 -0500 | [diff] [blame] | 352 | memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 353 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 354 | event_trigger_unlock_commit(trace_file, buffer, event, entry, |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 355 | irq_flags, pc); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 356 | } |
| 357 | |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 358 | static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 359 | { |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 360 | struct trace_array *tr = data; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 361 | struct trace_event_file *trace_file; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 362 | struct syscall_trace_exit *entry; |
| 363 | struct syscall_metadata *sys_data; |
| 364 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 365 | struct ring_buffer *buffer; |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 366 | unsigned long irq_flags; |
| 367 | int pc; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 368 | int syscall_nr; |
| 369 | |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 370 | syscall_nr = trace_get_syscall_nr(current, regs); |
Rabin Vincent | 086ba77 | 2014-10-29 23:06:58 +0100 | [diff] [blame] | 371 | if (syscall_nr < 0 || syscall_nr >= NR_syscalls) |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 372 | return; |
Tom Zanussi | d562aff | 2013-10-24 08:34:19 -0500 | [diff] [blame] | 373 | |
| 374 | /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE()) */ |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 375 | trace_file = rcu_dereference_sched(tr->exit_syscall_files[syscall_nr]); |
| 376 | if (!trace_file) |
Tom Zanussi | d562aff | 2013-10-24 08:34:19 -0500 | [diff] [blame] | 377 | return; |
| 378 | |
Steven Rostedt (Red Hat) | 09a5059 | 2015-05-13 15:21:25 -0400 | [diff] [blame] | 379 | if (trace_trigger_soft_disabled(trace_file)) |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 380 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 381 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 382 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 383 | if (!sys_data) |
| 384 | return; |
| 385 | |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 386 | local_save_flags(irq_flags); |
| 387 | pc = preempt_count(); |
| 388 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 389 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 390 | event = trace_buffer_lock_reserve(buffer, |
zhangwei(Jovi) | 11034ae | 2013-04-10 11:26:23 +0800 | [diff] [blame] | 391 | sys_data->exit_event->event.type, sizeof(*entry), |
| 392 | irq_flags, pc); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 393 | if (!event) |
| 394 | return; |
| 395 | |
| 396 | entry = ring_buffer_event_data(event); |
| 397 | entry->nr = syscall_nr; |
| 398 | entry->ret = syscall_get_return_value(current, regs); |
| 399 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 400 | event_trigger_unlock_commit(trace_file, buffer, event, entry, |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 401 | irq_flags, pc); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 404 | static int reg_event_syscall_enter(struct trace_event_file *file, |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 405 | struct trace_event_call *call) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 406 | { |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 407 | struct trace_array *tr = file->tr; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 408 | int ret = 0; |
| 409 | int num; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 410 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 411 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 412 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 413 | return -ENOSYS; |
| 414 | mutex_lock(&syscall_trace_lock); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 415 | if (!tr->sys_refcount_enter) |
| 416 | ret = register_trace_sys_enter(ftrace_syscall_enter, tr); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 417 | if (!ret) { |
Tom Zanussi | d562aff | 2013-10-24 08:34:19 -0500 | [diff] [blame] | 418 | rcu_assign_pointer(tr->enter_syscall_files[num], file); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 419 | tr->sys_refcount_enter++; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 420 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 421 | mutex_unlock(&syscall_trace_lock); |
| 422 | return ret; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 423 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 424 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 425 | static void unreg_event_syscall_enter(struct trace_event_file *file, |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 426 | struct trace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 427 | { |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 428 | struct trace_array *tr = file->tr; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 429 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 430 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 431 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 432 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 433 | return; |
| 434 | mutex_lock(&syscall_trace_lock); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 435 | tr->sys_refcount_enter--; |
Andreea-Cristina Bernat | fb5a613 | 2014-08-22 17:28:22 +0300 | [diff] [blame] | 436 | RCU_INIT_POINTER(tr->enter_syscall_files[num], NULL); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 437 | if (!tr->sys_refcount_enter) |
| 438 | unregister_trace_sys_enter(ftrace_syscall_enter, tr); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 439 | mutex_unlock(&syscall_trace_lock); |
| 440 | } |
| 441 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 442 | static int reg_event_syscall_exit(struct trace_event_file *file, |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 443 | struct trace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 444 | { |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 445 | struct trace_array *tr = file->tr; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 446 | int ret = 0; |
| 447 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 448 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 449 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 450 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 451 | return -ENOSYS; |
| 452 | mutex_lock(&syscall_trace_lock); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 453 | if (!tr->sys_refcount_exit) |
| 454 | ret = register_trace_sys_exit(ftrace_syscall_exit, tr); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 455 | if (!ret) { |
Tom Zanussi | d562aff | 2013-10-24 08:34:19 -0500 | [diff] [blame] | 456 | rcu_assign_pointer(tr->exit_syscall_files[num], file); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 457 | tr->sys_refcount_exit++; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 458 | } |
| 459 | mutex_unlock(&syscall_trace_lock); |
| 460 | return ret; |
| 461 | } |
| 462 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 463 | static void unreg_event_syscall_exit(struct trace_event_file *file, |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 464 | struct trace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 465 | { |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 466 | struct trace_array *tr = file->tr; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 467 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 468 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 469 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 470 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 471 | return; |
| 472 | mutex_lock(&syscall_trace_lock); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 473 | tr->sys_refcount_exit--; |
Andreea-Cristina Bernat | fb5a613 | 2014-08-22 17:28:22 +0300 | [diff] [blame] | 474 | RCU_INIT_POINTER(tr->exit_syscall_files[num], NULL); |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 475 | if (!tr->sys_refcount_exit) |
| 476 | unregister_trace_sys_exit(ftrace_syscall_exit, tr); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 477 | mutex_unlock(&syscall_trace_lock); |
| 478 | } |
| 479 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 480 | static int __init init_syscall_trace(struct trace_event_call *call) |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 481 | { |
| 482 | int id; |
Ian Munsie | ba97697 | 2011-02-03 14:27:20 +1100 | [diff] [blame] | 483 | int num; |
| 484 | |
| 485 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
| 486 | if (num < 0 || num >= NR_syscalls) { |
| 487 | pr_debug("syscall %s metadata not mapped, disabling ftrace event\n", |
| 488 | ((struct syscall_metadata *)call->data)->name); |
| 489 | return -ENOSYS; |
| 490 | } |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 491 | |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 492 | if (set_syscall_print_fmt(call) < 0) |
| 493 | return -ENOMEM; |
| 494 | |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 495 | id = trace_event_raw_init(call); |
| 496 | |
| 497 | if (id < 0) { |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 498 | free_syscall_print_fmt(call); |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 499 | return id; |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 500 | } |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 501 | |
| 502 | return id; |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 503 | } |
| 504 | |
Vaibhav Nagarnaik | 6f86ab9 | 2012-06-07 16:46:25 -0700 | [diff] [blame] | 505 | struct trace_event_functions enter_syscall_print_funcs = { |
| 506 | .trace = print_syscall_enter, |
| 507 | }; |
| 508 | |
| 509 | struct trace_event_functions exit_syscall_print_funcs = { |
| 510 | .trace = print_syscall_exit, |
| 511 | }; |
| 512 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 513 | struct trace_event_class __refdata event_class_syscall_enter = { |
Vaibhav Nagarnaik | 6f86ab9 | 2012-06-07 16:46:25 -0700 | [diff] [blame] | 514 | .system = "syscalls", |
| 515 | .reg = syscall_enter_register, |
| 516 | .define_fields = syscall_enter_define_fields, |
| 517 | .get_fields = syscall_get_enter_fields, |
| 518 | .raw_init = init_syscall_trace, |
| 519 | }; |
| 520 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 521 | struct trace_event_class __refdata event_class_syscall_exit = { |
Vaibhav Nagarnaik | 6f86ab9 | 2012-06-07 16:46:25 -0700 | [diff] [blame] | 522 | .system = "syscalls", |
| 523 | .reg = syscall_exit_register, |
| 524 | .define_fields = syscall_exit_define_fields, |
| 525 | .fields = LIST_HEAD_INIT(event_class_syscall_exit.fields), |
| 526 | .raw_init = init_syscall_trace, |
| 527 | }; |
| 528 | |
Ian Munsie | c763ba0 | 2011-02-03 14:27:22 +1100 | [diff] [blame] | 529 | unsigned long __init __weak arch_syscall_addr(int nr) |
Mike Frysinger | e7b8e67 | 2010-01-26 04:40:03 -0500 | [diff] [blame] | 530 | { |
| 531 | return (unsigned long)sys_call_table[nr]; |
| 532 | } |
| 533 | |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 534 | void __init init_ftrace_syscalls(void) |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 535 | { |
| 536 | struct syscall_metadata *meta; |
| 537 | unsigned long addr; |
| 538 | int i; |
| 539 | |
Thomas Meyer | 47b0edc | 2011-11-29 22:08:00 +0100 | [diff] [blame] | 540 | syscalls_metadata = kcalloc(NR_syscalls, sizeof(*syscalls_metadata), |
| 541 | GFP_KERNEL); |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 542 | if (!syscalls_metadata) { |
| 543 | WARN_ON(1); |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 544 | return; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | for (i = 0; i < NR_syscalls; i++) { |
| 548 | addr = arch_syscall_addr(i); |
| 549 | meta = find_syscall_meta(addr); |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 550 | if (!meta) |
| 551 | continue; |
| 552 | |
| 553 | meta->syscall_nr = i; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 554 | syscalls_metadata[i] = meta; |
| 555 | } |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 556 | } |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 557 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 558 | #ifdef CONFIG_PERF_EVENTS |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 559 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 560 | static DECLARE_BITMAP(enabled_perf_enter_syscalls, NR_syscalls); |
| 561 | static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); |
| 562 | static int sys_perf_refcount_enter; |
| 563 | static int sys_perf_refcount_exit; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 564 | |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 565 | static int perf_call_bpf_enter(struct trace_event_call *call, struct pt_regs *regs, |
| 566 | struct syscall_metadata *sys_data, |
| 567 | struct syscall_trace_enter *rec) |
| 568 | { |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 569 | struct syscall_tp_t { |
| 570 | unsigned long long regs; |
| 571 | unsigned long syscall_nr; |
Yonghong Song | 609320c | 2017-09-07 18:36:15 -0700 | [diff] [blame] | 572 | unsigned long args[SYSCALL_DEFINE_MAXARGS]; |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 573 | } param; |
| 574 | int i; |
| 575 | |
| 576 | *(struct pt_regs **)¶m = regs; |
| 577 | param.syscall_nr = rec->nr; |
| 578 | for (i = 0; i < sys_data->nb_args; i++) |
| 579 | param.args[i] = rec->args[i]; |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 580 | return trace_call_bpf(call, ¶m); |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 583 | static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 584 | { |
| 585 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 586 | struct syscall_trace_enter *rec; |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 587 | struct hlist_head *head; |
Steven Rostedt (Red Hat) | d08e411 | 2016-11-07 16:26:36 -0500 | [diff] [blame] | 588 | unsigned long args[6]; |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 589 | bool valid_prog_array; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 590 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 591 | int rctx; |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 592 | int size; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 593 | |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 594 | syscall_nr = trace_get_syscall_nr(current, regs); |
Rabin Vincent | 086ba77 | 2014-10-29 23:06:58 +0100 | [diff] [blame] | 595 | if (syscall_nr < 0 || syscall_nr >= NR_syscalls) |
Will Deacon | 60916a9 | 2012-08-16 18:14:14 +0100 | [diff] [blame] | 596 | return; |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 597 | if (!test_bit(syscall_nr, enabled_perf_enter_syscalls)) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 598 | return; |
| 599 | |
| 600 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 601 | if (!sys_data) |
| 602 | return; |
| 603 | |
Oleg Nesterov | 421c786 | 2013-06-17 19:02:07 +0200 | [diff] [blame] | 604 | head = this_cpu_ptr(sys_data->enter_event->perf_events); |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 605 | valid_prog_array = bpf_prog_array_valid(sys_data->enter_event); |
| 606 | if (!valid_prog_array && hlist_empty(head)) |
Oleg Nesterov | 421c786 | 2013-06-17 19:02:07 +0200 | [diff] [blame] | 607 | return; |
| 608 | |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 609 | /* get the size after alignment with the u32 buffer size field */ |
| 610 | size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); |
| 611 | size = ALIGN(size + sizeof(u32), sizeof(u64)); |
| 612 | size -= sizeof(u32); |
| 613 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 614 | rec = perf_trace_buf_alloc(size, NULL, &rctx); |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 615 | if (!rec) |
| 616 | return; |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 617 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 618 | rec->nr = syscall_nr; |
Steven Rostedt (Red Hat) | b35f549 | 2016-11-07 16:26:37 -0500 | [diff] [blame] | 619 | syscall_get_arguments(current, regs, args); |
Steven Rostedt (Red Hat) | d08e411 | 2016-11-07 16:26:36 -0500 | [diff] [blame] | 620 | memcpy(&rec->args, args, sizeof(unsigned long) * sys_data->nb_args); |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 621 | |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 622 | if ((valid_prog_array && |
| 623 | !perf_call_bpf_enter(sys_data->enter_event, regs, sys_data, rec)) || |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 624 | hlist_empty(head)) { |
| 625 | perf_swevent_put_recursion_context(rctx); |
| 626 | return; |
| 627 | } |
| 628 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 629 | perf_trace_buf_submit(rec, size, rctx, |
| 630 | sys_data->enter_event->event.type, 1, regs, |
Peter Zijlstra | 8fd0fbb | 2017-10-11 09:45:29 +0200 | [diff] [blame] | 631 | head, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 632 | } |
| 633 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 634 | static int perf_sysenter_enable(struct trace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 635 | { |
| 636 | int ret = 0; |
| 637 | int num; |
| 638 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 639 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 640 | |
| 641 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 642 | if (!sys_perf_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 643 | ret = register_trace_sys_enter(perf_syscall_enter, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 644 | if (ret) { |
Colin Ian King | d282b9c | 2016-09-12 14:46:23 +0100 | [diff] [blame] | 645 | pr_info("event trace: Could not activate syscall entry trace point"); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 646 | } else { |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 647 | set_bit(num, enabled_perf_enter_syscalls); |
| 648 | sys_perf_refcount_enter++; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 649 | } |
| 650 | mutex_unlock(&syscall_trace_lock); |
| 651 | return ret; |
| 652 | } |
| 653 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 654 | static void perf_sysenter_disable(struct trace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 655 | { |
| 656 | int num; |
| 657 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 658 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 659 | |
| 660 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 661 | sys_perf_refcount_enter--; |
| 662 | clear_bit(num, enabled_perf_enter_syscalls); |
| 663 | if (!sys_perf_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 664 | unregister_trace_sys_enter(perf_syscall_enter, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 665 | mutex_unlock(&syscall_trace_lock); |
| 666 | } |
| 667 | |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 668 | static int perf_call_bpf_exit(struct trace_event_call *call, struct pt_regs *regs, |
| 669 | struct syscall_trace_exit *rec) |
| 670 | { |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 671 | struct syscall_tp_t { |
| 672 | unsigned long long regs; |
| 673 | unsigned long syscall_nr; |
| 674 | unsigned long ret; |
| 675 | } param; |
| 676 | |
| 677 | *(struct pt_regs **)¶m = regs; |
| 678 | param.syscall_nr = rec->nr; |
| 679 | param.ret = rec->ret; |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 680 | return trace_call_bpf(call, ¶m); |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 683 | static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 684 | { |
| 685 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 686 | struct syscall_trace_exit *rec; |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 687 | struct hlist_head *head; |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 688 | bool valid_prog_array; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 689 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 690 | int rctx; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 691 | int size; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 692 | |
Steven Rostedt | f431b63 | 2013-02-12 16:18:59 -0500 | [diff] [blame] | 693 | syscall_nr = trace_get_syscall_nr(current, regs); |
Rabin Vincent | 086ba77 | 2014-10-29 23:06:58 +0100 | [diff] [blame] | 694 | if (syscall_nr < 0 || syscall_nr >= NR_syscalls) |
Will Deacon | 60916a9 | 2012-08-16 18:14:14 +0100 | [diff] [blame] | 695 | return; |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 696 | if (!test_bit(syscall_nr, enabled_perf_exit_syscalls)) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 697 | return; |
| 698 | |
| 699 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 700 | if (!sys_data) |
| 701 | return; |
| 702 | |
Oleg Nesterov | 421c786 | 2013-06-17 19:02:07 +0200 | [diff] [blame] | 703 | head = this_cpu_ptr(sys_data->exit_event->perf_events); |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 704 | valid_prog_array = bpf_prog_array_valid(sys_data->exit_event); |
| 705 | if (!valid_prog_array && hlist_empty(head)) |
Oleg Nesterov | 421c786 | 2013-06-17 19:02:07 +0200 | [diff] [blame] | 706 | return; |
| 707 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 708 | /* We can probably do that at build time */ |
| 709 | size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); |
| 710 | size -= sizeof(u32); |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 711 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 712 | rec = perf_trace_buf_alloc(size, NULL, &rctx); |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 713 | if (!rec) |
| 714 | return; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 715 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 716 | rec->nr = syscall_nr; |
| 717 | rec->ret = syscall_get_return_value(current, regs); |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 718 | |
Yonghong Song | e87c6bc38 | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 719 | if ((valid_prog_array && |
| 720 | !perf_call_bpf_exit(sys_data->exit_event, regs, rec)) || |
Yonghong Song | cf5f5ce | 2017-08-04 16:00:09 -0700 | [diff] [blame] | 721 | hlist_empty(head)) { |
| 722 | perf_swevent_put_recursion_context(rctx); |
| 723 | return; |
| 724 | } |
| 725 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 726 | perf_trace_buf_submit(rec, size, rctx, sys_data->exit_event->event.type, |
Peter Zijlstra | 8fd0fbb | 2017-10-11 09:45:29 +0200 | [diff] [blame] | 727 | 1, regs, head, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 730 | static int perf_sysexit_enable(struct trace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 731 | { |
| 732 | int ret = 0; |
| 733 | int num; |
| 734 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 735 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 736 | |
| 737 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 738 | if (!sys_perf_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 739 | ret = register_trace_sys_exit(perf_syscall_exit, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 740 | if (ret) { |
Colin Ian King | d282b9c | 2016-09-12 14:46:23 +0100 | [diff] [blame] | 741 | pr_info("event trace: Could not activate syscall exit trace point"); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 742 | } else { |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 743 | set_bit(num, enabled_perf_exit_syscalls); |
| 744 | sys_perf_refcount_exit++; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 745 | } |
| 746 | mutex_unlock(&syscall_trace_lock); |
| 747 | return ret; |
| 748 | } |
| 749 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 750 | static void perf_sysexit_disable(struct trace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 751 | { |
| 752 | int num; |
| 753 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 754 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 755 | |
| 756 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 757 | sys_perf_refcount_exit--; |
| 758 | clear_bit(num, enabled_perf_exit_syscalls); |
| 759 | if (!sys_perf_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 760 | unregister_trace_sys_exit(perf_syscall_exit, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 761 | mutex_unlock(&syscall_trace_lock); |
| 762 | } |
| 763 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 764 | #endif /* CONFIG_PERF_EVENTS */ |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 765 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 766 | static int syscall_enter_register(struct trace_event_call *event, |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 767 | enum trace_reg type, void *data) |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 768 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 769 | struct trace_event_file *file = data; |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 770 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 771 | switch (type) { |
| 772 | case TRACE_REG_REGISTER: |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 773 | return reg_event_syscall_enter(file, event); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 774 | case TRACE_REG_UNREGISTER: |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 775 | unreg_event_syscall_enter(file, event); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 776 | return 0; |
| 777 | |
| 778 | #ifdef CONFIG_PERF_EVENTS |
| 779 | case TRACE_REG_PERF_REGISTER: |
| 780 | return perf_sysenter_enable(event); |
| 781 | case TRACE_REG_PERF_UNREGISTER: |
| 782 | perf_sysenter_disable(event); |
| 783 | return 0; |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 784 | case TRACE_REG_PERF_OPEN: |
| 785 | case TRACE_REG_PERF_CLOSE: |
Jiri Olsa | 489c75c | 2012-02-15 15:51:50 +0100 | [diff] [blame] | 786 | case TRACE_REG_PERF_ADD: |
| 787 | case TRACE_REG_PERF_DEL: |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 788 | return 0; |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 789 | #endif |
| 790 | } |
| 791 | return 0; |
| 792 | } |
| 793 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 794 | static int syscall_exit_register(struct trace_event_call *event, |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 795 | enum trace_reg type, void *data) |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 796 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 797 | struct trace_event_file *file = data; |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 798 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 799 | switch (type) { |
| 800 | case TRACE_REG_REGISTER: |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 801 | return reg_event_syscall_exit(file, event); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 802 | case TRACE_REG_UNREGISTER: |
Steven Rostedt | 12ab74e | 2012-08-08 14:48:20 -0400 | [diff] [blame] | 803 | unreg_event_syscall_exit(file, event); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 804 | return 0; |
| 805 | |
| 806 | #ifdef CONFIG_PERF_EVENTS |
| 807 | case TRACE_REG_PERF_REGISTER: |
| 808 | return perf_sysexit_enable(event); |
| 809 | case TRACE_REG_PERF_UNREGISTER: |
| 810 | perf_sysexit_disable(event); |
| 811 | return 0; |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 812 | case TRACE_REG_PERF_OPEN: |
| 813 | case TRACE_REG_PERF_CLOSE: |
Jiri Olsa | 489c75c | 2012-02-15 15:51:50 +0100 | [diff] [blame] | 814 | case TRACE_REG_PERF_ADD: |
| 815 | case TRACE_REG_PERF_DEL: |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 816 | return 0; |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 817 | #endif |
| 818 | } |
| 819 | return 0; |
| 820 | } |