diff options
-rw-r--r-- | kernel/trace/trace_syscalls.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 9ee6386cf842..f837cccabcf7 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
@@ -301,6 +301,17 @@ struct trace_event event_syscall_exit = { | |||
301 | }; | 301 | }; |
302 | 302 | ||
303 | #ifdef CONFIG_EVENT_PROFILE | 303 | #ifdef CONFIG_EVENT_PROFILE |
304 | |||
305 | struct syscall_enter_record { | ||
306 | struct trace_entry entry; | ||
307 | unsigned long args[0]; | ||
308 | }; | ||
309 | |||
310 | struct syscall_exit_record { | ||
311 | struct trace_entry entry; | ||
312 | unsigned long ret; | ||
313 | }; | ||
314 | |||
304 | static DECLARE_BITMAP(enabled_prof_enter_syscalls, FTRACE_SYSCALL_MAX); | 315 | static DECLARE_BITMAP(enabled_prof_enter_syscalls, FTRACE_SYSCALL_MAX); |
305 | static DECLARE_BITMAP(enabled_prof_exit_syscalls, FTRACE_SYSCALL_MAX); | 316 | static DECLARE_BITMAP(enabled_prof_exit_syscalls, FTRACE_SYSCALL_MAX); |
306 | static int sys_prof_refcount_enter; | 317 | static int sys_prof_refcount_enter; |
@@ -308,8 +319,10 @@ static int sys_prof_refcount_exit; | |||
308 | 319 | ||
309 | static void prof_syscall_enter(struct pt_regs *regs, long id) | 320 | static void prof_syscall_enter(struct pt_regs *regs, long id) |
310 | { | 321 | { |
322 | struct syscall_enter_record *rec; | ||
311 | struct syscall_metadata *sys_data; | 323 | struct syscall_metadata *sys_data; |
312 | int syscall_nr; | 324 | int syscall_nr; |
325 | int size; | ||
313 | 326 | ||
314 | syscall_nr = syscall_get_nr(current, regs); | 327 | syscall_nr = syscall_get_nr(current, regs); |
315 | if (!test_bit(syscall_nr, enabled_prof_enter_syscalls)) | 328 | if (!test_bit(syscall_nr, enabled_prof_enter_syscalls)) |
@@ -319,7 +332,24 @@ static void prof_syscall_enter(struct pt_regs *regs, long id) | |||
319 | if (!sys_data) | 332 | if (!sys_data) |
320 | return; | 333 | return; |
321 | 334 | ||
322 | perf_tpcounter_event(sys_data->enter_id, 0, 1, NULL, 0); | 335 | /* get the size after alignment with the u32 buffer size field */ |
336 | size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); | ||
337 | size = ALIGN(size + sizeof(u32), sizeof(u64)); | ||
338 | size -= sizeof(u32); | ||
339 | |||
340 | do { | ||
341 | char raw_data[size]; | ||
342 | |||
343 | /* zero the dead bytes from align to not leak stack to user */ | ||
344 | *(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL; | ||
345 | |||
346 | rec = (struct syscall_enter_record *) raw_data; | ||
347 | tracing_generic_entry_update(&rec->entry, 0, 0); | ||
348 | rec->entry.type = sys_data->enter_id; | ||
349 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, | ||
350 | (unsigned long *)&rec->args); | ||
351 | perf_tpcounter_event(sys_data->enter_id, 0, 1, rec, size); | ||
352 | } while(0); | ||
323 | } | 353 | } |
324 | 354 | ||
325 | int reg_prof_syscall_enter(char *name) | 355 | int reg_prof_syscall_enter(char *name) |
@@ -364,6 +394,7 @@ void unreg_prof_syscall_enter(char *name) | |||
364 | static void prof_syscall_exit(struct pt_regs *regs, long ret) | 394 | static void prof_syscall_exit(struct pt_regs *regs, long ret) |
365 | { | 395 | { |
366 | struct syscall_metadata *sys_data; | 396 | struct syscall_metadata *sys_data; |
397 | struct syscall_exit_record rec; | ||
367 | int syscall_nr; | 398 | int syscall_nr; |
368 | 399 | ||
369 | syscall_nr = syscall_get_nr(current, regs); | 400 | syscall_nr = syscall_get_nr(current, regs); |
@@ -374,7 +405,11 @@ static void prof_syscall_exit(struct pt_regs *regs, long ret) | |||
374 | if (!sys_data) | 405 | if (!sys_data) |
375 | return; | 406 | return; |
376 | 407 | ||
377 | perf_tpcounter_event(sys_data->exit_id, 0, 1, NULL, 0); | 408 | tracing_generic_entry_update(&rec.entry, 0, 0); |
409 | rec.entry.type = sys_data->exit_id; | ||
410 | rec.ret = syscall_get_return_value(current, regs); | ||
411 | |||
412 | perf_tpcounter_event(sys_data->exit_id, 0, 1, &rec, sizeof(rec)); | ||
378 | } | 413 | } |
379 | 414 | ||
380 | int reg_prof_syscall_exit(char *name) | 415 | int reg_prof_syscall_exit(char *name) |