Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2722229ybv; Mon, 24 Feb 2020 10:18:37 -0800 (PST) X-Google-Smtp-Source: APXvYqz1iWhDOEBa6EDR3xY0fMB6lXlH2P9/N9gMCCx4EPr/z/BquOu4FX+zWpKVUdEvfd3vowHT X-Received: by 2002:a9d:3e43:: with SMTP id h3mr39321325otg.84.1582568317039; Mon, 24 Feb 2020 10:18:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582568317; cv=none; d=google.com; s=arc-20160816; b=LPZ0nCFYX/7pVSp85mOFuK21hh6e0thsdFjZuvC9qV0B5SXdVyj7kOkJlPsosyIndQ 1ClvULNcqEo2B6WJiPr2lCaAhuxz2gvU0YBUDeFnZKFeaMyEgfZlX20RigMHqNQeSwgz DYktEzGaonBu2TIA3DP7eFfpmQ/Hlto1ItHWwLhF/8wVB/E0PhrEvwgKyE2AwRCLwXY7 SKeuEq8stMxZhPF9ZFPoIkDrFjKLoKcjW76tCekzHks7uQWUjAe9dJZk52rtpLzWvJtw dP3qxJqYogX7ejtmiYPcCqb1WbRNDg73w9q+C0jSyZ7Gq9gEeBvG+SojyPc+a92qMKN4 BkVw== 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=ACi0L9E8gh6Yib24xQrizNHwo9NMM5aW1BdPE5fFDt4=; b=ZUWfoEOLGSLp+3nU8gsUoUGyinsWB+qgYheu9ChF5c3uKzHc+EnKEtiuW2EwEcQKqb qIHJ8Bkn2EG5/CtpoCZ1PFuMfz0jLUJQurIesuODPbpi83QleuNbBpc7rfwge/3rRuRa e0CCIUcVaTMrGvXxcnHitNO57jfZ/8UFgeeRakfSCBkqEGEKx75fJY/eJbiKbFuda4qx ffc436JGLLRPUgzzoHkBJ4BiGOIdGYl3idrX8+2I8prxazC1Vb2yc2SXg3qg/2Auljgg ikOQEhHd1kpfdH0Po7rzlNUZWtxgOUHuE+w0EJcBHyRCwxq2wORKm0hUxq+sFTOyDj/x T7JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KlhFXt6e; 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 z20si4858164oib.26.2020.02.24.10.18.24; Mon, 24 Feb 2020 10:18:37 -0800 (PST) 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=KlhFXt6e; 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 S1727867AbgBXSSQ (ORCPT + 99 others); Mon, 24 Feb 2020 13:18:16 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:32804 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgBXSSP (ORCPT ); Mon, 24 Feb 2020 13:18:15 -0500 Received: by mail-yb1-f194.google.com with SMTP id w190so5102614ybc.0 for ; Mon, 24 Feb 2020 10:18:15 -0800 (PST) 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=ACi0L9E8gh6Yib24xQrizNHwo9NMM5aW1BdPE5fFDt4=; b=KlhFXt6eLVbpn+FErpii8x78m31Z3Cb4EbsJnS/SNH1EU/KKrcT5Wfukkl71pQokIp /LtNWk0cuOxPMxUnusnJAneovgOTppyRuLCVkPwfrC4sTby+dIthQNrPmYqQYwkwVOP8 cJpCraFKejP7rwym5OiVL5Y6axyedk0wZ+668kTQmHoMw2FR2rX0nuQAcNz8zp8U/j56 luWcqkFpXDyIwWIdexkzKe9zK86/LERmYIIWyRe6nF5guuvd5lNU0lf2TclnVrUshGxy WQY2yLdtfPc6hMsYr/57PvQlOhCtYUiMSoMdLFZ/dbEN/1r0cSMouVgd8DogXvcKZuKb BPYQ== 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=ACi0L9E8gh6Yib24xQrizNHwo9NMM5aW1BdPE5fFDt4=; b=dwHKYMuXskUiyuf/ozahW71wIKIs0fjrl+HBMju0kKpsWfFZSLxU8jz3S2Jq34aPKz ezqKY+taEivUo6W8JFqszVyWVd6eZpjle7soTYn2kNIRxRbPmRPFHjX31EPQr5+vri37 ihqZFAD3f2Hj79oq3KsjeGayYI2IyMF88SByS7XUz4HKrC/hnXV4sMZ0fTlKKvKkV0wF IujwVrD2EZaJEqkA0jAiwa3cTGhjtEuddYeuzptRH3hqyACyeLcCbfDjvxe9Jj1iCw89 cKMUU3Gc92upUsWzpKIifxvU0XLl6Vre12lFmrbZeoLR4f8PrGyezDemnH9l/dJtDDX3 5E7Q== X-Gm-Message-State: APjAAAXI2SyOtSIiPc+7YBIU1gK88u0M1qRLNLrzp6MhaOXXnesCPzG6 gXe2JtVEso9/MVTEcu/xUa/5xzM= X-Received: by 2002:a25:fc27:: with SMTP id v39mr22017840ybd.473.1582568294370; Mon, 24 Feb 2020 10:18:14 -0800 (PST) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id i66sm5632383ywa.74.2020.02.24.10.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 10:18:14 -0800 (PST) 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 v2 1/8] x86, syscalls: Refactor SYSCALL_DEFINEx macros Date: Mon, 24 Feb 2020 13:17:50 -0500 Message-Id: <20200224181757.724961-2-brgerst@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200224181757.724961-1-brgerst@gmail.com> References: <20200224181757.724961-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 Pull the common code out from the SYSCALL_DEFINEx macros into a new __SYS_STUBx macro. Also conditionalize the X64 version in preparation for enabling syscall wrappers on 32-bit native kernels. Signed-off-by: Brian Gerst --- arch/x86/include/asm/syscall_wrapper.h | 86 ++++++++++++++------------ 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/arch/x86/include/asm/syscall_wrapper.h b/arch/x86/include/asm/syscall_wrapper.h index e2389ce9bf58..44ed358a2e3c 100644 --- a/arch/x86/include/asm/syscall_wrapper.h +++ b/arch/x86/include/asm/syscall_wrapper.h @@ -21,6 +21,22 @@ struct pt_regs; ,,(unsigned int)regs->dx,,(unsigned int)regs->si \ ,,(unsigned int)regs->di,,(unsigned int)regs->bp) +#define __SYS_STUBx(abi, name, ...) \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__##abi##_##name, ERRNO); \ + asmlinkage long __##abi##_##name(const struct pt_regs *regs) \ + { \ + return __se_##name(__VA_ARGS__); \ + } + +#ifdef CONFIG_X86_64 +#define __X64_SYS_STUBx(x, sys_name, ...) \ + __SYS_STUBx(x64, sys_name, \ + SC_X86_64_REGS_TO_ARGS(x, __VA_ARGS__)) +#else /* CONFIG_X86_64 */ +#define __X64_SYS_STUBx(x, sys_name, ...) +#endif /* CONFIG_X86_64 */ + #ifdef CONFIG_IA32_EMULATION /* * For IA32 emulation, we need to handle "compat" syscalls *and* create @@ -38,21 +54,13 @@ struct pt_regs; return __se_compat_sys_##name(); \ } -#define __IA32_COMPAT_SYS_STUBx(x, name, ...) \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__ia32_compat_sys##name, ERRNO); \ - asmlinkage long __ia32_compat_sys##name(const struct pt_regs *regs)\ - { \ - return __se_compat_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\ - } +#define __IA32_COMPAT_SYS_STUBx(x, compat_sys_name, ...) \ + __SYS_STUBx(ia32, compat_sys_name, \ + SC_IA32_REGS_TO_ARGS(x, __VA_ARGS__)) -#define __IA32_SYS_STUBx(x, name, ...) \ - asmlinkage long __ia32_sys##name(const struct pt_regs *regs); \ - ALLOW_ERROR_INJECTION(__ia32_sys##name, ERRNO); \ - asmlinkage long __ia32_sys##name(const struct pt_regs *regs) \ - { \ - return __se_sys##name(SC_IA32_REGS_TO_ARGS(x,__VA_ARGS__));\ - } +#define __IA32_SYS_STUBx(x, sys_name, ...) \ + __SYS_STUBx(ia32, sys_name, \ + SC_IA32_REGS_TO_ARGS(x, __VA_ARGS__)) /* * To keep the naming coherent, re-define SYSCALL_DEFINE0 to create an alias @@ -81,8 +89,8 @@ struct pt_regs; SYSCALL_ALIAS(__ia32_sys_##name, sys_ni_posix_timers) #else /* CONFIG_IA32_EMULATION */ -#define __IA32_COMPAT_SYS_STUBx(x, name, ...) -#define __IA32_SYS_STUBx(x, fullname, name, ...) +#define __IA32_COMPAT_SYS_STUBx(x, compat_sys_name, ...) +#define __IA32_SYS_STUBx(x, sys_name, ...) #endif /* CONFIG_IA32_EMULATION */ @@ -100,17 +108,13 @@ struct pt_regs; return __se_compat_sys_##name();\ } -#define __X32_COMPAT_SYS_STUBx(x, name, ...) \ - asmlinkage long __x32_compat_sys##name(const struct pt_regs *regs);\ - ALLOW_ERROR_INJECTION(__x32_compat_sys##name, ERRNO); \ - asmlinkage long __x32_compat_sys##name(const struct pt_regs *regs)\ - { \ - return __se_compat_sys##name(SC_X86_64_REGS_TO_ARGS(x,__VA_ARGS__));\ - } +#define __X32_COMPAT_SYS_STUBx(x, compat_sys_name, ...) \ + __SYS_STUBx(x32, compat_sys_name, \ + SC_X86_64_REGS_TO_ARGS(x, __VA_ARGS__)) #else /* CONFIG_X86_X32 */ #define __X32_COMPAT_SYS_STUB0(x, name) -#define __X32_COMPAT_SYS_STUBx(x, name, ...) +#define __X32_COMPAT_SYS_STUBx(x, compat_sys_name, ...) #endif /* CONFIG_X86_X32 */ @@ -131,16 +135,21 @@ struct pt_regs; } \ static inline long __do_compat_sys_##name(void) -#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ - static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ - static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ - __IA32_COMPAT_SYS_STUBx(x, name, __VA_ARGS__) \ - __X32_COMPAT_SYS_STUBx(x, name, __VA_ARGS__) \ - static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ - { \ - return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\ - } \ - static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) +#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ + static long \ + __se_compat_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)); \ + static inline long \ + __do_compat_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)); \ + __IA32_COMPAT_SYS_STUBx(x, compat_sys##name, __VA_ARGS__) \ + __X32_COMPAT_SYS_STUBx(x, compat_sys##name, __VA_ARGS__) \ + static long \ + __se_compat_sys##name(__MAP(x, __SC_LONG, __VA_ARGS__)) \ + { \ + return __do_compat_sys##name( \ + __MAP(x, __SC_DELOUSE, __VA_ARGS__)); \ + } \ + static inline long \ + __do_compat_sys##name(__MAP(x, __SC_DECL, __VA_ARGS__)) /* * As some compat syscalls may not be implemented, we need to expand @@ -192,15 +201,10 @@ struct pt_regs; * to the i386 calling convention (bx, cx, dx, si, di, bp). */ #define __SYSCALL_DEFINEx(x, name, ...) \ - asmlinkage long __x64_sys##name(const struct pt_regs *regs); \ - ALLOW_ERROR_INJECTION(__x64_sys##name, ERRNO); \ static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ - asmlinkage long __x64_sys##name(const struct pt_regs *regs) \ - { \ - return __se_sys##name(SC_X86_64_REGS_TO_ARGS(x,__VA_ARGS__));\ - } \ - __IA32_SYS_STUBx(x, name, __VA_ARGS__) \ + __X64_SYS_STUBx(x, sys##name, __VA_ARGS__) \ + __IA32_SYS_STUBx(x, sys##name, __VA_ARGS__) \ static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ { \ long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));\ -- 2.24.1