Skip to contentSkip to conversation

tracing: add compat syscall support

PATCH In review Jason Baron 6 participants 20 messages Feb 2, 2010 – Feb 10, 2010

Subsystems (10)
x86 Tracing s390 ABI/API +6 more subsystems
lore
Share & tools
lore
#1 lore raw

PATCH 1/6 x86: add NR_syscalls_compat, make ia32 syscall table visible

In reply to Jason Baron

Add 'NR_syscalls_compat' global for x86. Also, make 'ia32_sys_call_table' into a global.

---
 arch/x86/ia32/ia32entry.S     |    3 +++
 arch/x86/include/asm/compat.h |    2 ++
 2 files changed, 5 insertions(+), 0 deletions(-)
arch/x86/ia32/ia32entry.S +3 -0
index 53147ad..acc6fbf 100644
@@ -503,6 +503,7 @@ END(ia32_ptregs_common)
 
 	.section .rodata,"a"
 	.align 8
+.globl ia32_sys_call_table
 ia32_sys_call_table:
 	.quad sys_restart_syscall
 	.quad sys_exit
@@ -843,3 +844,5 @@ ia32_sys_call_table:
 	.quad sys_perf_event_open
 	.quad compat_sys_recvmmsg
 ia32_syscall_end:
+.globl NR_syscalls_compat
+NR_syscalls_compat: .int ((ia32_syscall_end - ia32_sys_call_table)/8)
arch/x86/include/asm/compat.h +2 -0
index 9a9c7bd..b5b78e6 100644
@@ -215,4 +215,6 @@ static inline int is_compat_task(void)
 	return current_thread_info()->status & TS_COMPAT;
 }
 
+extern int NR_syscalls_compat;
+
 #endif /* _ASM_X86_COMPAT_H */
Signature · 1 line
1.6.5.1
#2 lore raw

PATCH 2/6 x86: add arch_compat_syscall_addr()

In reply to Jason Baron

Add arch_compat_syscall_addr(int nr) for x86. This is in preparation for adding compat syscall support to the event tracer.

---
 arch/x86/kernel/ftrace.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/x86/kernel/ftrace.c +9 -0
index 3096892..da2568c 100644
@@ -488,9 +488,18 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 #ifdef CONFIG_FTRACE_SYSCALLS
 
 extern unsigned long *sys_call_table;
+extern unsigned long *ia32_sys_call_table;
 
 unsigned long __init arch_syscall_addr(int nr)
 {
 	return (unsigned long)(&sys_call_table)[nr];
 }
+
+#ifdef CONFIG_COMPAT
+unsigned long __init arch_compat_syscall_addr(int nr)
+{
+	return (unsigned long)(&ia32_sys_call_table)[nr];
+}
+#endif
+
 #endif
Signature · 1 line
1.6.5.1
#0 lore raw

cover tracing: add compat syscall support

Hi,

This series adds 'compat' syscall tracing support, and updates x86_64 to use this new functionality. Other arches still need to be implemented.

To provide arch support 3 interfaces need to be defined:
1) int is_compat_task(void);
- most arches seem to have this already
2) unsigned long arch_compat_syscall_addr(int nr);
- returns a pointer to the compat syscall entry corresponding to syscall 'nr'
3) int NR_syscalls_compat;
- number of entries in the compat syscall table.

Patches #1 and #2 in the series, implement the "NR_syscalls_compat" and the "arch_compat_syscall_addr()" for x86.

Patches #3 and #4 add the necessary 'core' support for compat syscalls to the event tracing code.

Finally, patches #5 and #6 convert 28 x86 compat syscalls to use the 'DEFINE_SYSCALL' macros, which is necessary for syscall tracing.

thanks,

-Jason

Jason Baron (6):
-x86: add NR_syscalls_compat, make ia32 syscall table visible -x86: add arch_compat_syscall_addr()
-tracing: remove syscall bitmaps in preparation for compat support -tracing: add tracing support for compat syscalls -syscalls: add define syscall prefix macro
-x86: convert compat syscalls to use 'DEFINE_SYSCALL()' macros

 arch/x86/ia32/ia32entry.S     |    3 +
 arch/x86/ia32/sys_ia32.c      |  106 ++++++++++++++++++++--------------------
 arch/x86/include/asm/compat.h |    2 +
 arch/x86/kernel/ftrace.c      |    9 ++++
 include/linux/compat.h        |    8 +++
 include/linux/syscalls.h      |   16 ++++++
 include/trace/syscall.h       |    8 +++
 kernel/trace/trace.h          |    2 +
 kernel/trace/trace_syscalls.c |  101 ++++++++++++++++++++++++++++-----------
 9 files changed, 174 insertions(+), 81 deletions(-)
#10 lore raw

PATCH 5/6 syscalls: add define syscall prefix macro

Add a new 'SYSCALL_PREFIX_DEFINE#()' style macro to include/linux/syscalls.h. This allows us to create syscalls via:

SYSCALL_PREFIX_DEFINE1(32_, mmap, struct mmap_arg_struct __user *, arg);

The standard 'SYSCALL_DEFINE#()' macro forces 'sys_blah', but for the 32 compat calls we want 'sys32_blah'.

---
 include/linux/syscalls.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/syscalls.h +8 -0
