x86/entry: Move max syscall number calculation to syscallhdr.sh
authorBrian Gerst <brgerst@gmail.com>
Fri, 13 Mar 2020 19:51:34 +0000 (15:51 -0400)
committerThomas Gleixner <tglx@linutronix.de>
Sat, 21 Mar 2020 15:03:21 +0000 (16:03 +0100)
Instead of using an array in asm-offsets to calculate the max syscall
number, calculate it when writing out the syscall headers.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200313195144.164260-9-brgerst@gmail.com
12 files changed:
arch/x86/entry/syscall_32.c
arch/x86/entry/syscall_64.c
arch/x86/entry/syscall_x32.c
arch/x86/entry/syscalls/syscallhdr.sh
arch/x86/entry/vdso/vdso32/vclock_gettime.c
arch/x86/include/asm/syscall.h
arch/x86/include/asm/unistd.h
arch/x86/kernel/asm-offsets_32.c
arch/x86/kernel/asm-offsets_64.c
arch/x86/um/sys_call_table_32.c
arch/x86/um/sys_call_table_64.c
arch/x86/um/user-offsets.c

index 7d17b3addbbb385c30e603686ddee19530e81ccb..3207cf685cdedb7eeb66438c5364ea5a034bd2ef 100644 (file)
@@ -4,7 +4,7 @@
 #include <linux/linkage.h>
 #include <linux/sys.h>
 #include <linux/cache.h>
-#include <asm/asm-offsets.h>
+#include <asm/unistd.h>
 #include <asm/syscall.h>
 
 #ifdef CONFIG_IA32_EMULATION
@@ -22,11 +22,11 @@ extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long, unsigned lon
 
 #define __SYSCALL_I386(nr, sym, qual) [nr] = sym,
 
