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