index 36af9db..8ddd27e 100644
@@ -210,6 +210,7 @@ struct perf_event_attr;
 	asmlinkage long sys_##sname(void)
 #else
 #define SYSCALL_DEFINE0(name)	   asmlinkage long sys_##name(void)
+#define SYSCALL_PREFIX_DEFINE0(pre, name)	   asmlinkage long sys_##name(void)
 #endif
 
 #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
@@ -219,6 +220,13 @@ struct perf_event_attr;
 #define SYSCALL_DEFINE5(name, ...) SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
 #define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
 
+#define SYSCALL_PREFIX_DEFINE1(pre, name, ...) SYSCALL_DEFINEx(1, pre##name, __VA_ARGS__)
+#define SYSCALL_PREFIX_DEFINE2(pre, name, ...) SYSCALL_DEFINEx(2, pre##name, __VA_ARGS__)
+#define SYSCALL_PREFIX_DEFINE3(pre, name, ...) SYSCALL_DEFINEx(3, pre##name, __VA_ARGS__)
+#define SYSCALL_PREFIX_DEFINE4(pre, name, ...) SYSCALL_DEFINEx(4, pre##name, __VA_ARGS__)
+#define SYSCALL_PREFIX_DEFINE5(pre, name, ...) SYSCALL_DEFINEx(5, pre##name, __VA_ARGS__)
+#define SYSCALL_PREFIX_DEFINE6(pre, name, ...) SYSCALL_DEFINEx(6, pre##name, __VA_ARGS__)
+
 #ifdef CONFIG_PPC64
 #define SYSCALL_ALIAS(alias, name)					\
 	asm ("\t.globl " #alias "\n\t.set " #alias ", " #name "\n"	\
Signature · 1 line
1.6.5.1
#3 lore raw

PATCH 3/6 tracing: remove syscall bitmaps in preparation for compat support

In reply to Jason Baron

In preparation for compat syscall tracing support, let's store the enabled syscalls, with the struct syscall_metadata itself. That way we don't duplicate enabled information when the compat table points to an entry in the regular syscall table. Also, allows us to remove the bitmap data structures completely.

---
 include/linux/syscalls.h      |    8 +++++++
 include/trace/syscall.h       |    4 +++
 kernel/trace/trace_syscalls.c |   42 +++++++++++++++++++---------------------
 3 files changed, 32 insertions(+), 22 deletions(-)
include/linux/syscalls.h +8 -0
index 0b99a97..36af9db 100644
@@ -183,6 +183,10 @@ struct perf_event_attr;
 		.nb_args 	= nb,				\
 		.types		= types_##sname,		\
 		.args		= args_##sname,			\
+		.ftrace_enter	= 0,				\
+		.ftrace_exit	= 0,				\
+		.perf_enter	= 0,				\
+		.perf_exit	= 0,				\
 		.enter_event	= &event_enter_##sname,		\
 		.exit_event	= &event_exit_##sname,		\
 	};
@@ -196,6 +200,10 @@ struct perf_event_attr;
 	  __syscall_meta__##sname = {				\
 		.name 		= "sys_"#sname,			\
 		.nb_args 	= 0,				\
+		.ftrace_enter	= 0,				\
+		.ftrace_exit	= 0,				\
+		.perf_enter	= 0,				\
+		.perf_exit	= 0,				\
 		.enter_event	= &event_enter__##sname,	\
 		.exit_event	= &event_exit__##sname,		\
 	};							\
include/trace/syscall.h +4 -0
index 0387100..8f5ac38 100644
@@ -25,6 +25,10 @@ struct syscall_metadata {
 	int		nb_args;
 	const char	**types;
 	const char	**args;
+	char		ftrace_enter;
+	char		ftrace_exit;
+	char		perf_enter;
+	char		perf_exit;
 
 	struct ftrace_event_call *enter_event;
 	struct ftrace_event_call *exit_event;
kernel/trace/trace_syscalls.c +20 -22

144 lines not on this page · raw message

Signature · 1 line
1.6.5.1
#19 lore raw

PATCH 6/6 x86: convert compat syscalls to use 'DEFINE_SYSCALL()' macros

In reply to Jason Baron

Convert x86 compat syscalls to use SYSCALL_PREFIX_DEFINE#() macros. This allows us to hook the compat syscalls into the event tracer.

---
 arch/x86/ia32/sys_ia32.c |  106 +++++++++++++++++++++++-----------------------
 1 files changed, 53 insertions(+), 53 deletions(-)
arch/x86/ia32/sys_ia32.c +53 -53
index 422572c..751d950 100644
@@ -50,15 +50,15 @@
 #define AA(__x)		((unsigned long)(__x))
 
 
-asmlinkage long sys32_truncate64(char __user *filename,
-				 unsigned long offset_low,
-				 unsigned long offset_high)
+SYSCALL_PREFIX_DEFINE3(32_, truncate64, char __user *, filename,
+				 unsigned long, offset_low,
+				 unsigned long, offset_high)
 {
        return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
 }
 
-asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
-				  unsigned long offset_high)
+SYSCALL_PREFIX_DEFINE3(32_, ftruncate64, unsigned int, fd, unsigned long, offset_low,
+				  unsigned long, offset_high)
 {
        return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
 }
@@ -95,8 +95,8 @@ static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
 	return 0;
 }
 