-__visible const sys_call_ptr_t ia32_sys_call_table[__NR_syscall_compat_max+1] = {
+__visible const sys_call_ptr_t ia32_sys_call_table[__NR_ia32_syscall_max+1] = {
        /*
         * Smells like a compiler bug -- it doesn't work
         * when the & below is removed.
         */
-       [0 ... __NR_syscall_compat_max] = &__sys_ni_syscall,
+       [0 ... __NR_ia32_syscall_max] = &__sys_ni_syscall,
 #include <asm/syscalls_32.h>
 };
index efb85c6dce132e9c750d2c09926b7842b42083cb..5dc6846979df744f5f7e3dc38483787127839213 100644 (file)
@@ -5,7 +5,7 @@
 #include <linux/sys.h>
 #include <linux/cache.h>
 #include <linux/syscalls.h>
-#include <asm/asm-offsets.h>
+#include <asm/unistd.h>
 #include <asm/syscall.h>
 
 #define __SYSCALL_X32(nr, sym, qual)
index d144ced7f582adb2fcc4a71de7731cae7ffc5be2..95abb6da0ecc6dd191b12b2276703286ca33e9c3 100644 (file)
@@ -5,7 +5,7 @@
 #include <linux/sys.h>
 #include <linux/cache.h>
 #include <linux/syscalls.h>
-#include <asm/asm-offsets.h>
+#include <asm/unistd.h>
 #include <asm/syscall.h>
 
 #define __SYSCALL_64(nr, sym, qual)
 
 #define __SYSCALL_X32(nr, sym, qual) [nr] = sym,
 
-asmlinkage const sys_call_ptr_t x32_sys_call_table[__NR_syscall_x32_max+1] = {
+asmlinkage const sys_call_ptr_t x32_sys_call_table[__NR_x32_syscall_max+1] = {
        /*
         * Smells like a compiler bug -- it doesn't work
         * when the & below is removed.
         */
-       [0 ... __NR_syscall_x32_max] = &__x64_sys_ni_syscall,
+       [0 ... __NR_x32_syscall_max] = &__x64_sys_ni_syscall,
 #include <asm/syscalls_64.h>
 };
index 12fbbcfe7ef353109f42b6e8b827be19f1e3b910..cc1e6385742707653d47c5f480bd41a647e1186a 100644 (file)
@@ -15,14 +15,21 @@ grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | (
     echo "#define ${fileguard} 1"
     echo ""
 
+    max=0
     while read nr abi name entry ; do
        if [ -z "$offset" ]; then
            echo "#define __NR_${prefix}${name} $nr"
        else
            echo "#define __NR_${prefix}${name} ($offset + $nr)"
         fi
+
+       max=$nr
     done
 
+    echo ""
+    echo "#ifdef __KERNEL__"
+    echo "#define __NR_${prefix}syscall_max $max"
+    echo "#endif"
     echo ""
     echo "#endif /* ${fileguard} */"
 ) > "$out"
index 9242b28418d58d11373a81d6aa0403f8eddae2b4..1e82bd43286cac91089380fcbb6d823e18cc49bf 100644 (file)
@@ -13,6 +13,7 @@
  */
 #undef CONFIG_64BIT
 #undef CONFIG_X86_64
+#undef CONFIG_COMPAT
 #undef CONFIG_PGTABLE_LEVELS
 #undef CONFIG_ILLEGAL_POINTER_VALUE
 #undef CONFIG_SPARSEMEM_VMEMMAP
index 8db3fdb6102ecb373f085de3a6033c645fbe644c..1ef8d7bffa15470e4d1b8cf8fbc72eb6905aefad 100644 (file)
@@ -13,7 +13,6 @@
 #include <uapi/linux/audit.h>
 #include <linux/sched.h>
 #include <linux/err.h>
-#include <asm/asm-offsets.h>   /* For NR_syscalls */
 #include <asm/thread_info.h>   /* for TS_COMPAT */
 #include <asm/unistd.h>
 
@@ -28,8 +27,6 @@ extern const sys_call_ptr_t sys_call_table[];
 
 #if defined(CONFIG_X86_32)
 #define ia32_sys_call_table sys_call_table
-#define __NR_syscall_compat_max __NR_syscall_max
-#define IA32_NR_syscalls NR_syscalls
 #endif
 
 #if defined(CONFIG_IA32_EMULATION)
index a7dd080749ce4e6aa527292dd1e61c352536da63..c1c3d31b15c0650f5c6feef4eef01cc7d81f1f2e 100644 (file)
 #  define __ARCH_WANT_SYS_OLD_MMAP
 #  define __ARCH_WANT_SYS_OLD_SELECT
 
+#  define __NR_ia32_syscall_max __NR_syscall_max
+
 # else
 
 #  include <asm/unistd_64.h>
 #  include <asm/unistd_64_x32.h>
+#  include <asm/unistd_32_ia32.h>
 #  define __ARCH_WANT_SYS_TIME
 #  define __ARCH_WANT_SYS_UTIME
 #  define __ARCH_WANT_COMPAT_SYS_PREADV64
 
 # endif
 
+# define NR_syscalls (__NR_syscall_max + 1)
+# define X32_NR_syscalls (__NR_x32_syscall_max + 1)
+# define IA32_NR_syscalls (__NR_ia32_syscall_max + 1)
+
 # define __ARCH_WANT_NEW_STAT
 # define __ARCH_WANT_OLD_READDIR
 # define __ARCH_WANT_OLD_STAT
index 82826f2275cce92ccb5941c98717962c38e8b61c..0dcac420b34146d8b2b58808ae7065c4b6a0d03d 100644 (file)
@@ -5,11 +5,6 @@
 
 #include <asm/ucontext.h>
 
-#define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
-static char syscalls[] = {
-#include <asm/syscalls_32.h>
-};
-
 /* workaround for a warning with -Wmissing-prototypes */
 void foo(void);
 
@@ -60,8 +55,4 @@ void foo(void)
        BLANK();
        OFFSET(stack_canary_offset, stack_canary, canary);
 #endif
-
-       BLANK();
-       DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
-       DEFINE(NR_syscalls, sizeof(syscalls));
 }
index 24d2fde30d0086d6d87ca4c09f17f12bd6bc0384..c2a47016f24334097fd6acd0ad3670259f4f7db8 100644 (file)
@@ -5,30 +5,6 @@
 
 #include <asm/ia32.h>
 
-#define __SYSCALL_64(nr, sym, qual) [nr] = 1,
-#define __SYSCALL_X32(nr, sym, qual)
-static char syscalls_64[] = {
-#include <asm/syscalls_64.h>
-};
-#undef __SYSCALL_64
-#undef __SYSCALL_X32
-
-#ifdef CONFIG_X86_X32_ABI
-#define __SYSCALL_64(nr, sym, qual)
-#define __SYSCALL_X32(nr, sym, qual) [nr] = 1,
-static char syscalls_x32[] = {
-#include <asm/syscalls_64.h>
-};
-#undef __SYSCALL_64
-#undef __SYSCALL_X32
-#endif
-
-#define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
-static char syscalls_ia32[] = {
-#include <asm/syscalls_32.h>
-};
-#undef __SYSCALL_I386
-
 #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_PARAVIRT_SPINLOCKS)
 #include <asm/kvm_para.h>
 #endif
@@ -90,17 +66,5 @@ int main(void)
        DEFINE(stack_canary_offset, offsetof(struct fixed_percpu_data, stack_canary));
        BLANK();
 #endif
-
-       DEFINE(__NR_syscall_max, sizeof(syscalls_64) - 1);
-       DEFINE(NR_syscalls, sizeof(syscalls_64));
-
-#ifdef CONFIG_X86_X32_ABI
-       DEFINE(__NR_syscall_x32_max, sizeof(syscalls_x32) - 1);
-       DEFINE(X32_NR_syscalls, sizeof(syscalls_x32));
-#endif
-
-       DEFINE(__NR_syscall_compat_max, sizeof(syscalls_ia32) - 1);
-       DEFINE(IA32_NR_syscalls, sizeof(syscalls_ia32));
-
        return 0;
 }
