diff mbox

[1/5] all: s390: move wrapper infrastructure to generic headers

Message ID 1453741047-5498-2-git-send-email-ynorov@caviumnetworks.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yury Norov Jan. 25, 2016, 4:57 p.m. UTC
__SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
unsigned long and pointer types are all 32-bit length.

linux/syscalls_structs.h header is introduced, because from now (see next patch)
structure types listed there are needed for both normal and compat mode.

cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
compat wrappers are enabled.

Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
asm-generated syscall table. But architectures that generate that tables with
C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) compat_##name'.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 arch/s390/include/asm/compat.h    | 17 +++++++++--
 arch/s390/kernel/compat_wrapper.c | 51 -------------------------------
 include/linux/compat.h            | 63 +++++++++++++++++++++++++++++++++++++++
 include/linux/syscalls.h          | 57 +----------------------------------
 include/linux/syscalls_structs.h  | 60 +++++++++++++++++++++++++++++++++++++
 include/uapi/asm-generic/unistd.h |  4 +++
 kernel/sys_ni.c                   |  8 +++++
 7 files changed, 151 insertions(+), 109 deletions(-)
 create mode 100644 include/linux/syscalls_structs.h

Comments

kernel test robot Jan. 25, 2016, 6:10 p.m. UTC | #1
Hi Yury,

[auto build test ERROR on v4.4-rc8]
[also build test ERROR on next-20160125]
[cannot apply to s390/features v4.5-rc1]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Yury-Norov/all-s390-move-wrapper-infrastructure-to-generic-headers/20160126-010134
config: s390-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=s390 

Note: the linux-review/Yury-Norov/all-s390-move-wrapper-infrastructure-to-generic-headers/20160126-010134 HEAD ef38065534a44f2efabd66ed0860b822cf98e49e builds fine.
      It only hurts bisectibility.