-asmlinkage long sys32_stat64(char __user *filename,
-			     struct stat64 __user *statbuf)
+SYSCALL_PREFIX_DEFINE2(32_, stat64, char __user *, filename,
+			     struct stat64 __user *, statbuf)
 {
 	struct kstat stat;
 	int ret = vfs_stat(filename, &stat);
@@ -106,8 +106,8 @@ asmlinkage long sys32_stat64(char __user *filename,
 	return ret;
 }
 
-asmlinkage long sys32_lstat64(char __user *filename,
-			      struct stat64 __user *statbuf)
+SYSCALL_PREFIX_DEFINE2(32_, lstat64, char __user *, filename,
+			      struct stat64 __user *, statbuf)
 {
 	struct kstat stat;
 	int ret = vfs_lstat(filename, &stat);
@@ -116,7 +116,7 @@ asmlinkage long sys32_lstat64(char __user *filename,
 	return ret;
 }
 
-asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
+SYSCALL_PREFIX_DEFINE2(32_, fstat64, unsigned int, fd, struct stat64 __user *, statbuf)
 {
 	struct kstat stat;
 	int ret = vfs_fstat(fd, &stat);
@@ -125,8 +125,8 @@ asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
 	return ret;
 }
 
-asmlinkage long sys32_fstatat(unsigned int dfd, char __user *filename,
-			      struct stat64 __user *statbuf, int flag)
+SYSCALL_PREFIX_DEFINE4(32_, fstatat, unsigned int, dfd, char __user *, filename,
+			      struct stat64 __user *, statbuf, int, flag)
 {
 	struct kstat stat;
 	int error;
@@ -152,7 +152,7 @@ struct mmap_arg_struct {
 	unsigned int offset;
 };
 
-asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg)
+SYSCALL_PREFIX_DEFINE1(32_, mmap, struct mmap_arg_struct __user *, arg)
 {
 	struct mmap_arg_struct a;
 
@@ -166,15 +166,15 @@ asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg)
 			       a.offset>>PAGE_SHIFT);
 }
 
-asmlinkage long sys32_mprotect(unsigned long start, size_t len,
-			       unsigned long prot)
+SYSCALL_PREFIX_DEFINE3(32_, mprotect, unsigned long, start, size_t, len,
+			       unsigned long, prot)
 {
 	return sys_mprotect(start, len, prot);
 }
 
-asmlinkage long sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
-				   struct sigaction32 __user *oact,
-				   unsigned int sigsetsize)
+SYSCALL_PREFIX_DEFINE4(32_, rt_sigaction, int, sig, struct sigaction32 __user *, act,
+				   struct sigaction32 __user *, oact,
+				   unsigned int, sigsetsize)
 {
 	struct k_sigaction new_ka, old_ka;
 	int ret;
@@ -248,8 +248,8 @@ asmlinkage long sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
 	return ret;
 }
 
-asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
-				struct old_sigaction32 __user *oact)
+SYSCALL_PREFIX_DEFINE3(32_, sigaction, int, sig, struct old_sigaction32 __user *, act,
+				struct old_sigaction32 __user *, oact)
 {
 	struct k_sigaction new_ka, old_ka;
 	int ret;
@@ -287,9 +287,9 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
 	return ret;
 }
 
-asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
-				     compat_sigset_t __user *oset,
-				     unsigned int sigsetsize)
+SYSCALL_PREFIX_DEFINE4(32_, rt_sigprocmask, int, how, compat_sigset_t __user *, set,
+				     compat_sigset_t __user *, oset,
+				     unsigned int, sigsetsize)
 {
 	sigset_t s;
 	compat_sigset_t s32;
@@ -327,7 +327,7 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
 	return 0;
 }
 
-asmlinkage long sys32_alarm(unsigned int seconds)
+SYSCALL_PREFIX_DEFINE1(32_, alarm, unsigned int, seconds)
 {
 	return alarm_setitimer(seconds);
 }
@@ -340,7 +340,7 @@ struct sel_arg_struct {
 	unsigned int tvp;
 };
 
-asmlinkage long sys32_old_select(struct sel_arg_struct __user *arg)
+SYSCALL_PREFIX_DEFINE1(32_, old_select, struct sel_arg_struct __user *, arg)
 {
 	struct sel_arg_struct a;
 
@@ -350,21 +350,21 @@ asmlinkage long sys32_old_select(struct sel_arg_struct __user *arg)
 				 compat_ptr(a.exp), compat_ptr(a.tvp));
 }
 
-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
-			      int options)
+SYSCALL_PREFIX_DEFINE3(32_, waitpid, compat_pid_t, pid, unsigned int *, stat_addr,
+			      int, options)
 {
 	return compat_sys_wait4(pid, stat_addr, options, NULL);
 }
 
 /* 32-bit timeval and related flotsam.  */
 
-asmlinkage long sys32_sysfs(int option, u32 arg1, u32 arg2)
+SYSCALL_PREFIX_DEFINE3(32_, sysfs, int, option, u32, arg1, u32, arg2)
 {
 	return sys_sysfs(option, arg1, arg2);
 }
 
-asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
-				    struct compat_timespec __user *interval)
+SYSCALL_PREFIX_DEFINE2(32_, sched_rr_get_interval, compat_pid_t, pid,
+				    struct compat_timespec __user *, interval)
 {
 	struct timespec t;
 	int ret;
@@ -378,8 +378,8 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
 	return ret;
 }
 
-asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
-				    compat_size_t sigsetsize)
+SYSCALL_PREFIX_DEFINE2(32_, rt_sigpending, compat_sigset_t __user *, set,
+				    compat_size_t, sigsetsize)
 {
 	sigset_t s;
 	compat_sigset_t s32;
@@ -402,8 +402,8 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
 	return ret;
 }
 
-asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
-				      compat_siginfo_t __user *uinfo)
+SYSCALL_PREFIX_DEFINE3(32_, rt_sigqueueinfo, int, pid, int, sig,
+				      compat_siginfo_t __user *, uinfo)
 {
 	siginfo_t info;
 	int ret;
@@ -418,22 +418,22 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
 }
 
 /* warning: next two assume little endian */
-asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
-			    u32 poslo, u32 poshi)
+SYSCALL_PREFIX_DEFINE5(32_, pread, unsigned int, fd, char __user *, ubuf, u32, count,
+			    u32, poslo, u32, poshi)
 {
 	return sys_pread64(fd, ubuf, count,
 			 ((loff_t)AA(poshi) << 32) | AA(poslo));
 }
 
-asmlinkage long sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count,
-			     u32 poslo, u32 poshi)
+SYSCALL_PREFIX_DEFINE5(32_, pwrite, unsigned int, fd, char __user *, ubuf, u32, count,
+			     u32, poslo, u32, poshi)
 {
 	return sys_pwrite64(fd, ubuf, count,
 			  ((loff_t)AA(poshi) << 32) | AA(poslo));
 }
 
 
-asmlinkage long sys32_personality(unsigned long personality)
+SYSCALL_PREFIX_DEFINE1(32_, personality, unsigned long, personality)
 {
 	int ret;
 
@@ -446,8 +446,8 @@ asmlinkage long sys32_personality(unsigned long personality)
 	return ret;
 }
 
-asmlinkage long sys32_sendfile(int out_fd, int in_fd,
-			       compat_off_t __user *offset, s32 count)
+SYSCALL_PREFIX_DEFINE4(32_, sendfile, int, out_fd, int, in_fd,
+			       compat_off_t __user *, offset, s32, count)
 {
 	mm_segment_t old_fs = get_fs();
 	int ret;
@@ -466,7 +466,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
 	return ret;
 }
 
-asmlinkage long sys32_olduname(struct oldold_utsname __user *name)
+SYSCALL_PREFIX_DEFINE1(32_, olduname, struct oldold_utsname __user *, name)
 {
 	char *arch = "x86_64";
 	int err;
@@ -518,8 +518,8 @@ long sys32_uname(struct old_utsname __user *name)
 	return err ? -EFAULT : 0;
 }
 
-asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
-			     compat_uptr_t __user *envp, struct pt_regs *regs)
+SYSCALL_PREFIX_DEFINE4(32_, execve, char __user *, name, compat_uptr_t __user *, argv,
+			compat_uptr_t __user *, envp, struct pt_regs *, regs)
 {
 	long error;
 	char *filename;
@@ -533,8 +533,8 @@ asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
 	return error;
 }
 
-asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
-			    struct pt_regs *regs)
+SYSCALL_PREFIX_DEFINE3(32_, clone, unsigned int, clone_flags, unsigned int, newsp,
+			    struct pt_regs *, regs)
 {
 	void __user *parent_tid = (void __user *)regs->dx;
 	void __user *child_tid = (void __user *)regs->di;
@@ -593,24 +593,24 @@ asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
 	return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
 }
 
-asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
-				      unsigned n_low, unsigned n_hi,  int flags)
+SYSCALL_PREFIX_DEFINE6(32_, sync_file_range, int, fd, unsigned, off_low, unsigned, off_hi,
+			unsigned, n_low, unsigned, n_hi,  int, flags)
 {
 	return sys_sync_file_range(fd,
 				   ((u64)off_hi << 32) | off_low,
 				   ((u64)n_hi << 32) | n_low, flags);
 }
 
-asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
-				size_t len, int advice)
+SYSCALL_PREFIX_DEFINE5(32_, fadvise64, int, fd, unsigned, offset_lo, unsigned, offset_hi,
+				size_t, len, int, advice)
 {
 	return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
 				len, advice);
 }
 
-asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
-				unsigned offset_hi, unsigned len_lo,
-				unsigned len_hi)
+SYSCALL_PREFIX_DEFINE6(32_, fallocate, int, fd, int, mode, unsigned, offset_lo,
+				unsigned, offset_hi, unsigned, len_lo,
+				unsigned, len_hi)
 {
 	return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
 			     ((u64)len_hi << 32) | len_lo);
Signature · 1 line
1.6.5.1
#4 lore raw

PATCH 4/6 tracing: add tracing support for compat syscalls

In reply to Jason Baron

Add core support to event tracing for compat syscalls. The basic idea is that we check if we have a compat task via 'is_compat_task()'. If so, we lookup in the new compat_syscalls_metadata table, the corresponding struct syscall_metadata, to check syscall arguments and whether or not we are enabled.

---
 include/linux/compat.h        |    8 +++++
 include/trace/syscall.h       |    4 ++
 kernel/trace/trace.h          |    2 +
 kernel/trace/trace_syscalls.c |   63 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 69 insertions(+), 8 deletions(-)
