aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Baron <jbaron@redhat.com>2009-08-10 16:52:31 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2009-08-11 14:35:26 -0400
commita871bd33a6c0bc86fb47cd02ea2650dd43d3d95f (patch)
treeb5720cdb3168ba0894b4bd2c1acc004cb19a692c
parent63fbdab3157b72467013fe4dcf88c85e45280ef7 (diff)
tracing: Add syscall tracepoints
add two tracepoints in syscall exit and entry path, conditioned on TIF_SYSCALL_FTRACE. Supports the syscall trace event code. Signed-off-by: Jason Baron <jbaron@redhat.com> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Jiaying Zhang <jiayingz@google.com> Cc: Martin Bligh <mbligh@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Masami Hiramatsu <mhiramat@redhat.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
-rw-r--r--arch/x86/kernel/ptrace.c7
-rw-r--r--include/trace/syscall.h20
-rw-r--r--kernel/tracepoint.c38
3 files changed, 63 insertions, 2 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 09ecbde91c13..34dd6f15185d 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -37,6 +37,9 @@
37 37
38#include <trace/syscall.h> 38#include <trace/syscall.h>
39 39
40DEFINE_TRACE(syscall_enter);
41DEFINE_TRACE(syscall_exit);
42
40#include "tls.h" 43#include "tls.h"
41 44
42enum x86_regset { 45enum x86_regset {
@@ -1498,7 +1501,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
1498 ret = -1L; 1501 ret = -1L;
1499 1502
1500 if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE))) 1503 if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
1501 ftrace_syscall_enter(regs); 1504 trace_syscall_enter(regs, regs->orig_ax);
1502 1505
1503 if (unlikely(current->audit_context)) { 1506 if (unlikely(current->audit_context)) {
1504 if (IS_IA32) 1507 if (IS_IA32)
@@ -1524,7 +1527,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
1524 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); 1527 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
1525 1528
1526 if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE))) 1529 if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
1527 ftrace_syscall_exit(regs); 1530 trace_syscall_exit(regs, regs->ax);
1528 1531
1529 if (test_thread_flag(TIF_SYSCALL_TRACE)) 1532 if (test_thread_flag(TIF_SYSCALL_TRACE))
1530 tracehook_report_syscall_exit(regs, 0); 1533 tracehook_report_syscall_exit(regs, 0);
diff --git a/include/trace/syscall.h b/include/trace/syscall.h
index c55fcce4fbb2..3951d774de18 100644
--- a/include/trace/syscall.h
+++ b/include/trace/syscall.h
@@ -1,8 +1,28 @@
1#ifndef _TRACE_SYSCALL_H 1#ifndef _TRACE_SYSCALL_H
2#define _TRACE_SYSCALL_H 2#define _TRACE_SYSCALL_H
3 3
4#include <linux/tracepoint.h>
5
4#include <asm/ptrace.h> 6#include <asm/ptrace.h>
5 7
8
9extern void syscall_regfunc(void);
10extern void syscall_unregfunc(void);
11
12DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
13 TP_PROTO(struct pt_regs *regs, long id),
14 TP_ARGS(regs, id),
15 syscall_regfunc,
16 syscall_unregfunc
17);
18
19DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
20 TP_PROTO(struct pt_regs *regs, long ret),
21 TP_ARGS(regs, ret),
22 syscall_regfunc,
23 syscall_unregfunc
24);
25
6/* 26/*
7 * A syscall entry in the ftrace syscalls array. 27 * A syscall entry in the ftrace syscalls array.
8 * 28 *
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 1ef5d3a601c7..070a42bb8920 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -24,6 +24,7 @@
24#include <linux/tracepoint.h> 24#include <linux/tracepoint.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/sched.h>
27 28
28extern struct tracepoint __start___tracepoints[]; 29extern struct tracepoint __start___tracepoints[];
29extern struct tracepoint __stop___tracepoints[]; 30extern struct tracepoint __stop___tracepoints[];
@@ -577,3 +578,40 @@ static int init_tracepoints(void)
577__initcall(init_tracepoints); 578__initcall(init_tracepoints);
578 579
579#endif /* CONFIG_MODULES */ 580#endif /* CONFIG_MODULES */
581
582static DEFINE_MUTEX(regfunc_mutex);
583static int sys_tracepoint_refcount;
584
585void syscall_regfunc(void)
586{
587 unsigned long flags;
588 struct task_struct *g, *t;
589
590 mutex_lock(&regfunc_mutex);
591 if (!sys_tracepoint_refcount) {
592 read_lock_irqsave(&tasklist_lock, flags);
593 do_each_thread(g, t) {
594 set_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
595 } while_each_thread(g, t);
596 read_unlock_irqrestore(&tasklist_lock, flags);
597 }
598 sys_tracepoint_refcount++;
599 mutex_unlock(&regfunc_mutex);
600}
601
602void syscall_unregfunc(void)
603{
604 unsigned long flags;
605 struct task_struct *g, *t;
606
607 mutex_lock(&regfunc_mutex);
608 sys_tracepoint_refcount--;
609 if (!sys_tracepoint_refcount) {
610 read_lock_irqsave(&tasklist_lock, flags);
611 do_each_thread(g, t) {
612 clear_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
613 } while_each_thread(g, t);
614 read_unlock_irqrestore(&tasklist_lock, flags);
615 }
616 mutex_unlock(&regfunc_mutex);
617}