All error/warnings (new ones prefixed by >>):

   fs/notify/fanotify/fanotify_user.c: In function 'compat_SyS_fanotify_mark':
   fs/notify/fanotify/fanotify_user.c:913:1: error: implicit declaration of function '__TYPE_IS_PTR' [-Werror=implicit-function-declaration]
    COMPAT_SYSCALL_DEFINE6(fanotify_mark,
    ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/linux/fanotify.h:4,
                    from include/linux/fanotify.h:4,
                    from fs/notify/fanotify/fanotify_user.c:1:
   fs/notify/fanotify/fanotify_user.c:914:5: error: expected expression before 'int'
        int, fanotify_fd, unsigned int, flags,
        ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
>> include/linux/syscalls.h:43:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP6(m,t,a,...) m(t,a), __MAP5(m,__VA_ARGS__)
                              ^
>> include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP6'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
>> include/linux/compat.h:45:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
     ^
   fs/notify/fanotify/fanotify_user.c:913:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE6'
    COMPAT_SYSCALL_DEFINE6(fanotify_mark,
    ^
   In file included from include/linux/compat.h:19:0,
                    from fs/notify/fanotify/fanotify_user.c:16:
   fs/notify/fanotify/fanotify_user.c:914:5: error: expected expression before 'int'
        int, fanotify_fd, unsigned int, flags,
        ^
   arch/s390/include/asm/compat.h:12:20: note: in definition of macro '__SC_DELOUSE'
     (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
                       ^
>> include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP6'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
>> include/linux/compat.h:45:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
     ^
   fs/notify/fanotify/fanotify_user.c:913:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE6'
    COMPAT_SYSCALL_DEFINE6(fanotify_mark,
    ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/linux/fanotify.h:4,
                    from include/linux/fanotify.h:4,
                    from fs/notify/fanotify/fanotify_user.c:1:
   fs/notify/fanotify/fanotify_user.c:914:23: error: expected expression before 'unsigned'
        int, fanotify_fd, unsigned int, flags,
                          ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:42:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP5(m,t,a,...) m(t,a), __MAP4(m,__VA_ARGS__)
                              ^
>> include/linux/syscalls.h:43:35: note: in expansion of macro '__MAP5'
    #define __MAP6(m,t,a,...) m(t,a), __MAP5(m,__VA_ARGS__)
                                      ^
>> include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP6'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
>> include/linux/compat.h:45:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
     ^
   fs/notify/fanotify/fanotify_user.c:913:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE6'
    COMPAT_SYSCALL_DEFINE6(fanotify_mark,
    ^
   In file included from include/linux/compat.h:19:0,
                    from fs/notify/fanotify/fanotify_user.c:16:
   fs/notify/fanotify/fanotify_user.c:914:23: error: expected expression before 'unsigned'
        int, fanotify_fd, unsigned int, flags,
                          ^
   arch/s390/include/asm/compat.h:12:20: note: in definition of macro '__SC_DELOUSE'
     (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
                       ^
>> include/linux/syscalls.h:43:35: note: in expansion of macro '__MAP5'
    #define __MAP6(m,t,a,...) m(t,a), __MAP5(m,__VA_ARGS__)
                                      ^
>> include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP6'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
>> include/linux/compat.h:45:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
     ^
   fs/notify/fanotify/fanotify_user.c:913:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE6'
    COMPAT_SYSCALL_DEFINE6(fanotify_mark,
    ^
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/linux/fanotify.h:4,
                    from include/linux/fanotify.h:4,
                    from fs/notify/fanotify/fanotify_user.c:1:
   fs/notify/fanotify/fanotify_user.c:915:5: error: expected expression before '__u32'
        __u32, mask0, __u32, mask1, int, dfd,
        ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:41:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP4(m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__)
                              ^
>> include/linux/syscalls.h:42:35: note: in expansion of macro '__MAP4'
    #define __MAP5(m,t,a,...) m(t,a), __MAP4(m,__VA_ARGS__)
                                      ^
>> include/linux/syscalls.h:43:35: note: in expansion of macro '__MAP5'
    #define __MAP6(m,t,a,...) m(t,a), __MAP5(m,__VA_ARGS__)
                                      ^
--
   arch/s390/kernel/compat_linux.c: In function 'compat_SyS_s390_chown16':
   arch/s390/kernel/compat_linux.c:89:1: error: implicit declaration of function '__TYPE_IS_PTR' [-Werror=implicit-function-declaration]
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from arch/s390/kernel/compat_linux.c:17:
   arch/s390/kernel/compat_linux.c:89:38: error: expected expression before 'const'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
                                         ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:40:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                              ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:89:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from arch/s390/include/asm/elf.h:119:0,
                    from include/linux/elf.h:4,
                    from include/linux/module.h:15,
                    from arch/s390/kernel/compat_linux.c:31:
   arch/s390/kernel/compat_linux.c:89:38: error: expected expression before 'const'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
                                         ^
   arch/s390/include/asm/compat.h:12:20: note: in definition of macro '__SC_DELOUSE'
     (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
                       ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:89:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from arch/s390/kernel/compat_linux.c:17:
   arch/s390/kernel/compat_linux.c:90:10: error: expected expression before 'u16'
             u16, user, u16, group)
             ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:39:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
                              ^
>> include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                                      ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:89:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from arch/s390/include/asm/elf.h:119:0,
                    from include/linux/elf.h:4,
                    from include/linux/module.h:15,
                    from arch/s390/kernel/compat_linux.c:31:
   arch/s390/kernel/compat_linux.c:90:10: error: expected expression before 'u16'
             u16, user, u16, group)
             ^
   arch/s390/include/asm/compat.h:12:20: note: in definition of macro '__SC_DELOUSE'
     (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
                       ^
>> include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                                      ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:89:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from arch/s390/kernel/compat_linux.c:17:
   arch/s390/kernel/compat_linux.c:90:21: error: expected expression before 'u16'
             u16, user, u16, group)
                        ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:38:23: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP1(m,t,a) m(t,a)
                          ^
>> include/linux/syscalls.h:39:35: note: in expansion of macro '__MAP1'
    #define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
                                      ^
>> include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                                      ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:89:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from arch/s390/include/asm/elf.h:119:0,
                    from include/linux/elf.h:4,
                    from include/linux/module.h:15,
                    from arch/s390/kernel/compat_linux.c:31:
   arch/s390/kernel/compat_linux.c:90:21: error: expected expression before 'u16'
             u16, user, u16, group)
                        ^
   arch/s390/include/asm/compat.h:12:20: note: in definition of macro '__SC_DELOUSE'
     (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
                       ^
>> include/linux/syscalls.h:39:35: note: in expansion of macro '__MAP1'
    #define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
                                      ^
>> include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                                      ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:89:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
    ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from arch/s390/kernel/compat_linux.c:17:
   arch/s390/kernel/compat_linux.c: In function 'compat_SyS_s390_lchown16':
   arch/s390/kernel/compat_linux.c:95:39: error: expected expression before 'const'
    COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *,
                                          ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:40:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                              ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:95:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *,
    ^
   In file included from arch/s390/include/asm/elf.h:119:0,
                    from include/linux/elf.h:4,
                    from include/linux/module.h:15,
                    from arch/s390/kernel/compat_linux.c:31:
   arch/s390/kernel/compat_linux.c:95:39: error: expected expression before 'const'
    COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *,
                                          ^
   arch/s390/include/asm/compat.h:12:20: note: in definition of macro '__SC_DELOUSE'
     (t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
                       ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
>> include/linux/compat.h:54:23: note: in expansion of macro '__MAP'
      return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
                          ^
   include/linux/compat.h:39:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
     COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
     ^
   arch/s390/kernel/compat_linux.c:95:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE3'
    COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *,
    ^
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from arch/s390/kernel/compat_linux.c:17:
   arch/s390/kernel/compat_linux.c:96:20: error: expected expression before 'u16'
             filename, u16, user, u16, group)
                       ^
   include/linux/compiler.h:464:19: note: in definition of macro '__compiletime_assert'
      bool __cond = !(condition);    \
                      ^
   include/linux/compiler.h:484:2: note: in expansion of macro '_compiletime_assert'
     _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
     ^
   include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
   include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
     ^
>> arch/s390/include/asm/compat.h:11:2: note: in expansion of macro 'BUILD_BUG_ON'
     BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
     ^
   include/linux/syscalls.h:39:27: note: in expansion of macro '__SC_DELOUSE'
    #define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
                              ^
>> include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
    #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
                                      ^
   include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP3'
    #define __MAP(n,...) __MAP##n(__VA_ARGS__)
                         ^
..

vim +11 arch/s390/kernel/compat_wrapper.c

1e4ec621 arch/s390/kernel/compat_wrapper.c Heiko Carstens 2014-03-29   5   */
1e4ec621 arch/s390/kernel/compat_wrapper.c Heiko Carstens 2014-03-29   6  
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27   7  #include <linux/syscalls.h>
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27   8  #include <linux/compat.h>
86d295e1 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27   9  #include "entry.h"
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  10  
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @11  COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  12  COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, newname);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  13  COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @14  COMPAT_SYSCALL_WRAP1(chdir, const char __user *, filename);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  15  COMPAT_SYSCALL_WRAP3(mknod, const char __user *, filename, umode_t, mode, unsigned, dev);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  16  COMPAT_SYSCALL_WRAP2(chmod, const char __user *, filename, umode_t, mode);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @17  COMPAT_SYSCALL_WRAP1(oldumount, char __user *, name);
b07edab2 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  18  COMPAT_SYSCALL_WRAP2(access, const char __user *, filename, int, mode);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @19  COMPAT_SYSCALL_WRAP2(rename, const char __user *, oldname, const char __user *, newname);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @20  COMPAT_SYSCALL_WRAP2(mkdir, const char __user *, pathname, umode_t, mode);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  21  COMPAT_SYSCALL_WRAP1(rmdir, const char __user *, pathname);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @22  COMPAT_SYSCALL_WRAP1(pipe, int __user *, fildes);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @23  COMPAT_SYSCALL_WRAP1(brk, unsigned long, brk);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  24  COMPAT_SYSCALL_WRAP2(signal, int, sig, __sighandler_t, handler);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  25  COMPAT_SYSCALL_WRAP1(acct, const char __user *, name);
473a0657 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  26  COMPAT_SYSCALL_WRAP2(umount, char __user *, name, int, flags);
be06fbf8 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  27  COMPAT_SYSCALL_WRAP1(chroot, const char __user *, filename);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  28  COMPAT_SYSCALL_WRAP3(sigsuspend, int, unused1, int, unused2, old_sigset_t, mask);
be06fbf8 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  29  COMPAT_SYSCALL_WRAP2(sethostname, char __user *, name, int, len);
be06fbf8 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  30  COMPAT_SYSCALL_WRAP2(symlink, const char __user *, old, const char __user *, new);
be06fbf8 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  31  COMPAT_SYSCALL_WRAP3(readlink, const char __user *, path, char __user *, buf, int, bufsiz);
be06fbf8 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  32  COMPAT_SYSCALL_WRAP1(uselib, const char __user *, library);
be06fbf8 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  33  COMPAT_SYSCALL_WRAP2(swapon, const char __user *, specialfile, int, swap_flags);
c355ce18 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  34  COMPAT_SYSCALL_WRAP4(reboot, int, magic1, int, magic2, unsigned int, cmd, void __user *, arg);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  35  COMPAT_SYSCALL_WRAP2(munmap, unsigned long, addr, size_t, len);
c355ce18 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @36  COMPAT_SYSCALL_WRAP3(syslog, int, type, char __user *, buf, int, len);
c355ce18 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  37  COMPAT_SYSCALL_WRAP1(swapoff, const char __user *, specialfile);
c355ce18 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @38  COMPAT_SYSCALL_WRAP2(setdomainname, char __user *, name, int, len);
c355ce18 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @39  COMPAT_SYSCALL_WRAP1(newuname, struct new_utsname __user *, name);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  40  COMPAT_SYSCALL_WRAP3(mprotect, unsigned long, start, size_t, len, unsigned long, prot);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @41  COMPAT_SYSCALL_WRAP3(init_module, void __user *, umod, unsigned long, len, const char __user *, uargs);
86d295e1 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  42  COMPAT_SYSCALL_WRAP2(delete_module, const char __user *, name_user, unsigned int, flags);
86d295e1 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  43  COMPAT_SYSCALL_WRAP4(quotactl, unsigned int, cmd, const char __user *, special, qid_t, id, void __user *, addr);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  44  COMPAT_SYSCALL_WRAP2(bdflush, int, func, long, data);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  45  COMPAT_SYSCALL_WRAP3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  46  COMPAT_SYSCALL_WRAP5(llseek, unsigned int, fd, unsigned long, high, unsigned long, low, loff_t __user *, result, unsigned int, whence);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @47  COMPAT_SYSCALL_WRAP3(msync, unsigned long, start, size_t, len, int, flags);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  48  COMPAT_SYSCALL_WRAP2(mlock, unsigned long, start, size_t, len);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  49  COMPAT_SYSCALL_WRAP2(munlock, unsigned long, start, size_t, len);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @50  COMPAT_SYSCALL_WRAP2(sched_setparam, pid_t, pid, struct sched_param __user *, param);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  51  COMPAT_SYSCALL_WRAP2(sched_getparam, pid_t, pid, struct sched_param __user *, param);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  52  COMPAT_SYSCALL_WRAP3(sched_setscheduler, pid_t, pid, int, policy, struct sched_param __user *, param);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  53  COMPAT_SYSCALL_WRAP5(mremap, unsigned long, addr, unsigned long, old_len, unsigned long, new_len, unsigned long, flags, unsigned long, new_addr);
0ebe3eec arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @54  COMPAT_SYSCALL_WRAP3(poll, struct pollfd __user *, ufds, unsigned int, nfds, int, timeout);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  55  COMPAT_SYSCALL_WRAP5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  56  COMPAT_SYSCALL_WRAP2(getcwd, char __user *, buf, unsigned long, size);
0ebe3eec arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27 @57  COMPAT_SYSCALL_WRAP2(capget, cap_user_header_t, header, cap_user_data_t, dataptr);
0ebe3eec arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-27  58  COMPAT_SYSCALL_WRAP2(capset, cap_user_header_t, header, const cap_user_data_t, data);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @59  COMPAT_SYSCALL_WRAP3(lchown, const char __user *, filename, uid_t, user, gid_t, group);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @60  COMPAT_SYSCALL_WRAP2(getgroups, int, gidsetsize, gid_t __user *, grouplist);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  61  COMPAT_SYSCALL_WRAP2(setgroups, int, gidsetsize, gid_t __user *, grouplist);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @62  COMPAT_SYSCALL_WRAP3(getresuid, uid_t __user *, ruid, uid_t __user *, euid, uid_t __user *, suid);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @63  COMPAT_SYSCALL_WRAP3(getresgid, gid_t __user *, rgid, gid_t __user *, egid, gid_t __user *, sgid);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  64  COMPAT_SYSCALL_WRAP3(chown, const char __user *, filename, uid_t, user, gid_t, group);
24e4c2aa arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  65  COMPAT_SYSCALL_WRAP2(pivot_root, const char __user *, new_root, const char __user *, put_old);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  66  COMPAT_SYSCALL_WRAP3(mincore, unsigned long, start, size_t, len, unsigned char __user *, vec);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  67  COMPAT_SYSCALL_WRAP3(madvise, unsigned long, start, size_t, len, int, behavior);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  68  COMPAT_SYSCALL_WRAP5(setxattr, const char __user *, path, const char __user *, name, const void __user *, value, size_t, size, int, flags);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  69  COMPAT_SYSCALL_WRAP5(lsetxattr, const char __user *, path, const char __user *, name, const void __user *, value, size_t, size, int, flags);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  70  COMPAT_SYSCALL_WRAP5(fsetxattr, int, fd, const char __user *, name, const void __user *, value, size_t, size, int, flags);
18421166 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  71  COMPAT_SYSCALL_WRAP3(getdents64, unsigned int, fd, struct linux_dirent64 __user *, dirent, unsigned int, count);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  72  COMPAT_SYSCALL_WRAP4(getxattr, const char __user *, path, const char __user *, name, void __user *, value, size_t, size);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  73  COMPAT_SYSCALL_WRAP4(lgetxattr, const char __user *, path, const char __user *, name, void __user *, value, size_t, size);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  74  COMPAT_SYSCALL_WRAP4(fgetxattr, int, fd, const char __user *, name, void __user *, value, size_t, size);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  75  COMPAT_SYSCALL_WRAP3(listxattr, const char __user *, path, char __user *, list, size_t, size);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  76  COMPAT_SYSCALL_WRAP3(llistxattr, const char __user *, path, char __user *, list, size_t, size);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  77  COMPAT_SYSCALL_WRAP3(flistxattr, int, fd, char __user *, list, size_t, size);
18421166 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  78  COMPAT_SYSCALL_WRAP2(removexattr, const char __user *, path, const char __user *, name);
18421166 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  79  COMPAT_SYSCALL_WRAP2(lremovexattr, const char __user *, path, const char __user *, name);
18421166 arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  80  COMPAT_SYSCALL_WRAP2(fremovexattr, int, fd, const char __user *, name);
9c4d62fa arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28 @81  COMPAT_SYSCALL_WRAP1(set_tid_address, int __user *, tidptr);
9c4d62fa arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  82  COMPAT_SYSCALL_WRAP4(epoll_ctl, int, epfd, int, op, int, fd, struct epoll_event __user *, event);
9c4d62fa arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  83  COMPAT_SYSCALL_WRAP4(epoll_wait, int, epfd, struct epoll_event __user *, events, int, maxevents, int, timeout);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01 @84  COMPAT_SYSCALL_WRAP1(io_destroy, aio_context_t, ctx);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  85  COMPAT_SYSCALL_WRAP3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, struct io_event __user *, result);
9c4d62fa arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-02-28  86  COMPAT_SYSCALL_WRAP1(mq_unlink, const char __user *, name);
ab4f8bba arch/s390/kernel/compat_wrap.c    Heiko Carstens 2014-03-01  87  COMPAT_SYSCALL_WRAP5(add_key, const char __user *, tp, const char __user *, dsc, const void __user *, pld, size_t, len, key_serial_t, id);

:::::: The code at line 11 was first introduced by commit
:::::: b07edab23c7f93db0e7ab09bd7f5eddc421f6e8c s390/compat: convert system call wrappers to C part 01

:::::: TO: Heiko Carstens <heiko.carstens@de.ibm.com>
:::::: CC: Heiko Carstens <heiko.carstens@de.ibm.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Heiko Carstens Jan. 28, 2016, 12:16 p.m. UTC | #2
Hello Yury,

On Mon, Jan 25, 2016 at 07:57:23PM +0300, Yury Norov wrote:
> __SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
> moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
> unsigned long and pointer types are all 32-bit length.
> 
> linux/syscalls_structs.h header is introduced, because from now (see next patch)
> structure types listed there are needed for both normal and compat mode.
> 
> cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
> compat wrappers are enabled.
> 
> Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
> asm-generated syscall table. But architectures that generate that tables with
> C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) compat_##name'.
> 
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>

...

> diff --git a/include/linux/compat.h b/include/linux/compat.h
> index a76c917..1a761ea 100644
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -718,4 +718,67 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
>  #define is_compat_task() (0)
>  
>  #endif /* CONFIG_COMPAT */
> +
> +#ifdef CONFIG_COMPAT_WRAPPER
> +
> +#ifndef __TYPE_IS_PTR
> +#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64))
> +#endif
> +
> +#ifndef __SC_COMPAT_TYPE
> +#define __SC_COMPAT_TYPE(t, a) \
> +	__typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
> +#endif
> +
> +#ifndef __SC_COMPAT_CAST
> +#define __SC_COMPAT_CAST(t, a) ({					\
> +	BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&		\
> +		     !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));		\
> +	((t) ((t)(-1) < 0 ? (s64)(s32)(a) : (u64)(u32)(a)));		\
> +})
> +#endif
> +
> +#ifndef SYSCALL_DEFINE_WRAPx
> +/*
> + * The SYSCALL_DEFINE_WRAP macro generates system call wrappers to be used by
> + * compat tasks. These wrappers will only be used for system calls where only
> + * the system call arguments need sign or zero extension or zeroing of upper
> + * bits of pointers.
> + * Note: since the wrapper function will afterwards call a system call which
> + * again performs zero and sign extension for all system call arguments with
> + * a size of less than eight bytes, these compat wrappers only touch those
> + * system call arguments with a size of eight bytes ((unsigned) long and
> + * pointers). Zero and sign extension for e.g. int parameters will be done by
> + * the regular system call wrappers.
> + */
> +#define SYSCALL_DEFINE_WRAPx(x, name, ...)						\
> +asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));				\
> +asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))			\
> +		__attribute__((alias(__stringify(compat_SyS##name))));			\
> +asmlinkage long compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__));		\
> +asmlinkage long compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))			\
> +{											\
> +	return sys##name(__MAP(x,__SC_COMPAT_CAST,__VA_ARGS__));			\
> +}											\
> +SYSCALL_DEFINEx(x, name, __VA_ARGS__)
> +#endif
> +
> +#define SYSCALL_DEFINE_WRAP1(name, ...) SYSCALL_DEFINE_WRAPx(1, _##name, __VA_ARGS__)
> +#define SYSCALL_DEFINE_WRAP2(name, ...) SYSCALL_DEFINE_WRAPx(2, _##name, __VA_ARGS__)
> +#define SYSCALL_DEFINE_WRAP3(name, ...) SYSCALL_DEFINE_WRAPx(3, _##name, __VA_ARGS__)
> +#define SYSCALL_DEFINE_WRAP4(name, ...) SYSCALL_DEFINE_WRAPx(4, _##name, __VA_ARGS__)
> +#define SYSCALL_DEFINE_WRAP5(name, ...) SYSCALL_DEFINE_WRAPx(5, _##name, __VA_ARGS__)
> +#define SYSCALL_DEFINE_WRAP6(name, ...) SYSCALL_DEFINE_WRAPx(6, _##name, __VA_ARGS__)
> +
> +#else
> +
> +#define SYSCALL_DEFINE_WRAP1	SYSCALL_DEFINE1
> +#define SYSCALL_DEFINE_WRAP2    SYSCALL_DEFINE2
> +#define SYSCALL_DEFINE_WRAP3    SYSCALL_DEFINE3
> +#define SYSCALL_DEFINE_WRAP4    SYSCALL_DEFINE4
> +#define SYSCALL_DEFINE_WRAP5    SYSCALL_DEFINE5
> +#define SYSCALL_DEFINE_WRAP6    SYSCALL_DEFINE6
> +
> +#endif /* CONFIG_COMPAT_WRAPPER */