include/linux/compat.h +8 -0
index ef68119..ab2cda2 100644
@@ -353,5 +353,13 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename,
 asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
 				  int flags, int mode);
 
+#else /* CONFIG_COMPAT */
+
+#define NR_syscalls_compat 0
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */
include/trace/syscall.h +4 -0
index 8f5ac38..1cc1d1e 100644
@@ -22,6 +22,7 @@
 struct syscall_metadata {
 	const char	*name;
 	int		syscall_nr;
+	int		compat_syscall_nr;
 	int		nb_args;
 	const char	**types;
 	const char	**args;
@@ -36,6 +37,9 @@ struct syscall_metadata {
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 extern unsigned long arch_syscall_addr(int nr);
+#ifdef CONFIG_COMPAT
+extern unsigned long arch_compat_syscall_addr(int nr);
+#endif
 extern int init_syscall_trace(struct ftrace_event_call *call);
 
 extern int syscall_enter_define_fields(struct ftrace_event_call *call);
kernel/trace/trace.h +2 -0
index ce077fb..0ed0d2e 100644
@@ -94,12 +94,14 @@ extern struct tracer boot_tracer;
 struct syscall_trace_enter {
 	struct trace_entry	ent;
 	int			nr;
+	int			compat;
 	unsigned long		args[];
 };
 
 struct syscall_trace_exit {
 	struct trace_entry	ent;
 	int			nr;
+	int			compat;
 	long			ret;
 };
 
kernel/trace/trace_syscalls.c +55 -8

162 lines not on this page · raw message

Signature · 1 line
1.6.5.1
#5 lore raw

Re: [PATCH 4/6] tracing: add tracing support for compat syscalls

Quoted 21 lines · Jason Baron

Add core support to event tracing for compat syscalls. The basic idea is that we check if we have a compat task via 'is_compat_task()'. If so, we lookup in the new compat_syscalls_metadata table, the corresponding struct syscall_metadata, to check syscall arguments and whether or not we are enabled.

---
 include/linux/compat.h        |    8 +++++
 include/trace/syscall.h       |    4 ++
 kernel/trace/trace.h          |    2 +
 kernel/trace/trace_syscalls.c |   63 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 69 insertions(+), 8 deletions(-)
include/linux/compat.h +0 -0
index ef68119..ab2cda2 100644
@@ -353,5 +353,13 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename,
 asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
 				  int flags, int mode);
 

include/linux/compat.h asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename, · line 365

Quoted 10 lines
include/linux/compat.h +8 -0
+#else /* CONFIG_COMPAT */
+
+#define NR_syscalls_compat 0
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */

This part will break compilation on s390, since it has already the same function defined for !CONFIG_COMPAT.
In order to avoid the whole ifdef mess some s390 files do include asm/compat.h instead of linux/compat.h. This will get messy :)

#11 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

In reply to Jason Baron
Quoted 7 lines · Jason Baron

Add a new 'SYSCALL_PREFIX_DEFINE#()' style macro to include/linux/syscalls.h. This allows us to create syscalls via:

SYSCALL_PREFIX_DEFINE1(32_, mmap, struct mmap_arg_struct __user *, arg);

The standard 'SYSCALL_DEFINE#()' macro forces 'sys_blah', but for the 32 compat calls we want 'sys32_blah'.

Not really. That's what you want for x86. But the generic name for compat syscalls is compat_sys_whatever. The arch specific compat syscalls don't follow a common naming scheme (yet).
Especially if you consider the idea to get automated correct sign extension via hpa's planned script for compat syscalls it would be good if you would just name that define something like SYSCALL_COMPAT.. or COMPAT_SYSCALL..
That way it would be easy to add a hook in there.

#6 lore raw

Re: [PATCH 4/6] tracing: add tracing support for compat syscalls

In reply to Heiko Carstens
Quoted 22 lines · Heiko Carstens
Quoted 21 lines · Jason Baron

Add core support to event tracing for compat syscalls. The basic idea is that we check if we have a compat task via 'is_compat_task()'. If so, we lookup in the new compat_syscalls_metadata table, the corresponding struct syscall_metadata, to check syscall arguments and whether or not we are enabled.

---
 include/linux/compat.h        |    8 +++++
 include/trace/syscall.h       |    4 ++
 kernel/trace/trace.h          |    2 +
 kernel/trace/trace_syscalls.c |   63 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 69 insertions(+), 8 deletions(-)
include/linux/compat.h +0 -0
index ef68119..ab2cda2 100644
@@ -353,5 +353,13 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename,
 asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
 				  int flags, int mode);
 
Quoted 13 lines

include/linux/compat.h asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename, · line 365

Quoted 10 lines
include/linux/compat.h +8 -0
+#else /* CONFIG_COMPAT */
+
+#define NR_syscalls_compat 0
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */

This part will break compilation on s390, since it has already the same function defined for !CONFIG_COMPAT.

If multiple arches want this definition, then it seems the the common include/linux/compat.h is good place for it.

Quoted 2 lines

In order to avoid the whole ifdef mess some s390 files do include asm/compat.h instead of linux/compat.h. This will get messy :)

is there a way for s390 to use the common include/linux/compat.h file? what other arch defs are required?

