Skip to contentSkip to conversation

csky: Update syscall_trace_enter/exit implementation

PATCH In review [email protected] 2 participants 5 messages Mar 25, 2019

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 csky: Update syscall_trace_enter/exit implementation

From: Guo Ren <[email protected]>

Previous syscall_trace implementation couldn't support AUDITSYSCALL and SYSCALL_TRACEPOINTS. Now we redesign it to support audit_syscall and syscall_tracepoints just like other archs'.

Cc Dmitry V. Levin <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 arch/csky/Kconfig                   |  2 ++
 arch/csky/include/asm/syscall.h     |  2 ++
 arch/csky/include/asm/thread_info.h | 25 ++++++++-----------
 arch/csky/include/asm/unistd.h      |  2 ++
 arch/csky/include/uapi/asm/ptrace.h |  5 ++++
 arch/csky/kernel/entry.S            | 21 +++++++---------
 arch/csky/kernel/ptrace.c           | 50 +++++++++++++++++--------------------
 7 files changed, 54 insertions(+), 53 deletions(-)
arch/csky/Kconfig +2 -0
index 114cb2f..55048020 100644
@@ -28,6 +28,7 @@ config CSKY
 	select GENERIC_SCHED_CLOCK
 	select GENERIC_SMP_IDLE_THREAD
 	select HAVE_ARCH_TRACEHOOK
+	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_GRAPH_TRACER
@@ -39,6 +40,7 @@ config CSKY
 	select HAVE_PERF_EVENTS
 	select HAVE_DMA_API_DEBUG
 	select HAVE_DMA_CONTIGUOUS
+	select HAVE_SYSCALL_TRACEPOINTS
 	select MAY_HAVE_SPARSE_IRQ
 	select MODULES_USE_ELF_RELA if MODULES
 	select OF
arch/csky/include/asm/syscall.h +2 -0
index d637445..bc484c9 100644
@@ -8,6 +8,8 @@
 #include <abi/regdef.h>
 #include <uapi/linux/audit.h>
 