How about if you rename SYSCALL_DEFINE_WRAP to SYSCALL_COMPAT_DEFINE which
has the semantics that no dedicated compat system call exists (aka system
call is compat safe).

Then convert all existing SYSCALL_DEFINE'd system calls for which no compat
variant exists to SYSCALL_COMPAT_DEFINE.

This would allow to specify "compat_sys_<syscallname>" in the compat system
call table for _all_ system calls.

No need to look up if a compat variant (or wrapper) exists or
sys_<syscallname> should be used instead. Also no possibility for security
bugs that could creep in because SYSCALL_DEFINE has been used instead of
SYSCALL_DEFINE_WRAP.

Ideally the implementation would only generate an alias if no sign/zero
extension is necessary.

Trivially this would be true for system calls without arguments like e.g.
sys_fork() which would get a compat_sys_fork alias without any further
code.

I'm not sure how difficult it is to implement the same logic for system
calls that have parameters. That is: either generate a
compat_sys_<syscallname> wrapper function, or if the SYSCALL_COMPAT_DEFINE
macro figures out that no zero sign extension is required, only an alias
without any additional code.

I think in the long term something like this is much easier to maintain.

Does that make sense?
Yury Norov Jan. 28, 2016, 4:31 p.m. UTC | #3
On Thu, Jan 28, 2016 at 01:16:18PM +0100, Heiko Carstens wrote:
> Hello Yury,
> 
> On Mon, Jan 25, 2016 at 07:57:23PM +0300, Yury Norov wrote:
> > __SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
> > moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
> > unsigned long and pointer types are all 32-bit length.
> > 
> > linux/syscalls_structs.h header is introduced, because from now (see next patch)
> > structure types listed there are needed for both normal and compat mode.
> > 
> > cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
> > compat wrappers are enabled.
> > 
> > Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
> > asm-generated syscall table. But architectures that generate that tables with
> > C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) compat_##name'.
> > 
> > Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> 
> ...
> 