thanks,

-Jason

#12 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

In reply to Heiko Carstens
Quoted 9 lines · Heiko Carstens
Quoted 7 lines · Jason Baron

Add a new 'SYSCALL_PREFIX_DEFINE#()' style macro to include/linux/syscalls.h. This allows us to create syscalls via:

SYSCALL_PREFIX_DEFINE1(32_, mmap, struct mmap_arg_struct __user *, arg);

The standard 'SYSCALL_DEFINE#()' macro forces 'sys_blah', but for the 32 compat calls we want 'sys32_blah'.

Quoted 7 lines

Not really. That's what you want for x86. But the generic name for compat syscalls is compat_sys_whatever. The arch specific compat syscalls don't follow a common naming scheme (yet).
Especially if you consider the idea to get automated correct sign extension via hpa's planned script for compat syscalls it would be good if you would just name that define something like SYSCALL_COMPAT.. or COMPAT_SYSCALL..
That way it would be easy to add a hook in there.

So I was trying to keep the names of the arch ia32 compat sys calls the same, ie 'sys32_blah'. However, I agree a common naming scheme makes more sense. what about 'arch_compat_sys_blah'? So as to distinguish from the common compat syscalls 'compat_sys_blah'.

thanks,

-Jason

#13 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

Quoted 4 lines · Jason Baron

So I was trying to keep the names of the arch ia32 compat sys calls the same, ie 'sys32_blah'. However, I agree a common naming scheme makes more sense. what about 'arch_compat_sys_blah'? So as to distinguish from the common compat syscalls 'compat_sys_blah'.

Why do you need to distinguish them? I would hope that we never need to have a kernel with both a generic and an arch specific compat version of the same syscall.

Arnd

#7 lore raw

Re: [PATCH 4/6] tracing: add tracing support for compat syscalls

In reply to Jason Baron
Quoted 37 lines · Jason Baron
Quoted 22 lines · Heiko Carstens
Quoted 21 lines · Jason Baron

Add core support to event tracing for compat syscalls. The basic idea is that we check if we have a compat task via 'is_compat_task()'. If so, we lookup in the new compat_syscalls_metadata table, the corresponding struct syscall_metadata, to check syscall arguments and whether or not we are enabled.

---
 include/linux/compat.h        |    8 +++++
 include/trace/syscall.h       |    4 ++
 kernel/trace/trace.h          |    2 +
 kernel/trace/trace_syscalls.c |   63 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 69 insertions(+), 8 deletions(-)
include/linux/compat.h +0 -0
index ef68119..ab2cda2 100644
@@ -353,5 +353,13 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename,
 asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
 				  int flags, int mode);
 
Quoted 13 lines

include/linux/compat.h asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user * filename, · line 365

Quoted 10 lines
include/linux/compat.h +8 -0
+#else /* CONFIG_COMPAT */
+
+#define NR_syscalls_compat 0
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */

This part will break compilation on s390, since it has already the same function defined for !CONFIG_COMPAT.

Quoted 8 lines

If multiple arches want this definition, then it seems the the common include/linux/compat.h is good place for it.

Quoted 2 lines

In order to avoid the whole ifdef mess some s390 files do include asm/compat.h instead of linux/compat.h. This will get messy :)

is there a way for s390 to use the common include/linux/compat.h file? what other arch defs are required?

Yes of course it is possible (I think :). I'll send a patch.

#16 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

In reply to Jason Baron
Quoted 18 lines · Jason Baron
Quoted 9 lines · Heiko Carstens
Quoted 7 lines · Jason Baron

Add a new 'SYSCALL_PREFIX_DEFINE#()' style macro to include/linux/syscalls.h. This allows us to create syscalls via:

SYSCALL_PREFIX_DEFINE1(32_, mmap, struct mmap_arg_struct __user *, arg);

The standard 'SYSCALL_DEFINE#()' macro forces 'sys_blah', but for the 32 compat calls we want 'sys32_blah'.

Quoted 7 lines

Not really. That's what you want for x86. But the generic name for compat syscalls is compat_sys_whatever. The arch specific compat syscalls don't follow a common naming scheme (yet).
Especially if you consider the idea to get automated correct sign extension via hpa's planned script for compat syscalls it would be good if you would just name that define something like SYSCALL_COMPAT.. or COMPAT_SYSCALL..
That way it would be easy to add a hook in there.

Quoted 4 lines

So I was trying to keep the names of the arch ia32 compat sys calls the same, ie 'sys32_blah'. However, I agree a common naming scheme makes more sense. what about 'arch_compat_sys_blah'? So as to distinguish from the common compat syscalls 'compat_sys_blah'.

Hi,
I can't find my copy of the original posting... sorry about that.

Are these new SYSCALL macros just a shorthand/shortcut to cut down on typing (and/or errors)?

The added level of indirection makes problems for scripts/kernel-doc (well, if any of the syscalls have kernel-doc notation, that is). I'd prefer not to see 2 levels of macros for defining a syscall, but if it has to live, please look into updating scripts/kernel-doc also.

thanks,

Signature · 1 line
~Randy
#17 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

Quoted 19 lines · Randy Dunlap
Quoted 18 lines · Jason Baron
Quoted 16 lines · Heiko Carstens
Quoted 7 lines · Jason Baron