+extern void *sys_call_table[];
+
 static inline int
 syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
 {
arch/csky/include/asm/thread_info.h +11 -14
index 0e9d035..207a932 100644
@@ -51,29 +51,26 @@ static inline struct thread_info *current_thread_info(void)
 
 #endif /* !__ASSEMBLY__ */
 
-/* entry.S relies on these definitions!
- * bits 0-5 are tested at every exception exit
- */
 #define TIF_SIGPENDING		0	/* signal pending */
 #define TIF_NOTIFY_RESUME	1       /* callback before returning to user */
 #define TIF_NEED_RESCHED	2	/* rescheduling necessary */
 #define TIF_SYSCALL_TRACE	5	/* syscall trace active */
-#define TIF_DELAYED_TRACE	14	/* single step a syscall */
+#define TIF_SYSCALL_TRACEPOINT	6       /* syscall tracepoint instrumentation */
+#define TIF_SYSCALL_AUDIT	7	/* syscall auditing */
 #define TIF_POLLING_NRFLAG	16	/* poll_idle() is TIF_NEED_RESCHED */
 #define TIF_MEMDIE		18      /* is terminating due to OOM killer */
-#define TIF_FREEZE		19	/* thread is freezing for suspend */
 #define TIF_RESTORE_SIGMASK	20	/* restore signal mask in do_signal() */
 #define TIF_SECCOMP		21	/* secure computing */
 
-#define _TIF_SIGPENDING         (1 << TIF_SIGPENDING)
-#define _TIF_NOTIFY_RESUME      (1 << TIF_NOTIFY_RESUME)
-#define _TIF_NEED_RESCHED       (1 << TIF_NEED_RESCHED)
-#define _TIF_SYSCALL_TRACE      (1 << TIF_SYSCALL_TRACE)
-#define _TIF_DELAYED_TRACE	(1 << TIF_DELAYED_TRACE)
-#define _TIF_POLLING_NRFLAG     (1 << TIF_POLLING_NRFLAG)
+#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
+#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
+#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
+#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
+#define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
+#define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
 #define _TIF_MEMDIE		(1 << TIF_MEMDIE)
-#define _TIF_FREEZE             (1 << TIF_FREEZE)
-#define _TIF_RESTORE_SIGMASK    (1 << TIF_RESTORE_SIGMASK)
-#define _TIF_SECCOMP            (1 << TIF_SECCOMP)
+#define _TIF_RESTORE_SIGMASK	(1 << TIF_RESTORE_SIGMASK)
+#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 
 #endif	/* _ASM_CSKY_THREAD_INFO_H */
arch/csky/include/asm/unistd.h +2 -0
index 2844874..da7a182 100644
@@ -2,3 +2,5 @@
 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
 
 #include <uapi/asm/unistd.h>
+
+#define NR_syscalls (__NR_syscalls)
arch/csky/include/uapi/asm/ptrace.h +5 -0
index a4eaa8d..9bf5b1a 100644
@@ -62,6 +62,11 @@ struct user_fp {
 #define instruction_pointer(regs) ((regs)->pc)
 #define profile_pc(regs) instruction_pointer(regs)
 
+static inline unsigned long regs_return_value(struct pt_regs *regs)
+{
+	return regs->a0;
+}
+
 #endif /* __KERNEL__ */
 #endif /* __ASSEMBLY__ */
 #endif /* _CSKY_PTRACE_H */
arch/csky/kernel/entry.S +9 -12
index 5137ed9..ebd1957 100644
@@ -136,8 +136,8 @@ ENTRY(csky_systemcall)
 	bmaski  r10, THREAD_SHIFT
 	andn    r9, r10
 	ldw     r8, (r9, TINFO_FLAGS)
-	btsti   r8, TIF_SYSCALL_TRACE
-	bt      1f
+	andi	r8, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
+	bt      csky_syscall_trace
 #if defined(__CSKYABIV2__)
 	subi    sp, 8
 	stw  	r5, (sp, 0x4)
@@ -150,10 +150,9 @@ ENTRY(csky_systemcall)
 	stw     a0, (sp, LSAVE_A0)      /* Save return value */
 	jmpi    ret_from_exception
 
-1:
-	movi	a0, 0                   /* enter system call */
-	mov	a1, sp                  /* sp = pt_regs pointer */
-	jbsr	syscall_trace
+csky_syscall_trace:
+	mov	a0, sp                  /* sp = pt_regs pointer */
+	jbsr	syscall_trace_enter
 	/* Prepare args before do system call */
 	ldw	a0, (sp, LSAVE_A0)
 	ldw	a1, (sp, LSAVE_A1)
@@ -173,9 +172,8 @@ ENTRY(csky_systemcall)
 #endif
 	stw	a0, (sp, LSAVE_A0)	/* Save return value */
 
-	movi    a0, 1                   /* leave system call */
-	mov     a1, sp                  /* right now, sp --> pt_regs */
-	jbsr    syscall_trace
+	mov     a0, sp                  /* right now, sp --> pt_regs */
+	jbsr    syscall_trace_exit
 	br	ret_from_exception
 
 ENTRY(ret_from_kernel_thread)
@@ -193,9 +191,8 @@ ENTRY(ret_from_fork)
 	movi	r11_sig, 1
 	btsti	r8, TIF_SYSCALL_TRACE
 	bf	3f
-	movi	a0, 1
-	mov	a1, sp			/* sp = pt_regs pointer */
-	jbsr	syscall_trace
+	mov	a0, sp			/* sp = pt_regs pointer */
+	jbsr	syscall_trace_exit
 3:
 	jbsr	ret_from_exception
 
arch/csky/kernel/ptrace.c +23 -27

76 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

On Mon, Mar 25, 2019 at 08:03:39PM +0800, [email protected] wrote:
[...]

Quoted 6 lines
arch/csky/include/uapi/asm/ptrace.h +0 -0
index a4eaa8d..9bf5b1a 100644
@@ -62,6 +62,11 @@ struct user_fp {
 #define instruction_pointer(regs) ((regs)->pc)

arch/csky/include/uapi/asm/ptrace.h struct user_fp { · line 72

Quoted 10 lines
arch/csky/include/uapi/asm/ptrace.h +5 -0
 #define profile_pc(regs) instruction_pointer(regs)
 
+static inline unsigned long regs_return_value(struct pt_regs *regs)
+{
+	return regs->a0;
+}
+
 #endif /* __KERNEL__ */
 #endif /* __ASSEMBLY__ */
 #endif /* _CSKY_PTRACE_H */

I wonder why we have this #ifdef __KERNEL__ code in the uapi namespace, it defeats the idea of uapi. Doesn't it belong to non-uapi include/asm/ptrace.h namespace?

Signature · 1 line
ldv
author maintainer
#2 lore raw

Thx Dmitry,

Quoted 10 lines · Dmitry V. Levin

On Mon, Mar 25, 2019 at 08:03:39PM +0800, [email protected] wrote:
[...]

Quoted 8 lines
arch/csky/include/uapi/asm/ptrace.h +0 -0
index a4eaa8d..9bf5b1a 100644
@@ -62,6 +62,11 @@ struct user_fp {
 #define instruction_pointer(regs) ((regs)->pc)
 #define profile_pc(regs) instruction_pointer(regs)
 
Quoted 12 lines

arch/csky/include/uapi/asm/ptrace.h struct user_fp { · line 72

Quoted 8 lines
arch/csky/include/uapi/asm/ptrace.h +5 -0
+static inline unsigned long regs_return_value(struct pt_regs *regs)
+{
+	return regs->a0;
+}
+
 #endif /* __KERNEL__ */
 #endif /* __ASSEMBLY__ */
 #endif /* _CSKY_PTRACE_H */

I wonder why we have this #ifdef __KERNEL__ code in the uapi namespace, it defeats the idea of uapi. Doesn't it belong to non-uapi include/asm/ptrace.h namespace?

Yes, I should move __KERNEL__ codes into arch/csky/include/asm/ptrace.h. But it'll be another patch for the modification. Any other problems?

Best Regards
Guo Ren

Signature · 3 lines
Strace-devel mailing list
[email protected]
https://lists.strace.io/mailman/listinfo/strace-devel
author maintainer
#4 lore raw
In reply to [email protected]
Quoted 16 lines · On Mon, Mar 25, 2019 at 08:03:39PM +0800, [email protected] wrote:

From: Guo Ren <[email protected]>

Previous syscall_trace implementation couldn't support AUDITSYSCALL and SYSCALL_TRACEPOINTS. Now we redesign it to support audit_syscall and syscall_tracepoints just like other archs'.

Cc Dmitry V. Levin <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 arch/csky/Kconfig                   |  2 ++
 arch/csky/include/asm/syscall.h     |  2 ++
 arch/csky/include/asm/thread_info.h | 25 ++++++++-----------
 arch/csky/include/asm/unistd.h      |  2 ++
 arch/csky/include/uapi/asm/ptrace.h |  5 ++++
 arch/csky/kernel/entry.S            | 21 +++++++---------

...

Quoted 42 lines
arch/csky/kernel/entry.S +7 -9
index 5137ed9..ebd1957 100644
@@ -136,8 +136,8 @@ ENTRY(csky_systemcall)
 	bmaski  r10, THREAD_SHIFT
 	andn    r9, r10
 	ldw     r8, (r9, TINFO_FLAGS)
-	btsti   r8, TIF_SYSCALL_TRACE
-	bt      1f
+	andi	r8, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
+	bt      csky_syscall_trace
 #if defined(__CSKYABIV2__)
 	subi    sp, 8
 	stw  	r5, (sp, 0x4)
@@ -150,10 +150,9 @@ ENTRY(csky_systemcall)
 	stw     a0, (sp, LSAVE_A0)      /* Save return value */
 	jmpi    ret_from_exception
 
-1:
-	movi	a0, 0                   /* enter system call */
-	mov	a1, sp                  /* sp = pt_regs pointer */
-	jbsr	syscall_trace
+csky_syscall_trace:
+	mov	a0, sp                  /* sp = pt_regs pointer */
+	jbsr	syscall_trace_enter
 	/* Prepare args before do system call */
 	ldw	a0, (sp, LSAVE_A0)
 	ldw	a1, (sp, LSAVE_A1)
@@ -173,9 +172,8 @@ ENTRY(csky_systemcall)
 #endif
 	stw	a0, (sp, LSAVE_A0)	/* Save return value */
 
-	movi    a0, 1                   /* leave system call */
-	mov     a1, sp                  /* right now, sp --> pt_regs */
-	jbsr    syscall_trace
+	mov     a0, sp                  /* right now, sp --> pt_regs */
+	jbsr    syscall_trace_exit
 	br	ret_from_exception
 
 ENTRY(ret_from_kernel_thread)

arch/csky/kernel/entry.S ENTRY(ret_from_fork) · line 192

Quoted 2 lines
arch/csky/kernel/entry.S +0 -0
@@ -193,9 +191,8 @@ ENTRY(ret_from_fork)
 	movi	r11_sig, 1
 	btsti	r8, TIF_SYSCALL_TRACE

It's wrong, I should use:
+ andi r8, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)

Best Regards
Guo Ren

#3 lore raw
In reply to Guo Ren
Quoted 24 lines · Guo Ren
Quoted 10 lines · Dmitry V. Levin

On Mon, Mar 25, 2019 at 08:03:39PM +0800, [email protected] wrote:
[...]

Quoted 8 lines
arch/csky/include/uapi/asm/ptrace.h +0 -0
index a4eaa8d..9bf5b1a 100644
@@ -62,6 +62,11 @@ struct user_fp {
 #define instruction_pointer(regs) ((regs)->pc)
 #define profile_pc(regs) instruction_pointer(regs)
 
Quoted 12 lines

arch/csky/include/uapi/asm/ptrace.h struct user_fp { · line 72

Quoted 8 lines
arch/csky/include/uapi/asm/ptrace.h +5 -0
+static inline unsigned long regs_return_value(struct pt_regs *regs)
+{
+	return regs->a0;
+}
+
 #endif /* __KERNEL__ */
 #endif /* __ASSEMBLY__ */
 #endif /* _CSKY_PTRACE_H */

I wonder why we have this #ifdef __KERNEL__ code in the uapi namespace, it defeats the idea of uapi. Doesn't it belong to non-uapi include/asm/ptrace.h namespace?

Quoted 2 lines

Yes, I should move __KERNEL__ codes into arch/csky/include/asm/ptrace.h. But it'll be another patch for the modification. Any other problems?

From UAPI perspective? No, I don't see any more UAPI issues with the patch.

Signature · 1 line
ldv