Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2103416ybh; Fri, 13 Mar 2020 12:54:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvZIwSg9LhcKBhirs+1sugo6WxUX1HZnfEmH5KBEnlH60W5M7q/wyLCh9p8dsCxfFdvvjYc X-Received: by 2002:aca:488a:: with SMTP id v132mr8493047oia.166.1584129293121; Fri, 13 Mar 2020 12:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584129293; cv=none; d=google.com; s=arc-20160816; b=wQlonC1bXIY8N+ZIGqraXVdn9QvqhCajJjCFgn4yuOUYfvzKI5CkTaGE/SRh+i1VUU cA5DZdJVvo4QKMy5dEq1jyiS3hpMCvkdY5JKgVsyR92bEE57vtLFCRUJrFSUWlWFJMbK aG5YNPByfirZVLKEVj6S+q8cQ2Ubzhjdc2ggqfneSWYh2XUG4rBMR+JZkkb05/L9mj6e fIUQ4+MKvdPr5n+KU+dhjpzR/Be4isT/tvVS29iqE69qgZCeba6dk5lsjxWw617FLwWg qqS/IPkXjnVDl99HNV+pMY5+Gw+C0vCbvfeF7npIM56RK0Qz2BUxexadQSsaVqdJWd/w 4swg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bVyWwFJqViC83OcoKVFg7qqvJmczpS8nLV1bfH3wEfY=; b=qXrVjGhBIBCdul5cTJ5nD4fEAxmjUNILwPPZNgZtkvS8/Hx+xUH0vhaVOf3lDGlS0h SyykRjHhWANSvsk0eSo1L5nzbLykvM/CEruxB04RhurH2gbJiEr4G4IXMnKERTY+ZYXB sHcwU828iouyHowcMFDXBYDYUpOrirbPRc6nvhoFvGO/x+IYOuZbXiB39I7LiZuoeNxf iNaI6Xy9kNL3M8kLJUn5cLELcaRqEiLasdqQF/7nigK7fCWOi7eQ8Uux2249Gt8MEGdz 5VMhxULmUKwavby/bowAbSQAsoGdmsaW/zMj4zcfDk5B9DpcLZJA89dG58aN2nD9AapB tRxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FJYWlSa0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u136si3495855oif.197.2020.03.13.12.54.41; Fri, 13 Mar 2020 12:54:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FJYWlSa0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727595AbgCMTxD (ORCPT + 99 others); Fri, 13 Mar 2020 15:53:03 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:33479 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727413AbgCMTwW (ORCPT ); Fri, 13 Mar 2020 15:52:22 -0400 Received: by mail-qk1-f195.google.com with SMTP id p62so14715149qkb.0 for ; Fri, 13 Mar 2020 12:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bVyWwFJqViC83OcoKVFg7qqvJmczpS8nLV1bfH3wEfY=; b=FJYWlSa0iFHDmYPqCNHxVXM60K0i+L7YdQWHwadM7xZtSRF426AYbgsezNsvccCfnk VVOprL2+3OqKYw3zMxNdr1GeKhUI/5gufWsAdCwH4zET5d6TtrMB0FTNmS8pb81LGhc3 RMzEtXH9ITFgmlqpRKhSNZEyj25E5DRr/YpZUiCdhlwXhyBWW8lkDLXjw0gtESLVgCIT iO/ugnjFQLucaq3uETvTY15+wQPQUUedU8uOML8YheRjunM6KJkrpa7e8w1DTtqXVUQc OGuOYRqLl+PBXqORVKznx0c/AjGq1lxJJHILpbgGhniqiQ1kRbThEAnPMv0vMlQKauUD PIvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bVyWwFJqViC83OcoKVFg7qqvJmczpS8nLV1bfH3wEfY=; b=ICbr7YvUi9ZDOw2FNRxYuNKl3m7EbEN3g4t8bqp7yfD5ENPAIpADwSVc6fr+ikI1Il TtWVCrdx0IOUodMXyuZvxxUdxEIFlajgUDaniYz39xbFxt00Umt46ugWIdaRN0MDDPRg uE4cjDSsYovSHTNSUjq2nA2NTWBcgxLBrhkpESmG12v55c5M5Dzhg675jAZUjxqtpDBX ZA1qU8vNll8XBwH3QuCIl9TRgDenpoDaCGqunJ+Hf/Cqe8vOIujftt5U26MuMeBD7B9N nZFpq049fLr6RCTY8E60deUDpWlbqCL5G9Fvej4DfKOvgDHh+G97ao061EwWrpSkXV6b jbAA== X-Gm-Message-State: ANhLgQ0quF0JwMl0dztRSN7jr60Guvi7QdRnxBsw0sXsIS+45tmXQHW5 0V4gcEM2eq7rpmBW+cWYbPskd8s= X-Received: by 2002:a37:9dc9:: with SMTP id g192mr14943877qke.50.1584129139858; Fri, 13 Mar 2020 12:52:19 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id i28sm31475599qtc.57.2020.03.13.12.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 12:52:19 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Dominik Brodowski , Brian Gerst Subject: [PATCH v4 08/18] x86: Move max syscall number calculation to syscallhdr.sh Date: Fri, 13 Mar 2020 15:51:34 -0400 Message-Id: <20200313195144.164260-9-brgerst@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313195144.164260-1-brgerst@gmail.com> References: <20200313195144.164260-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/entry/syscall_32.c | 6 ++-- arch/x86/entry/syscall_64.c | 2 +- arch/x86/entry/syscall_x32.c | 6 ++-- arch/x86/entry/syscalls/syscallhdr.sh | 7 ++++ arch/x86/entry/vdso/vdso32/vclock_gettime.c | 1 + arch/x86/include/asm/syscall.h | 3 -- arch/x86/include/asm/unistd.h | 7 ++++ arch/x86/kernel/asm-offsets_32.c | 9 ------ arch/x86/kernel/asm-offsets_64.c | 36 --------------------- arch/x86/um/sys_call_table_32.c | 2 +- arch/x86/um/sys_call_table_64.c | 2 +- arch/x86/um/user-offsets.c | 15 --------- 12 files changed, 24 insertions(+), 72 deletions(-) diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index 7d17b3addbbb..3207cf685cde 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #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 }; diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index efb85c6dce13..5dc6846979df 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #define __SYSCALL_X32(nr, sym, qual) diff --git a/arch/x86/entry/syscall_x32.c b/arch/x86/entry/syscall_x32.c index d144ced7f582..95abb6da0ecc 100644 --- a/arch/x86/entry/syscall_x32.c +++ b/arch/x86/entry/syscall_x32.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #define __SYSCALL_64(nr, sym, qual) @@ -16,11 +16,11 @@ #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 }; diff --git a/arch/x86/entry/syscalls/syscallhdr.sh b/arch/x86/entry/syscalls/syscallhdr.sh index 12fbbcfe7ef3..cc1e63857427 100644 --- a/arch/x86/entry/syscalls/syscallhdr.sh +++ b/arch/x86/entry/syscalls/syscallhdr.sh @@ -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" diff --git a/arch/x86/entry/vdso/vdso32/vclock_gettime.c b/arch/x86/entry/vdso/vdso32/vclock_gettime.c index 9242b28418d5..1e82bd43286c 100644 --- a/arch/x86/entry/vdso/vdso32/vclock_gettime.c +++ b/arch/x86/entry/vdso/vdso32/vclock_gettime.c @@ -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 diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h index d20ffc518cf4..f4d010d0fa30 100644 --- a/arch/x86/include/asm/syscall.h +++ b/arch/x86/include/asm/syscall.h @@ -13,7 +13,6 @@ #include #include #include -#include /* For NR_syscalls */ #include /* for TS_COMPAT */ #include @@ -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) diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h index a7dd080749ce..c1c3d31b15c0 100644 --- a/arch/x86/include/asm/unistd.h +++ b/arch/x86/include/asm/unistd.h @@ -13,10 +13,13 @@ # define __ARCH_WANT_SYS_OLD_MMAP # define __ARCH_WANT_SYS_OLD_SELECT +# define __NR_ia32_syscall_max __NR_syscall_max + # else # include # include +# include # define __ARCH_WANT_SYS_TIME # define __ARCH_WANT_SYS_UTIME # define __ARCH_WANT_COMPAT_SYS_PREADV64 @@ -26,6 +29,10 @@ # 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 diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c index 2b4256ebe86e..6e043f295a60 100644 --- a/arch/x86/kernel/asm-offsets_32.c +++ b/arch/x86/kernel/asm-offsets_32.c @@ -7,11 +7,6 @@ #include -#define __SYSCALL_I386(nr, sym, qual) [nr] = 1, -static char syscalls[] = { -#include -}; - /* workaround for a warning with -Wmissing-prototypes */ void foo(void); @@ -63,10 +58,6 @@ void foo(void) OFFSET(stack_canary_offset, stack_canary, canary); #endif - BLANK(); - DEFINE(__NR_syscall_max, sizeof(syscalls) - 1); - DEFINE(NR_syscalls, sizeof(syscalls)); - BLANK(); DEFINE(EFI_svam, offsetof(efi_runtime_services_t, set_virtual_address_map)); } diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c index 24d2fde30d00..c2a47016f243 100644 --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c @@ -5,30 +5,6 @@ #include -#define __SYSCALL_64(nr, sym, qual) [nr] = 1, -#define __SYSCALL_X32(nr, sym, qual) -static char syscalls_64[] = { -#include -}; -#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 -}; -#undef __SYSCALL_64 -#undef __SYSCALL_X32 -#endif - -#define __SYSCALL_I386(nr, sym, qual) [nr] = 1, -static char syscalls_ia32[] = { -#include -}; -#undef __SYSCALL_I386 - #if defined(CONFIG_KVM_GUEST) && defined(CONFIG_PARAVIRT_SPINLOCKS) #include #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; } diff --git a/arch/x86/um/sys_call_table_32.c b/arch/x86/um/sys_call_table_32.c index 9649b5ad2ca2..a0d75c560030 100644 --- a/arch/x86/um/sys_call_table_32.c +++ b/arch/x86/um/sys_call_table_32.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #define __NO_STUBS diff --git a/arch/x86/um/sys_call_table_64.c b/arch/x86/um/sys_call_table_64.c index c8bc7fb8cbd6..fa97740badd5 100644 --- a/arch/x86/um/sys_call_table_64.c +++ b/arch/x86/um/sys_call_table_64.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #define __NO_STUBS diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c index 5b37b7f952dd..c51dd8363d25 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -9,18 +9,6 @@ #include #include -#ifdef __i386__ -#define __SYSCALL_I386(nr, sym, qual) [nr] = 1, -static char syscalls[] = { -#include -}; -#else -#define __SYSCALL_64(nr, sym, qual) [nr] = 1, -static char syscalls[] = { -#include -}; -#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)); } -- 2.24.1