Skip to content

Commit 5c7be9a

Browse files
author
Sergey Matyukevich
committed
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 <sergey.matyukevich@synopsys.com>
1 parent b250424 commit 5c7be9a

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

arch/arc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ config ARC
4141
select HAVE_REGS_AND_STACK_ACCESS_API
4242
select HAVE_MOD_ARCH_SPECIFIC
4343
select HAVE_PERF_EVENTS
44+
select HAVE_SYSCALL_TRACEPOINTS
4445
select IRQ_DOMAIN
4546
select MODULES_USE_ELF_RELA
4647
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
8282
#define TIF_NOTIFY_SIGNAL 5 /* signal notifications exist */
8383
#define TIF_SYSCALL_TRACE 15 /* syscall trace active */
8484
#define TIF_MEMDIE 16
85+
#define TIF_SYSCALL_TRACEPOINT 17 /* syscall tracepoint instrumentation */
8586

8687
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8788
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -91,11 +92,14 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
9192
#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL)
9293
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9394
#define _TIF_MEMDIE (1<<TIF_MEMDIE)
95+
#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9496

9597
/* work to do on interrupt/exception return */
9698
#define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
9799
_TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL)
98100

101+
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
102+
99103
/*
100104
* _TIF_ALLWORK_MASK includes SYSCALL_TRACE, but we don't need it.
101105
* SYSCALL_TRACE is anyway seperately/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)
@@ -224,8 +224,8 @@ ENTRY(EV_Trap)
224224

225225
; syscall tracing ongoing, invoke pre-post-hooks around syscall
226226
GET_CURR_THR_INFO_FLAGS r10
227-
btst r10, TIF_SYSCALL_TRACE
228-
bnz tracesys ; this never comes back
227+
and.f 0, r10, _TIF_SYSCALL_WORK
228+
bnz tracesys ; this never comes back
229229

230230
;============ Normal syscall case
231231

arch/arc/kernel/ptrace.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <linux/elf.h>
1212
#include <asm/asm-offsets.h>
1313

14+
#define CREATE_TRACE_POINTS
15+
#include <trace/events/syscalls.h>
16+
1417
struct pt_regs_offset {
1518
const char *name;
1619
int offset;
@@ -363,15 +366,27 @@ long arch_ptrace(struct task_struct *child, long request,
363366

364367
asmlinkage int syscall_trace_enter(struct pt_regs *regs)
365368
{
366-
if (tracehook_report_syscall_entry(regs))
367-
return -1;
369+
if (test_thread_flag(TIF_SYSCALL_TRACE))
370+
if (tracehook_report_syscall_entry(regs))
371+
return -1;
372+
373+
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
374+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
375+
trace_sys_enter(regs, syscall_get_nr(current, regs));
376+
#endif
368377

369378
return regs->r8;
370379
}
371380

372381
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
373382
{
374-
tracehook_report_syscall_exit(regs, 0);
383+
if (test_thread_flag(TIF_SYSCALL_TRACE))
384+
tracehook_report_syscall_exit(regs, 0);
385+
386+
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
387+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
388+
trace_sys_exit(regs, regs_return_value(regs));
389+
#endif
375390
}
376391

377392
int regs_query_register_offset(const char *name)

0 commit comments

Comments
 (0)