Frederic Weisbecker | 47788c5 | 2009-04-08 20:40:59 +0200 | [diff] [blame] | 1 | #include <trace/syscall.h> |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 2 | #include <trace/events/syscalls.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 3 | #include <linux/slab.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 4 | #include <linux/kernel.h> |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 5 | #include <linux/ftrace.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 6 | #include <linux/perf_event.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 7 | #include <asm/syscall.h> |
| 8 | |
| 9 | #include "trace_output.h" |
| 10 | #include "trace.h" |
| 11 | |
Frederic Weisbecker | 5be71b6 | 2009-03-15 22:10:37 +0100 | [diff] [blame] | 12 | static DEFINE_MUTEX(syscall_trace_lock); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 13 | static int sys_refcount_enter; |
| 14 | static int sys_refcount_exit; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 15 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); |
| 16 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 17 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 18 | static int syscall_enter_register(struct ftrace_event_call *event, |
| 19 | enum trace_reg type); |
| 20 | static int syscall_exit_register(struct ftrace_event_call *event, |
| 21 | enum trace_reg type); |
| 22 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 23 | static int syscall_enter_define_fields(struct ftrace_event_call *call); |
| 24 | static int syscall_exit_define_fields(struct ftrace_event_call *call); |
| 25 | |
| 26 | static struct list_head * |
| 27 | syscall_get_enter_fields(struct ftrace_event_call *call) |
| 28 | { |
| 29 | struct syscall_metadata *entry = call->data; |
| 30 | |
| 31 | return &entry->enter_fields; |
| 32 | } |
| 33 | |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 34 | struct trace_event_functions enter_syscall_print_funcs = { |
Lai Jiangshan | 7f85803 | 2011-01-14 17:49:02 +0800 | [diff] [blame] | 35 | .trace = print_syscall_enter, |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct trace_event_functions exit_syscall_print_funcs = { |
Lai Jiangshan | 7f85803 | 2011-01-14 17:49:02 +0800 | [diff] [blame] | 39 | .trace = print_syscall_exit, |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 42 | struct ftrace_event_class event_class_syscall_enter = { |
Lai Jiangshan | 7f85803 | 2011-01-14 17:49:02 +0800 | [diff] [blame] | 43 | .system = "syscalls", |
| 44 | .reg = syscall_enter_register, |
| 45 | .define_fields = syscall_enter_define_fields, |
| 46 | .get_fields = syscall_get_enter_fields, |
| 47 | .raw_init = init_syscall_trace, |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct ftrace_event_class event_class_syscall_exit = { |
Lai Jiangshan | 7f85803 | 2011-01-14 17:49:02 +0800 | [diff] [blame] | 51 | .system = "syscalls", |
| 52 | .reg = syscall_exit_register, |
| 53 | .define_fields = syscall_exit_define_fields, |
| 54 | .fields = LIST_HEAD_INIT(event_class_syscall_exit.fields), |
| 55 | .raw_init = init_syscall_trace, |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 58 | extern struct syscall_metadata *__start_syscalls_metadata[]; |
| 59 | extern struct syscall_metadata *__stop_syscalls_metadata[]; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 60 | |
| 61 | static struct syscall_metadata **syscalls_metadata; |
| 62 | |
Ian Munsie | b2d5549 | 2011-02-03 14:27:23 +1100 | [diff] [blame^] | 63 | #ifndef ARCH_HAS_SYSCALL_MATCH_SYM_NAME |
| 64 | static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) |
| 65 | { |
| 66 | /* |
| 67 | * Only compare after the "sys" prefix. Archs that use |
| 68 | * syscall wrappers may have syscalls symbols aliases prefixed |
| 69 | * with "SyS" instead of "sys", leading to an unwanted |
| 70 | * mismatch. |
| 71 | */ |
| 72 | return !strcmp(sym + 3, name + 3); |
| 73 | } |
| 74 | #endif |
| 75 | |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 76 | static __init struct syscall_metadata * |
| 77 | find_syscall_meta(unsigned long syscall) |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 78 | { |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 79 | struct syscall_metadata **start; |
| 80 | struct syscall_metadata **stop; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 81 | char str[KSYM_SYMBOL_LEN]; |
| 82 | |
| 83 | |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 84 | start = __start_syscalls_metadata; |
| 85 | stop = __stop_syscalls_metadata; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 86 | kallsyms_lookup(syscall, NULL, NULL, NULL, str); |
| 87 | |
| 88 | for ( ; start < stop; start++) { |
Ian Munsie | b2d5549 | 2011-02-03 14:27:23 +1100 | [diff] [blame^] | 89 | if ((*start)->name && arch_syscall_match_sym_name(str, (*start)->name)) |
Steven Rostedt | 3d56e33 | 2011-02-02 17:06:09 -0500 | [diff] [blame] | 90 | return *start; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 91 | } |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | static struct syscall_metadata *syscall_nr_to_meta(int nr) |
| 96 | { |
| 97 | if (!syscalls_metadata || nr >= NR_syscalls || nr < 0) |
| 98 | return NULL; |
| 99 | |
| 100 | return syscalls_metadata[nr]; |
| 101 | } |
| 102 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 103 | enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 104 | print_syscall_enter(struct trace_iterator *iter, int flags, |
| 105 | struct trace_event *event) |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 106 | { |
| 107 | struct trace_seq *s = &iter->seq; |
| 108 | struct trace_entry *ent = iter->ent; |
| 109 | struct syscall_trace_enter *trace; |
| 110 | struct syscall_metadata *entry; |
| 111 | int i, ret, syscall; |
| 112 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 113 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 114 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 115 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 116 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 117 | if (!entry) |
| 118 | goto end; |
| 119 | |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 120 | if (entry->enter_event->event.type != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 121 | WARN_ON_ONCE(1); |
| 122 | goto end; |
| 123 | } |
| 124 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 125 | ret = trace_seq_printf(s, "%s(", entry->name); |
| 126 | if (!ret) |
| 127 | return TRACE_TYPE_PARTIAL_LINE; |
| 128 | |
| 129 | for (i = 0; i < entry->nb_args; i++) { |
| 130 | /* parameter types */ |
Li Zefan | ba8b3a4 | 2009-08-17 16:55:18 +0800 | [diff] [blame] | 131 | if (trace_flags & TRACE_ITER_VERBOSE) { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 132 | ret = trace_seq_printf(s, "%s ", entry->types[i]); |
| 133 | if (!ret) |
| 134 | return TRACE_TYPE_PARTIAL_LINE; |
| 135 | } |
| 136 | /* parameter values */ |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 137 | ret = trace_seq_printf(s, "%s: %lx%s", entry->args[i], |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 138 | trace->args[i], |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 139 | i == entry->nb_args - 1 ? "" : ", "); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 140 | if (!ret) |
| 141 | return TRACE_TYPE_PARTIAL_LINE; |
| 142 | } |
| 143 | |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 144 | ret = trace_seq_putc(s, ')'); |
| 145 | if (!ret) |
| 146 | return TRACE_TYPE_PARTIAL_LINE; |
| 147 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 148 | end: |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 149 | ret = trace_seq_putc(s, '\n'); |
| 150 | if (!ret) |
| 151 | return TRACE_TYPE_PARTIAL_LINE; |
| 152 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 153 | return TRACE_TYPE_HANDLED; |
| 154 | } |
| 155 | |
| 156 | enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 157 | print_syscall_exit(struct trace_iterator *iter, int flags, |
| 158 | struct trace_event *event) |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 159 | { |
| 160 | struct trace_seq *s = &iter->seq; |
| 161 | struct trace_entry *ent = iter->ent; |
| 162 | struct syscall_trace_exit *trace; |
| 163 | int syscall; |
| 164 | struct syscall_metadata *entry; |
| 165 | int ret; |
| 166 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 167 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 168 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 169 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 170 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 171 | if (!entry) { |
| 172 | trace_seq_printf(s, "\n"); |
| 173 | return TRACE_TYPE_HANDLED; |
| 174 | } |
| 175 | |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 176 | if (entry->exit_event->event.type != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 177 | WARN_ON_ONCE(1); |
| 178 | return TRACE_TYPE_UNHANDLED; |
| 179 | } |
| 180 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 181 | ret = trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, |
| 182 | trace->ret); |
| 183 | if (!ret) |
| 184 | return TRACE_TYPE_PARTIAL_LINE; |
| 185 | |
| 186 | return TRACE_TYPE_HANDLED; |
| 187 | } |
| 188 | |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 189 | extern char *__bad_type_size(void); |
| 190 | |
| 191 | #define SYSCALL_FIELD(type, name) \ |
| 192 | sizeof(type) != sizeof(trace.name) ? \ |
| 193 | __bad_type_size() : \ |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 194 | #type, #name, offsetof(typeof(trace), name), \ |
| 195 | sizeof(trace.name), is_signed_type(type) |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 196 | |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 197 | static |
| 198 | int __set_enter_print_fmt(struct syscall_metadata *entry, char *buf, int len) |
| 199 | { |
| 200 | int i; |
| 201 | int pos = 0; |
| 202 | |
| 203 | /* When len=0, we just calculate the needed length */ |
| 204 | #define LEN_OR_ZERO (len ? len - pos : 0) |
| 205 | |
| 206 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); |
| 207 | for (i = 0; i < entry->nb_args; i++) { |
| 208 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s: 0x%%0%zulx%s", |
| 209 | entry->args[i], sizeof(unsigned long), |
| 210 | i == entry->nb_args - 1 ? "" : ", "); |
| 211 | } |
| 212 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); |
| 213 | |
| 214 | for (i = 0; i < entry->nb_args; i++) { |
| 215 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
| 216 | ", ((unsigned long)(REC->%s))", entry->args[i]); |
| 217 | } |
| 218 | |
| 219 | #undef LEN_OR_ZERO |
| 220 | |
| 221 | /* return the length of print_fmt */ |
| 222 | return pos; |
| 223 | } |
| 224 | |
| 225 | static int set_syscall_print_fmt(struct ftrace_event_call *call) |
| 226 | { |
| 227 | char *print_fmt; |
| 228 | int len; |
| 229 | struct syscall_metadata *entry = call->data; |
| 230 | |
| 231 | if (entry->enter_event != call) { |
| 232 | call->print_fmt = "\"0x%lx\", REC->ret"; |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | /* First: called with 0 length to calculate the needed length */ |
| 237 | len = __set_enter_print_fmt(entry, NULL, 0); |
| 238 | |
| 239 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
| 240 | if (!print_fmt) |
| 241 | return -ENOMEM; |
| 242 | |
| 243 | /* Second: actually write the @print_fmt */ |
| 244 | __set_enter_print_fmt(entry, print_fmt, len + 1); |
| 245 | call->print_fmt = print_fmt; |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static void free_syscall_print_fmt(struct ftrace_event_call *call) |
| 251 | { |
| 252 | struct syscall_metadata *entry = call->data; |
| 253 | |
| 254 | if (entry->enter_event == call) |
| 255 | kfree(call->print_fmt); |
| 256 | } |
| 257 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 258 | static int syscall_enter_define_fields(struct ftrace_event_call *call) |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 259 | { |
| 260 | struct syscall_trace_enter trace; |
Lai Jiangshan | 31c16b1 | 2009-12-01 16:23:30 +0800 | [diff] [blame] | 261 | struct syscall_metadata *meta = call->data; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 262 | int ret; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 263 | int i; |
| 264 | int offset = offsetof(typeof(trace), args); |
| 265 | |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 266 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr), FILTER_OTHER); |
| 267 | if (ret) |
| 268 | return ret; |
| 269 | |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 270 | for (i = 0; i < meta->nb_args; i++) { |
Frederic Weisbecker | aeaeae1 | 2009-08-27 05:09:51 +0200 | [diff] [blame] | 271 | ret = trace_define_field(call, meta->types[i], |
| 272 | meta->args[i], offset, |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 273 | sizeof(unsigned long), 0, |
| 274 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 275 | offset += sizeof(unsigned long); |
| 276 | } |
| 277 | |
| 278 | return ret; |
| 279 | } |
| 280 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 281 | static int syscall_exit_define_fields(struct ftrace_event_call *call) |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 282 | { |
| 283 | struct syscall_trace_exit trace; |
| 284 | int ret; |
| 285 | |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 286 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr), FILTER_OTHER); |
| 287 | if (ret) |
| 288 | return ret; |
| 289 | |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 290 | ret = trace_define_field(call, SYSCALL_FIELD(long, ret), |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 291 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 292 | |
| 293 | return ret; |
| 294 | } |
| 295 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 296 | void ftrace_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 297 | { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 298 | struct syscall_trace_enter *entry; |
| 299 | struct syscall_metadata *sys_data; |
| 300 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 301 | struct ring_buffer *buffer; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 302 | int size; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 303 | int syscall_nr; |
| 304 | |
| 305 | syscall_nr = syscall_get_nr(current, regs); |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 306 | if (syscall_nr < 0) |
| 307 | return; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 308 | if (!test_bit(syscall_nr, enabled_enter_syscalls)) |
| 309 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 310 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 311 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 312 | if (!sys_data) |
| 313 | return; |
| 314 | |
| 315 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
| 316 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 317 | event = trace_current_buffer_lock_reserve(&buffer, |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 318 | sys_data->enter_event->event.type, size, 0, 0); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 319 | if (!event) |
| 320 | return; |
| 321 | |
| 322 | entry = ring_buffer_event_data(event); |
| 323 | entry->nr = syscall_nr; |
| 324 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); |
| 325 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 326 | if (!filter_current_check_discard(buffer, sys_data->enter_event, |
| 327 | entry, event)) |
| 328 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 331 | void ftrace_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 332 | { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 333 | struct syscall_trace_exit *entry; |
| 334 | struct syscall_metadata *sys_data; |
| 335 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 336 | struct ring_buffer *buffer; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 337 | int syscall_nr; |
| 338 | |
| 339 | syscall_nr = syscall_get_nr(current, regs); |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 340 | if (syscall_nr < 0) |
| 341 | return; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 342 | if (!test_bit(syscall_nr, enabled_exit_syscalls)) |
| 343 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 344 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 345 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 346 | if (!sys_data) |
| 347 | return; |
| 348 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 349 | event = trace_current_buffer_lock_reserve(&buffer, |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 350 | sys_data->exit_event->event.type, sizeof(*entry), 0, 0); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 351 | if (!event) |
| 352 | return; |
| 353 | |
| 354 | entry = ring_buffer_event_data(event); |
| 355 | entry->nr = syscall_nr; |
| 356 | entry->ret = syscall_get_return_value(current, regs); |
| 357 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 358 | if (!filter_current_check_discard(buffer, sys_data->exit_event, |
| 359 | entry, event)) |
| 360 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 363 | int reg_event_syscall_enter(struct ftrace_event_call *call) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 364 | { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 365 | int ret = 0; |
| 366 | int num; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 367 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 368 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 369 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 370 | return -ENOSYS; |
| 371 | mutex_lock(&syscall_trace_lock); |
| 372 | if (!sys_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 373 | ret = register_trace_sys_enter(ftrace_syscall_enter, NULL); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 374 | if (!ret) { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 375 | set_bit(num, enabled_enter_syscalls); |
| 376 | sys_refcount_enter++; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 377 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 378 | mutex_unlock(&syscall_trace_lock); |
| 379 | return ret; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 380 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 381 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 382 | void unreg_event_syscall_enter(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 383 | { |
| 384 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 385 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 386 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 387 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 388 | return; |
| 389 | mutex_lock(&syscall_trace_lock); |
| 390 | sys_refcount_enter--; |
| 391 | clear_bit(num, enabled_enter_syscalls); |
| 392 | if (!sys_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 393 | unregister_trace_sys_enter(ftrace_syscall_enter, NULL); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 394 | mutex_unlock(&syscall_trace_lock); |
| 395 | } |
| 396 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 397 | int reg_event_syscall_exit(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 398 | { |
| 399 | int ret = 0; |
| 400 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 401 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 402 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 403 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 404 | return -ENOSYS; |
| 405 | mutex_lock(&syscall_trace_lock); |
| 406 | if (!sys_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 407 | ret = register_trace_sys_exit(ftrace_syscall_exit, NULL); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 408 | if (!ret) { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 409 | set_bit(num, enabled_exit_syscalls); |
| 410 | sys_refcount_exit++; |
| 411 | } |
| 412 | mutex_unlock(&syscall_trace_lock); |
| 413 | return ret; |
| 414 | } |
| 415 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 416 | void unreg_event_syscall_exit(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 417 | { |
| 418 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 419 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 420 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Ian Munsie | 3773b389 | 2011-02-03 14:27:21 +1100 | [diff] [blame] | 421 | if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 422 | return; |
| 423 | mutex_lock(&syscall_trace_lock); |
| 424 | sys_refcount_exit--; |
| 425 | clear_bit(num, enabled_exit_syscalls); |
| 426 | if (!sys_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 427 | unregister_trace_sys_exit(ftrace_syscall_exit, NULL); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 428 | mutex_unlock(&syscall_trace_lock); |
| 429 | } |
| 430 | |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 431 | int init_syscall_trace(struct ftrace_event_call *call) |
| 432 | { |
| 433 | int id; |
Ian Munsie | ba97697 | 2011-02-03 14:27:20 +1100 | [diff] [blame] | 434 | int num; |
| 435 | |
| 436 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
| 437 | if (num < 0 || num >= NR_syscalls) { |
| 438 | pr_debug("syscall %s metadata not mapped, disabling ftrace event\n", |
| 439 | ((struct syscall_metadata *)call->data)->name); |
| 440 | return -ENOSYS; |
| 441 | } |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 442 | |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 443 | if (set_syscall_print_fmt(call) < 0) |
| 444 | return -ENOMEM; |
| 445 | |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 446 | id = trace_event_raw_init(call); |
| 447 | |
| 448 | if (id < 0) { |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 449 | free_syscall_print_fmt(call); |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 450 | return id; |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 451 | } |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 452 | |
| 453 | return id; |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 454 | } |
| 455 | |
Ian Munsie | c763ba0 | 2011-02-03 14:27:22 +1100 | [diff] [blame] | 456 | unsigned long __init __weak arch_syscall_addr(int nr) |
Mike Frysinger | e7b8e67 | 2010-01-26 04:40:03 -0500 | [diff] [blame] | 457 | { |
| 458 | return (unsigned long)sys_call_table[nr]; |
| 459 | } |
| 460 | |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 461 | int __init init_ftrace_syscalls(void) |
| 462 | { |
| 463 | struct syscall_metadata *meta; |
| 464 | unsigned long addr; |
| 465 | int i; |
| 466 | |
| 467 | syscalls_metadata = kzalloc(sizeof(*syscalls_metadata) * |
| 468 | NR_syscalls, GFP_KERNEL); |
| 469 | if (!syscalls_metadata) { |
| 470 | WARN_ON(1); |
| 471 | return -ENOMEM; |
| 472 | } |
| 473 | |
| 474 | for (i = 0; i < NR_syscalls; i++) { |
| 475 | addr = arch_syscall_addr(i); |
| 476 | meta = find_syscall_meta(addr); |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 477 | if (!meta) |
| 478 | continue; |
| 479 | |
| 480 | meta->syscall_nr = i; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 481 | syscalls_metadata[i] = meta; |
| 482 | } |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | core_initcall(init_ftrace_syscalls); |
| 487 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 488 | #ifdef CONFIG_PERF_EVENTS |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 489 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 490 | static DECLARE_BITMAP(enabled_perf_enter_syscalls, NR_syscalls); |
| 491 | static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); |
| 492 | static int sys_perf_refcount_enter; |
| 493 | static int sys_perf_refcount_exit; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 494 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 495 | 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] | 496 | { |
| 497 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 498 | struct syscall_trace_enter *rec; |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 499 | struct hlist_head *head; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 500 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 501 | int rctx; |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 502 | int size; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 503 | |
| 504 | syscall_nr = syscall_get_nr(current, regs); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 505 | if (!test_bit(syscall_nr, enabled_perf_enter_syscalls)) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 506 | return; |
| 507 | |
| 508 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 509 | if (!sys_data) |
| 510 | return; |
| 511 | |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 512 | /* get the size after alignment with the u32 buffer size field */ |
| 513 | size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); |
| 514 | size = ALIGN(size + sizeof(u32), sizeof(u64)); |
| 515 | size -= sizeof(u32); |
| 516 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 517 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
| 518 | "perf buffer not large enough")) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 519 | return; |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 520 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 521 | rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, |
Steven Rostedt | ff5f149 | 2010-05-21 11:49:57 -0400 | [diff] [blame] | 522 | sys_data->enter_event->event.type, regs, &rctx); |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 523 | if (!rec) |
| 524 | return; |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 525 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 526 | rec->nr = syscall_nr; |
| 527 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, |
| 528 | (unsigned long *)&rec->args); |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 529 | |
Peter Zijlstra | 3771f07 | 2010-05-21 12:31:09 +0200 | [diff] [blame] | 530 | head = this_cpu_ptr(sys_data->enter_event->perf_events); |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 531 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 532 | } |
| 533 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 534 | int perf_sysenter_enable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 535 | { |
| 536 | int ret = 0; |
| 537 | int num; |
| 538 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 539 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 540 | |
| 541 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 542 | if (!sys_perf_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 543 | ret = register_trace_sys_enter(perf_syscall_enter, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 544 | if (ret) { |
| 545 | pr_info("event trace: Could not activate" |
| 546 | "syscall entry trace point"); |
| 547 | } else { |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 548 | set_bit(num, enabled_perf_enter_syscalls); |
| 549 | sys_perf_refcount_enter++; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 550 | } |
| 551 | mutex_unlock(&syscall_trace_lock); |
| 552 | return ret; |
| 553 | } |
| 554 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 555 | void perf_sysenter_disable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 556 | { |
| 557 | int num; |
| 558 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 559 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 560 | |
| 561 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 562 | sys_perf_refcount_enter--; |
| 563 | clear_bit(num, enabled_perf_enter_syscalls); |
| 564 | if (!sys_perf_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 565 | unregister_trace_sys_enter(perf_syscall_enter, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 566 | mutex_unlock(&syscall_trace_lock); |
| 567 | } |
| 568 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 569 | 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] | 570 | { |
| 571 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 572 | struct syscall_trace_exit *rec; |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 573 | struct hlist_head *head; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 574 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 575 | int rctx; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 576 | int size; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 577 | |
| 578 | syscall_nr = syscall_get_nr(current, regs); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 579 | if (!test_bit(syscall_nr, enabled_perf_exit_syscalls)) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 580 | return; |
| 581 | |
| 582 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 583 | if (!sys_data) |
| 584 | return; |
| 585 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 586 | /* We can probably do that at build time */ |
| 587 | size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); |
| 588 | size -= sizeof(u32); |
Frederic Weisbecker | 19007a6 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 589 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 590 | /* |
| 591 | * Impossible, but be paranoid with the future |
| 592 | * How to put this check outside runtime? |
| 593 | */ |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 594 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
| 595 | "exit event has grown above perf buffer size")) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 596 | return; |
| 597 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 598 | rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, |
Steven Rostedt | ff5f149 | 2010-05-21 11:49:57 -0400 | [diff] [blame] | 599 | sys_data->exit_event->event.type, regs, &rctx); |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 600 | if (!rec) |
| 601 | return; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 602 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 603 | rec->nr = syscall_nr; |
| 604 | rec->ret = syscall_get_return_value(current, regs); |
| 605 | |
Peter Zijlstra | 3771f07 | 2010-05-21 12:31:09 +0200 | [diff] [blame] | 606 | head = this_cpu_ptr(sys_data->exit_event->perf_events); |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 607 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 610 | int perf_sysexit_enable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 611 | { |
| 612 | int ret = 0; |
| 613 | int num; |
| 614 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 615 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 616 | |
| 617 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 618 | if (!sys_perf_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 619 | ret = register_trace_sys_exit(perf_syscall_exit, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 620 | if (ret) { |
| 621 | pr_info("event trace: Could not activate" |
Wenji Huang | 6574658 | 2010-02-24 15:40:22 +0800 | [diff] [blame] | 622 | "syscall exit trace point"); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 623 | } else { |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 624 | set_bit(num, enabled_perf_exit_syscalls); |
| 625 | sys_perf_refcount_exit++; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 626 | } |
| 627 | mutex_unlock(&syscall_trace_lock); |
| 628 | return ret; |
| 629 | } |
| 630 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 631 | void perf_sysexit_disable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 632 | { |
| 633 | int num; |
| 634 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 635 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 636 | |
| 637 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 638 | sys_perf_refcount_exit--; |
| 639 | clear_bit(num, enabled_perf_exit_syscalls); |
| 640 | if (!sys_perf_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 641 | unregister_trace_sys_exit(perf_syscall_exit, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 642 | mutex_unlock(&syscall_trace_lock); |
| 643 | } |
| 644 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 645 | #endif /* CONFIG_PERF_EVENTS */ |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 646 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 647 | static int syscall_enter_register(struct ftrace_event_call *event, |
| 648 | enum trace_reg type) |
| 649 | { |
| 650 | switch (type) { |
| 651 | case TRACE_REG_REGISTER: |
| 652 | return reg_event_syscall_enter(event); |
| 653 | case TRACE_REG_UNREGISTER: |
| 654 | unreg_event_syscall_enter(event); |
| 655 | return 0; |
| 656 | |
| 657 | #ifdef CONFIG_PERF_EVENTS |
| 658 | case TRACE_REG_PERF_REGISTER: |
| 659 | return perf_sysenter_enable(event); |
| 660 | case TRACE_REG_PERF_UNREGISTER: |
| 661 | perf_sysenter_disable(event); |
| 662 | return 0; |
| 663 | #endif |
| 664 | } |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | static int syscall_exit_register(struct ftrace_event_call *event, |
| 669 | enum trace_reg type) |
| 670 | { |
| 671 | switch (type) { |
| 672 | case TRACE_REG_REGISTER: |
| 673 | return reg_event_syscall_exit(event); |
| 674 | case TRACE_REG_UNREGISTER: |
| 675 | unreg_event_syscall_exit(event); |
| 676 | return 0; |
| 677 | |
| 678 | #ifdef CONFIG_PERF_EVENTS |
| 679 | case TRACE_REG_PERF_REGISTER: |
| 680 | return perf_sysexit_enable(event); |
| 681 | case TRACE_REG_PERF_UNREGISTER: |
| 682 | perf_sysexit_disable(event); |
| 683 | return 0; |
| 684 | #endif |
| 685 | } |
| 686 | return 0; |
| 687 | } |