Add a new 'SYSCALL_PREFIX_DEFINE#()' style macro to include/linux/syscalls.h. This allows us to create syscalls via:

SYSCALL_PREFIX_DEFINE1(32_, mmap, struct mmap_arg_struct __user *, arg);

The standard 'SYSCALL_DEFINE#()' macro forces 'sys_blah', but for the 32 compat calls we want 'sys32_blah'.

Not really. That's what you want for x86. But the generic name for compat syscalls is compat_sys_whatever. The arch specific compat syscalls don't follow a common naming scheme (yet).
Especially if you consider the idea to get automated correct sign extension via hpa's planned script for compat syscalls it would be good if you would just name that define something like SYSCALL_COMPAT.. or COMPAT_SYSCALL..
That way it would be easy to add a hook in there.

Quoted 8 lines
Quoted 4 lines

So I was trying to keep the names of the arch ia32 compat sys calls the same, ie 'sys32_blah'. However, I agree a common naming scheme makes more sense. what about 'arch_compat_sys_blah'? So as to distinguish from the common compat syscalls 'compat_sys_blah'.

Hi,
I can't find my copy of the original posting... sorry about that.

http://marc.info/?l=linux-kernel&m=126514576917582&w=2

Quoted 3 lines

Are these new SYSCALL macros just a shorthand/shortcut to cut down on typing (and/or errors)?

Most of the copat syscall are currently not using the 'SYCALL_DEFINE()' family of macros. For my purposes, the use of these macros allows them to be tied into the event tracing system. These macros append 'sys_' to the begging of the system call name. However, for compat syscall which are named 'sys32_blah', these macros are not sufficient. Thus, the need to introduce some new macros for the compat syscalls.

Quoted 5 lines

The added level of indirection makes problems for scripts/kernel-doc (well, if any of the syscalls have kernel-doc notation, that is). I'd prefer not to see 2 levels of macros for defining a syscall, but if it has to live, please look into updating scripts/kernel-doc also.

good point. I'll make sure the docs work properly.

thanks,

-Jason

#14 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 4 lines · Jason Baron

So I was trying to keep the names of the arch ia32 compat sys calls the same, ie 'sys32_blah'. However, I agree a common naming scheme makes more sense. what about 'arch_compat_sys_blah'? So as to distinguish from the common compat syscalls 'compat_sys_blah'.

Why do you need to distinguish them? I would hope that we never need to have a kernel with both a generic and an arch specific compat version of the same syscall.

Well, the usual alignment or number of arguments issues could lead to just that. We should deal with it the same way as for native syscalls.

#15 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

Quoted 7 lines · On Monday 08 February 2010 18:54:07 Christoph Hellwig wrote:
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines · Jason Baron

So I was trying to keep the names of the arch ia32 compat sys calls the same, ie 'sys32_blah'. However, I agree a common naming scheme makes more sense. what about 'arch_compat_sys_blah'? So as to distinguish from the common compat syscalls 'compat_sys_blah'.

Quoted 6 lines
Quoted 3 lines

Why do you need to distinguish them? I would hope that we never need to have a kernel with both a generic and an arch specific compat version of the same syscall.

Well, the usual alignment or number of arguments issues could lead to just that. We should deal with it the same way as for native syscalls.

Ah, right. The arch specific syscall may just be a wrapper calling the generic function, so we need them both.

Arnd

#8 lore raw

Re: [PATCH 4/6] tracing: add tracing support for compat syscalls

In reply to Jason Baron
Quoted 6 lines · Jason Baron
Quoted 2 lines · Heiko Carstens

In order to avoid the whole ifdef mess some s390 files do include asm/compat.h instead of linux/compat.h. This will get messy :)

is there a way for s390 to use the common include/linux/compat.h file? what other arch defs are required?

The patch below is the smallest solution so that s390 still compiles and probably even works:

Subject: [PATCH] compat: have generic is_compat_task for !CONFIG_COMPAT

From: Heiko Carstens <[email protected]>

..instead of an arch specific one.

---
 arch/s390/include/asm/compat.h  |    7 -------
 arch/s390/kernel/ptrace.c       |    2 +-
 arch/s390/kernel/setup.c        |    2 +-
 arch/s390/mm/mmap.c             |    2 +-
 drivers/s390/block/dasd_eckd.c  |    2 +-
 drivers/s390/block/dasd_ioctl.c |    1 +
 drivers/s390/char/fs3270.c      |    1 +
 drivers/s390/char/vmcp.c        |    1 +
 drivers/s390/cio/chsc_sch.c     |    1 +
 drivers/s390/scsi/zfcp_cfdc.c   |    1 +
 include/linux/compat.h          |    7 +++++++
 11 files changed, 16 insertions(+), 11 deletions(-)
arch/s390/include/asm/compat.h +0 -7
@@ -171,13 +171,6 @@ static inline int is_compat_task(void)
 	return test_thread_flag(TIF_31BIT);
 }
 
-#else
-
-static inline int is_compat_task(void)
-{
-	return 0;
-}
-
 #endif
 
 static inline void __user *compat_alloc_user_space(long len)
arch/s390/kernel/ptrace.c +1 -1
@@ -36,8 +36,8 @@
 #include <linux/regset.h>
 #include <linux/tracehook.h>
 #include <linux/seccomp.h>
