Skip to content

Commit 055b121

Browse files
AKASHI Takahirowildea01
AKASHI Takahiro
authored andcommitted
arm64: ftrace: Add system call tracepoint
This patch allows system call entry or exit to be traced as ftrace events, ie. sys_enter_*/sys_exit_*, if CONFIG_FTRACE_SYSCALLS is enabled. Those events appear and can be controlled under ${sysfs}/tracing/events/syscalls/ Please note that we can't trace compat system calls here because AArch32 mode does not share the same syscall table with AArch64. Just define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS in order to avoid unexpected results (bogus syscalls reported or even hang-up). Acked-by: Will Deacon <[email protected]> Signed-off-by: AKASHI Takahiro <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 3711784 commit 055b121

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

arch/arm64/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ config ARM64
4848
select HAVE_PERF_EVENTS
4949
select HAVE_PERF_REGS
5050
select HAVE_PERF_USER_STACK_DUMP
51+
select HAVE_SYSCALL_TRACEPOINTS
5152
select IRQ_DOMAIN
5253
select MODULES_USE_ELF_RELA
5354
select NO_BOOTMEM

arch/arm64/include/asm/ftrace.h

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
1818

1919
#ifndef __ASSEMBLY__
20+
#include <linux/compat.h>
21+
2022
extern void _mcount(unsigned long);
2123
extern void *return_address(unsigned int);
2224

@@ -36,6 +38,22 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
3638
}
3739

3840
#define ftrace_return_address(n) return_address(n)
41+
42+
/*
43+
* Because AArch32 mode does not share the same syscall table with AArch64,
44+
* tracing compat syscalls may result in reporting bogus syscalls or even
45+
* hang-up, so just do not trace them.
46+
* See kernel/trace/trace_syscalls.c
47+
*
48+
* x86 code says:
49+
* If the user realy wants these, then they should use the
50+
* raw syscall tracepoints with filtering.
51+
*/
52+
#define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
53+
static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
54+
{
55+
return is_compat_task();
56+
}
3957
#endif /* ifndef __ASSEMBLY__ */
4058

4159
#endif /* __ASM_FTRACE_H */

arch/arm64/include/asm/syscall.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <linux/err.h>
2020

21+
extern const void *sys_call_table[];
2122

2223
static inline int syscall_get_nr(struct task_struct *task,
2324
struct pt_regs *regs)

arch/arm64/include/asm/unistd.h

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@
2929
#endif
3030
#define __ARCH_WANT_SYS_CLONE
3131
#include <uapi/asm/unistd.h>
32+
33+
#define NR_syscalls (__NR_syscalls)

arch/arm64/kernel/ptrace.c

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
#include <asm/traps.h>
4343
#include <asm/system_misc.h>
4444

45+
#define CREATE_TRACE_POINTS
46+
#include <trace/events/syscalls.h>
47+
4548
/*
4649
* TODO: does not yet catch signals sent when the child dies.
4750
* in exit.c or in signal.c.
@@ -1093,11 +1096,17 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10931096
if (test_thread_flag(TIF_SYSCALL_TRACE))
10941097
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
10951098

1099+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
1100+
trace_sys_enter(regs, regs->syscallno);
1101+
10961102
return regs->syscallno;
10971103
}
10981104

10991105
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
11001106
{
1107+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
1108+
trace_sys_exit(regs, regs_return_value(regs));
1109+
11011110
if (test_thread_flag(TIF_SYSCALL_TRACE))
11021111
tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);
11031112
}

0 commit comments

Comments
 (0)