Skip to content

Commit 5ac9efa

Browse files
Dominik BrodowskiIngo Molnar
Dominik Brodowski
authored and
Ingo Molnar
committed
syscalls/core, syscalls/x86: Clean up compat syscall stub naming convention
Tidy the naming convention for compat syscall subs. Hints which describe the purpose of the stub go in front and receive a double underscore to denote that they are generated on-the-fly by the COMPAT_SYSCALL_DEFINEx() macro. For the generic case, this means: t kernel_waitid # common C function (see kernel/exit.c) __do_compat_sys_waitid # inlined helper doing the actual work # (takes original parameters as declared) T __se_compat_sys_waitid # sign-extending C function calling inlined # helper (takes parameters of type long, # casts them to unsigned long and then to # the declared type) T compat_sys_waitid # alias to __se_compat_sys_waitid() # (taking parameters as declared), to # be included in syscall table For x86, the naming is as follows: t kernel_waitid # common C function (see kernel/exit.c) __do_compat_sys_waitid # inlined helper doing the actual work # (takes original parameters as declared) t __se_compat_sys_waitid # sign-extending C function calling inlined # helper (takes parameters of type long, # casts them to unsigned long and then to # the declared type) T __ia32_compat_sys_waitid # IA32_EMULATION 32-bit-ptregs -> C stub, # calls __se_compat_sys_waitid(); to be # included in syscall table T __x32_compat_sys_waitid # x32 64-bit-ptregs -> C stub, calls # __se_compat_sys_waitid(); to be included # in syscall table If only one of IA32_EMULATION and x32 is enabled, __se_compat_sys_waitid() may be inlined into the stub __{ia32,x32}_compat_sys_waitid(). Suggested-by: Ingo Molnar <[email protected]> Signed-off-by: Dominik Brodowski <[email protected]> Cc: Al Viro <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent e145242 commit 5ac9efa

File tree

7 files changed

+205
-200
lines changed

7 files changed

+205
-200
lines changed

Documentation/process/adding-syscalls.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ First, the entry in ``arch/x86/entry/syscalls/syscall_32.tbl`` gets an extra
360360
column to indicate that a 32-bit userspace program running on a 64-bit kernel
361361
should hit the compat entry point::
362362

363-
380 i386 xyzzy sys_xyzzy compat_sys_xyzzy
363+
380 i386 xyzzy sys_xyzzy __ia32_compat_sys_xyzzy
364364

365365
Second, you need to figure out what should happen for the x32 ABI version of
366366
the new system call. There's a choice here: the layout of the arguments
@@ -373,7 +373,7 @@ the compatibility wrapper::
373373

374374
333 64 xyzzy sys_xyzzy
375375
...
376-
555 x32 xyzzy compat_sys_xyzzy
376+
555 x32 xyzzy __x32_compat_sys_xyzzy
377377