Hi Heiko,

> How about if you rename SYSCALL_DEFINE_WRAP to SYSCALL_COMPAT_DEFINE which
> has the semantics that no dedicated compat system call exists (aka system
> call is compat safe).
> 
> Then convert all existing SYSCALL_DEFINE'd system calls for which no compat
> variant exists to SYSCALL_COMPAT_DEFINE.
> 
> This would allow to specify "compat_sys_<syscallname>" in the compat system
> call table for _all_ system calls.
> 

We can modify SYSCALL_DEFINEx macro to declare weak "compat_sys_<syscallname>"
symbol for each syscall. So if strong compat symbol will be declared
somwere else, it will owerride the weak one. Being under COMPAT_WRAPPER
config, it will not affect someone else except s390 and aarch64/ilp32.
The downside of this approach is that we'll have to move wrapper
machinery to 'include/linux/syscalls.h', thought under wrapper config.

> No need to look up if a compat variant (or wrapper) exists or
> sys_<syscallname> should be used instead. Also no possibility for security
> bugs that could creep in because SYSCALL_DEFINE has been used instead of
> SYSCALL_DEFINE_WRAP.

If we'll choose to stay with current approach, we'll definitely need
to update documentation.

> 
> Ideally the implementation would only generate an alias if no sign/zero
> extension is necessary.
> 
> Trivially this would be true for system calls without arguments like e.g.
> sys_fork() which would get a compat_sys_fork alias without any further
> code.
> 
> I'm not sure how difficult it is to implement the same logic for system
> calls that have parameters. That is: either generate a
> compat_sys_<syscallname> wrapper function, or if the SYSCALL_COMPAT_DEFINE
> macro figures out that no zero sign extension is required, only an alias
> without any additional code.
> 
> I think in the long term something like this is much easier to maintain.
> 
> Does that make sense?

For me, the most important adwantage of this approach is that we don't
need the list of 'magic' system calls anymore. It's even more
important if we'll face a requirement to support ABI that differs from
both natural and ilp32 ABIs. New __SC_COMPAT_CAST will do all the job
for us.

The downsides are that we'll have unneeded wrappers for some syscalls,
if linker will not clear them, and wasting of space if we'll find no
way how to explain compiler to generate simple alias when it's
enough... 

I'll play with it and write you what I'll come to.

Yury.
Yury Norov Feb. 1, 2016, 11:42 a.m. UTC | #4
On Thu, Jan 28, 2016 at 07:31:09PM +0300, Yury Norov wrote:
> On Thu, Jan 28, 2016 at 01:16:18PM +0100, Heiko Carstens wrote:
> > Hello Yury,
> > 
> > On Mon, Jan 25, 2016 at 07:57:23PM +0300, Yury Norov wrote:
> > > __SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
> > > moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
> > > unsigned long and pointer types are all 32-bit length.
> > > 
> > > linux/syscalls_structs.h header is introduced, because from now (see next patch)
> > > structure types listed there are needed for both normal and compat mode.
> > > 
> > > cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
> > > compat wrappers are enabled.
> > > 
> > > Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
> > > asm-generated syscall table. But architectures that generate that tables with
> > > C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) compat_##name'.
> > > 
> > > Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
> > 
> > ...
> > 
> 
> Hi Heiko,
> 
> > How about if you rename SYSCALL_DEFINE_WRAP to SYSCALL_COMPAT_DEFINE which
> > has the semantics that no dedicated compat system call exists (aka system
> > call is compat safe).
> > 
> > Then convert all existing SYSCALL_DEFINE'd system calls for which no compat
> > variant exists to SYSCALL_COMPAT_DEFINE.
> > 
> > This would allow to specify "compat_sys_<syscallname>" in the compat system
> > call table for _all_ system calls.
> > 
> 
> We can modify SYSCALL_DEFINEx macro to declare weak "compat_sys_<syscallname>"
> symbol for each syscall. So if strong compat symbol will be declared
> somwere else, it will owerride the weak one. Being under COMPAT_WRAPPER
> config, it will not affect someone else except s390 and aarch64/ilp32.
> The downside of this approach is that we'll have to move wrapper
> machinery to 'include/linux/syscalls.h', thought under wrapper config.
> 
> > No need to look up if a compat variant (or wrapper) exists or
> > sys_<syscallname> should be used instead. Also no possibility for security
> > bugs that could creep in because SYSCALL_DEFINE has been used instead of
> > SYSCALL_DEFINE_WRAP.
> 
> If we'll choose to stay with current approach, we'll definitely need
> to update documentation.
> 
> > 
> > Ideally the implementation would only generate an alias if no sign/zero
> > extension is necessary.
> > 
> > Trivially this would be true for system calls without arguments like e.g.
> > sys_fork() which would get a compat_sys_fork alias without any further
> > code.
> > 
> > I'm not sure how difficult it is to implement the same logic for system
> > calls that have parameters. That is: either generate a
> > compat_sys_<syscallname> wrapper function, or if the SYSCALL_COMPAT_DEFINE
> > macro figures out that no zero sign extension is required, only an alias
> > without any additional code.
> > 
> > I think in the long term something like this is much easier to maintain.
> > 
> > Does that make sense?
> 
> For me, the most important adwantage of this approach is that we don't
> need the list of 'magic' system calls anymore. It's even more
> important if we'll face a requirement to support ABI that differs from
> both natural and ilp32 ABIs. New __SC_COMPAT_CAST will do all the job
> for us.
> 
> The downsides are that we'll have unneeded wrappers for some syscalls,
> if linker will not clear them, and wasting of space if we'll find no
> way how to explain compiler to generate simple alias when it's
> enough... 
> 
> I'll play with it and write you what I'll come to.
> 
> Yury.

