x86/entry: Move max syscall number calculation to syscallhdr.sh

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
This commit is contained in:
Brian Gerst 2020-03-13 15:51:34 -04:00 committed by Thomas Gleixner
parent 2e487c3579
commit 0872098804
12 changed files with 24 additions and 72 deletions

View File

@ -4,7 +4,7 @@
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/sys.h> #include <linux/sys.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <asm/asm-offsets.h> #include <asm/unistd.h>
#include <asm/syscall.h> #include <asm/syscall.h>
#ifdef CONFIG_IA32_EMULATION #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, #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 * Smells like a compiler bug -- it doesn't work
* when the & below is removed. * 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> #include <asm/syscalls_32.h>
}; };

View File

@ -5,7 +5,7 @@
#include <linux/sys.h> #include <linux/sys.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <asm/asm-offsets.h> #include <asm/unistd.h>
#include <asm/syscall.h> #include <asm/syscall.h>
#define __SYSCALL_X32(nr, sym, qual) #define __SYSCALL_X32(nr, sym, qual)

View File

@ -5,7 +5,7 @@
#include <linux/sys.h> #include <linux/sys.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/syscalls.h> #include <linux/syscalls.h>
#include <asm/asm-offsets.h> #include <asm/unistd.h>
#include <asm/syscall.h> #include <asm/syscall.h>
#define __SYSCALL_64(nr, sym, qual) #define __SYSCALL_64(nr, sym, qual)
@ -16,11 +16,11 @@
#define __SYSCALL_X32(nr, sym, qual) [nr] = sym, #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 * Smells like a compiler bug -- it doesn't work
* when the & below is removed. * 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> #include <asm/syscalls_64.h>
}; };

View File

@ -15,14 +15,21 @@ grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | (
echo "#define ${fileguard} 1" echo "#define ${fileguard} 1"
echo "" echo ""
max=0
while read nr abi name entry ; do while read nr abi name entry ; do
if [ -z "$offset" ]; then if [ -z "$offset" ]; then
echo "#define __NR_${prefix}${name} $nr" echo "#define __NR_${prefix}${name} $nr"
else else
echo "#define __NR_${prefix}${name} ($offset + $nr)" echo "#define __NR_${prefix}${name} ($offset + $nr)"
fi fi
max=$nr
done done
echo ""
echo "#ifdef __KERNEL__"
echo "#define __NR_${prefix}syscall_max $max"
echo "#endif"
echo "" echo ""
echo "#endif /* ${fileguard} */" echo "#endif /* ${fileguard} */"
) > "$out" ) > "$out"

View File

@ -13,6 +13,7 @@
*/ */
#undef CONFIG_64BIT #undef CONFIG_64BIT
#undef CONFIG_X86_64 #undef CONFIG_X86_64
#undef CONFIG_COMPAT
#undef CONFIG_PGTABLE_LEVELS #undef CONFIG_PGTABLE_LEVELS
#undef CONFIG_ILLEGAL_POINTER_VALUE #undef CONFIG_ILLEGAL_POINTER_VALUE
#undef CONFIG_SPARSEMEM_VMEMMAP #undef CONFIG_SPARSEMEM_VMEMMAP

View File

@ -13,7 +13,6 @@
#include <uapi/linux/audit.h> #include <uapi/linux/audit.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/err.h> #include <linux/err.h>
#include <asm/asm-offsets.h> /* For NR_syscalls */
#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/thread_info.h> /* for TS_COMPAT */
#include <asm/unistd.h> #include <asm/unistd.h>
@ -28,8 +27,6 @@ extern const sys_call_ptr_t sys_call_table[];
#if defined(CONFIG_X86_32) #if defined(CONFIG_X86_32)
#define ia32_sys_call_table sys_call_table #define ia32_sys_call_table sys_call_table
#define __NR_syscall_compat_max __NR_syscall_max
#define IA32_NR_syscalls NR_syscalls
#endif #endif
#if defined(CONFIG_IA32_EMULATION) #if defined(CONFIG_IA32_EMULATION)

View File

@ -13,10 +13,13 @@
# define __ARCH_WANT_SYS_OLD_MMAP # define __ARCH_WANT_SYS_OLD_MMAP
# define __ARCH_WANT_SYS_OLD_SELECT # define __ARCH_WANT_SYS_OLD_SELECT
# define __NR_ia32_syscall_max __NR_syscall_max
# else # else
# include <asm/unistd_64.h> # include <asm/unistd_64.h>
# include <asm/unistd_64_x32.h> # include <asm/unistd_64_x32.h>
# include <asm/unistd_32_ia32.h>
# define __ARCH_WANT_SYS_TIME # define __ARCH_WANT_SYS_TIME
# define __ARCH_WANT_SYS_UTIME # define __ARCH_WANT_SYS_UTIME
# define __ARCH_WANT_COMPAT_SYS_PREADV64 # define __ARCH_WANT_COMPAT_SYS_PREADV64
@ -26,6 +29,10 @@
# endif # 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_NEW_STAT
# define __ARCH_WANT_OLD_READDIR # define __ARCH_WANT_OLD_READDIR
# define __ARCH_WANT_OLD_STAT # define __ARCH_WANT_OLD_STAT

View File

@ -5,11 +5,6 @@
#include <asm/ucontext.h> #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 */ /* workaround for a warning with -Wmissing-prototypes */
void foo(void); void foo(void);
@ -60,8 +55,4 @@ void foo(void)
BLANK(); BLANK();
OFFSET(stack_canary_offset, stack_canary, canary); OFFSET(stack_canary_offset, stack_canary, canary);
#endif #endif
BLANK();
DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
DEFINE(NR_syscalls, sizeof(syscalls));
} }

View File

@ -5,30 +5,6 @@
#include <asm/ia32.h> #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) #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_PARAVIRT_SPINLOCKS)
#include <asm/kvm_para.h> #include <asm/kvm_para.h>
#endif #endif
@ -90,17 +66,5 @@ int main(void)
DEFINE(stack_canary_offset, offsetof(struct fixed_percpu_data, stack_canary)); DEFINE(stack_canary_offset, offsetof(struct fixed_percpu_data, stack_canary));
BLANK(); BLANK();
#endif #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; return 0;
} }

View File

@ -7,7 +7,7 @@
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/sys.h> #include <linux/sys.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <generated/user_constants.h> #include <asm/unistd.h>
#include <asm/syscall.h> #include <asm/syscall.h>
#define __NO_STUBS #define __NO_STUBS

View File

@ -7,7 +7,7 @@
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/sys.h> #include <linux/sys.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <generated/user_constants.h> #include <asm/unistd.h>
#include <asm/syscall.h> #include <asm/syscall.h>
#define __NO_STUBS #define __NO_STUBS

View File

@ -9,18 +9,6 @@
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <asm/types.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) \ #define DEFINE(sym, val) \
asm volatile("\n->" #sym " %0 " #val : : "i" (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_READ, PROT_READ);
DEFINE(UM_PROT_WRITE, PROT_WRITE); DEFINE(UM_PROT_WRITE, PROT_WRITE);
DEFINE(UM_PROT_EXEC, PROT_EXEC); DEFINE(UM_PROT_EXEC, PROT_EXEC);
DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
DEFINE(NR_syscalls, sizeof(syscalls));
} }