index 9649b5ad2ca2a54325573d4f389163b935e6c772..a0d75c560030560eab7ecbe0f80c34129c9c1bf4 100644 (file)
@@ -7,7 +7,7 @@
 #include <linux/linkage.h>
 #include <linux/sys.h>
 #include <linux/cache.h>
-#include <generated/user_constants.h>
+#include <asm/unistd.h>
 #include <asm/syscall.h>
 
 #define __NO_STUBS
index c8bc7fb8cbd65460a3c7c0bfd8cdc5baceeb9e89..fa97740badd5626b1a34f1728c4ccd903894952c 100644 (file)
@@ -7,7 +7,7 @@
 #include <linux/linkage.h>
 #include <linux/sys.h>
 #include <linux/cache.h>
-#include <generated/user_constants.h>
+#include <asm/unistd.h>
 #include <asm/syscall.h>
 
 #define __NO_STUBS
index 5b37b7f952ddffc4cb76b53e590609fcb2d076a5..c51dd8363d25849ce35188336552e590896846d7 100644 (file)
@@ -9,18 +9,6 @@
 #include <linux/ptrace.h>
 #include <asm/types.h>
 
-#ifdef __i386__
-#define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
-static char syscalls[] = {
-#include <asm/syscalls_32.h>
-};
-#else
-#define __SYSCALL_64(nr, sym, qual) [nr] = 1,
-static char syscalls[] = {
-#include <asm/syscalls_64.h>
-};
-#endif
-
 #define DEFINE(sym, val) \
        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
 
@@ -94,7 +82,4 @@ void foo(void)
        DEFINE(UM_PROT_READ, PROT_READ);
        DEFINE(UM_PROT_WRITE, PROT_WRITE);
        DEFINE(UM_PROT_EXEC, PROT_EXEC);
-
-       DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
-       DEFINE(NR_syscalls, sizeof(syscalls));
 }