Hi Heiko,

I tried this idea, and I don't like what happened.
 - Wrappers around safe syscalls does exist. We can remove it by
   overcomplicating __SC_COMPAT_CAST, but I don't like it.
 - We still need to declare numerous list of new compat syscalls.
   And it becomes even bigger, as we need to declare all compat
   syscall versions not declared in include/linux/compat.h already.
   (Currently - only for unsafe syscalls.)
 - 'Weak' trick doesn't work for the whole kernel, so we'd figure out
   some new prefix for wrapped syscalls. Or declare all non-compat
   syscalls explicitly with SYSCALL_COMPAT_DEFINE. So the list of
   replacements grow. And for me, it's harder to explain why we are
   wrapping safe syscalls. Or we introduce another bunch of useless
   wrappers (with new prefix), and have to handle it in non-compat code.
 - With all listed above, we move all wrapper logic to non-compat
   'include/linux/syscalls.h' header. Which is not a good idea, if it
   doesn't benefit us much in return.

> > No need to look up if a compat variant (or wrapper) exists or
> > sys_<syscallname> should be used instead. Also no possibility for security
> > bugs that could creep in because SYSCALL_DEFINE has been used instead of
> > SYSCALL_DEFINE_WRAP.

I thought again about it. With current version, it's very easy to
define whether we have wrapper or not - just by macro we use. Once
reviewed, this list is hardly to be changed frequently. If someone is
introducing new syscall, it will attract much attention, so security
risk is minimal.

Maybe I missed some elegant implementation, and if so  I'll be happy
if someone'll point me out. But with what I see, I'd vote for what we
have now. (Plus description in docs, plus renaming new macro.)

Yury.
Heiko Carstens Feb. 2, 2016, 7:39 a.m. UTC | #5
On Mon, Feb 01, 2016 at 02:42:51PM +0300, Yury Norov wrote:
> Hi Heiko,
> 
> I tried this idea, and I don't like what happened.
>  - Wrappers around safe syscalls does exist. We can remove it by
>    overcomplicating __SC_COMPAT_CAST, but I don't like it.
>  - We still need to declare numerous list of new compat syscalls.
>    And it becomes even bigger, as we need to declare all compat
>    syscall versions not declared in include/linux/compat.h already.
>    (Currently - only for unsafe syscalls.)
>  - 'Weak' trick doesn't work for the whole kernel, so we'd figure out
>    some new prefix for wrapped syscalls. Or declare all non-compat
>    syscalls explicitly with SYSCALL_COMPAT_DEFINE. So the list of
>    replacements grow. And for me, it's harder to explain why we are
>    wrapping safe syscalls. Or we introduce another bunch of useless
>    wrappers (with new prefix), and have to handle it in non-compat code.
>  - With all listed above, we move all wrapper logic to non-compat
>    'include/linux/syscalls.h' header. Which is not a good idea, if it
>    doesn't benefit us much in return.
> 
> > > No need to look up if a compat variant (or wrapper) exists or
> > > sys_<syscallname> should be used instead. Also no possibility for security
> > > bugs that could creep in because SYSCALL_DEFINE has been used instead of
> > > SYSCALL_DEFINE_WRAP.
> 
> I thought again about it. With current version, it's very easy to
> define whether we have wrapper or not - just by macro we use. Once
> reviewed, this list is hardly to be changed frequently. If someone is
> introducing new syscall, it will attract much attention, so security
> risk is minimal.
> 
> Maybe I missed some elegant implementation, and if so  I'll be happy
> if someone'll point me out. But with what I see, I'd vote for what we
> have now. (Plus description in docs, plus renaming new macro.)

Well, I'd like to have some proof by the compiler or linker that nothing
went wrong. Which seems hard if only selected system call defines will be
converted to the new defines.

How can you tell that nothing has been forgotten?

Also, what happens if the prototype of a system call get's changed shortly
after it was merged. We might miss such changes and have bugs.

Therefore, and to get to a solution, I think we should stick with your
first idea, which only moves the compat_wrapper.c file.

Before doing that I think you should actually revert this patch: my commit
7681df456f97 ("s390/compat: remove superfluous compat wrappers") probably
wasn't a very bright idea :)

This again allows me to use only compat system calls in s390's system call
table (execpt for system calls without parameters, but that can be easily
fixed).

What I still don't like is that you need to add all the protoypes. Why are
the system call tables actually written in C and not in asm?
Yury Norov Feb. 2, 2016, 3:43 p.m. UTC | #6
On Tue, Feb 02, 2016 at 08:39:13AM +0100, Heiko Carstens wrote:
> On Mon, Feb 01, 2016 at 02:42:51PM +0300, Yury Norov wrote:
> > Hi Heiko,
> > 
> > I tried this idea, and I don't like what happened.
> >  - Wrappers around safe syscalls does exist. We can remove it by
> >    overcomplicating __SC_COMPAT_CAST, but I don't like it.
> >  - We still need to declare numerous list of new compat syscalls.
> >    And it becomes even bigger, as we need to declare all compat
> >    syscall versions not declared in include/linux/compat.h already.
> >    (Currently - only for unsafe syscalls.)
> >  - 'Weak' trick doesn't work for the whole kernel, so we'd figure out
> >    some new prefix for wrapped syscalls. Or declare all non-compat
> >    syscalls explicitly with SYSCALL_COMPAT_DEFINE. So the list of
> >    replacements grow. And for me, it's harder to explain why we are
> >    wrapping safe syscalls. Or we introduce another bunch of useless
> >    wrappers (with new prefix), and have to handle it in non-compat code.
> >  - With all listed above, we move all wrapper logic to non-compat
> >    'include/linux/syscalls.h' header. Which is not a good idea, if it
> >    doesn't benefit us much in return.
> > 
> > > > No need to look up if a compat variant (or wrapper) exists or
> > > > sys_<syscallname> should be used instead. Also no possibility for security
> > > > bugs that could creep in because SYSCALL_DEFINE has been used instead of
> > > > SYSCALL_DEFINE_WRAP.
> > 
> > I thought again about it. With current version, it's very easy to
> > define whether we have wrapper or not - just by macro we use. Once
> > reviewed, this list is hardly to be changed frequently. If someone is
> > introducing new syscall, it will attract much attention, so security
> > risk is minimal.
> > 
> > Maybe I missed some elegant implementation, and if so  I'll be happy
> > if someone'll point me out. But with what I see, I'd vote for what we
> > have now. (Plus description in docs, plus renaming new macro.)
> 
> Well, I'd like to have some proof by the compiler or linker that nothing
> went wrong. Which seems hard if only selected system call defines will be
> converted to the new defines.
> 
> How can you tell that nothing has been forgotten?
> 
> Also, what happens if the prototype of a system call get's changed shortly
> after it was merged. We might miss such changes and have bugs.
> 

