diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-03-06 23:53:00 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-03-13 01:25:44 -0400 |
commit | 1b3fa2ce64363c289b3b14723cca7290bf91cfce (patch) | |
tree | fcf6988ca5fa716e7f3964c3a29954fe80b03fd7 | |
parent | ee08c6eccb7d1295516f7cf420fddf7b14e9146f (diff) |
tracing/x86: basic implementation of syscall tracing for x86
Provide the x86 trace callbacks to trace syscalls.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
LKML-Reference: <1236401580-5758-3-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | arch/x86/Kconfig | 1 | ||||
-rw-r--r-- | arch/x86/include/asm/thread_info.h | 9 | ||||
-rw-r--r-- | arch/x86/kernel/ptrace.c | 7 |
3 files changed, 14 insertions, 3 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index bdcee12c25ab..b0a638b4199a 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -35,6 +35,7 @@ config X86 | |||
35 | select HAVE_FUNCTION_GRAPH_TRACER | 35 | select HAVE_FUNCTION_GRAPH_TRACER |
36 | select HAVE_FUNCTION_TRACE_MCOUNT_TEST | 36 | select HAVE_FUNCTION_TRACE_MCOUNT_TEST |
37 | select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE | 37 | select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE |
38 | select HAVE_FTRACE_SYSCALLS | ||
38 | select HAVE_KVM | 39 | select HAVE_KVM |
39 | select HAVE_ARCH_KGDB | 40 | select HAVE_ARCH_KGDB |
40 | select HAVE_ARCH_TRACEHOOK | 41 | select HAVE_ARCH_TRACEHOOK |
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index df9d5f78385e..8820a73ae090 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h | |||
@@ -94,6 +94,7 @@ struct thread_info { | |||
94 | #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ | 94 | #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ |
95 | #define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */ | 95 | #define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */ |
96 | #define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */ | 96 | #define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */ |
97 | #define TIF_SYSCALL_FTRACE 27 /* for ftrace syscall instrumentation */ | ||
97 | 98 | ||
98 | #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) | 99 | #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) |
99 | #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) | 100 | #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) |
@@ -115,15 +116,17 @@ struct thread_info { | |||
115 | #define _TIF_FORCED_TF (1 << TIF_FORCED_TF) | 116 | #define _TIF_FORCED_TF (1 << TIF_FORCED_TF) |
116 | #define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR) | 117 | #define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR) |
117 | #define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR) | 118 | #define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR) |
119 | #define _TIF_SYSCALL_FTRACE (1 << TIF_SYSCALL_FTRACE) | ||
118 | 120 | ||
119 | /* work to do in syscall_trace_enter() */ | 121 | /* work to do in syscall_trace_enter() */ |
120 | #define _TIF_WORK_SYSCALL_ENTRY \ | 122 | #define _TIF_WORK_SYSCALL_ENTRY \ |
121 | (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | \ | 123 | (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_FTRACE | \ |
122 | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | _TIF_SINGLESTEP) | 124 | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | _TIF_SINGLESTEP) |
123 | 125 | ||
124 | /* work to do in syscall_trace_leave() */ | 126 | /* work to do in syscall_trace_leave() */ |
125 | #define _TIF_WORK_SYSCALL_EXIT \ | 127 | #define _TIF_WORK_SYSCALL_EXIT \ |
126 | (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP) | 128 | (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \ |
129 | _TIF_SYSCALL_FTRACE) | ||
127 | 130 | ||
128 | /* work to do on interrupt/exception return */ | 131 | /* work to do on interrupt/exception return */ |
129 | #define _TIF_WORK_MASK \ | 132 | #define _TIF_WORK_MASK \ |
@@ -132,7 +135,7 @@ struct thread_info { | |||
132 | _TIF_SINGLESTEP|_TIF_SECCOMP|_TIF_SYSCALL_EMU)) | 135 | _TIF_SINGLESTEP|_TIF_SECCOMP|_TIF_SYSCALL_EMU)) |
133 | 136 | ||
134 | /* work to do on any return to user space */ | 137 | /* work to do on any return to user space */ |
135 | #define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP) | 138 | #define _TIF_ALLWORK_MASK ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_FTRACE) |
136 | 139 | ||
137 | /* Only used for 64 bit */ | 140 | /* Only used for 64 bit */ |
138 | #define _TIF_DO_NOTIFY_MASK \ | 141 | #define _TIF_DO_NOTIFY_MASK \ |
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 3d9672e59c16..99749d6e87a8 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/audit.h> | 21 | #include <linux/audit.h> |
22 | #include <linux/seccomp.h> | 22 | #include <linux/seccomp.h> |
23 | #include <linux/signal.h> | 23 | #include <linux/signal.h> |
24 | #include <linux/ftrace.h> | ||
24 | 25 | ||
25 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
26 | #include <asm/pgtable.h> | 27 | #include <asm/pgtable.h> |
@@ -1416,6 +1417,9 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs) | |||
1416 | tracehook_report_syscall_entry(regs)) | 1417 | tracehook_report_syscall_entry(regs)) |
1417 | ret = -1L; | 1418 | ret = -1L; |
1418 | 1419 | ||
1420 | if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE))) | ||
1421 | ftrace_syscall_enter(regs); | ||
1422 | |||
1419 | if (unlikely(current->audit_context)) { | 1423 | if (unlikely(current->audit_context)) { |
1420 | if (IS_IA32) | 1424 | if (IS_IA32) |
1421 | audit_syscall_entry(AUDIT_ARCH_I386, | 1425 | audit_syscall_entry(AUDIT_ARCH_I386, |
@@ -1439,6 +1443,9 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs) | |||
1439 | if (unlikely(current->audit_context)) | 1443 | if (unlikely(current->audit_context)) |
1440 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); | 1444 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); |
1441 | 1445 | ||
1446 | if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE))) | ||
1447 | ftrace_syscall_exit(regs); | ||
1448 | |||
1442 | if (test_thread_flag(TIF_SYSCALL_TRACE)) | 1449 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
1443 | tracehook_report_syscall_exit(regs, 0); | 1450 | tracehook_report_syscall_exit(regs, 0); |
1444 | 1451 | ||