Enable pt_regs based syscalls for x86-32 native
Subsystems (3)
cover Enable pt_regs based syscalls for x86-32 native
This patch series cleans up the x86 syscall wrapper code and converts the 32-bit native kernel over to pt_regs based syscalls.
Brian Gerst (5):
x86: Refactor syscall_wrapper.h
x86: Move 32-bit compat syscalls to common location
x86-32: Enable syscall wrappers
x86-64: Use syscall wrappers for x32_rt_sigreturn
x86: Drop asmlinkage from syscalls
arch/x86/Kconfig | 2 +-
arch/x86/entry/common.c | 20 +-
arch/x86/entry/syscall_32.c | 13 +-
arch/x86/entry/syscall_64.c | 9 +-
arch/x86/entry/syscalls/syscall_32.tbl | 818 ++++++++++++-------------
arch/x86/entry/syscalls/syscall_64.tbl | 2 +-
arch/x86/entry/syscalls/syscalltbl.sh | 33 +-
arch/x86/ia32/Makefile | 2 +-
arch/x86/include/asm/sighandling.h | 5 -
arch/x86/include/asm/syscall.h | 8 +-
arch/x86/include/asm/syscall_wrapper.h | 372 +++++------
arch/x86/include/asm/syscalls.h | 29 -
arch/x86/kernel/Makefile | 2 +
arch/x86/kernel/signal.c | 2 +-
arch/x86/{ia32 => kernel}/sys_ia32.c | 130 ++--
arch/x86/um/sys_call_table_32.c | 10 +
16 files changed, 722 insertions(+), 735 deletions(-)
rename arch/x86/{ia32 => kernel}/sys_ia32.c (83%)Signature · 1 line
2.24.1
PATCH 1/5 x86: Refactor syscall_wrapper.h
Refactor syscall_wrapper.h to make the code more understandable, and prepare for enabling pt_regs based syscalls for 32-bit native.
--- arch/x86/include/asm/syscall_wrapper.h | 363 +++++++++++++------------ 1 file changed, 194 insertions(+), 169 deletions(-)
arch/x86/include/asm/syscall_wrapper.h +194 -169
@@ -8,6 +8,40 @@struct pt_regs ; +/* +* Instead of the generic __SYSCALL_DEFINEx() definition, this macro takes +* struct pt_regs *regs as the only argument of the syscall stub named +* __x64_sys_*(). It decodes just the registers it needs and passes them on to +* the __se_sys_*() wrapper performing sign extension and then to the +* __do_sys_*() function doing the actual job. These wrappers and functions +* are inlined (at least in very most cases), meaning that the assembly looks +* as follows (slightly re-ordered for better readability): +* +* <__x64_sys_recv>: <-- syscall with 4 parameters +* callq <__fentry__> +* +* mov 0x70(%rdi),%rdi <-- decode regs->di +* mov 0x68(%rdi),%rsi <-- decode regs->si +* mov 0x60(%rdi),%rdx <-- decode regs->dx +* mov 0x38(%rdi),%rcx <-- decode regs->r10 +* +* xor %r9d,%r9d <-- clear %r9 +* xor %r8d,%r8d <-- clear %r8 +* +* callq __sys_recvfrom <-- do the actual work in __sys_recvfrom() +* which takes 6 arguments +* +* cltq <-- extend return value to 64-bit +* retq <-- return +* +* This approach avoids leaking random user-provided register content down +* the call chain. +* +* If IA32_EMULATION is enabled, this macro generates an additional wrapper +* named __ia32_sys_*() which decodes the struct pt_regs *regs according +* to the i386 calling convention (bx, cx, dx, si, di, bp). +*/ +/* Mapping of registers to parameters for syscalls on x86-64 and x32 */ #define SC_X86_64_REGS_TO_ARGS (x, ...) \ __MAP(x,__SC_ARGS \
@@ -21,68 +55,146 @@ struct pt_regs; ,,(unsigned int)regs->dx,,(unsigned int)regs->si \ ,,(unsigned int)regs->di,,(unsigned int)regs->bp) -#ifdef CONFIG_IA32_EMULATION -/* -* For IA32 emulation, we need to handle "compat" syscalls *and* create -* additional wrappers (aptly named __ia32_sys_xyzzy) which decode the -* ia32 regs in the proper order for shared or "common" syscalls. As some -* syscalls may not be implemented, we need to expand COND_SYSCALL in -* kernel/sys_ni.c and SYS_NI in kernel/time/posix-stubs.c to cover this -* case as well. -*/ -#define __IA32_COMPAT_SYS_STUB0 (x, name) \ - asmlinkage long __ia32_compat_sys_##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__ia32_compat_sys_##name, ERRNO); \ - asmlinkage long __ia32_compat_sys_##name(const struct pt_regs *regs)\ +#define __SYS_STUBx (abi, name, ...) \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs) \ { \ - return __se_compat_sys_##name(); \ + return __se_##name(__VA_ARGS__); \ } -#define __IA32_COMPAT_SYS_STUBx (x, name, ...) \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__ia32_compat_sys##name, ERRNO); \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs)\ +#define __SYS_STUB0 (abi, name) \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs) \ { \ - return __se_compat_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\ + return __do_##name(); \ } -#define __IA32_SYS_STUBx (x, name, ...) \ - asmlinkage long __ia32_sys##name(const struct pt_regs *regs); \ - ALLOW_ERROR_INJECTION(__ia32_sys##name, ERRNO); \ - asmlinkage long __ia32_sys##name(const struct pt_regs *regs) \ +#define __COND_SYSCALL (abi, name) \ + asmlinkage __weak long \ + __##abi##_##name(const struct pt_regs *regs) \ { \ - return __se_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\ + return sys_ni_syscall(); \ } +#ifdef CONFIG_X86_64 +#define __X64_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(x64, name, SC_X86_64_REGS_TO_ARGS(x, __VA_ARGS__)) + +#define __X64_SYS_STUB0 (name) \ + __SYS_STUB0(x64, name) + +#define __X64_COND_SYSCALL (name) \ + __COND_SYSCALL(x64, name) + +#define __X64_SYS_NI (name) \ + SYSCALL_ALIAS(__x64_sys_##name, sys_ni_posix_timers) + +#else /* CONFIG_X86_64 */ +#define __X64_SYS_STUBx (x, name, ...) +#define __X64_SYS_STUB0 (name) +#define __X64_COND_SYSCALL (name) +#define __X64_SYS_NI (name) +#endif /* CONFIG_X86_64 */ + + +#if defined(CONFIG_X86_32 ) || defined(CONFIG_IA32_EMULATION ) +#define __IA32_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(ia32, name, SC_IA32_REGS_TO_ARGS(x, __VA_ARGS__)) + +#define __IA32_SYS_STUB0 (name) \ + __SYS_STUB0(ia32, name) + +#define __IA32_COND_SYSCALL (name) \ + __COND_SYSCALL(ia32, name) + +#define __IA32_SYS_NI (name) \ + SYSCALL_ALIAS(__ia32_sys_##name, sys_ni_posix_timers) + +#else /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */ +#define __IA32_SYS_STUBx (x, name, ...) +#define __IA32_SYS_STUB0 (name) +#define __IA32_COND_SYSCALL (name) +#define __IA32_SYS_NI (name) +#endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */ + + +#define __SYSCALL_DEFINEx (x, name, ...) \ + static long \ + __se_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)); \ + static inline long \ + __do_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)); \ + __X64_SYS_STUBx(x, sys##name, __VA_ARGS__) \ + __IA32_SYS_STUBx(x, sys##name, __VA_ARGS__) \ + static long \ + __se_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)) \ + { \ + long ret = __do_sys##name(__MAP(x, __SC_CAST, \ + __VA_ARGS__)); \ + __MAP(x, __SC_TEST, __VA_ARGS__); \ + __PROTECT(x, ret, __MAP(x, __SC_ARGS, __VA_ARGS__)); \ + return ret; \ + } \ + static inline long \ + __do_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) +/* -* To keep the naming coherent, re-define SYSCALL_DEFINE0 to create an alias -* named __ia32_sys_*() +* As the generic SYSCALL_DEFINE0() macro does not decode any parameters for +* obvious reasons, and passing struct pt_regs *regs to it in %rdi does not +* hurt, we only need to re-define it here to keep the naming congruent to +* SYSCALL_DEFINEx() -- which is essential for the COND_SYSCALL() and SYS_NI() +* macros to work correctly. */ +#define SYSCALL_DEFINE0 (name) \ + SYSCALL_METADATA(_##name, 0); \ + static inline long __do_sys_##name(void); \ + __X64_SYS_STUB0(sys_##name) \ + __IA32_SYS_STUB0(sys_##name) \ + static inline long __do_sys_##name(void) -#define SYSCALL_DEFINE0 (sname) \ - SYSCALL_METADATA(_##sname, 0); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused);\ - ALLOW_ERROR_INJECTION(__x64_sys_##sname, ERRNO); \ - SYSCALL_ALIAS(__ia32_sys_##sname, __x64_sys_##sname); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused) - -#define COND_SYSCALL (name) \ - asmlinkage __weak long __x64_sys_##name(const struct pt_regs *__unused) \ - { \ - return sys_ni_syscall(); \ - } \ - asmlinkage __weak long __ia32_sys_##name(const struct pt_regs *__unused)\ - { \ - return sys_ni_syscall(); \ - } +#define COND_SYSCALL (name) \ + __X64_COND_SYSCALL(sys_##name) \ + __IA32_COND_SYSCALL(sys_##name) -#define SYS_NI (name) \ - SYSCALL_ALIAS(__x64_sys_##name, sys_ni_posix_timers); \ - SYSCALL_ALIAS(__ia32_sys_##name, sys_ni_posix_timers) +#define SYS_NI (name) \ + __X64_SYS_NI(name) \ + __IA32_SYS_NI(name) + + +#ifdef CONFIG_COMPAT +/* +* Compat means IA32_EMULATION and/or X86_X32. As they use a different +* mapping of registers to parameters, we need to generate stubs for each +* of them. +*/ + +#ifdef CONFIG_IA32_EMULATION +/* +* For IA32 emulation, we need to handle "compat" syscalls *and* create +* additional wrappers (aptly named __ia32_sys_xyzzy) which decode the +* ia32 regs in the proper order for shared or "common" syscalls. As some +* syscalls may not be implemented, we need to expand COND_SYSCALL in +* kernel/sys_ni.c and SYS_NI in kernel/time/posix-stubs.c to cover this +* case as well. +*/ +#define __IA32_COMPAT_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(ia32, name, SC_IA32_REGS_TO_ARGS(x, __VA_ARGS__)) + +#define __IA32_COMPAT_SYS_STUB0 (name) \ + __SYS_STUB0(ia32, name) + +#define __IA32_COMPAT_COND_SYSCALL (name) \ + __COND_SYSCALL(ia32, name) + +#define __IA32_COMPAT_SYS_NI (name) \ + SYSCALL_ALIAS(__ia32_compat_sys_##name, sys_ni_posix_timers)#else /* CONFIG_IA32_EMULATION */ #define __IA32_COMPAT_SYS_STUBx (x, name, ...) -#define __IA32_SYS_STUBx (x, fullname, name, ...) +#define __IA32_COMPAT_SYS_STUB0 (name) +#define __IA32_COMPAT_COND_SYSCALL (name) +#define __IA32_COMPAT_SYS_NI (name)#endif /* CONFIG_IA32_EMULATION */
@@ -92,55 +204,48 @@ struct pt_regs;* of the x86-64-style parameter ordering of x32 syscalls. The syscalls common * with x86_64 obviously do not need such care. */ -#define __X32_COMPAT_SYS_STUB0 (x, name, ...) \ - asmlinkage long __x32_compat_sys_##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__x32_compat_sys_##name, ERRNO); \ - asmlinkage long __x32_compat_sys_##name(const struct pt_regs *regs)\ - { \ - return __se_compat_sys_##name();\ - } -#define __X32_COMPAT_SYS_STUBx (x, name, ...) \ - asmlinkage long __x32_compat_sys##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__x32_compat_sys##name, ERRNO); \ - asmlinkage long __x32_compat_sys##name(const struct pt_regs *regs)\ - { \ - return __se_compat_sys##name(SC_X86_64_REGS_TO_ARGS(x,__VA_ARGS__));\ - } + __SYS_STUBx(x32, name, SC_X86_64_REGS_TO_ARGS(x, __VA_ARGS__)) + +#define __X32_COMPAT_SYS_STUB0 (name) \ + __SYS_STUB0(x32, name) + +#define __X32_COMPAT_COND_SYSCALL (name) \ + __COND_SYSCALL(x32, name) + +#define __X32_COMPAT_SYS_NI (name) \ + SYSCALL_ALIAS(__x32_compat_sys_##name, sys_ni_posix_timers)#else /* CONFIG_X86_X32 */ -#define __X32_COMPAT_SYS_STUB0 (x, name)#define __X32_COMPAT_SYS_STUBx (x, name, ...) +#define __X32_COMPAT_SYS_STUB0 (name) +#define __X32_COMPAT_COND_SYSCALL (name) +#define __X32_COMPAT_SYS_NI (name)#endif /* CONFIG_X86_X32 */ -#ifdef CONFIG_COMPAT -/* -* Compat means IA32_EMULATION and/or X86_X32. As they use a different -* mapping of registers to parameters, we need to generate stubs for each -* of them. -*/ -#define COMPAT_SYSCALL_DEFINE0 (name) \ - static long __se_compat_sys_##name(void); \ - static inline long __do_compat_sys_##name(void); \ - __IA32_COMPAT_SYS_STUB0(x, name) \ - __X32_COMPAT_SYS_STUB0(x, name) \ - static long __se_compat_sys_##name(void) \ +#define COMPAT_SYSCALL_DEFINEx (x, name, ...) \ + static long \ + __se_compat_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)); \ + static inline long \ + __do_compat_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)); \ + __IA32_COMPAT_SYS_STUBx(x, compat_sys##name, __VA_ARGS__) \ + __X32_COMPAT_SYS_STUBx(x, compat_sys##name, __VA_ARGS__) \ + static long \ + __se_compat_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)) \ { \ - return __do_compat_sys_##name(); \ + return __do_compat_sys##name(__MAP(x, __SC_DELOUSE, \ + __VA_ARGS__)); \ } \ - static inline long __do_compat_sys_##name(void) + static inline long \ + __do_compat_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) -#define COMPAT_SYSCALL_DEFINEx (x, name, ...) \ - static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ - static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ - __IA32_COMPAT_SYS_STUBx(x, name, __VA_ARGS__) \ - __X32_COMPAT_SYS_STUBx(x, name, __VA_ARGS__) \ - static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ - { \ - return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\ - } \ - static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) +#define COMPAT_SYSCALL_DEFINE0 (name) \ + SYSCALL_METADATA(_##name, 0); \ + static inline long __do_compat_sys_##name(void); \ + __IA32_COMPAT_SYS_STUB0(compat_sys_##name) \ + __X32_COMPAT_SYS_STUB0(compat_sys_##name) \ + static inline long __do_compat_sys_##name(void)/* * As some compat syscalls may not be implemented, we need to expand
@@ -148,96 +253,16 @@ struct pt_regs;* kernel/time/posix-stubs.c to cover this case as well. */ #define COND_SYSCALL_COMPAT (name) \ - cond_syscall(__ia32_compat_sys_##name); \ - cond_syscall(__x32_compat_sys_##name) + __IA32_COMPAT_COND_SYSCALL(compat_sys_##name) \ + __X32_COMPAT_COND_SYSCALL(compat_sys_##name)#define COMPAT_SYS_NI (name) \ - SYSCALL_ALIAS(__ia32_compat_sys_##name, sys_ni_posix_timers); \ - SYSCALL_ALIAS(__x32_compat_sys_##name, sys_ni_posix_timers) + __IA32_COMPAT_SYS_NI(name) \ + __X32_COMPAT_SYS_NI(name)#endif /* CONFIG_COMPAT */ -/* -* Instead of the generic __SYSCALL_DEFINEx() definition, this macro takes -* struct pt_regs *regs as the only argument of the syscall stub named -* __x64_sys_*(). It decodes just the registers it needs and passes them on to -* the __se_sys_*() wrapper performing sign extension and then to the -* __do_sys_*() function doing the actual job. These wrappers and functions -* are inlined (at least in very most cases), meaning that the assembly looks -* as follows (slightly re-ordered for better readability): -* -* <__x64_sys_recv>: <-- syscall with 4 parameters -* callq <__fentry__> -* -* mov 0x70(%rdi),%rdi <-- decode regs->di -* mov 0x68(%rdi),%rsi <-- decode regs->si -* mov 0x60(%rdi),%rdx <-- decode regs->dx -* mov 0x38(%rdi),%rcx <-- decode regs->r10 -* -* xor %r9d,%r9d <-- clear %r9 -* xor %r8d,%r8d <-- clear %r8 -* -* callq __sys_recvfrom <-- do the actual work in __sys_recvfrom() -* which takes 6 arguments -* -* cltq <-- extend return value to 64-bit -* retq <-- return -* -* This approach avoids leaking random user-provided register content down -* the call chain. -* -* If IA32_EMULATION is enabled, this macro generates an additional wrapper -* named __ia32_sys_*() which decodes the struct pt_regs *regs according -* to the i386 calling convention (bx, cx, dx, si, di, bp). -*/ -#define __SYSCALL_DEFINEx (x, name, ...) \ - asmlinkage long __x64_sys##name(const struct pt_regs *regs); \ - ALLOW_ERROR_INJECTION(__x64_sys##name, ERRNO); \ - static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ - static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ - asmlinkage long __x64_sys##name(const struct pt_regs *regs) \ - { \ - return __se_sys##name(SC_X86_64_REGS_TO_ARGS(x,__VA_ARGS__));\ - } \ - __IA32_SYS_STUBx(x, name, __VA_ARGS__) \ - static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ - { \ - long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));\ - __MAP(x,__SC_TEST,__VA_ARGS__); \ - __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \ - return ret; \ - } \ - static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) - -/* -* As the generic SYSCALL_DEFINE0() macro does not decode any parameters for -* obvious reasons, and passing struct pt_regs *regs to it in %rdi does not -* hurt, we only need to re-define it here to keep the naming congruent to -* SYSCALL_DEFINEx() -- which is essential for the COND_SYSCALL() and SYS_NI() -* macros to work correctly. -*/ -#ifndef SYSCALL_DEFINE0 -#define SYSCALL_DEFINE0 (sname) \ - SYSCALL_METADATA(_##sname, 0); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused);\ - ALLOW_ERROR_INJECTION(__x64_sys_##sname, ERRNO); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused) -#endif - -#ifndef COND_SYSCALL -#define COND_SYSCALL (name) \ - asmlinkage __weak long __x64_sys_##name(const struct pt_regs *__unused) \ - { \ - return sys_ni_syscall(); \ - } -#endif - -#ifndef SYS_NI -#define SYS_NI (name) SYSCALL_ALIAS(__x64_sys_##name, sys_ni_posix_timers); -#endif - -/* * For VSYSCALLS, we need to declare these three syscalls with the new * pt_regs-based calling convention for in-kernel use.
Signature · 1 line
2.24.1
PATCH 2/5 x86: Move 32-bit compat syscalls to common location
In reply to Brian GerstMove the 32-bit wrappers for syscalls that take 64-bit arguments (loff_t) to a common location so that native 32-bit can use them in preparation for enabling pt_regs-based syscalls.
---
arch/x86/entry/syscalls/syscall_32.tbl | 18 ++--
arch/x86/ia32/Makefile | 2 +-
arch/x86/kernel/Makefile | 2 +
arch/x86/{ia32 => kernel}/sys_ia32.c | 130 ++++++++++++-------------
arch/x86/um/sys_call_table_32.c | 10 ++
5 files changed, 87 insertions(+), 75 deletions(-)
rename arch/x86/{ia32 => kernel}/sys_ia32.c (83%)arch/x86/entry/syscalls/syscall_32.tbl +9 -9
@@ -191,8 +191,8 @@ 177 i386 rt_sigtimedwait sys_rt_sigtimedwait_time32 __ia32_compat_sys_rt_sigtimedwait_time32 178 i386 rt_sigqueueinfo sys_rt_sigqueueinfo __ia32_compat_sys_rt_sigqueueinfo 179 i386 rt_sigsuspend sys_rt_sigsuspend __ia32_compat_sys_rt_sigsuspend -180 i386 pread64 sys_pread64 __ia32_compat_sys_x86_pread -181 i386 pwrite64 sys_pwrite64 __ia32_compat_sys_x86_pwrite +180 i386 pread64 sys_x86_pread __ia32_sys_x86_pread +181 i386 pwrite64 sys_x86_pwrite __ia32_sys_x86_pwrite 182 i386 chown sys_chown16 __ia32_sys_chown16 183 i386 getcwd sys_getcwd __ia32_sys_getcwd 184 i386 capget sys_capget __ia32_sys_capget
@@ -204,8 +204,8 @@ 190 i386 vfork sys_vfork __ia32_sys_vfork 191 i386 ugetrlimit sys_getrlimit __ia32_compat_sys_getrlimit 192 i386 mmap2 sys_mmap_pgoff __ia32_sys_mmap_pgoff -193 i386 truncate64 sys_truncate64 __ia32_compat_sys_x86_truncate64 -194 i386 ftruncate64 sys_ftruncate64 __ia32_compat_sys_x86_ftruncate64 +193 i386 truncate64 sys_x86_truncate64 __ia32_sys_x86_truncate64 +194 i386 ftruncate64 sys_x86_ftruncate64 __ia32_sys_x86_ftruncate64 195 i386 stat64 sys_stat64 __ia32_compat_sys_x86_stat64 196 i386 lstat64 sys_lstat64 __ia32_compat_sys_x86_lstat64 197 i386 fstat64 sys_fstat64 __ia32_compat_sys_x86_fstat64
@@ -236,7 +236,7 @@ # 222 is unused # 223 is unused 224 i386 gettid sys_gettid __ia32_sys_gettid -225 i386 readahead sys_readahead __ia32_compat_sys_x86_readahead +225 i386 readahead sys_x86_readahead __ia32_sys_x86_readahead 226 i386 setxattr sys_setxattr __ia32_sys_setxattr 227 i386 lsetxattr sys_lsetxattr __ia32_sys_lsetxattr 228 i386 fsetxattr sys_fsetxattr __ia32_sys_fsetxattr
@@ -261,7 +261,7 @@ 247 i386 io_getevents sys_io_getevents_time32 __ia32_sys_io_getevents_time32 248 i386 io_submit sys_io_submit __ia32_compat_sys_io_submit 249 i386 io_cancel sys_io_cancel __ia32_sys_io_cancel -250 i386 fadvise64 sys_fadvise64 __ia32_compat_sys_x86_fadvise64 +250 i386 fadvise64 sys_x86_fadvise64 __ia32_sys_x86_fadvise64 # 251 is available for reuse (was briefly sys_set_zone_reclaim) 252 i386 exit_group sys_exit_group __ia32_sys_exit_group 253 i386 lookup_dcookie sys_lookup_dcookie __ia32_compat_sys_lookup_dcookie
@@ -283,7 +283,7 @@ 269 i386 fstatfs64 sys_fstatfs64 __ia32_compat_sys_fstatfs64 270 i386 tgkill sys_tgkill __ia32_sys_tgkill 271 i386 utimes sys_utimes_time32 __ia32_sys_utimes_time32 -272 i386 fadvise64_64 sys_fadvise64_64 __ia32_compat_sys_x86_fadvise64_64 +272 i386 fadvise64_64 sys_x86_fadvise64_64 __ia32_sys_x86_fadvise64_64 273 i386 vserver 274 i386 mbind sys_mbind __ia32_sys_mbind 275 i386 get_mempolicy sys_get_mempolicy __ia32_compat_sys_get_mempolicy
@@ -325,7 +325,7 @@ 311 i386 set_robust_list sys_set_robust_list __ia32_compat_sys_set_robust_list 312 i386 get_robust_list sys_get_robust_list __ia32_compat_sys_get_robust_list 313 i386 splice sys_splice __ia32_sys_splice -314 i386 sync_file_range sys_sync_file_range __ia32_compat_sys_x86_sync_file_range +314 i386 sync_file_range sys_x86_sync_file_range __ia32_sys_x86_sync_file_range 315 i386 tee sys_tee __ia32_sys_tee 316 i386 vmsplice sys_vmsplice __ia32_compat_sys_vmsplice 317 i386 move_pages sys_move_pages __ia32_compat_sys_move_pages
@@ -335,7 +335,7 @@ 321 i386 signalfd sys_signalfd __ia32_compat_sys_signalfd 322 i386 timerfd_create sys_timerfd_create __ia32_sys_timerfd_create 323 i386 eventfd sys_eventfd __ia32_sys_eventfd -324 i386 fallocate sys_fallocate __ia32_compat_sys_x86_fallocate +324 i386 fallocate sys_x86_fallocate __ia32_sys_x86_fallocate 325 i386 timerfd_settime sys_timerfd_settime32 __ia32_sys_timerfd_settime32 326 i386 timerfd_gettime sys_timerfd_gettime32 __ia32_sys_timerfd_gettime32 327 i386 signalfd4 sys_signalfd4 __ia32_compat_sys_signalfd4
arch/x86/ia32/Makefile +1 -1
@@ -3,7 +3,7 @@ # Makefile for the ia32 kernel emulation subsystem. # -obj-$(CONFIG_IA32_EMULATION) := sys_ia32.o ia32_signal.o +obj-$(CONFIG_IA32_EMULATION) := ia32_signal.o obj-$(CONFIG_IA32_AOUT) += ia32_aout.o
arch/x86/kernel/Makefile +2 -0
@@ -57,6 +57,8 @@ obj-y += setup.o x86_init.o i8259.o irqinit.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-y += probe_roms.o +obj-$(CONFIG_X86_32) += sys_ia32.o +obj-$(CONFIG_IA32_EMULATION) += sys_ia32.o obj-$(CONFIG_X86_64) += sys_x86_64.o obj-$(CONFIG_X86_ESPFIX64) += espfix_64.o obj-$(CONFIG_SYSFS) += ksysfs.o
arch/x86/kernel/sys_ia32.c renamed from arch/x86/ia32/sys_ia32.c +65 -65
154 lines not on this page · raw message
arch/x86/um/sys_call_table_32.c +10 -0
@@ -26,6 +26,16 @@#define old_mmap sys_old_mmap +#define sys_x86_pread sys_pread64 +#define sys_x86_pwrite sys_pwrite64 +#define sys_x86_truncate64 sys_truncate64 +#define sys_x86_ftruncate64 sys_ftruncate64 +#define sys_x86_readahead sys_readahead +#define sys_x86_fadvise64 sys_fadvise64 +#define sys_x86_fadvise64_64 sys_fadvise64_64 +#define sys_x86_sync_file_range sys_sync_file_range +#define sys_x86_fallocate sys_fallocate +#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) ;#include <asm/syscalls_32.h>
Signature · 1 line
2.24.1
PATCH 4/5 x86-64: Use syscall wrappers for x32_rt_sigreturn
In reply to Brian Gerst--- arch/x86/entry/syscalls/syscall_64.tbl | 2 +- arch/x86/include/asm/sighandling.h | 5 ----- arch/x86/kernel/signal.c | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/entry/syscalls/syscall_64.tbl +1 -1
@@ -367,7 +367,7 @@ # is defined. # 512 x32 rt_sigaction __x32_compat_sys_rt_sigaction -513 x32 rt_sigreturn sys32_x32_rt_sigreturn +513 x32 rt_sigreturn __x32_compat_sys_x32_rt_sigreturn 514 x32 ioctl __x32_compat_sys_ioctl 515 x32 readv __x32_compat_sys_readv 516 x32 writev __x32_compat_sys_writev
arch/x86/include/asm/sighandling.h +0 -5
@@ -17,9 +17,4 @@ void signal_fault(struct pt_regs *regs, void __user *frame, char *where);int setup_sigcontext (struct sigcontext __user *sc,void __user *fpstate,struct pt_regs *regs,unsigned long mask); - -#ifdef CONFIG_X86_X32_ABI -asmlinkage long sys32_x32_rt_sigreturn (void ); -#endif -#endif /* _ASM_X86_SIGHANDLING_H */
arch/x86/kernel/signal.c +1 -1
@@ -859,7 +859,7 @@ void signal_fault(struct pt_regs *regs, void __user *frame, char *where) }#ifdef CONFIG_X86_X32_ABI -asmlinkage long sys32_x32_rt_sigreturn (void ) +COMPAT_SYSCALL_DEFINE0 (x32_rt_sigreturn) {struct pt_regs *regs =current_pt_regs ();struct rt_sigframe_x32 __user *frame;
Signature · 1 line
2.24.1
PATCH 3/5 x86-32: Enable syscall wrappers
In reply to Brian GerstEnable pt_regs based syscalls for 32-bit.
--- arch/x86/Kconfig | 2 +- arch/x86/entry/common.c | 20 +- arch/x86/entry/syscall_32.c | 11 +- arch/x86/entry/syscall_64.c | 7 - arch/x86/entry/syscalls/syscall_32.tbl | 818 ++++++++++++------------- arch/x86/entry/syscalls/syscalltbl.sh | 33 +- arch/x86/include/asm/syscall.h | 6 - arch/x86/include/asm/syscall_wrapper.h | 3 + arch/x86/include/asm/syscalls.h | 29 - 9 files changed, 442 insertions(+), 487 deletions(-)
arch/x86/Kconfig +1 -1
@@ -30,7 +30,6 @@ config X86_64 select MODULES_USE_ELF_RELA select NEED_DMA_MAP_STATE select SWIOTLB - select ARCH_HAS_SYSCALL_WRAPPER config FORCE_DYNAMIC_FTRACE def_bool y
@@ -79,6 +78,7 @@ config X86 select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE + select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
arch/x86/entry/common.c +7 -13
@@ -334,20 +334,7 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs)if (likely (nr < IA32_NR_syscalls)) { nr =array_index_nospec (nr, IA32_NR_syscalls); -#ifdef CONFIG_IA32_EMULATION regs->ax = ia32_sys_call_table[nr](regs); -#else -/* -* It's possible that a 32-bit syscall implementation -* takes a 64-bit parameter but nonetheless assumes that -* the high bits are zero. Make sure we zero-extend all -* of the args. -*/ - regs->ax = ia32_sys_call_table[nr]( - (unsigned int )regs->bx, (unsigned int )regs->cx, - (unsigned int )regs->dx, (unsigned int )regs->si, - (unsigned int )regs->di, (unsigned int )regs->bp); -#endif /* CONFIG_IA32_EMULATION */ }syscall_return_slowpath (regs);
@@ -439,3 +426,10 @@ __visible long do_fast_syscall_32(struct pt_regs *regs) #endif }#endif + +extern asmlinkage long sys_ni_syscall (void ); + +SYSCALL_DEFINE0 (ni_syscall) +{ +return sys_ni_syscall (); +}
arch/x86/entry/syscall_32.c +2 -9
@@ -4,18 +4,11 @@#include <linux/linkage.h> #include <linux/sys.h> #include <linux/cache.h> +#include <linux/syscalls.h> #include <asm/asm-offsets.h> #include <asm/syscall.h> -#ifdef CONFIG_IA32_EMULATION -/* On X86_64, we use struct pt_regs * to pass parameters to syscalls */ #define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *); -#define __sys_ni_syscall __ia32_sys_ni_syscall -#else /* CONFIG_IA32_EMULATION */ -#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); -extern asmlinkage long sys_ni_syscall (unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -#define __sys_ni_syscall sys_ni_syscall -#endif /* CONFIG_IA32_EMULATION */ #include <asm/syscalls_32.h> #undef __SYSCALL_I386
@@ -27,6 +20,6 @@ __visible const sys_call_ptr_t ia32_sys_call_table[__NR_syscall_compat_max+1] =* Smells like a compiler bug -- it doesn't work * when the & below is removed. */ - [0 ... __NR_syscall_compat_max] = &__sys_ni_syscall, + [0 ... __NR_syscall_compat_max] = &__ia32_sys_ni_syscall,#include <asm/syscalls_32.h> };
arch/x86/entry/syscall_64.c +0 -7
@@ -8,13 +8,6 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -extern asmlinkage long sys_ni_syscall (void ); - -SYSCALL_DEFINE0 (ni_syscall) -{ -return sys_ni_syscall (); -} -#define __SYSCALL_64 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *);#define __SYSCALL_X32 (nr, sym, qual) __SYSCALL_64(nr, sym, qual)#include <asm/syscalls_64.h>
arch/x86/entry/syscalls/syscall_32.tbl +409 -409
843 lines not on this page · raw message
arch/x86/entry/syscalls/syscalltbl.sh +20 -13
@@ -36,25 +36,32 @@ emit() { if [ "$abi" = "64" -a "${entry}" != "${entry#__x64_sys}" ]; then umlentry="sys${entry#__x64_sys}" fi + if [ "$abi" = "I386" -a "${entry}" != "${entry#__ia32_sys}" ]; then + umlentry="sys${entry#__ia32_sys}" + fi - if [ -z "$compat" ]; then - if [ -n "$entry" -a -z "$umlentry" ]; then - syscall_macro "$abi" "$nr" "$entry" - elif [ -n "$umlentry" ]; then # implies -n "$entry" + if [ -n "$entry" ]; then + if [ -n "$umlentry" ]; then echo "#ifdef CONFIG_X86" - syscall_macro "$abi" "$nr" "$entry" + fi + + if [ -n "$compat" ]; then + echo "#ifdef CONFIG_X86_32" + fi + + syscall_macro "$abi" "$nr" "$entry" + + if [ -n "$compat" ]; then + echo "#else /* CONFIG_X86_32 */" + syscall_macro "$abi" "$nr" "$compat" + echo "#endif" + fi + + if [ -n "$umlentry" ]; then echo "#else /* CONFIG_UML */" syscall_macro "$abi" "$nr" "$umlentry" echo "#endif" fi - else - echo "#ifdef CONFIG_X86_32" - if [ -n "$entry" ]; then - syscall_macro "$abi" "$nr" "$entry" - fi - echo "#else" - syscall_macro "$abi" "$nr" "$compat" - echo "#endif" fi }
arch/x86/include/asm/syscall.h +0 -6
@@ -17,13 +17,7 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> -#ifdef CONFIG_X86_64 typedef asmlinkage long (*sys_call_ptr_t )(const struct pt_regs *); -#else -typedef asmlinkage long (*sys_call_ptr_t )(unsigned long ,unsigned long , -unsigned long ,unsigned long , -unsigned long ,unsigned long ); -#endif /* CONFIG_X86_64 */ extern const sys_call_ptr_t sys_call_table[];#if defined(CONFIG_X86_32 )
arch/x86/include/asm/syscall_wrapper.h +3 -0
@@ -8,6 +8,9 @@struct pt_regs ; +extern asmlinkage long __x64_sys_ni_syscall (const struct pt_regs *regs); +extern asmlinkage long __ia32_sys_ni_syscall (const struct pt_regs *regs); +/* * Instead of the generic __SYSCALL_DEFINEx() definition, this macro takes * struct pt_regs *regs as the only argument of the syscall stub named
arch/x86/include/asm/syscalls.h +0 -29
@@ -17,33 +17,4 @@/* kernel/ioport.c */ long ksys_ioperm (unsigned long from,unsigned long num,int turn_on); -#ifdef CONFIG_X86_32 -/* -* These definitions are only valid on pure 32-bit systems; x86-64 uses a -* different syscall calling convention -*/ -asmlinkage long sys_ioperm (unsigned long ,unsigned long ,int ); -asmlinkage long sys_iopl (unsigned int ); - -/* kernel/ldt.c */ -asmlinkage long sys_modify_ldt (int ,void __user *,unsigned long ); - -/* kernel/signal.c */ -asmlinkage long sys_rt_sigreturn (void ); - -/* kernel/tls.c */ -asmlinkage long sys_set_thread_area (struct user_desc __user *); -asmlinkage long sys_get_thread_area (struct user_desc __user *); - -/* X86_32 only */ - -/* kernel/signal.c */ -asmlinkage long sys_sigreturn (void ); - -/* kernel/vm86_32.c */ -struct vm86_struct ; -asmlinkage long sys_vm86old (struct vm86_struct __user *); -asmlinkage long sys_vm86 (unsigned long ,unsigned long ); - -#endif /* CONFIG_X86_32 */ #endif /* _ASM_X86_SYSCALLS_H */
Signature · 1 line
2.24.1
PATCH 5/5 x86: Drop asmlinkage from syscalls
In reply to Brian Gerstasmlinkage is no longer required since the syscall ABI is now fully under x86 architecture control. This makes the 32-bit native syscalls a bit more effecient by passing in regs via EAX instead of on the stack.
--- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/syscall_64.c | 2 +- arch/x86/include/asm/syscall.h | 2 +- arch/x86/include/asm/syscall_wrapper.h | 20 ++++++++++---------- 4 files changed, 13 insertions(+), 13 deletions(-)
arch/x86/entry/syscall_32.c +1 -1
@@ -8,7 +8,7 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#define __SYSCALL_I386 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *); +#define __SYSCALL_I386 (nr, sym, qual) extern long sym(const struct pt_regs *);#include <asm/syscalls_32.h> #undef __SYSCALL_I386
arch/x86/entry/syscall_64.c +1 -1
@@ -8,7 +8,7 @@#include <asm/asm-offsets.h> #include <asm/syscall.h> -#define __SYSCALL_64 (nr, sym, qual) extern asmlinkage long sym(const struct pt_regs *); +#define __SYSCALL_64 (nr, sym, qual) extern long sym(const struct pt_regs *);#define __SYSCALL_X32 (nr, sym, qual) __SYSCALL_64(nr, sym, qual)#include <asm/syscalls_64.h> #undef __SYSCALL_64
arch/x86/include/asm/syscall.h +1 -1
@@ -17,7 +17,7 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> -typedef asmlinkage long (*sys_call_ptr_t )(const struct pt_regs *); +typedef long (*sys_call_ptr_t )(const struct pt_regs *);extern const sys_call_ptr_t sys_call_table[];#if defined(CONFIG_X86_32 )
arch/x86/include/asm/syscall_wrapper.h +10 -10
@@ -8,8 +8,8 @@struct pt_regs ; -extern asmlinkage long __x64_sys_ni_syscall (const struct pt_regs *regs); -extern asmlinkage long __ia32_sys_ni_syscall (const struct pt_regs *regs); +extern long __x64_sys_ni_syscall (const struct pt_regs *regs); +extern long __ia32_sys_ni_syscall (const struct pt_regs *regs);/* * Instead of the generic __SYSCALL_DEFINEx() definition, this macro takes
@@ -59,23 +59,23 @@ extern asmlinkage long __ia32_sys_ni_syscall(const struct pt_regs *regs); ,,(unsigned int)regs->di,,(unsigned int)regs->bp)#define __SYS_STUBx (abi, name, ...) \ - asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + long __##abi##_##name(const struct pt_regs *regs); \ ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ - asmlinkage long __##abi##_##name(const struct pt_regs *regs) \ + long __##abi##_##name(const struct pt_regs *regs) \ { \ return __se_##name(__VA_ARGS__); \ }#define __SYS_STUB0 (abi, name) \ - asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + long __##abi##_##name(const struct pt_regs *regs); \ ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ - asmlinkage long __##abi##_##name(const struct pt_regs *regs) \ + long __##abi##_##name(const struct pt_regs *regs) \ { \ return __do_##name(); \ }#define __COND_SYSCALL (abi, name) \ - asmlinkage __weak long \ + __weak long \ __##abi##_##name(const struct pt_regs *regs) \ { \ return sys_ni_syscall(); \
@@ -270,8 +270,8 @@ extern asmlinkage long __ia32_sys_ni_syscall(const struct pt_regs *regs);* For VSYSCALLS, we need to declare these three syscalls with the new * pt_regs-based calling convention for in-kernel use. */ -asmlinkage long __x64_sys_getcpu (const struct pt_regs *regs); -asmlinkage long __x64_sys_gettimeofday (const struct pt_regs *regs); -asmlinkage long __x64_sys_time (const struct pt_regs *regs); +long __x64_sys_getcpu (const struct pt_regs *regs); +long __x64_sys_gettimeofday (const struct pt_regs *regs); +long __x64_sys_time (const struct pt_regs *regs);#endif /* _ASM_X86_SYSCALL_WRAPPER_H */
Signature · 1 line
2.24.1
Re: [PATCH 4/5] x86-64: Use syscall wrappers for x32_rt_sigreturn
In reply to Brian GerstQuoted 1 line · Brian Gerst
Signed-off-by Brian Gerst <[email protected]>
Re: [PATCH 5/5] x86: Drop asmlinkage from syscalls
In reply to Brian GerstQuoted 5 lines · Brian Gerst
asmlinkage is no longer required since the syscall ABI is now fully under x86 architecture control. This makes the 32-bit native syscalls a bit more effecient by passing in regs via EAX instead of on the stack.
Signed-off-by Brian Gerst <[email protected]>
Thanks,
Dominik
Re: [PATCH 3/5] x86-32: Enable syscall wrappers
In reply to Brian GerstQuoted 3 lines · Brian Gerst
Enable
pt_regsbased syscalls for 32-bit.Signed-off-by Brian Gerst <[email protected]>
Brian,
Quoted 2 lines · Brian Gerst
This patch series cleans up the x86 syscall wrapper code and converts the 32-bit native kernel over to
pt_regsbased syscalls.
thanks for your patchset. Could you explain a bit more what the rationale is. Due to asmlinkage, it doesn't leak "random user-provided register content down the call chain" (as was the case for x86-64). But it may be cleaner, and you mention in patch 5/5 that the new way is "a bit more efficient" -- do you have numbers?
Thanks,
Dominik
Re: [PATCH 1/5] x86: Refactor syscall_wrapper.h
In reply to Brian GerstQuoted 1 line
+ * Instead of the generic
__SYSCALL_DEFINEx()definition, this macro takes
If you move the description to the top (the reason for that is understandable), you can't talk about "this macro" any more -- as "this macro" is "__SYSCALL_DEFINEx()" which is defined far further below.
Quoted 18 lines
+ * struct
pt_regs*regs as the only argument of the syscall stub named
+ * __x64_sys_*(). It decodes just the registers it needs and passes them on to
+ * the __se_sys_*() wrapper performing sign extension and then to the
+ * __do_sys_*() function doing the actual job. These wrappers and functions
+ * are inlined (at least in very most cases), meaning that the assembly looks
+ * as follows (slightly re-ordered for better readability):
+ *
+ * <__x64_sys_recv>: <-- syscall with 4 parameters
+ * callq <__fentry__>
+ *
+ * mov 0x70(%rdi),%rdi <-- decoderegs->di
+ * mov 0x68(%rdi),%rsi <-- decoderegs->si
+ * mov 0x60(%rdi),%rdx <-- decoderegs->dx
+ * mov 0x38(%rdi),%rcx <-- decoderegs->r10
+ *
+ * xor %r9d,%r9d <-- clear %r9
+ * xor %r8d,%r8d <-- clear %r8
+ *
Quoted 8 lines
+ * callq
__sys_recvfrom<-- do the actual work in__sys_recvfrom()
+ * which takes 6 arguments
+ *
+ * cltq <-- extend return value to 64-bit
+ * retq <-- return
+ *
+ * This approach avoids leaking random user-provided register content down
+ * the call chain.
... maybe add the rationale for x86-32 here (in patch 3/5)?
Quoted 3 lines
+ * If
IA32_EMULATIONis enabled, this macro generates an additional wrapper
+ * named __ia32_sys_*() which decodes the structpt_regs*regs according
+ * to the i386 calling convention (bx, cx, dx, si, di, bp).
... and this likely needs an update in patch 3/5 as well
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 72
Quoted 12 lines
arch/x86/include/asm/syscall_wrapper.h +5
-5-#define __IA32_COMPAT_SYS_STUBx (x, name, ...) \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__ia32_compat_sys##name, ERRNO); \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs)\ +#define __SYS_STUB0 (abi, name) \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs) \ { \ - return __se_compat_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\ + return __do_##name(); \ }
Instead of __se_compat_sys##name, now __do_comapt_sys##name is called. This should be equivalent for zero-argument syscalls, but maybe make that change explicit.
In general terms, I am not sure that the new code is more readable (but I may be biased) as the conversion to the proper calling convention for the ABI has to be done by the callee and is not done in the caller. Also, there are now three levels of macros instead of two.
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 83
Quoted 3 lines
arch/x86/include/asm/syscall_wrapper.h +3
-0+#ifdef CONFIG_X86_64 +#define __X64_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(x64, name, SC_X86_64_REGS_TO_ARGS(x, __VA_ARGS__))
s/name/sys_name/g please -- this isn't the name of the syscall any more, but appended by sys (applies to a number of macros)
Quoted 10 lines
- * named __ia32_sys_*()
+ * As the genericSYSCALL_DEFINE0()macro does not decode any parameters for
+ * obvious reasons, and passing structpt_regs*regs to it in %rdi does not
+ * hurt, we only need to re-define it here to keep the naming congruent to
+ *SYSCALL_DEFINEx()-- which is essential for theCOND_SYSCALL()andSYS_NI()
+ * macros to work correctly.
*/arch/x86/include/asm/syscall_wrapper.h +3
-0+#define SYSCALL_DEFINE0 (name) \ + SYSCALL_METADATA(_##name, 0); \ + static inline long __do_sys_##name(void); \
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 67
Quoted 10 lines
arch/x86/include/asm/syscall_wrapper.h +3
-6+ __X64_SYS_STUB0(sys_##name) \ + __IA32_SYS_STUB0(sys_##name) \ + static inline long __do_sys_##name(void) -#define SYSCALL_DEFINE0 (sname) \ - SYSCALL_METADATA(_##sname, 0); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused);\ - ALLOW_ERROR_INJECTION(__x64_sys_##sname, ERRNO); \ - SYSCALL_ALIAS(__ia32_sys_##sname, __x64_sys_##sname); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused)
OK, this is a bit more complex change -- you don't use SYSCALL_ALIAS any more, but define two asmlinakge functions which then call __do_sys_##name(). Maybe needs an explanation in the changelog...
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 182
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(ia32, name, SC_IA32_REGS_TO_ARGS(x, __VA_ARGS__))
s/name/compat_sys_name/g/ -- please make it a bit more explicit what "name" we are talking about here,
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 185
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_SYS_STUB0 (name) \ + __SYS_STUB0(ia32, name)
and here,
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 188
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_COND_SYSCALL (name) \ + __COND_SYSCALL(ia32, name)
and here,
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 191
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_SYS_NI (name) \ + SYSCALL_ALIAS(__ia32_compat_sys_##name, sys_ni_posix_timers)
... but not here, as here "name" is actually "name".
Thanks,
Dominik
Re: [PATCH 2/5] x86: Move 32-bit compat syscalls to common location
In reply to Brian Gerstarch/x86/kernel/Makefile obj-y += setup.o x86_init.o i8259.o irqinit.o · line 61
Quoted 8 lines · Brian Gerst
arch/x86/kernel/Makefile +2
-0@@ -57,6 +57,8 @@ obj-y += setup.o x86_init.o i8259.o irqinit.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-y += probe_roms.o +obj-$(CONFIG_X86_32) += sys_ia32.o +obj-$(CONFIG_IA32_EMULATION) += sys_ia32.o
That doesn't look nicely...
Other than that, the patch looks trivial enough.
Thanks,
Dominik
Quoted 4 lines · Dominik Brodowski
Brian,
On Fri, Feb 21, 2020 at 12:09:29AM -0500, Brian Gerst wrote:
Quoted 8 lines
Quoted 2 lines
This patch series cleans up the x86 syscall wrapper code and converts the 32-bit native kernel over to
pt_regsbased syscalls.thanks for your patchset. Could you explain a bit more what the rationale is. Due to asmlinkage, it doesn't leak "random user-provided register content down the call chain" (as was the case for x86-64). But it may be cleaner, and you mention in patch 5/5 that the new way is "a bit more efficient" -- do you have numbers?
The main rationale for this patch set is to make the 32-bit native kernel consistent with the 64-bit kernel. It's also slightly more efficient because the old code pushed all 6 arguments onto the stack whereas the new code only reads the args the syscall needs, with the pt_regs pointer passed in through a register. By efficient I mean that it uses fewer instructions and stack accesses, not that it will actually have a significant difference on a benchmark.
--
Brian Gerst
Re: [PATCH 2/5] x86: Move 32-bit compat syscalls to common location
In reply to Dominik BrodowskiQuoted 12 lines · Dominik Brodowski
arch/x86/kernel/Makefile obj-y += setup.o x86_init.o i8259.o irqinit.o · line 61
Quoted 8 lines · Brian Gerst
arch/x86/kernel/Makefile +2
-0@@ -57,6 +57,8 @@ obj-y += setup.o x86_init.o i8259.o irqinit.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-y += probe_roms.o +obj-$(CONFIG_X86_32) += sys_ia32.o +obj-$(CONFIG_IA32_EMULATION) += sys_ia32.oThat doesn't look nicely...
Do you have a better suggestion? That's similar to how tls.o is already handled.
--
Brian Gerst
Re: [PATCH 1/5] x86: Refactor syscall_wrapper.h
In reply to Dominik BrodowskiQuoted 35 lines · Dominik Brodowski
Quoted 2 lines
+ * Instead of the generic
__SYSCALL_DEFINEx()definition, this macro takesIf you move the description to the top (the reason for that is understandable), you can't talk about "this macro" any more -- as "this macro" is "
__SYSCALL_DEFINEx()" which is defined far further below.Quoted 21 lines
+ * struct
pt_regs*regs as the only argument of the syscall stub named
+ * __x64_sys_*(). It decodes just the registers it needs and passes them on to
+ * the __se_sys_*() wrapper performing sign extension and then to the
+ * __do_sys_*() function doing the actual job. These wrappers and functions
+ * are inlined (at least in very most cases), meaning that the assembly looks
+ * as follows (slightly re-ordered for better readability):
+ *
+ * <__x64_sys_recv>: <-- syscall with 4 parameters
+ * callq <__fentry__>
+ *+ * mov 0x70(%rdi),%rdi <-- decode regs->di + * mov 0x68(%rdi),%rsi <-- decode regs->si + * mov 0x60(%rdi),%rdx <-- decode regs->dx + * mov 0x38(%rdi),%rcx <-- decode regs->r10 + * + * xor %r9d,%r9d <-- clear %r9 + * xor %r8d,%r8d <-- clear %r8+ *
+ * callq__sys_recvfrom<-- do the actual work in__sys_recvfrom()
+ * which takes 6 arguments
+ *Quoted 5 lines
+ * cltq <-- extend return value to 64-bit + * retq <-- return+ *
+ * This approach avoids leaking random user-provided register content down
+ * the call chain.
Quoted 7 lines
... maybe add the rationale for x86-32 here (in patch 3/5)?
Quoted 3 lines
+ * If
IA32_EMULATIONis enabled, this macro generates an additional wrapper
+ * named __ia32_sys_*() which decodes the structpt_regs*regs according
+ * to the i386 calling convention (bx, cx, dx, si, di, bp).... and this likely needs an update in patch 3/5 as well
I will update that comment section. The code for 32-bit will follow the same pattern, just with different register names.
Quoted 8 lines
Quoted 8 lines
arch/x86/include/asm/syscall_wrapper.h +4
-4-#define __IA32_COMPAT_SYS_STUBx (x, name, ...) \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__ia32_compat_sys##name, ERRNO); \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs)\ +#define __SYS_STUB0 (abi, name) \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs) \
Quoted 8 lines
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 72
Quoted 4 lines
{ \arch/x86/include/asm/syscall_wrapper.h +1
-1- return __se_compat_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\ + return __do_##name(); \ }Instead of __se_compat_sys##name, now __do_comapt_sys##name is called. This should be equivalent for zero-argument syscalls, but maybe make that change explicit.
The __se_* layer (sign-extension) is unnecessary when there are no arguments to extend. But I can make that a separate patch if that makes it clearer.
Quoted 4 lines
In general terms, I am not sure that the new code is more readable (but I may be biased) as the conversion to the proper calling convention for the ABI has to be done by the callee and is not done in the caller. Also, there are now three levels of macros instead of two.
I added the __STUBx layer to avoid 4 copies of the same boilerplate code. The middle layer is needed because you can't have #ifdefs inside a macro.
Quoted 23 lines
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 83
Quoted 5 lines
arch/x86/include/asm/syscall_wrapper.h +3
-0+#ifdef CONFIG_X86_64 +#define __X64_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(x64, name, SC_X86_64_REGS_TO_ARGS(x, __VA_ARGS__))s/name/sys_name/g please -- this isn't the name of the syscall any more, but appended by sys (applies to a number of macros)
Quoted 14 lines
- * named __ia32_sys_*()
+ * As the genericSYSCALL_DEFINE0()macro does not decode any parameters for
+ * obvious reasons, and passing structpt_regs*regs to it in %rdi does not
+ * hurt, we only need to re-define it here to keep the naming congruent to
+ *SYSCALL_DEFINEx()-- which is essential for theCOND_SYSCALL()andSYS_NI()
+ * macros to work correctly.
*/arch/x86/include/asm/syscall_wrapper.h +6
-0+#define SYSCALL_DEFINE0 (name) \ + SYSCALL_METADATA(_##name, 0); \ + static inline long __do_sys_##name(void); \ + __X64_SYS_STUB0(sys_##name) \ + __IA32_SYS_STUB0(sys_##name) \ + static inline long __do_sys_##name(void)
Quoted 10 lines
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 67
Quoted 6 lines
arch/x86/include/asm/syscall_wrapper.h +0
-6-#define SYSCALL_DEFINE0 (sname) \ - SYSCALL_METADATA(_##sname, 0); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused);\ - ALLOW_ERROR_INJECTION(__x64_sys_##sname, ERRNO); \ - SYSCALL_ALIAS(__ia32_sys_##sname, __x64_sys_##sname); \ - asmlinkage long __x64_sys_##sname(const struct pt_regs *__unused)OK, this is a bit more complex change -- you don't use
SYSCALL_ALIASany more, but define two asmlinakge functions which then call __do_sys_##name(). Maybe needs an explanation in the changelog...
IIRC this was because in the 32-bit native case the __x64_* variant wasn't present to alias to. I'll see if I can come up with a different solution.
Quoted 16 lines
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 182
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_SYS_STUBx (x, name, ...) \ + __SYS_STUBx(ia32, name, SC_IA32_REGS_TO_ARGS(x, __VA_ARGS__))s/name/compat_sys_name/g/ -- please make it a bit more explicit what "name" we are talking about here,
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 185
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_SYS_STUB0 (name) \ + __SYS_STUB0(ia32, name)and here,
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 188
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_COND_SYSCALL (name) \ + __COND_SYSCALL(ia32, name)and here,
Quoted 7 lines
arch/x86/include/asm/syscall_wrapper.h struct pt_regs; · line 191
Quoted 2 lines
arch/x86/include/asm/syscall_wrapper.h +2
-0+#define __IA32_COMPAT_SYS_NI (name) \ + SYSCALL_ALIAS(__ia32_compat_sys_##name, sys_ni_posix_timers)... but not here, as here "name" is actually "name".
Thanks,
Dominik
--
Brian Gerst
Quoted 15 lines · Brian Gerst
Quoted 4 lines · Dominik Brodowski
Brian,
On Fri, Feb 21, 2020 at 12:09:29AM -0500, Brian Gerst wrote:
Quoted 8 lines
Quoted 2 lines
This patch series cleans up the x86 syscall wrapper code and converts the 32-bit native kernel over to
pt_regsbased syscalls.thanks for your patchset. Could you explain a bit more what the rationale is. Due to asmlinkage, it doesn't leak "random user-provided register content down the call chain" (as was the case for x86-64). But it may be cleaner, and you mention in patch 5/5 that the new way is "a bit more efficient" -- do you have numbers?
Quoted 7 lines
The main rationale for this patch set is to make the 32-bit native kernel consistent with the 64-bit kernel. It's also slightly more efficient because the old code pushed all 6 arguments onto the stack whereas the new code only reads the args the syscall needs, with the
pt_regspointer passed in through a register. By efficient I mean that it uses fewer instructions and stack accesses, not that it will actually have a significant difference on a benchmark.
OK, could you add such an explanation to the patchset then, please? Thanks, Dominik
Re: [PATCH 2/5] x86: Move 32-bit compat syscalls to common location
In reply to Brian GerstQuoted 15 lines · Brian Gerst
Quoted 12 lines · Dominik Brodowski
arch/x86/kernel/Makefile obj-y += setup.o x86_init.o i8259.o irqinit.o · line 61
Quoted 8 lines · Brian Gerst
arch/x86/kernel/Makefile +2
-0@@ -57,6 +57,8 @@ obj-y += setup.o x86_init.o i8259.o irqinit.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-y += probe_roms.o +obj-$(CONFIG_X86_32) += sys_ia32.o +obj-$(CONFIG_IA32_EMULATION) += sys_ia32.oThat doesn't look nicely...
Quoted 2 lines
Do you have a better suggestion? That's similar to how tls.o is already handled.
Besides modifying Kconfig? No, unfortunately not.
Thanks,
Dominik