As for now, there's no such proof, and everything is OK. Syscall ABI
is extremely conservative, and Greg KH, and other people spent a lot
of efforts to keep it that way. This is the only reason for me to not
worry much about it. Modification of syscall ABI is virtually
impossible now, because it breaks binary compatibility. Even addition
of new syscall is very difficult procedure.
(Documentation/adding-syscalls.txt begins with section "System Call
Alternatives".)

We can invent some protection, but it will cost us in complexity and/or
runtime delays. Because syscall ABI is so stable, I think it's OK to
review wrappers carefully once, and they will be fine for long time.

> Therefore, and to get to a solution, I think we should stick with your
> first idea, which only moves the compat_wrapper.c file.
> 
> Before doing that I think you should actually revert this patch: my commit
> 7681df456f97 ("s390/compat: remove superfluous compat wrappers") probably
> wasn't a very bright idea :)
> 

This patch is OK for me. pid_t, uid_t, gid_t, unsigned and signed int
types are all 32-bit both on LP64 and ILP32. Normally, compiler should
care about top halves... Did I miss something?

> This again allows me to use only compat system calls in s390's system call
> table (execpt for system calls without parameters, but that can be easily
> fixed).
> 
> What I still don't like is that you need to add all the protoypes. Why are
> the system call tables actually written in C and not in asm?

Because generic unistd code is multi-platform by intention.

I don't know much about s390 specifics. Maybe because of that I do not
understand completely your worries. I'm OK with both 1st and 2nd
version, but I'd choose 2nd one because it allows inlines, and we
don't need the compat_wrapper.c.
Heiko Carstens Feb. 2, 2016, 4:08 p.m. UTC | #7
On Tue, Feb 02, 2016 at 06:43:31PM +0300, Yury Norov wrote:
> > Well, I'd like to have some proof by the compiler or linker that nothing
> > went wrong. Which seems hard if only selected system call defines will be
> > converted to the new defines.
> > 
> > How can you tell that nothing has been forgotten?
> > 
> > Also, what happens if the prototype of a system call get's changed shortly
> > after it was merged. We might miss such changes and have bugs.
> > 
> 
> As for now, there's no such proof, and everything is OK. Syscall ABI
> is extremely conservative, and Greg KH, and other people spent a lot
> of efforts to keep it that way. This is the only reason for me to not
> worry much about it. Modification of syscall ABI is virtually
> impossible now, because it breaks binary compatibility. Even addition
> of new syscall is very difficult procedure.
> (Documentation/adding-syscalls.txt begins with section "System Call
> Alternatives".)

Well... during the years a lot of system calls have been added. And we've
also seen last-minute changes or reverts. So I don't share your optimistic
view here :)

See e.g. 485d52768685 ("sys_personality: change sys_personality() to accept
"unsigned int" instead of u_long") would have been a candidate which could
silently break architectures which need compat wrappers.

> We can invent some protection, but it will cost us in complexity and/or
> runtime delays. Because syscall ABI is so stable, I think it's OK to
> review wrappers carefully once, and they will be fine for long time.

Here I don't agree with you. These interfaces are so important that I'd
like to have a waterproof method that these don't break.  If this involves
a couple of superfluous instructions then that's what I'm willing to pay
for it.

> > Before doing that I think you should actually revert this patch: my commit
> > 7681df456f97 ("s390/compat: remove superfluous compat wrappers") probably
> > wasn't a very bright idea :)
> This patch is OK for me. pid_t, uid_t, gid_t, unsigned and signed int
> types are all 32-bit both on LP64 and ILP32. Normally, compiler should
> care about top halves... Did I miss something?

The patch was correct when writing it, but e.g. a patch like named above
would introduce a possible bug which would go in unnoticed.
The only thing we save is a _single_ unconditional branch here. I'd say
that's well worth it if you get a (hopefully) always bug free sign and zero
extension infrastructure in return.

> I don't know much about s390 specifics. Maybe because of that I do not
> understand completely your worries. I'm OK with both 1st and 2nd
> version, but I'd choose 2nd one because it allows inlines, and we
> don't need the compat_wrapper.c.

It would be only nicer if we can guarentee correctness all the time. That
being said I'm about to revert my own commit :)

So if you want to go without compat_wrapper.c then we should have a
solution which will do the right thing all the time without that a system
call author has to know about the sign and zero extension issue some
architectures face. It _will_ go wrong.
Heiko Carstens Feb. 2, 2016, 7:54 p.m. UTC | #8
Hi Yury,

On Tue, Feb 02, 2016 at 05:08:26PM +0100, Heiko Carstens wrote:
> See e.g. 485d52768685 ("sys_personality: change sys_personality() to accept
> "unsigned int" instead of u_long") would have been a candidate which could
> silently break architectures which need compat wrappers.

Ok, this example is of course wrong. But now I can claim that also somebody
who should know better makes these mistakes.. :)

> > I don't know much about s390 specifics. Maybe because of that I do not
> > understand completely your worries. I'm OK with both 1st and 2nd
> > version, but I'd choose 2nd one because it allows inlines, and we
> > don't need the compat_wrapper.c.
> 
> It would be only nicer if we can guarentee correctness all the time. That
> being said I'm about to revert my own commit :)
> 
> So if you want to go without compat_wrapper.c then we should have a
> solution which will do the right thing all the time without that a system
> call author has to know about the sign and zero extension issue some
> architectures face. It _will_ go wrong.

So I think I can summarize my point to: if you can enforce correctness, why
shouldn't you do it if the performance impact is only a single instruction.

However I'll try to write an addon patch to your patch series. Maybe we can
still get rid of compat_wrapper.c in a way which makes both of us happy.
Also.. the idea with the alias names for compat wrappers does seem to have
the disadvantage that it will pollute /proc/kallsyms for example.

Anyway, I'm not sure if I will be able to come up with something this week
though.
Yury Norov Feb. 2, 2016, 8:41 p.m. UTC | #9
On Tue, Feb 02, 2016 at 08:54:34PM +0100, Heiko Carstens wrote:
> Hi Yury,
> 
> On Tue, Feb 02, 2016 at 05:08:26PM +0100, Heiko Carstens wrote:
> > See e.g. 485d52768685 ("sys_personality: change sys_personality() to accept
> > "unsigned int" instead of u_long") would have been a candidate which could
> > silently break architectures which need compat wrappers.
> 
> Ok, this example is of course wrong. But now I can claim that also somebody
> who should know better makes these mistakes.. :)
> 

Yep, this is a bad example. :) Moreover, this patch is coming from year 2010,
and it shows how stable the syscall ABI is.

> > > I don't know much about s390 specifics. Maybe because of that I do not
> > > understand completely your worries. I'm OK with both 1st and 2nd
> > > version, but I'd choose 2nd one because it allows inlines, and we
> > > don't need the compat_wrapper.c.
> > 
> > It would be only nicer if we can guarentee correctness all the time. That
> > being said I'm about to revert my own commit :)
> > 
> > So if you want to go without compat_wrapper.c then we should have a
> > solution which will do the right thing all the time without that a system
> > call author has to know about the sign and zero extension issue some
> > architectures face. It _will_ go wrong.
> 
> So I think I can summarize my point to: if you can enforce correctness, why
> shouldn't you do it if the performance impact is only a single instruction.

For aarch64 it's 5 instructions. But what's more important (if ever),
another wrapper takes another i-cache line...
        <compat_SyS_ftruncate>:
        stp     x29, x30, [sp,#-16]!
        mov     x29, sp
        bl      d40 <do_sys_ftruncate.constprop.3>
        ldp     x29, x30, [sp],#16
        ret

> 
> However I'll try to write an addon patch to your patch series. Maybe we can
> still get rid of compat_wrapper.c in a way which makes both of us happy.
> Also.. the idea with the alias names for compat wrappers does seem to have
> the disadvantage that it will pollute /proc/kallsyms for example.
> 
> Anyway, I'm not sure if I will be able to come up with something this week
> though.

Great, I'm looking forward...

My point is. Syscall ABI is so stable and so important that too much
people are involved in development and testing of it. So automatic
checks are almost useless, as all bugs will be found during
development and review. I think, community is able to pay enough
attention to review a couple of such patches per decade.
But I'm OK with some automatic checker, if it will be :
 - not too complicated, as complex code makes bugs by itself;
 - not too expensive;
 - not too ugly (my one is definitely ugly).
Heiko Carstens Feb. 3, 2016, 8:01 a.m. UTC | #10
On Tue, Feb 02, 2016 at 11:41:56PM +0300, Yury Norov wrote:
> On Tue, Feb 02, 2016 at 08:54:34PM +0100, Heiko Carstens wrote:
> > So I think I can summarize my point to: if you can enforce correctness, why
> > shouldn't you do it if the performance impact is only a single instruction.
> 
> For aarch64 it's 5 instructions. But what's more important (if ever),
> another wrapper takes another i-cache line...
>         <compat_SyS_ftruncate>:
>         stp     x29, x30, [sp,#-16]!
>         mov     x29, sp
>         bl      d40 <do_sys_ftruncate.constprop.3>
>         ldp     x29, x30, [sp],#16
>         ret

Why does gcc allocate a stackframe here? Don't you have tail call
optimization?
Heiko Carstens Feb. 17, 2016, 8:22 a.m. UTC | #11
On Tue, Feb 02, 2016 at 11:41:56PM +0300, Yury Norov wrote:
> > However I'll try to write an addon patch to your patch series. Maybe we can
> > still get rid of compat_wrapper.c in a way which makes both of us happy.
> > Also.. the idea with the alias names for compat wrappers does seem to have
> > the disadvantage that it will pollute /proc/kallsyms for example.
> > 
> > Anyway, I'm not sure if I will be able to come up with something this week
> > though.
> 
> Great, I'm looking forward...

Hi Yuri,

after playing around with this a bit I couldn't come up with a solution
that I'm happy with, unfortunately.

So in order to make some progress here I'd vote that we simply move the
existing compat_wrapper.c from arch/s390 to common code like you did in
your first approach and leave the existing SYSCALL macros alone.

That will have hardly any effect to anybody else and your problem is
solved while s390 still works.

Does that make sense?
Yury Norov Feb. 17, 2016, 1:57 p.m. UTC | #12
On Wed, Feb 17, 2016 at 09:22:10AM +0100, Heiko Carstens wrote:
> On Tue, Feb 02, 2016 at 11:41:56PM +0300, Yury Norov wrote:
> > > However I'll try to write an addon patch to your patch series. Maybe we can
> > > still get rid of compat_wrapper.c in a way which makes both of us happy.
> > > Also.. the idea with the alias names for compat wrappers does seem to have
> > > the disadvantage that it will pollute /proc/kallsyms for example.
> > > 
> > > Anyway, I'm not sure if I will be able to come up with something this week
> > > though.
> > 
> > Great, I'm looking forward...
> 
> Hi Yuri,
> 
> after playing around with this a bit I couldn't come up with a solution
> that I'm happy with, unfortunately.
> 
> So in order to make some progress here I'd vote that we simply move the
> existing compat_wrapper.c from arch/s390 to common code like you did in
> your first approach and leave the existing SYSCALL macros alone.
> 
> That will have hardly any effect to anybody else and your problem is
> solved while s390 still works.
> 
> Does that make sense?
> 

OK. This week I'll split v1 as I did with v2, and send it here. So
we'll have two versions, and so will start true elections. :)

> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox

Patch

diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index d350ed9..46cb4be 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -7,13 +7,26 @@ 
 #include <linux/sched.h>
 #include <linux/thread_info.h>
 
-#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64))
-
 #define __SC_DELOUSE(t,v) ({ \
 	BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
 	(t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
 })
 
+#define __SC_COMPAT_CAST(t, a)						\
+({									\
+	long __ReS = a;							\
+									\
+	BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&		\
+		     !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));		\
+	if (__TYPE_IS_L(t))						\
+		__ReS = (s32)a;						\
+	if (__TYPE_IS_UL(t))						\
+		__ReS = (u32)a;						\
+	if (__TYPE_IS_PTR(t))						\
+		__ReS = a & 0x7fffffff;					\
+	(t)__ReS;							\
+})
+
 #define PSW32_MASK_PER		0x40000000UL
 #define PSW32_MASK_DAT		0x04000000UL
 #define PSW32_MASK_IO		0x02000000UL