378378
If no pointers are involved, then it is preferable to re-use the 64-bit system
379379
call for the x32 ABI (and consequently the entry in

arch/x86/entry/syscalls/syscall_32.tbl

+126-126
Large diffs are not rendered by default.

arch/x86/entry/syscalls/syscall_64.tbl

+36-36
Original file line numberDiff line numberDiff line change
@@ -342,43 +342,43 @@
342342

343343
#
344344
# x32-specific system call numbers start at 512 to avoid cache impact
345-
# for native 64-bit operation. The __compat_sys_x32 stubs are created
345+
# for native 64-bit operation. The __x32_compat_sys stubs are created
346346
# on-the-fly for compat_sys_*() compatibility system calls if X86_X32
347347
# is defined.
348348
#
349-
512 x32 rt_sigaction __compat_sys_x32_rt_sigaction
349+
512 x32 rt_sigaction __x32_compat_sys_rt_sigaction
350350
513 x32 rt_sigreturn sys32_x32_rt_sigreturn
351-
514 x32 ioctl __compat_sys_x32_ioctl
352-
515 x32 readv __compat_sys_x32_readv
353-
516 x32 writev __compat_sys_x32_writev
354-
517 x32 recvfrom __compat_sys_x32_recvfrom
355-
518 x32 sendmsg __compat_sys_x32_sendmsg
356-
519 x32 recvmsg __compat_sys_x32_recvmsg
357-
520 x32 execve __compat_sys_x32_execve/ptregs
358-
521 x32 ptrace __compat_sys_x32_ptrace
359-
522 x32 rt_sigpending __compat_sys_x32_rt_sigpending
360-
523 x32 rt_sigtimedwait __compat_sys_x32_rt_sigtimedwait
361-
524 x32 rt_sigqueueinfo __compat_sys_x32_rt_sigqueueinfo
362-
525 x32 sigaltstack __compat_sys_x32_sigaltstack
363-
526 x32 timer_create __compat_sys_x32_timer_create
364-
527 x32 mq_notify __compat_sys_x32_mq_notify
365-
528 x32 kexec_load __compat_sys_x32_kexec_load
366-
529 x32 waitid __compat_sys_x32_waitid
367-
530 x32 set_robust_list __compat_sys_x32_set_robust_list
368-
531 x32 get_robust_list __compat_sys_x32_get_robust_list
369-
532 x32 vmsplice __compat_sys_x32_vmsplice
370-
533 x32 move_pages __compat_sys_x32_move_pages
371-
534 x32 preadv __compat_sys_x32_preadv64
372-
535 x32 pwritev __compat_sys_x32_pwritev64
373-
536 x32 rt_tgsigqueueinfo __compat_sys_x32_rt_tgsigqueueinfo
374-
537 x32 recvmmsg __compat_sys_x32_recvmmsg
375-
538 x32 sendmmsg __compat_sys_x32_sendmmsg
376-
539 x32 process_vm_readv __compat_sys_x32_process_vm_readv
377-
540 x32 process_vm_writev __compat_sys_x32_process_vm_writev
378-
541 x32 setsockopt __compat_sys_x32_setsockopt
379-
542 x32 getsockopt __compat_sys_x32_getsockopt
380-
543 x32 io_setup __compat_sys_x32_io_setup
381-
544 x32 io_submit __compat_sys_x32_io_submit
382-
545 x32 execveat __compat_sys_x32_execveat/ptregs
383-
546 x32 preadv2 __compat_sys_x32_preadv64v2
384-
547 x32 pwritev2 __compat_sys_x32_pwritev64v2
351+
514 x32 ioctl __x32_compat_sys_ioctl
352+
515 x32 readv __x32_compat_sys_readv
353+
516 x32 writev __x32_compat_sys_writev
354+
517 x32 recvfrom __x32_compat_sys_recvfrom
355+
518 x32 sendmsg __x32_compat_sys_sendmsg
356+
519 x32 recvmsg __x32_compat_sys_recvmsg
357+
520 x32 execve __x32_compat_sys_execve/ptregs
358+
521 x32 ptrace __x32_compat_sys_ptrace
359+
522 x32 rt_sigpending __x32_compat_sys_rt_sigpending
360+
523 x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait
361+
524 x32 rt_sigqueueinfo __x32_compat_sys_rt_sigqueueinfo
362+
525 x32 sigaltstack __x32_compat_sys_sigaltstack
363+
526 x32 timer_create __x32_compat_sys_timer_create
364+
527 x32 mq_notify __x32_compat_sys_mq_notify
365+
528 x32 kexec_load __x32_compat_sys_kexec_load
366+
529 x32 waitid __x32_compat_sys_waitid
367+
530 x32 set_robust_list __x32_compat_sys_set_robust_list
368+
531 x32 get_robust_list __x32_compat_sys_get_robust_list
369+
532 x32 vmsplice __x32_compat_sys_vmsplice
370+
533 x32 move_pages __x32_compat_sys_move_pages
371+
534 x32 preadv __x32_compat_sys_preadv64
372+
535 x32 pwritev __x32_compat_sys_pwritev64
373+
536 x32 rt_tgsigqueueinfo __x32_compat_sys_rt_tgsigqueueinfo
374+
537 x32 recvmmsg __x32_compat_sys_recvmmsg
375+
538 x32 sendmmsg __x32_compat_sys_sendmmsg
376+
539 x32 process_vm_readv __x32_compat_sys_process_vm_readv
377+
540 x32 process_vm_writev __x32_compat_sys_process_vm_writev
378+
541 x32 setsockopt __x32_compat_sys_setsockopt
379+
542 x32 getsockopt __x32_compat_sys_getsockopt
380+
543 x32 io_setup __x32_compat_sys_io_setup
381+
544 x32 io_submit __x32_compat_sys_io_submit
382+
545 x32 execveat __x32_compat_sys_execveat/ptregs
383+
546 x32 preadv2 __x32_compat_sys_preadv64v2
384+
547 x32 pwritev2 __x32_compat_sys_pwritev64v2

arch/x86/include/asm/syscall_wrapper.h

+22-22
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
* case as well.
3030
*/
3131
#define COMPAT_SC_IA32_STUBx(x, name, ...) \
32-
asmlinkage long __compat_sys_ia32##name(const struct pt_regs *regs);\
33-
ALLOW_ERROR_INJECTION(__compat_sys_ia32##name, ERRNO); \
34-
asmlinkage long __compat_sys_ia32##name(const struct pt_regs *regs)\
32+
asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs);\
33+
ALLOW_ERROR_INJECTION(__ia32_compat_sys##name, ERRNO); \
34+
asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs)\
3535
{ \
36-
return c_SyS##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\
36+
return __se_compat_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\
3737
} \
3838

3939
#define SC_IA32_WRAPPERx(x, name, ...) \
@@ -65,11 +65,11 @@
6565
* with x86_64 obviously do not need such care.
6666
*/
6767
#define COMPAT_SC_X32_STUBx(x, name, ...) \
68-
asmlinkage long __compat_sys_x32##name(const struct pt_regs *regs);\
69-
ALLOW_ERROR_INJECTION(__compat_sys_x32##name, ERRNO); \
70-
asmlinkage long __compat_sys_x32##name(const struct pt_regs *regs)\
68+
asmlinkage long __x32_compat_sys##name(const struct pt_regs *regs);\
69+
ALLOW_ERROR_INJECTION(__x32_compat_sys##name, ERRNO); \
70+
asmlinkage long __x32_compat_sys##name(const struct pt_regs *regs)\
7171
{ \
72-
return c_SyS##name(SC_X86_64_REGS_TO_ARGS(x,__VA_ARGS__));\
72+
return __se_compat_sys##name(SC_X86_64_REGS_TO_ARGS(x,__VA_ARGS__));\
7373
} \
7474

7575
#else /* CONFIG_X86_X32 */
@@ -84,29 +84,29 @@
8484
* of them. There is no need to implement COMPAT_SYSCALL_DEFINE0, as it is
8585
* unused on x86.
8686
*/
87-
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
88-
static long c_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
89-
static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
90-
COMPAT_SC_IA32_STUBx(x, name, __VA_ARGS__) \
91-
COMPAT_SC_X32_STUBx(x, name, __VA_ARGS__) \
92-
static long c_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
93-
{ \
94-
return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
95-
} \
96-
static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
87+
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
88+
static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
89+
static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
90+
COMPAT_SC_IA32_STUBx(x, name, __VA_ARGS__) \
91+
COMPAT_SC_X32_STUBx(x, name, __VA_ARGS__) \
92+
static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
93+
{ \
94+
return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
95+
} \
96+
static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
9797

9898
/*
9999
* As some compat syscalls may not be implemented, we need to expand
100100
* COND_SYSCALL_COMPAT in kernel/sys_ni.c and COMPAT_SYS_NI in
101101
* kernel/time/posix-stubs.c to cover this case as well.
102102
*/
103103
#define COND_SYSCALL_COMPAT(name) \
104-
cond_syscall(__compat_sys_ia32_##name); \
105-
cond_syscall(__compat_sys_x32_##name)
104+
cond_syscall(__ia32_compat_sys_##name); \
105+
cond_syscall(__x32_compat_sys_##name)
106106

107107
#define COMPAT_SYS_NI(name) \
108-
SYSCALL_ALIAS(__compat_sys_ia32_##name, sys_ni_posix_timers); \
109-
SYSCALL_ALIAS(__compat_sys_x32_##name, sys_ni_posix_timers)
108+
SYSCALL_ALIAS(__ia32_compat_sys_##name, sys_ni_posix_timers); \
109+
SYSCALL_ALIAS(__x32_compat_sys_##name, sys_ni_posix_timers)
110110

111111
#endif /* CONFIG_COMPAT */
112112

arch/x86/include/asm/syscalls.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
long ksys_ioperm(unsigned long from, unsigned long num, int turn_on);
2121

2222
#ifdef CONFIG_X86_32
23-
/*
23+
/*
2424
* These definitions are only valid on pure 32-bit systems; x86-64 uses a
2525
* different syscall calling convention
2626
*/

include/linux/compat.h

+17-12
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,24 @@
6363
#define COMPAT_SYSCALL_DEFINE6(name, ...) \
6464
COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
6565

66+
/*
67+
* The asmlinkage stub is aliased to a function named __se_compat_sys_*() which
68+
* sign-extends 32-bit ints to longs whenever needed. The actual work is
69+
* done within __do_compat_sys_*().
70+
*/
6671
#ifndef COMPAT_SYSCALL_DEFINEx
67-
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
68-
asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
69-
asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
70-
__attribute__((alias(__stringify(compat_SyS##name)))); \
71-
ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
72-
static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
73-
asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
74-
asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
75-
{ \
76-
return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
77-
} \
78-
static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
72+
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
73+
asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
74+
asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
75+
__attribute__((alias(__stringify(__se_compat_sys##name)))); \
76+
ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
77+
static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
78+
asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
79+
asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
80+
{ \
81+
return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
82+
} \
83+
static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
7984
#endif /* COMPAT_SYSCALL_DEFINEx */
8085

8186
#ifndef compat_user_stack_pointer

scripts/bloat-o-meter

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def getsizes(file, format):
3131
# strip generated symbols
3232
if name.startswith("__mod_"): continue
3333
if name.startswith("__se_sys"): continue
34-
if name.startswith("compat_SyS_"): continue
34+
if name.startswith("__se_compat_sys"): continue
3535
if name == "linux_banner": continue
3636
# statics and some other optimizations adds random .NUMBER
3737
name = re_NUMBER.sub('', name)

0 commit comments

Comments
 (0)