Skip to content

Commit fb0b549

Browse files
Sergey Matyukevichvineetgarc
authored andcommitted
ARC: implement syscall tracepoints
Implement all the bits required to support HAVE_SYSCALL_TRACEPOINTS according to Documentation/trace/ftrace-design.rst. Signed-off-by: Sergey Matyukevich <[email protected]> Signed-off-by: Vineet Gupta <[email protected]>
1 parent b3bbf6a commit fb0b549

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

arch/arc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ config ARC
3939
select HAVE_REGS_AND_STACK_ACCESS_API
4040
select HAVE_MOD_ARCH_SPECIFIC
4141
select HAVE_PERF_EVENTS
42+
select HAVE_SYSCALL_TRACEPOINTS
4243
select IRQ_DOMAIN
4344
select MODULES_USE_ELF_RELA
4445
select OF

arch/arc/include/asm/syscall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <asm/unistd.h>
1313
#include <asm/ptrace.h> /* in_syscall() */
1414

15+
extern void *sys_call_table[];
16+
1517
static inline long
1618
syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
1719
{

arch/arc/include/asm/thread_info.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
7878
#define TIF_SYSCALL_AUDIT 4 /* syscall auditing active */
7979
#define TIF_NOTIFY_SIGNAL 5 /* signal notifications exist */
8080
#define TIF_SYSCALL_TRACE 15 /* syscall trace active */
81-
8281
/* true if poll_idle() is polling TIF_NEED_RESCHED */
8382
#define TIF_MEMDIE 16
83+
#define TIF_SYSCALL_TRACEPOINT 17 /* syscall tracepoint instrumentation */
8484

8585
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8686
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -89,11 +89,14 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
8989
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9090
#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL)
9191
#define _TIF_MEMDIE (1<<TIF_MEMDIE)
92+
#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9293

9394
/* work to do on interrupt/exception return */
9495
#define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
9596
_TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL)
9697

98+
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
99+
97100
/*
98101
* _TIF_ALLWORK_MASK includes SYSCALL_TRACE, but we don't need it.
99102
* SYSCALL_TRACE is anyway separately/unconditionally tested right after a

arch/arc/kernel/entry.S

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ ENTRY(sys_clone_wrapper)
2929
DISCARD_CALLEE_SAVED_USER
3030

3131
GET_CURR_THR_INFO_FLAGS r10
32-
btst r10, TIF_SYSCALL_TRACE
33-
bnz tracesys_exit
32+
and.f 0, r10, _TIF_SYSCALL_WORK
33+
bnz tracesys_exit
3434

3535
b .Lret_from_system_call
3636
END(sys_clone_wrapper)
@@ -41,8 +41,8 @@ ENTRY(sys_clone3_wrapper)
4141
DISCARD_CALLEE_SAVED_USER
4242

4343
GET_CURR_THR_INFO_FLAGS r10
44-
btst r10, TIF_SYSCALL_TRACE
45-
bnz tracesys_exit
44+
and.f 0, r10, _TIF_SYSCALL_WORK
45+
bnz tracesys_exit
4646

4747
b .Lret_from_system_call
4848
END(sys_clone3_wrapper)
@@ -247,8 +247,8 @@ ENTRY(EV_Trap)
247247

248248
; If syscall tracing ongoing, invoke pre-post-hooks
249249
GET_CURR_THR_INFO_FLAGS r10
250-
btst r10, TIF_SYSCALL_TRACE
251-
bnz tracesys ; this never comes back
250+
and.f 0, r10, _TIF_SYSCALL_WORK
251+
bnz tracesys ; this never comes back
252252

253253
;============ Normal syscall case
254254

arch/arc/kernel/ptrace.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <linux/unistd.h>
1010
#include <linux/elf.h>
1111

12+
#define CREATE_TRACE_POINTS
13+
#include <trace/events/syscalls.h>
14+
1215
struct pt_regs_offset {
1316
const char *name;
1417
int offset;
@@ -340,15 +343,27 @@ long arch_ptrace(struct task_struct *child, long request,
340343

341344
asmlinkage int syscall_trace_entry(struct pt_regs *regs)
342345
{
343-
if (ptrace_report_syscall_entry(regs))
344-
return ULONG_MAX;
346+
if (test_thread_flag(TIF_SYSCALL_TRACE))
347+
if (ptrace_report_syscall_entry(regs))
348+
return ULONG_MAX;
349+
350+
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
351+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
352+
trace_sys_enter(regs, syscall_get_nr(current, regs));
353+
#endif
345354

346355
return regs->r8;
347356
}
348357

349358
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
350359
{
351-
ptrace_report_syscall_exit(regs, 0);
360+
if (test_thread_flag(TIF_SYSCALL_TRACE))
361+
ptrace_report_syscall_exit(regs, 0);
362+
363+
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
364+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
365+
trace_sys_exit(regs, regs_return_value(regs));
366+
#endif
352367
}
353368

354369
int regs_query_register_offset(const char *name)

0 commit comments

Comments
 (0)