diff --git a/arch/s390/kernel/compat_wrapper.c b/arch/s390/kernel/compat_wrapper.c
index fac4eed..527f75d 100644
--- a/arch/s390/kernel/compat_wrapper.c
+++ b/arch/s390/kernel/compat_wrapper.c
@@ -8,57 +8,6 @@ 
 #include <linux/compat.h>
 #include "entry.h"
 
-#define COMPAT_SYSCALL_WRAP1(name, ...) \
-	COMPAT_SYSCALL_WRAPx(1, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP2(name, ...) \
-	COMPAT_SYSCALL_WRAPx(2, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP3(name, ...) \
-	COMPAT_SYSCALL_WRAPx(3, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP4(name, ...) \
-	COMPAT_SYSCALL_WRAPx(4, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP5(name, ...) \
-	COMPAT_SYSCALL_WRAPx(5, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP6(name, ...) \
-	COMPAT_SYSCALL_WRAPx(6, _##name, __VA_ARGS__)
-
-#define __SC_COMPAT_TYPE(t, a) \
-	__typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
-
-#define __SC_COMPAT_CAST(t, a)						\
-({									\
-	long __ReS = a;							\
-									\
-	BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&		\
-		     !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));		\
-	if (__TYPE_IS_L(t))						\
-		__ReS = (s32)a;						\
-	if (__TYPE_IS_UL(t))						\
-		__ReS = (u32)a;						\
-	if (__TYPE_IS_PTR(t))						\
-		__ReS = a & 0x7fffffff;					\
-	(t)__ReS;							\
-})
-
-/*
- * The COMPAT_SYSCALL_WRAP macro generates system call wrappers to be used by
- * compat tasks. These wrappers will only be used for system calls where only
- * the system call arguments need sign or zero extension or zeroing of the upper
- * 33 bits of pointers.
- * Note: since the wrapper function will afterwards call a system call which
- * again performs zero and sign extension for all system call arguments with
- * a size of less than eight bytes, these compat wrappers only touch those
- * system call arguments with a size of eight bytes ((unsigned) long and
- * pointers). Zero and sign extension for e.g. int parameters will be done by
- * the regular system call wrappers.
- */
-#define COMPAT_SYSCALL_WRAPx(x, name, ...)					\
-asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));			\
-asmlinkage long notrace compat_sys##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__));\
-asmlinkage long notrace compat_sys##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))	\
-{										\
-	return sys##name(__MAP(x,__SC_COMPAT_CAST,__VA_ARGS__));		\
-}
-
 COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
 COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, newname);
 COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
diff --git a/include/linux/compat.h b/include/linux/compat.h
index a76c917..1a761ea 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -718,4 +718,67 @@  asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
 #define is_compat_task() (0)
 
 #endif /* CONFIG_COMPAT */
+
+#ifdef CONFIG_COMPAT_WRAPPER
+
+#ifndef __TYPE_IS_PTR
+#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), u64))
+#endif
+
+#ifndef __SC_COMPAT_TYPE
+#define __SC_COMPAT_TYPE(t, a) \
+	__typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
+#endif
+
+#ifndef __SC_COMPAT_CAST
+#define __SC_COMPAT_CAST(t, a) ({					\
+	BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&		\
+		     !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));		\
+	((t) ((t)(-1) < 0 ? (s64)(s32)(a) : (u64)(u32)(a)));		\
+})
+#endif
+
+#ifndef SYSCALL_DEFINE_WRAPx
+/*
+ * The SYSCALL_DEFINE_WRAP macro generates system call wrappers to be used by
+ * compat tasks. These wrappers will only be used for system calls where only
+ * the system call arguments need sign or zero extension or zeroing of upper
+ * bits of pointers.
+ * Note: since the wrapper function will afterwards call a system call which
+ * again performs zero and sign extension for all system call arguments with
+ * a size of less than eight bytes, these compat wrappers only touch those
+ * system call arguments with a size of eight bytes ((unsigned) long and
+ * pointers). Zero and sign extension for e.g. int parameters will be done by
+ * the regular system call wrappers.
+ */
+#define SYSCALL_DEFINE_WRAPx(x, name, ...)						\
+asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));				\
+asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))			\
+		__attribute__((alias(__stringify(compat_SyS##name))));			\
+asmlinkage long compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__));		\
+asmlinkage long compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))			\
+{											\
+	return sys##name(__MAP(x,__SC_COMPAT_CAST,__VA_ARGS__));			\
+}											\
+SYSCALL_DEFINEx(x, name, __VA_ARGS__)
+#endif
+
+#define SYSCALL_DEFINE_WRAP1(name, ...) SYSCALL_DEFINE_WRAPx(1, _##name, __VA_ARGS__)
+#define SYSCALL_DEFINE_WRAP2(name, ...) SYSCALL_DEFINE_WRAPx(2, _##name, __VA_ARGS__)
+#define SYSCALL_DEFINE_WRAP3(name, ...) SYSCALL_DEFINE_WRAPx(3, _##name, __VA_ARGS__)
+#define SYSCALL_DEFINE_WRAP4(name, ...) SYSCALL_DEFINE_WRAPx(4, _##name, __VA_ARGS__)
+#define SYSCALL_DEFINE_WRAP5(name, ...) SYSCALL_DEFINE_WRAPx(5, _##name, __VA_ARGS__)
+#define SYSCALL_DEFINE_WRAP6(name, ...) SYSCALL_DEFINE_WRAPx(6, _##name, __VA_ARGS__)
+
+#else
+
+#define SYSCALL_DEFINE_WRAP1	SYSCALL_DEFINE1
+#define SYSCALL_DEFINE_WRAP2    SYSCALL_DEFINE2
+#define SYSCALL_DEFINE_WRAP3    SYSCALL_DEFINE3
+#define SYSCALL_DEFINE_WRAP4    SYSCALL_DEFINE4
+#define SYSCALL_DEFINE_WRAP5    SYSCALL_DEFINE5
+#define SYSCALL_DEFINE_WRAP6    SYSCALL_DEFINE6
+
+#endif /* CONFIG_COMPAT_WRAPPER */
+
 #endif /* _LINUX_COMPAT_H */
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index c2b66a2..1942cf4 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -11,62 +11,7 @@ 
 #ifndef _LINUX_SYSCALLS_H
 #define _LINUX_SYSCALLS_H
 
