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