+#include <linux/compat.h>
 #include <trace/syscall.h>
-#include <asm/compat.h>
 #include <asm/segment.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
arch/s390/kernel/setup.c +1 -1
@@ -43,7 +43,7 @@
 #include <linux/reboot.h>
 #include <linux/topology.h>
 #include <linux/ftrace.h>
-
+#include <linux/compat.h>
 #include <asm/ipl.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
arch/s390/mm/mmap.c +1 -1
@@ -27,8 +27,8 @@
 #include <linux/personality.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/compat.h>
 #include <asm/pgalloc.h>
-#include <asm/compat.h>
 
 /*
  * Top of mmap area (just below the process stack).
drivers/s390/block/dasd_eckd.c +1 -1
@@ -14,6 +14,7 @@
 
 #include <linux/stddef.h>
 #include <linux/kernel.h>
+#include <linux/compat.h>
 #include <linux/slab.h>
 #include <linux/hdreg.h>	/* HDIO_GETGEO			    */
 #include <linux/bio.h>
@@ -23,7 +24,6 @@
 #include <asm/debug.h>
 #include <asm/idals.h>
 #include <asm/ebcdic.h>
-#include <asm/compat.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/cio.h>
drivers/s390/block/dasd_ioctl.c +1 -0
@@ -17,6 +17,7 @@
 #include <linux/fs.h>
 #include <linux/blkpg.h>
 #include <linux/smp_lock.h>
+#include <linux/compat.h>
 #include <asm/compat.h>
 #include <asm/ccwdev.h>
 #include <asm/cmb.h>
drivers/s390/char/fs3270.c +1 -0
@@ -14,6 +14,7 @@
 #include <linux/list.h>
 #include <linux/types.h>
 #include <linux/smp_lock.h>
+#include <linux/compat.h>
 
 #include <asm/compat.h>
 #include <asm/ccwdev.h>
drivers/s390/char/vmcp.c +1 -0
@@ -19,6 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
+#include <linux/compat.h>
 #include <asm/compat.h>
 #include <asm/cpcmd.h>
 #include <asm/debug.h>
drivers/s390/cio/chsc_sch.c +1 -0
@@ -8,6 +8,7 @@
  */
 
 #include <linux/device.h>
+#include <linux/compat.h>
 #include <linux/module.h>
 #include <linux/uaccess.h>
 #include <linux/miscdevice.h>
drivers/s390/scsi/zfcp_cfdc.c +1 -0
@@ -12,6 +12,7 @@
 
 #include <linux/types.h>
 #include <linux/miscdevice.h>
+#include <linux/compat.h>
 #include <asm/compat.h>
 #include <asm/ccwdev.h>
 #include "zfcp_def.h"
include/linux/compat.h +7 -0
@@ -353,5 +353,12 @@ asmlinkage long compat_sys_newfstatat(un
 asmlinkage long compat_sys_openat(unsigned int dfd, const char __user *filename,
 				  int flags, int mode);
 
+#else /* CONFIG_COMPAT */
+
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */
#9 lore raw

Re: [PATCH 4/6] tracing: add tracing support for compat syscalls

Quoted 13 lines · Heiko Carstens
Quoted 2 lines

is there a way for s390 to use the common include/linux/compat.h file? what other arch defs are required?

The patch below is the smallest solution so that s390 still compiles and probably even works:

Subject: [PATCH] compat: have generic is_compat_task for !CONFIG_COMPAT

From: Heiko Carstens <[email protected]>

..instead of an arch specific one.

Quoted 14 lines
---
 arch/s390/include/asm/compat.h  |    7 -------
 arch/s390/kernel/ptrace.c       |    2 +-
 arch/s390/kernel/setup.c        |    2 +-
 arch/s390/mm/mmap.c             |    2 +-
 drivers/s390/block/dasd_eckd.c  |    2 +-
 drivers/s390/block/dasd_ioctl.c |    1 +
 drivers/s390/char/fs3270.c      |    1 +
 drivers/s390/char/vmcp.c        |    1 +
 drivers/s390/cio/chsc_sch.c     |    1 +
 drivers/s390/scsi/zfcp_cfdc.c   |    1 +
 include/linux/compat.h          |    7 +++++++
 11 files changed, 16 insertions(+), 11 deletions(-)

looks good. I'll include this patch when I repost the revised series.

thanks!

-Jason

maintainer
#18 lore raw

Re: [PATCH 5/6] syscalls: add define syscall prefix macro

In reply to Jason Baron
Quoted 7 lines · Jason Baron

Most of the copat syscall are currently not using the 'SYCALL_DEFINE()' family of macros. For my purposes, the use of these macros allows them to be tied into the event tracing system. These macros append 'sys_' to the begging of the system call name. However, for compat syscall which are named 'sys32_blah', these macros are not sufficient. Thus, the need to introduce some new macros for the compat syscalls.

Quoted 7 lines
Quoted 5 lines

The added level of indirection makes problems for scripts/kernel-doc (well, if any of the syscalls have kernel-doc notation, that is). I'd prefer not to see 2 levels of macros for defining a syscall, but if it has to live, please look into updating scripts/kernel-doc also.

good point. I'll make sure the docs work properly.

Could you also make sure 'make TAGS' is updated too. See scripts/tags.sh and search for SYSCALL

-- Steve