-struct epoll_event;
-struct iattr;
-struct inode;
-struct iocb;
-struct io_event;
-struct iovec;
-struct itimerspec;
-struct itimerval;
-struct kexec_segment;
-struct linux_dirent;
-struct linux_dirent64;
-struct list_head;
-struct mmap_arg_struct;
-struct msgbuf;
-struct user_msghdr;
-struct mmsghdr;
-struct msqid_ds;
-struct new_utsname;
-struct nfsctl_arg;
-struct __old_kernel_stat;
-struct oldold_utsname;
-struct old_utsname;
-struct pollfd;
-struct rlimit;
-struct rlimit64;
-struct rusage;
-struct sched_param;
-struct sched_attr;
-struct sel_arg_struct;
-struct semaphore;
-struct sembuf;
-struct shmid_ds;
-struct sockaddr;
-struct stat;
-struct stat64;
-struct statfs;
-struct statfs64;
-struct __sysctl_args;
-struct sysinfo;
-struct timespec;
-struct timeval;
-struct timex;
-struct timezone;
-struct tms;
-struct utimbuf;
-struct mq_attr;
-struct compat_stat;
-struct compat_timeval;
-struct robust_list_head;
-struct getcpu_cache;
-struct old_linux_dirent;
-struct perf_event_attr;
-struct file_handle;
-struct sigaltstack;
-union bpf_attr;
-
+#include <linux/syscalls_structs.h>
 #include <linux/types.h>
 #include <linux/aio_abi.h>
 #include <linux/capability.h>
diff --git a/include/linux/syscalls_structs.h b/include/linux/syscalls_structs.h
new file mode 100644
index 0000000..a920cbc
--- /dev/null
+++ b/include/linux/syscalls_structs.h
@@ -0,0 +1,60 @@ 
+#ifndef _LINUX_SYSCALL_STRUCTS_H
+#define _LINUX_SYSCALL_STRUCTS_H
+
+struct epoll_event;
+struct iattr;
+struct inode;
+struct iocb;
+struct io_event;
+struct iovec;
+struct itimerspec;
+struct itimerval;
+struct kexec_segment;
+struct linux_dirent;
+struct linux_dirent64;
+struct list_head;
+struct mmap_arg_struct;
+struct msgbuf;
+struct user_msghdr;
+struct mmsghdr;
+struct msqid_ds;
+struct new_utsname;
+struct nfsctl_arg;
+struct __old_kernel_stat;
+struct oldold_utsname;
+struct old_utsname;
+struct pollfd;
+struct rlimit;
+struct rlimit64;
+struct rusage;
+struct sched_param;
+struct sched_attr;
+struct sel_arg_struct;
+struct semaphore;
+struct sembuf;
+struct shmid_ds;
+struct sockaddr;
+struct stat;
+struct stat64;
+struct statfs;
+struct statfs64;
+struct __sysctl_args;
+struct sysinfo;
+struct timespec;
+struct timeval;
+struct timex;
+struct timezone;
+struct tms;
+struct utimbuf;
+struct mq_attr;
+struct compat_stat;
+struct compat_timeval;
+struct robust_list_head;
+struct getcpu_cache;
+struct old_linux_dirent;
+struct perf_event_attr;
+struct file_handle;
+struct sigaltstack;
+union bpf_attr;
+
+#endif /* _LINUX_SYSCALL_STRUCTS_H */
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index 1324b02..a8380ad 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -29,6 +29,10 @@ 
 #define __SC_COMP_3264(_nr, _32, _64, _comp) __SC_3264(_nr, _32, _64)
 #endif
 
+#ifndef __SC_WRAP
+#define __SC_WRAP __SYSCALL
+#endif
+
 #define __NR_io_setup 0
 __SC_COMP(__NR_io_setup, sys_io_setup, compat_sys_io_setup)
 #define __NR_io_destroy 1
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 0623787..8c99a45 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -16,6 +16,14 @@  asmlinkage long sys_ni_syscall(void)
 	return -ENOSYS;
 }
 
+#ifdef CONFIG_COMPAT_WRAPPER
+#define cond_syscall_wrapped(name)	\
+	cond_syscall(name);		\
+	cond_syscall(compat_##name);
+#else
+#define cond_syscall_wrapped	cond_syscall
+#endif
+
 cond_syscall(sys_quotactl);
 cond_syscall(sys32_quotactl);
 cond_syscall(sys_acct);