From patchwork Wed Dec 8 11:08:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 357D1C433EF for ; Wed, 8 Dec 2021 11:09:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242142.418838 (Exim 4.92) (envelope-from ) id 1muuoK-0006ox-1q; Wed, 08 Dec 2021 11:08:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242142.418838; Wed, 08 Dec 2021 11:08:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoJ-0006oq-US; Wed, 08 Dec 2021 11:08:31 +0000 Received: by outflank-mailman (input) for mailman id 242142; Wed, 08 Dec 2021 11:08:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoI-0006Yt-MZ for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:08:30 +0000 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [2607:f8b0:4864:20::431]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2c3b62af-5817-11ec-a831-37629979565c; Wed, 08 Dec 2021 12:08:30 +0100 (CET) Received: by mail-pf1-x431.google.com with SMTP id k64so2122889pfd.11 for ; Wed, 08 Dec 2021 03:08:30 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id b10sm2960927pft.179.2021.12.08.03.08.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:08:28 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2c3b62af-5817-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TnQefY0SqcDF3kPq8KJwIjgVaMNVB8DughUGvzU8o18=; b=ZkLOIb1g7XpNcLLrO2xyloqg63+eDW8c1N54mOfbRuFF15rJgWz2gE91JKdJydbYqG 8eL+r+UhBdoKdktkRc6tlgzDzsYJ6NEY/1TBuKklxnRsWEthwhlQQghbv4vM7av0dghG YG6zw3TvtD0aPRSriB0gRBQvxZg2vVXXuprrdD3o0j3Qbt2CneEC83iXlxyIWawDUhZw D0iIjqE7yyGv7egqdw5VoqBiJosZhNCpE68DlbCNteQlDu4Axl6SfUW4B/3Jil8jexsd tyJwF/W/PbqJoQPqUimewZeAPGV5Cx7WcudydaUIl40hyGzVhigr/W2WRHOIV/UiSSyJ MqXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TnQefY0SqcDF3kPq8KJwIjgVaMNVB8DughUGvzU8o18=; b=chaDo3jPeHj8/RyCOEgJ9dczW6Rv5/pEswDAI6O6FfYF41wg6kxr4fGEUXeknvzFAN p3jUc9jNqScsTgG++vxbN623aCLcD+NResC8ARmP5F5jnlMJjwiemGWZR0hrIwpyQtsf sbdQo/r4aM/Dx8/VFktWDWVEcDocq/q0zB2S5qMXu0oL364XdsxpGM2khQw0Ggmi73+U 1tVf7/BX7lWoOL1SiLGCt9jLylLl1d6DMmZiSbSVd+ONuGh7CcWcD2w8zDL2cqLKXpsM EtY4Wf/UwamfSpCt0SKXbCM/d8eYOzbTAlw/hQG+irYiV+fYetR/zgM88soXS/q0tNgc 8JOQ== X-Gm-Message-State: AOAM530YBJ5V32M/Ij18vSwP0dUGogjPXQU1DaSMmLHBLzXczPFzS18G tNRKXX7SyaUzMc1tSCAXMX4= X-Google-Smtp-Source: ABdhPJy9TsqtHV5JdjlSkcLb9NlmtdqMIVu0NVHyePzQqWTpNS604qrVcpVV8sNyEJaBLMfE3D+HqQ== X-Received: by 2002:a05:6a00:a18:b0:4a7:ef65:ddfb with SMTP id p24-20020a056a000a1800b004a7ef65ddfbmr4953445pfh.17.1638961708633; Wed, 08 Dec 2021 03:08:28 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 01/11] x86/entry: Use swapgs and native_iret directly in swapgs_restore_regs_and_return_to_usermode Date: Wed, 8 Dec 2021 19:08:23 +0800 Message-Id: <20211208110833.65366-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan swapgs_restore_regs_and_return_to_usermode() is used in native code (non-xenpv) only now, so it doesn't need the PV-aware SWAPGS and INTERRUPT_RETURN. Signed-off-by: Lai Jiangshan Reviewed-by: Juergen Gross --- arch/x86/entry/entry_64.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 97b1f84bb53f..d95a02ecee16 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -608,8 +608,8 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL) /* Restore RDI. */ popq %rdi - SWAPGS - INTERRUPT_RETURN + swapgs + jmp native_iret SYM_INNER_LABEL(restore_regs_and_return_to_kernel, SYM_L_GLOBAL) From patchwork Wed Dec 8 11:08:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C3DEC433FE for ; Wed, 8 Dec 2021 11:09:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242143.418849 (Exim 4.92) (envelope-from ) id 1muuoS-0007Af-AU; Wed, 08 Dec 2021 11:08:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242143.418849; Wed, 08 Dec 2021 11:08:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoS-0007AU-7C; Wed, 08 Dec 2021 11:08:40 +0000 Received: by outflank-mailman (input) for mailman id 242143; Wed, 08 Dec 2021 11:08:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoR-0006Yt-4P for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:08:39 +0000 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [2607:f8b0:4864:20::102a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 312e853b-5817-11ec-a831-37629979565c; Wed, 08 Dec 2021 12:08:38 +0100 (CET) Received: by mail-pj1-x102a.google.com with SMTP id fv9-20020a17090b0e8900b001a6a5ab1392so1816347pjb.1 for ; Wed, 08 Dec 2021 03:08:38 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id e29sm2222262pge.17.2021.12.08.03.08.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:08:36 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 312e853b-5817-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v0Rti8J9O/DOw+Q8wf2xojRDpLT8xHVZ9Lxf2e0cKZk=; b=PsLrL5Aie1ZtnPQWX5QQBbXXhbTKSUKu0PazbTlH+ol9j3w7v0vsbVraLGwI8/WUBo 4JFmDJF1Et2cG6j/knBCajQznDaPYEV9uSmcNxrp0vZqTMFNZiS2SDO75XkRhd5Vvo9d iLJGeDUeMxGOuQ9nEeBVyRfyOPmkTlLH91yzjTTVSbHnK38Z+QOAMnm5Va2wTSFbnJfJ L8u2+h3MCb0UMPsvd3lGAk9BW7XraGPnmMNDp1DmWaALPZBg//tjNUNJfUiPJyE54GZA uoM15nO2f6/MMfuxIpBsbi2/4pmj+7Z/2GspSMt57V6sUf7bF36VCpuwxizpG3+DZLvh vyew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v0Rti8J9O/DOw+Q8wf2xojRDpLT8xHVZ9Lxf2e0cKZk=; b=7DIQE05OQ3NOvA7HDjZ5uHMzGGX8GfrzSoAhSZ62u+2TBnBQLvlyeYpVfbSoKez/Hg S8A7l/SuH8AQ791cJVnyeHS+p81ACg+DHf2qEbnnmnbk3M+mRESX6B2iZXd97xUKFWLS vp6Y+XsvSnfr8SF/crtM+UmFMBQfq4hqS64hjnMk2/HAj56d47AVoFsLEeH0IrhYXOt/ Drwi4u9MR8fHAEATkM2NGmk6PpbWsMA+gU+Q82ZTATpqRLkT/cvhvT03GxAeBfYdyxfk AwCF/DMbalLDKY4JmGSee+Sto7PZO47C/hw8giJtLF2Ozo31MUAU5dmU8HlsPJBK8ceT ZS2A== X-Gm-Message-State: AOAM530orrPGkHjtkxVvvKl7imlBM846k6R7JCnGlvVUkB8JKrce2sBk 99gPXrRxiLauHCIqzjzKffo= X-Google-Smtp-Source: ABdhPJxpeELdxfo0JipJhaLLz4786jh3lr2fXOrOICnzD3O4qx8UMsz1Z1IGRVnoqDN8NDdQgTJz/g== X-Received: by 2002:a17:90b:3889:: with SMTP id mu9mr6279578pjb.160.1638961716971; Wed, 08 Dec 2021 03:08:36 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Joerg Roedel , "Chang S. Bae" Subject: [PATCH 02/11] x86/traps: Move pt_regs only in fixup_bad_iret() Date: Wed, 8 Dec 2021 19:08:24 +0800 Message-Id: <20211208110833.65366-3-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan fixup_bad_iret() and sync_regs() have similar arguments and do similar work that copies full or partial pt_regs to a place and switches stack after return. They are quite the same, but fixup_bad_iret() not only copies the pt_regs but also the return address of error_entry() while sync_regs() copies the pt_regs only and the return address of error_entry() was preserved and handled in ASM code. This patch makes fixup_bad_iret() work like sync_regs() and the handling of the return address of error_entry() is moved in ASM code. It removes the need to use the struct bad_iret_stack, simplifies fixup_bad_iret() and makes the ASM error_entry() call fixup_bad_iret() as the same as calling sync_regs() which adds readability because the calling patterns are exactly the same. It is prepared for later patch to do the stack switch after the error_entry() which simplifies the code further. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 5 ++++- arch/x86/include/asm/traps.h | 2 +- arch/x86/kernel/traps.c | 17 ++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index d95a02ecee16..f8faff3ca61e 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1040,9 +1040,12 @@ SYM_CODE_START_LOCAL(error_entry) * Pretend that the exception came from user mode: set up pt_regs * as if we faulted immediately after IRET. */ - mov %rsp, %rdi + popq %r12 /* save return addr in %12 */ + movq %rsp, %rdi /* arg0 = pt_regs pointer */ call fixup_bad_iret mov %rax, %rsp + ENCODE_FRAME_POINTER + pushq %r12 jmp .Lerror_entry_from_usermode_after_swapgs SYM_CODE_END(error_entry) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index 6221be7cafc3..1cdd7e8bcba7 100644 --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h @@ -13,7 +13,7 @@ #ifdef CONFIG_X86_64 asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs); asmlinkage __visible notrace -struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s); +struct pt_regs *fixup_bad_iret(struct pt_regs *bad_regs); void __init trap_init(void); asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *eregs); #endif diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index c9d566dcf89a..a6c0bc9ee36f 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -761,13 +761,8 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r } #endif -struct bad_iret_stack { - void *error_entry_ret; - struct pt_regs regs; -}; - asmlinkage __visible noinstr -struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) +struct pt_regs *fixup_bad_iret(struct pt_regs *bad_regs) { /* * This is called from entry_64.S early in handling a fault @@ -777,19 +772,19 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) * just below the IRET frame) and we want to pretend that the * exception came from the IRET target. */ - struct bad_iret_stack tmp, *new_stack = - (struct bad_iret_stack *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; + struct pt_regs tmp, *new_stack = + (struct pt_regs *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; /* Copy the IRET target to the temporary storage. */ - __memcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); + __memcpy(&tmp.ip, (void *)bad_regs->sp, 5*8); /* Copy the remainder of the stack from the current stack. */ - __memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + __memcpy(&tmp, bad_regs, offsetof(struct pt_regs, ip)); /* Update the entry stack */ __memcpy(new_stack, &tmp, sizeof(tmp)); - BUG_ON(!user_mode(&new_stack->regs)); + BUG_ON(!user_mode(new_stack)); return new_stack; } #endif From patchwork Wed Dec 8 11:08:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0629FC433FE for ; Wed, 8 Dec 2021 11:09:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242144.418860 (Exim 4.92) (envelope-from ) id 1muuoX-0007XF-Qg; Wed, 08 Dec 2021 11:08:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242144.418860; Wed, 08 Dec 2021 11:08:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoX-0007X5-LX; Wed, 08 Dec 2021 11:08:45 +0000 Received: by outflank-mailman (input) for mailman id 242144; Wed, 08 Dec 2021 11:08:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoW-0006Yt-GP for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:08:44 +0000 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [2607:f8b0:4864:20::530]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 346da667-5817-11ec-a831-37629979565c; Wed, 08 Dec 2021 12:08:43 +0100 (CET) Received: by mail-pg1-x530.google.com with SMTP id r138so1736993pgr.13 for ; Wed, 08 Dec 2021 03:08:43 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id a16sm2254924pgm.57.2021.12.08.03.08.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:08:41 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 346da667-5817-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=74fcl84eMF3trMMN2JVz1x4AFBWc9HU1GFAGLmUM5eE=; b=VKlr4hE6P3/KVxbIhcLJDA0sF52nL0lnTLSlQue1EOi6nOPZmlq7+N6t34Z4nlAn6S 6NYswFiLZFVt72m7dLmKsXjcv49Tzn4Vfnpcat4WRibMq/7lLfmYUvxqlDrF2qI/vqdA 5aiicTqsTeo5rZI/iqEDgXPe0X06ShRim5daAufoj+27dBC6vjm3F6QWqdhhrBeccdlx vioUF/TKnCwOTAFHjtjXkA2ZHEBTUJBfBC9YS2QXCQak02LJEkZyHt3r3mxI7EG3xklk 0XSnYu5Z2L1fze0kQgB0lt62j14Jn3CZPbd5zi5beWbTOrpQnWraqlF9nD9BmgP3hxz8 xxDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=74fcl84eMF3trMMN2JVz1x4AFBWc9HU1GFAGLmUM5eE=; b=ETyW2lETc1herkLk/EiUKJV11X5B1Oas8zxXRMNOp4rg5v72qYkew7jPQAOurEcIk2 BNKwIVNv67+tftEx5pL8/AxngnKxU28po8UGf3rNr+5MuKtE2n/H4bDF/MW8N+ZANr9C IZg0ZzRAnm/rWBD/6eIj4PXLnzJe3tJsoQN7VtJQKTkq3xfkrzBz0uBQXjc9dkil27Nk z+XprFGkxMg9Bh4CZNsRFY5HG3z8qfo6dKZ18qbMc4DjZHZJpKbMa7UCxG7+DYCAkDfW 8755+04V/51WSe436gTZXYOi+GDnW0PskJB5YoWCbqKIhCdqhc8tGfFKNljVufuMuZez rrdQ== X-Gm-Message-State: AOAM532JwxB2IizVr4Ix2Ni1OgNKbYk8NJyNo+yBUZZYM/mik4WilOhK 1+L2IObTvqa50cjIjo8vOEo= X-Google-Smtp-Source: ABdhPJwdwD0NWVFtmrZKBdCkBw1nVwlMCHpLBoT9j05zLnwJyoppx7uciS4Kg9RdTDjqkCWrZh05WA== X-Received: by 2002:a63:e43:: with SMTP id 3mr29449478pgo.73.1638961722423; Wed, 08 Dec 2021 03:08:42 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 03/11] x86/entry: Switch the stack after error_entry() returns Date: Wed, 8 Dec 2021 19:08:25 +0800 Message-Id: <20211208110833.65366-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan error_entry() calls sync_regs() to settle/copy the pt_regs and switches the stack directly after sync_regs(). But error_entry() itself is also a function call, the switching has to handle the return address of it together, which causes the work complicated and tangly. Switching to the stack after error_entry() makes the code simpler and intuitive. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index f8faff3ca61e..6baa7413f7eb 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -323,6 +323,8 @@ SYM_CODE_END(ret_from_fork) .macro idtentry_body cfunc has_error_code:req call error_entry + movq %rax, %rsp /* switch stack settled by sync_regs() */ + ENCODE_FRAME_POINTER UNWIND_HINT_REGS movq %rsp, %rdi /* pt_regs pointer into 1st argument*/ @@ -981,14 +983,10 @@ SYM_CODE_START_LOCAL(error_entry) /* We have user CR3. Change to kernel CR3. */ SWITCH_TO_KERNEL_CR3 scratch_reg=%rax + leaq 8(%rsp), %rdi /* arg0 = pt_regs pointer */ .Lerror_entry_from_usermode_after_swapgs: /* Put us onto the real thread stack. */ - popq %r12 /* save return addr in %12 */ - movq %rsp, %rdi /* arg0 = pt_regs pointer */ call sync_regs - movq %rax, %rsp /* switch stack */ - ENCODE_FRAME_POINTER - pushq %r12 ret /* @@ -1020,6 +1018,7 @@ SYM_CODE_START_LOCAL(error_entry) */ .Lerror_entry_done_lfence: FENCE_SWAPGS_KERNEL_ENTRY + leaq 8(%rsp), %rax /* return pt_regs pointer */ ret .Lbstep_iret: @@ -1040,12 +1039,9 @@ SYM_CODE_START_LOCAL(error_entry) * Pretend that the exception came from user mode: set up pt_regs * as if we faulted immediately after IRET. */ - popq %r12 /* save return addr in %12 */ - movq %rsp, %rdi /* arg0 = pt_regs pointer */ + leaq 8(%rsp), %rdi /* arg0 = pt_regs pointer */ call fixup_bad_iret - mov %rax, %rsp - ENCODE_FRAME_POINTER - pushq %r12 + mov %rax, %rdi jmp .Lerror_entry_from_usermode_after_swapgs SYM_CODE_END(error_entry) From patchwork Wed Dec 8 11:08:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B147EC433F5 for ; Wed, 8 Dec 2021 11:09:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242148.418870 (Exim 4.92) (envelope-from ) id 1muuod-0007xR-1B; Wed, 08 Dec 2021 11:08:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242148.418870; Wed, 08 Dec 2021 11:08:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoc-0007xG-UH; Wed, 08 Dec 2021 11:08:50 +0000 Received: by outflank-mailman (input) for mailman id 242148; Wed, 08 Dec 2021 11:08:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoc-0007Ud-3S for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:08:50 +0000 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [2607:f8b0:4864:20::436]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 37c10856-5817-11ec-9d12-4777fae47e2b; Wed, 08 Dec 2021 12:08:49 +0100 (CET) Received: by mail-pf1-x436.google.com with SMTP id r130so2188747pfc.1 for ; Wed, 08 Dec 2021 03:08:49 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id p17sm3404857pfh.86.2021.12.08.03.08.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:08:47 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 37c10856-5817-11ec-9d12-4777fae47e2b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RcBSE4oPibzeIhyf2Qp5YqTgR/bF+VmAeF/brxTC5FU=; b=D0KfkWiPHhKhRJUZdR5kq7I4HpNBJdRwa55sv9BMfhZ3vbJVIPNqKGnE1ONGnrlI34 2uQvzZB8c1W/Hzmk9lJIBvPuBZIZBDzlhZ6uIuU9VZOKqWnOAHB9aMyyXNK8KcmbcQV/ bQjVtI9HtkySFmOwWp9onHdlvBxih0vvgFOJHMQjs9U8tAoDeS0Tt29U9Ye6sau5kAxz J/DeQH5dwbfQl7bRYn+aIrOkMti5RoJtWalneYj8OgUE/4cpA9PctgdhPmFe30GA+AfV HgbSnUq6EfLPRCS7X+q0+QvEnT3ZXqXLMRNwgKgKcUcvvo/VDdu5ix0k/Mo8225S/GHA bJ1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RcBSE4oPibzeIhyf2Qp5YqTgR/bF+VmAeF/brxTC5FU=; b=yVkxtcDkw60pEpnnd0QuPE42u9tz9HgBIn7a0JMf/GLEAJwksZge6oNRNwdS0lJvI5 84BhDOXz2mts7Ej2jfXoq+8QNv3zNP3wmgx1CZd9R7BYCRpcKmtnnMpcLXFZwheN1ff6 xh01oYtzzRFJ7ChlbMO0B5zA0n4eh7GJBw7QlSax5b9N3QfViLiIosEZXXwTQvdgbDiZ S33LrbwVlyb9dSttozh8IZJGXLrHfFiy5ASiWcEAcpQHIWFF4cBxMSeCFmacbu3XGfRa jCk705/7qcOMgz1Q/X4himD8Y+BTlA/jH10b/0nAh5s8I71w1yhfi2hsbW6snYi9mT/e 2tPA== X-Gm-Message-State: AOAM533c8HwJFY7qXd7coz/XScI2uV6/v+xWtWKxbgULXc3oJfkfthba WgHOyAEBjycDZNuQWSQTaOQ= X-Google-Smtp-Source: ABdhPJwB9xEYc6yaPMgbaAjXzRhRbjCMiDT7xaBXucJ4jA6rNMMEh2pDhUz6bzCHuWkJVnkpO7Wxhg== X-Received: by 2002:a05:6a00:1a8e:b0:49f:a4a9:8f1e with SMTP id e14-20020a056a001a8e00b0049fa4a98f1emr4890452pfv.67.1638961727985; Wed, 08 Dec 2021 03:08:47 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 04/11] x86/entry: move PUSH_AND_CLEAR_REGS out of error_entry Date: Wed, 8 Dec 2021 19:08:26 +0800 Message-Id: <20211208110833.65366-5-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan Moving PUSH_AND_CLEAR_REGS out of error_entry doesn't change any functionality. It will enlarge the size: size arch/x86/entry/entry_64.o.before: text data bss dec hex filename 17916 384 0 18300 477c arch/x86/entry/entry_64.o size --format=SysV arch/x86/entry/entry_64.o.before: .entry.text 5528 0 .orc_unwind 6456 0 .orc_unwind_ip 4304 0 size arch/x86/entry/entry_64.o.after: text data bss dec hex filename 26868 384 0 27252 6a74 arch/x86/entry/entry_64.o size --format=SysV arch/x86/entry/entry_64.o.after: .entry.text 8200 0 .orc_unwind 10224 0 .orc_unwind_ip 6816 0 But .entry.text in x86_64 is 2M aligned, enlarging it to 8.2k doesn't enlarge the final text size. The tables .orc_unwind[_ip] are enlarged due to it adds many pushes. It is prepared for not calling error_entry() from XENPV in later patch and for future converting the whole error_entry into C code. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 6baa7413f7eb..72ceb4b70822 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -322,6 +322,9 @@ SYM_CODE_END(ret_from_fork) */ .macro idtentry_body cfunc has_error_code:req + PUSH_AND_CLEAR_REGS + ENCODE_FRAME_POINTER + call error_entry movq %rax, %rsp /* switch stack settled by sync_regs() */ ENCODE_FRAME_POINTER @@ -969,8 +972,6 @@ SYM_CODE_END(paranoid_exit) SYM_CODE_START_LOCAL(error_entry) UNWIND_HINT_FUNC cld - PUSH_AND_CLEAR_REGS save_ret=1 - ENCODE_FRAME_POINTER 8 testb $3, CS+8(%rsp) jz .Lerror_kernelspace From patchwork Wed Dec 8 11:08:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5413C433F5 for ; Wed, 8 Dec 2021 11:09:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242149.418882 (Exim 4.92) (envelope-from ) id 1muuoj-0008NI-E5; Wed, 08 Dec 2021 11:08:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242149.418882; Wed, 08 Dec 2021 11:08:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoj-0008NB-8U; Wed, 08 Dec 2021 11:08:57 +0000 Received: by outflank-mailman (input) for mailman id 242149; Wed, 08 Dec 2021 11:08:55 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoh-0006Yt-KY for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:08:55 +0000 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [2607:f8b0:4864:20::42c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3b13cd72-5817-11ec-a831-37629979565c; Wed, 08 Dec 2021 12:08:55 +0100 (CET) Received: by mail-pf1-x42c.google.com with SMTP id x131so2117615pfc.12 for ; Wed, 08 Dec 2021 03:08:54 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id d3sm3454696pfv.57.2021.12.08.03.08.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:08:53 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3b13cd72-5817-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=94qtwsHdBUcVzdr14fQH4QqeaELVSejvb9k+dDp4o2k=; b=gdJwJexPSIx1/o0kGlFH/3siK2BWmqN/Qya2wWAwRpJBABJCf7cZVPY1vV9uKphzCM wDiL42S9zLojg/9rYkV+8Gcyug0bNkhyprI3HL5IVv6FPdbDYpG0Q+9f1fcLvsLyHqlJ 6d+3RCpxWxTSvIGQUyD3iKktmbGyZSKRYFR81PlrbYQogKQmi6fZOJTId9b93ecmVF2Q eT3UjTw/vZKqvqEL/qGLIrdAM1QDCdiqpnZVGVu3jSXv5teHhN5/T/g/zvUjMZ6G722x jjKFxOz0lcm/NslZErC/EI4Yi0rOzfoSzQ5g0N+HuIY4WjIjEBS0MHTo4NO9TZ3LRbFW TNpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=94qtwsHdBUcVzdr14fQH4QqeaELVSejvb9k+dDp4o2k=; b=Ba7keV8NGEKXsNX4HoGD1ZSQNQWw0OLkR6TS2sZO8Z0KYRMCxSm5Ug3Goqwa0ExRXT QZhDEB0L1Y4GIJoV5NpwTD9aGFVvIN7eopFEa6EhitcJHlswX2OGTFrC3e/pmI4NhVdL elr3jYrvyVn/5apmJ++5hc4Epk7lxaAE/jhosQ8LYN0D3P61DdEfdyxfzCFxrY/fYZu6 9XEDFS/3Uv/WTN/ziJeBdKj1wB9PVQkkyVTryAQFMnz9fMeLA+JIXpjNYDsKvTzYmZ79 RZdmhjlPkryQ12VsFO3j/cXXNDGD8jQjXc+Et1bvQYOIo2zGaZds4hWDDrRpjmUqioSg /34w== X-Gm-Message-State: AOAM533o7E3HBoiYfvbbNMPSPFDNVHglCpBIsE9NzdhQkwf0x9jC98Ms 45t9WdWIKok6oYiSFOfjxMw= X-Google-Smtp-Source: ABdhPJzMp2m1CIOe5Z9utqdinpuLznocfHk1h5+AWYqs9CoFg7FElyyIpiFD9TM9L0u194BTWXvhUw== X-Received: by 2002:a62:8449:0:b0:4ad:56ba:2f1d with SMTP id k70-20020a628449000000b004ad56ba2f1dmr4928492pfd.37.1638961733585; Wed, 08 Dec 2021 03:08:53 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 05/11] x86/entry: Move cld to the start of idtentry Date: Wed, 8 Dec 2021 19:08:27 +0800 Message-Id: <20211208110833.65366-6-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan Make it next to CLAC Suggested-by: Peter Zijlstra Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 72ceb4b70822..ee1d4adcdab0 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -356,6 +356,7 @@ SYM_CODE_END(ret_from_fork) SYM_CODE_START(\asmsym) UNWIND_HINT_IRET_REGS offset=\has_error_code*8 ASM_CLAC + cld .if \has_error_code == 0 pushq $-1 /* ORIG_RAX: no syscall to restart */ @@ -423,6 +424,7 @@ SYM_CODE_END(\asmsym) SYM_CODE_START(\asmsym) UNWIND_HINT_IRET_REGS ASM_CLAC + cld pushq $-1 /* ORIG_RAX: no syscall to restart */ @@ -478,6 +480,7 @@ SYM_CODE_END(\asmsym) SYM_CODE_START(\asmsym) UNWIND_HINT_IRET_REGS ASM_CLAC + cld /* * If the entry is from userspace, switch stacks and treat it as @@ -539,6 +542,7 @@ SYM_CODE_END(\asmsym) SYM_CODE_START(\asmsym) UNWIND_HINT_IRET_REGS offset=8 ASM_CLAC + cld /* paranoid_entry returns GS information for paranoid_exit in EBX. */ call paranoid_entry @@ -853,7 +857,6 @@ SYM_CODE_END(xen_failsafe_callback) */ SYM_CODE_START_LOCAL(paranoid_entry) UNWIND_HINT_FUNC - cld PUSH_AND_CLEAR_REGS save_ret=1 ENCODE_FRAME_POINTER 8 @@ -971,7 +974,6 @@ SYM_CODE_END(paranoid_exit) */ SYM_CODE_START_LOCAL(error_entry) UNWIND_HINT_FUNC - cld testb $3, CS+8(%rsp) jz .Lerror_kernelspace @@ -1104,6 +1106,7 @@ SYM_CODE_START(asm_exc_nmi) */ ASM_CLAC + cld /* Use %rdx as our temp variable throughout */ pushq %rdx @@ -1123,7 +1126,6 @@ SYM_CODE_START(asm_exc_nmi) */ swapgs - cld FENCE_SWAPGS_USER_ENTRY SWITCH_TO_KERNEL_CR3 scratch_reg=%rdx movq %rsp, %rdx From patchwork Wed Dec 8 11:08:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB461C433EF for ; Wed, 8 Dec 2021 11:09:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242155.418892 (Exim 4.92) (envelope-from ) id 1muuoo-0000V1-Ko; Wed, 08 Dec 2021 11:09:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242155.418892; Wed, 08 Dec 2021 11:09:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuoo-0000Uu-HH; Wed, 08 Dec 2021 11:09:02 +0000 Received: by outflank-mailman (input) for mailman id 242155; Wed, 08 Dec 2021 11:09:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuon-0007Ud-0I for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:09:01 +0000 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [2607:f8b0:4864:20::42f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3e5084b6-5817-11ec-9d12-4777fae47e2b; Wed, 08 Dec 2021 12:09:00 +0100 (CET) Received: by mail-pf1-x42f.google.com with SMTP id i12so2152989pfd.6 for ; Wed, 08 Dec 2021 03:09:00 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id gc22sm5791712pjb.57.2021.12.08.03.08.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:08:58 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3e5084b6-5817-11ec-9d12-4777fae47e2b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GTzYOcv7GXMsuudeRCCVKvQE4p4RTznbhZKVu0xYKUU=; b=km30WDN3p/x6O1LN4IM4fy77QF1NVRUPK5sP06Gal6+QGtjqpUUYFI0ArnBEImqtBx AuUANxaE5TNvqfzwlIxrjFaBsxfD6p1eT/U6KemlwxP4SBJRnkOXwocKlRobPiXwphiK nnKNx8a17oUYe1aBF9xVYjEfT0JHyVlsyWpuNHWRttKft7eHMogyjA4hHEpDixYozui/ Yp9HWHVmMbUx0pUgEzC7X+43ukc3qPqWPrcwKNA92/m1IkWkKcYC2169qQXVTznVDh9C 8FdQ3N0QnfLfiyMM1qnRw3/LhI95W2mPf5Ae8J85boc7Vk+qIFVR2qqDY1HLZcu21xTg Tx+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GTzYOcv7GXMsuudeRCCVKvQE4p4RTznbhZKVu0xYKUU=; b=ygSohSlCfvG7LQhGRAIs7IFPZ0Ye6C6+oFRnaZVHZCqchFjPO2CI1F7p98Jb5lXGxh 3y8eCocAKpr3t8duCMdKyOgPLtfGThZ5bJyCkg3tWjsUPUpb+jwI0gXjAMI0y/Ow4XAQ 3fMejLW6MiidNGJeFiWaPKlVqpi0IC3D5UKSWgphUIcmIYMK1QpBb7ichbS5RWcuUfjR aD/lPQzzI+XF0iAmCnl365aYpN4cFPwV9ccUp3ULaC30oQ2JlKt9hgWU+Q4mOcuX0SnP HIW9NMzhOkTvQEBSt7Vm15tLtWcRDJ60F1+cO33qH/L3WiotgcEGrfbkHBY39XP79yxw VycA== X-Gm-Message-State: AOAM532kDaHDOUM/0Fewub5NNBSQ8EZujuNIwdNgpHeMZMdQe0o2MchW 5tYTgVgQLhH8UqxE9FFL2qE= X-Google-Smtp-Source: ABdhPJyG8RspzExM0YLJHIGBovB6b/ZNv9oPLLxl7bIY/uiUpBpyPdvWlt/3qAb05wwKy/zxp0w/Lw== X-Received: by 2002:a05:6a00:ad0:b0:4a3:1056:e2ae with SMTP id c16-20020a056a000ad000b004a31056e2aemr4931125pfl.2.1638961739024; Wed, 08 Dec 2021 03:08:59 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 06/11] x86/entry: Don't call error_entry for XENPV Date: Wed, 8 Dec 2021 19:08:28 +0800 Message-Id: <20211208110833.65366-7-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan When in XENPV, it is already in the task stack, and it can't fault for native_iret() nor native_load_gs_index() since XENPV uses its own pvops for iret and load_gs_index(). And it doesn't need to switch CR3. So there is no reason to call error_entry() in XENPV. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index ee1d4adcdab0..383070aa9272 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -325,8 +325,17 @@ SYM_CODE_END(ret_from_fork) PUSH_AND_CLEAR_REGS ENCODE_FRAME_POINTER - call error_entry - movq %rax, %rsp /* switch stack settled by sync_regs() */ + /* + * Call error_entry and switch stack settled by sync_regs(). + * + * When in XENPV, it is already in the task stack, and it can't fault + * for native_iret() nor native_load_gs_index() since XENPV uses its + * own pvops for iret and load_gs_index(). And it doesn't need to + * switch CR3. So it can skip invoking error_entry(). + */ + ALTERNATIVE "call error_entry; movq %rax, %rsp", \ + "", X86_FEATURE_XENPV + ENCODE_FRAME_POINTER UNWIND_HINT_REGS From patchwork Wed Dec 8 11:08:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F4038C433EF for ; Wed, 8 Dec 2021 11:09:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242159.418904 (Exim 4.92) (envelope-from ) id 1muuot-0000xE-Uu; Wed, 08 Dec 2021 11:09:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242159.418904; Wed, 08 Dec 2021 11:09:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuot-0000wu-R6; Wed, 08 Dec 2021 11:09:07 +0000 Received: by outflank-mailman (input) for mailman id 242159; Wed, 08 Dec 2021 11:09:06 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuos-0007Ud-QC for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:09:06 +0000 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [2607:f8b0:4864:20::102e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 41c645b6-5817-11ec-9d12-4777fae47e2b; Wed, 08 Dec 2021 12:09:06 +0100 (CET) Received: by mail-pj1-x102e.google.com with SMTP id v23so1664666pjr.5 for ; Wed, 08 Dec 2021 03:09:06 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id b18sm2455866pjo.31.2021.12.08.03.09.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:09:04 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 41c645b6-5817-11ec-9d12-4777fae47e2b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8qfk8rEd7OE7FkctKlJZZ9kD8w0vOU1vAluUq/sa8Oc=; b=l7nygggwydXZUAu4zkqtbtTRWY39vFf8FLQk4PTAPrhXI+tzr6CLSDOcbjAIFholoR ZflKnIP1dr60YP3ogLki0mS5fzvW2s2sJ5JJjEOnEcnqaWFXcDIqGKfbpVG5umYF7IuV XbGokOAZ7qo1h+G1Bfk0/lmfvpWFvQF3DWBtRJl8/CnxVy53GK6huw6txhzHw8osD5Bs OMUKn0L37dEZLYVTT7lapANuDqunPxOpcQlA+VF0ffqg433s/FhOPxw6l+uZTJK2URXY u7aPuRJNHxAhjbmWX/mle+316jDesbf0dAlNAH5fyU9efV13TpPnGDNyw76aFmOqi4by 5IXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8qfk8rEd7OE7FkctKlJZZ9kD8w0vOU1vAluUq/sa8Oc=; b=ka+2mO4WD88MS0SWkqc+1akBJgM5vI4yVuTSBn8xAc0mW2HapwnLhPbCgYx/QHxEA3 sBfXugyl0zl5/FHNQRgnOoYbPwMIOcZkSCpLrHQkw2p3lTfQ4TnHz8bg2IVFHc/FdYr/ NZQpIx/JDBEdX8i16uG/MkkNQ3AsPyGF68uvOljklHWnSLd61ADthMS8z83jHCwfP+2x zBKORXoGBZp6kcH5/T2akQ4EAK7F+jfUoeK71HhxckUES4gUBTb6CMmHP91Srxoy/7A5 lJ3FvY7/wF9JofwFeYloiS3duKlt9hYBTnrIKIvOBSGLn7pyRmwUHnNGN2QXbS4L/XKb Q6yA== X-Gm-Message-State: AOAM531CPy2KKRI8Y5xjakU+VynmAkQ1tpLT2ixeW8rtHsscp9i3QHk+ 7AdaeeiVGD3gUPsuz5tuTWk= X-Google-Smtp-Source: ABdhPJyX9L5YCir717yBDgGNa36Bhmc2dDItA2/uZBarVsl66m2fKt+O9ZG0+5iKAc//bNxdDvNjmA== X-Received: by 2002:a17:90b:612:: with SMTP id gb18mr6498365pjb.0.1638961744681; Wed, 08 Dec 2021 03:09:04 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 07/11] x86/entry: Convert SWAPGS to swapgs in error_entry() Date: Wed, 8 Dec 2021 19:08:29 +0800 Message-Id: <20211208110833.65366-8-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan XENPV doesn't use error_entry() anymore, so the pv-aware SWAPGS can be changed to native swapgs. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 383070aa9272..6100007fd03f 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -990,7 +990,7 @@ SYM_CODE_START_LOCAL(error_entry) * We entered from user mode or we're pretending to have entered * from user mode due to an IRET fault. */ - SWAPGS + swapgs FENCE_SWAPGS_USER_ENTRY /* We have user CR3. Change to kernel CR3. */ SWITCH_TO_KERNEL_CR3 scratch_reg=%rax @@ -1022,7 +1022,7 @@ SYM_CODE_START_LOCAL(error_entry) * gsbase and proceed. We'll fix up the exception and land in * .Lgs_change's error handler with kernel gsbase. */ - SWAPGS + swapgs /* * Issue an LFENCE to prevent GS speculation, regardless of whether it is a @@ -1043,7 +1043,7 @@ SYM_CODE_START_LOCAL(error_entry) * We came from an IRET to user mode, so we have user * gsbase and CR3. Switch to kernel gsbase and CR3: */ - SWAPGS + swapgs FENCE_SWAPGS_USER_ENTRY SWITCH_TO_KERNEL_CR3 scratch_reg=%rax From patchwork Wed Dec 8 11:08:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5771DC433F5 for ; Wed, 8 Dec 2021 11:17:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242186.418925 (Exim 4.92) (envelope-from ) id 1muuwY-0004TX-6p; Wed, 08 Dec 2021 11:17:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242186.418925; Wed, 08 Dec 2021 11:17:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuwY-0004TQ-3k; Wed, 08 Dec 2021 11:17:02 +0000 Received: by outflank-mailman (input) for mailman id 242186; Wed, 08 Dec 2021 11:17:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muup1-0006Yt-6J for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:09:15 +0000 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [2607:f8b0:4864:20::435]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 468925f5-5817-11ec-a831-37629979565c; Wed, 08 Dec 2021 12:09:14 +0100 (CET) Received: by mail-pf1-x435.google.com with SMTP id z6so2145783pfe.7 for ; Wed, 08 Dec 2021 03:09:14 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id q10sm3232415pfk.180.2021.12.08.03.09.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:09:12 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 468925f5-5817-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4OSMT+TQw2RUHxNW8atVbB9ZMIOeuqyP7ER0LvB+dp8=; b=p9amC8ioLdWqBeAJ4CjkDRZ1SNu2S6IWtNPrQgya84oZpDa9clfN6COADE//h/Kczz kQ+fmFgTFQoLYUpO3SxmFlpuPVleUj1yU37SK/cIZ0B+1mzWQP1bXTdmwTYJqBqgidym s3Qnw3+ezN8X07/YBXDOFJMTCWVdRYuXNtqsZb9MYstubPgHdxVejo3WZ/+NjwbHXH2U 8tjQd71AvCYyeR33oziwHtkT65rxg9yzijXFTi0+rKnlPvNRCFSokL+RsxQRBvOrVIrU w/GkvVUeb2F4qxGFfEyZK3vg73sGRS4uXqjhQZh5lj5xic5xJsV2YQ+0E79kCZaZeBK8 qj8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4OSMT+TQw2RUHxNW8atVbB9ZMIOeuqyP7ER0LvB+dp8=; b=sLtDYEapG9TOyv52Jjozb9YXPNWpHknkGvwfvv1A0wZ1cP5tuixjH3pDIOpY58yP0n nYrYTZkH4IBT9/TO4z+PVxx4T4iy97Agsgsx9dVJVHR4ndOmD1zmLT4+QDs+rQ14UlUT zabPop6ORuqpg8surRWM0+6eUdBuw7C4evKFYr2SEA/FqCZf/v7y0NpmG5Rm+60GR7ec h7RTMIIYgnoLCy7zOPbB55aad94j0YWu4Blq59dgaVxgQhVPuT8TJWwETsaBLe0eEYfF R7Pvime0zRVylUicmKz2SFYUkyqamoc3IILrDiqb2OFqFDUxomqb/OXKTfsRmx3CKg04 VGog== X-Gm-Message-State: AOAM5335gThepBertzopR7foo9NJRHRrsm0tCGeISj8R0cRMk78vfoui 7F/RSNt8jYStAK4etYh8iSU= X-Google-Smtp-Source: ABdhPJyXGPiRK3kSpyhR6KL61u0teYkSKfkL2XAKTjzosU2gZ8Lz/nBoNiGVciQ2kf7/fPZtckPd8w== X-Received: by 2002:a63:6a03:: with SMTP id f3mr28895124pgc.618.1638961752671; Wed, 08 Dec 2021 03:09:12 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Juergen Gross , "Peter Zijlstra (Intel)" , Joerg Roedel , "Chang S. Bae" , Jan Kiszka Subject: [PATCH 08/11] x86/entry: Use idtentry macro for entry_INT80_compat Date: Wed, 8 Dec 2021 19:08:30 +0800 Message-Id: <20211208110833.65366-9-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan entry_INT80_compat is identical to idtentry macro except a special handling for %rax in the prolog. Add the prolog to idtentry and use idtentry for entry_INT80_compat. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 18 ++++++ arch/x86/entry/entry_64_compat.S | 102 ------------------------------- arch/x86/include/asm/idtentry.h | 47 ++++++++++++++ arch/x86/include/asm/proto.h | 4 -- 4 files changed, 65 insertions(+), 106 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 6100007fd03f..1fd5efaa99b3 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -371,6 +371,24 @@ SYM_CODE_START(\asmsym) pushq $-1 /* ORIG_RAX: no syscall to restart */ .endif + .if \vector == IA32_SYSCALL_VECTOR + /* + * User tracing code (ptrace or signal handlers) might assume + * that the saved RAX contains a 32-bit number when we're + * invoking a 32-bit syscall. Just in case the high bits are + * nonzero, zero-extend the syscall number. (This could almost + * certainly be deleted with no ill effects.) + */ + movl %eax, %eax + + /* + * do_int80_syscall_32() expects regs->orig_ax to be user ax, + * and regs->ax to be $-ENOSYS. + */ + movq %rax, (%rsp) + movq $-ENOSYS, %rax + .endif + .if \vector == X86_TRAP_BP /* * If coming from kernel space, create a 6-word gap to allow the diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S index 0051cf5c792d..a4fcea0cab14 100644 --- a/arch/x86/entry/entry_64_compat.S +++ b/arch/x86/entry/entry_64_compat.S @@ -311,105 +311,3 @@ sysret32_from_system_call: swapgs sysretl SYM_CODE_END(entry_SYSCALL_compat) - -/* - * 32-bit legacy system call entry. - * - * 32-bit x86 Linux system calls traditionally used the INT $0x80 - * instruction. INT $0x80 lands here. - * - * This entry point can be used by 32-bit and 64-bit programs to perform - * 32-bit system calls. Instances of INT $0x80 can be found inline in - * various programs and libraries. It is also used by the vDSO's - * __kernel_vsyscall fallback for hardware that doesn't support a faster - * entry method. Restarted 32-bit system calls also fall back to INT - * $0x80 regardless of what instruction was originally used to do the - * system call. - * - * This is considered a slow path. It is not used by most libc - * implementations on modern hardware except during process startup. - * - * Arguments: - * eax system call number - * ebx arg1 - * ecx arg2 - * edx arg3 - * esi arg4 - * edi arg5 - * ebp arg6 - */ -SYM_CODE_START(entry_INT80_compat) - UNWIND_HINT_EMPTY - /* - * Interrupts are off on entry. - */ - ASM_CLAC /* Do this early to minimize exposure */ - SWAPGS - - /* - * User tracing code (ptrace or signal handlers) might assume that - * the saved RAX contains a 32-bit number when we're invoking a 32-bit - * syscall. Just in case the high bits are nonzero, zero-extend - * the syscall number. (This could almost certainly be deleted - * with no ill effects.) - */ - movl %eax, %eax - - /* switch to thread stack expects orig_ax and rdi to be pushed */ - pushq %rax /* pt_regs->orig_ax */ - pushq %rdi /* pt_regs->di */ - - /* Need to switch before accessing the thread stack. */ - SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi - - /* In the Xen PV case we already run on the thread stack. */ - ALTERNATIVE "", "jmp .Lint80_keep_stack", X86_FEATURE_XENPV - - movq %rsp, %rdi - movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp - - pushq 6*8(%rdi) /* regs->ss */ - pushq 5*8(%rdi) /* regs->rsp */ - pushq 4*8(%rdi) /* regs->eflags */ - pushq 3*8(%rdi) /* regs->cs */ - pushq 2*8(%rdi) /* regs->ip */ - pushq 1*8(%rdi) /* regs->orig_ax */ - pushq (%rdi) /* pt_regs->di */ -.Lint80_keep_stack: - - pushq %rsi /* pt_regs->si */ - xorl %esi, %esi /* nospec si */ - pushq %rdx /* pt_regs->dx */ - xorl %edx, %edx /* nospec dx */ - pushq %rcx /* pt_regs->cx */ - xorl %ecx, %ecx /* nospec cx */ - pushq $-ENOSYS /* pt_regs->ax */ - pushq %r8 /* pt_regs->r8 */ - xorl %r8d, %r8d /* nospec r8 */ - pushq %r9 /* pt_regs->r9 */ - xorl %r9d, %r9d /* nospec r9 */ - pushq %r10 /* pt_regs->r10*/ - xorl %r10d, %r10d /* nospec r10 */ - pushq %r11 /* pt_regs->r11 */ - xorl %r11d, %r11d /* nospec r11 */ - pushq %rbx /* pt_regs->rbx */ - xorl %ebx, %ebx /* nospec rbx */ - pushq %rbp /* pt_regs->rbp */ - xorl %ebp, %ebp /* nospec rbp */ - pushq %r12 /* pt_regs->r12 */ - xorl %r12d, %r12d /* nospec r12 */ - pushq %r13 /* pt_regs->r13 */ - xorl %r13d, %r13d /* nospec r13 */ - pushq %r14 /* pt_regs->r14 */ - xorl %r14d, %r14d /* nospec r14 */ - pushq %r15 /* pt_regs->r15 */ - xorl %r15d, %r15d /* nospec r15 */ - - UNWIND_HINT_REGS - - cld - - movq %rsp, %rdi - call do_int80_syscall_32 - jmp swapgs_restore_regs_and_return_to_usermode -SYM_CODE_END(entry_INT80_compat) diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 1345088e9902..38cb2e0dc2c7 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -204,6 +204,20 @@ __visible noinstr void func(struct pt_regs *regs, \ \ static noinline void __##func(struct pt_regs *regs, u32 vector) +/** + * DECLARE_IDTENTRY_IA32_EMULATION - Declare functions for int80 + * @vector: Vector number (ignored for C) + * @asm_func: Function name of the entry point + * @cfunc: The C handler called from the ASM entry point (ignored for C) + * + * Declares two functions: + * - The ASM entry point: asm_func + * - The XEN PV trap entry point: xen_##asm_func (maybe unused) + */ +#define DECLARE_IDTENTRY_IA32_EMULATION(vector, asm_func, cfunc) \ + asmlinkage void asm_func(void); \ + asmlinkage void xen_##asm_func(void) + /** * DECLARE_IDTENTRY_SYSVEC - Declare functions for system vector entry points * @vector: Vector number (ignored for C) @@ -430,6 +444,35 @@ __visible noinstr void func(struct pt_regs *regs, \ #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ idtentry vector asm_##func func has_error_code=1 +/* + * 32-bit legacy system call entry. + * + * 32-bit x86 Linux system calls traditionally used the INT $0x80 + * instruction. INT $0x80 lands here. + * + * This entry point can be used by 32-bit and 64-bit programs to perform + * 32-bit system calls. Instances of INT $0x80 can be found inline in + * various programs and libraries. It is also used by the vDSO's + * __kernel_vsyscall fallback for hardware that doesn't support a faster + * entry method. Restarted 32-bit system calls also fall back to INT + * $0x80 regardless of what instruction was originally used to do the + * system call. + * + * This is considered a slow path. It is not used by most libc + * implementations on modern hardware except during process startup. + * + * Arguments: + * eax system call number + * ebx arg1 + * ecx arg2 + * edx arg3 + * esi arg4 + * edi arg5 + * ebp arg6 + */ +#define DECLARE_IDTENTRY_IA32_EMULATION(vector, asm_func, cfunc) \ + idtentry vector asm_func cfunc has_error_code=0 + /* Special case for 32bit IRET 'trap'. Do not emit ASM code */ #define DECLARE_IDTENTRY_SW(vector, func) @@ -631,6 +674,10 @@ DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, common_interrupt); DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, spurious_interrupt); #endif +#ifdef CONFIG_IA32_EMULATION +DECLARE_IDTENTRY_IA32_EMULATION(IA32_SYSCALL_VECTOR, entry_INT80_compat, do_int80_syscall_32); +#endif + /* System vector entry points */ #ifdef CONFIG_X86_LOCAL_APIC DECLARE_IDTENTRY_SYSVEC(ERROR_APIC_VECTOR, sysvec_error_interrupt); diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h index feed36d44d04..c4d331fe65ff 100644 --- a/arch/x86/include/asm/proto.h +++ b/arch/x86/include/asm/proto.h @@ -28,10 +28,6 @@ void entry_SYSENTER_compat(void); void __end_entry_SYSENTER_compat(void); void entry_SYSCALL_compat(void); void entry_SYSCALL_compat_safe_stack(void); -void entry_INT80_compat(void); -#ifdef CONFIG_XEN_PV -void xen_entry_INT80_compat(void); -#endif #endif void x86_configure_nx(void); From patchwork Wed Dec 8 11:08:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 107B4C433F5 for ; Wed, 8 Dec 2021 11:09:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242167.418915 (Exim 4.92) (envelope-from ) id 1muup8-0001uC-8y; Wed, 08 Dec 2021 11:09:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242167.418915; Wed, 08 Dec 2021 11:09:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muup8-0001tu-5c; Wed, 08 Dec 2021 11:09:22 +0000 Received: by outflank-mailman (input) for mailman id 242167; Wed, 08 Dec 2021 11:09:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muup7-0007Ud-Dd for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:09:21 +0000 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [2607:f8b0:4864:20::1034]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4a81ed7d-5817-11ec-9d12-4777fae47e2b; Wed, 08 Dec 2021 12:09:20 +0100 (CET) Received: by mail-pj1-x1034.google.com with SMTP id gt5so1693916pjb.1 for ; Wed, 08 Dec 2021 03:09:20 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id s15sm2665417pjs.51.2021.12.08.03.09.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:09:19 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4a81ed7d-5817-11ec-9d12-4777fae47e2b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WphTuTVslZby+oDEm50XCSesh2uHM5bzyfp9NXbgOWI=; b=htwdJLPu0gbuBqzNfz7sUj3efCTwW2LVgoh7ceQ0BMbkeYhPhXwXqOasG0Bd8RJnve XAAXE8iaSVBK6I6+t8twEOP/RHaK4mAkcL91G9J2LxApElT1FlYqrg1s/Gg2QuqLEqAt Xp4KqW62Iq1m5547lpOp1SrpBcM3mYOrFm91iX6Fb7OiOY1ScjdTivEC2Oy/lIyYlKLm gZAsMcM2ZGf8cfQoKLV6309j6vQq+DLsm0OVA24wlnmsN4Ki2w52UEmZGesy0mkRCwlx D6oBpssBTUieU9+0PWVIpucZ1qx6OzKjivCUNTWYSj2ChMJ0rvHeSI5cVlCD5IXjw/IB 1w0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WphTuTVslZby+oDEm50XCSesh2uHM5bzyfp9NXbgOWI=; b=v37213tr9wswWg62gCLkWID6Mdy3oT1EcZSpZTDzIt3QRa2LujTgOdQsl5pmXPbJwQ vV0kKdkhiCwixlGtwq7p9jvnxx5WdBFXs0JhKT7QqiFW89LddJqLBR+SDOlRDaazpt4W iJZdSPWMI+K8KpxL4RIvF298JjkbfY0WVOEPoQ1/QZXF1U/lgztS0pHb2O42DEMPs4CO ILS7UyFgNZDkYw5RPIDvIFW/8UXItZPkheSb1xJoWYOEuWwIeTpEtfwhfnNmEqvBdxGy 3VfkQPT+cvhcqlsdCcmcFKR+Dj02plcWi/AQbyKUWUrgmpTnCeivZ5cslYVX9xw7pQKe amuQ== X-Gm-Message-State: AOAM533h+kU09W9yYg6DOD8sBTqkOaWoi2iR7E1G8EiCgDMu+0//uPEX L01jru2hHdEr4e4bJplFnyhvCuhiIpQ= X-Google-Smtp-Source: ABdhPJygiu3o+VoYWbdot6ZOwAuTCklCWFi5NzkjvztY5lMtfZYeyM7huQwfqLtMKHLX/ykwc3TFVw== X-Received: by 2002:a17:90b:357:: with SMTP id fh23mr6446123pjb.238.1638961759479; Wed, 08 Dec 2021 03:09:19 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 09/11] x86/entry: Convert SWAPGS to swapgs in entry_SYSENTER_compat() Date: Wed, 8 Dec 2021 19:08:31 +0800 Message-Id: <20211208110833.65366-10-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan XENPV has its own entry point for SYSENTER, it doesn't use entry_SYSENTER_compat. So the pv-awared SWAPGS can be changed to swapgs. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64_compat.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S index a4fcea0cab14..72e017c3941f 100644 --- a/arch/x86/entry/entry_64_compat.S +++ b/arch/x86/entry/entry_64_compat.S @@ -49,7 +49,7 @@ SYM_CODE_START(entry_SYSENTER_compat) UNWIND_HINT_EMPTY /* Interrupts are off on entry. */ - SWAPGS + swapgs pushq %rax SWITCH_TO_KERNEL_CR3 scratch_reg=%rax From patchwork Wed Dec 8 11:08:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D5B2C4332F for ; Wed, 8 Dec 2021 11:17:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242199.418948 (Exim 4.92) (envelope-from ) id 1muux9-0005bK-ON; Wed, 08 Dec 2021 11:17:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242199.418948; Wed, 08 Dec 2021 11:17:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muux9-0005bD-Ji; Wed, 08 Dec 2021 11:17:39 +0000 Received: by outflank-mailman (input) for mailman id 242199; Wed, 08 Dec 2021 11:17:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muupE-0007Ud-1V for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:09:28 +0000 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [2607:f8b0:4864:20::102d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4e6e9293-5817-11ec-9d12-4777fae47e2b; Wed, 08 Dec 2021 12:09:27 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so4089251pjb.5 for ; Wed, 08 Dec 2021 03:09:27 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id e4sm2315444pgi.21.2021.12.08.03.09.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:09:25 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4e6e9293-5817-11ec-9d12-4777fae47e2b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Kd9tDbqkXgV+uDS+ZN2PkifPpO4nwWCGziDx4Ai290=; b=DZBRV+VFT9+KfIlW9vI1YNTWjjSwY9UVdpausVhNvxvTeFCAhQr4BL86f1ZVb5wqYx daMm0jsnf1EZop+hPS3Rsl+eU347P7jXAR0P3RT2+WtY7EQ2A2yWN79dg12hx04Hs3DY iR2cUpLa4sLw2jps+ZS2rPZ95nG7mTU3J1k/V23q7IYOzjDvAuCF7BShXIc9S6F75RGg tKsQ5jKl/9h3kXq8Er5D+XxIEwR7FRorkvKKVlKBNuLRh7xuwrknY5JB9iLYWlgPc5Ip brHSmlHdSmwtVh6ZsE/XtTcbGI9NZy6tbBUp6sONJacjKJ0aJI0Wz9IDXReHISQ2qhXx 46UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/Kd9tDbqkXgV+uDS+ZN2PkifPpO4nwWCGziDx4Ai290=; b=ckuCa7xf9HC2M7SwH15Lt1z8BgwaooPpW6t1czVAVVQAPj06lA66j/cuEOg0gGDiq8 qCMu924EbpK4NrVia2+RkulnNLNEmmVlIEhrZE3sfZhfYwHETvXuUEQ7fsRqFV0oXiVz Fz60KjtB3aCUkja55SN90v2hrrCWCV0inUl1cN5JkSQbFyUU0Swv5jZbJy1XcC0QJjH7 NImcJZHjnV58vbz8ejbsIh21dgPHUsDeHcVAlLoTlIKhl2/g6P8MT0Ikj7Ygk5RtYE5A KG7LyTTj4NdV5VuZV5vGY69extgE9UzIJPzAAGJwD6uR41GAhlwjxcaCQz6nxrdlRlJX ABpQ== X-Gm-Message-State: AOAM532DNMvkNCHxmy84mqytauBDn5WagnP9SatAoNoe912g8uN6bGNJ i1K7Rb/zvkyuFkgLCEvDjW8= X-Google-Smtp-Source: ABdhPJwtuS/bFQhmnmbhADvj6guciKxV5lk7NvScGFOlc2udq8C8NxlaMojhnh/rnPK9YGSNXl3k8g== X-Received: by 2002:a17:90a:e00c:: with SMTP id u12mr6251592pjy.139.1638961766047; Wed, 08 Dec 2021 03:09:26 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Juergen Gross , "Peter Zijlstra (Intel)" , "Kirill A. Shutemov" Subject: [PATCH 10/11] x86: Remove the definition of SWAPGS Date: Wed, 8 Dec 2021 19:08:32 +0800 Message-Id: <20211208110833.65366-11-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan There is no user of the pv-aware SWAPGS anymore. Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/irqflags.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h index 87761396e8cc..ac2e4cc47210 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -140,13 +140,11 @@ static __always_inline void arch_local_irq_restore(unsigned long flags) #else #ifdef CONFIG_X86_64 #ifdef CONFIG_XEN_PV -#define SWAPGS ALTERNATIVE "swapgs", "", X86_FEATURE_XENPV #define INTERRUPT_RETURN \ ANNOTATE_RETPOLINE_SAFE; \ ALTERNATIVE_TERNARY("jmp *paravirt_iret(%rip);", \ X86_FEATURE_XENPV, "jmp xen_iret;", "jmp native_iret;") #else -#define SWAPGS swapgs #define INTERRUPT_RETURN jmp native_iret #endif #endif From patchwork Wed Dec 8 11:08:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12664083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06206C433F5 for ; Wed, 8 Dec 2021 11:17:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.242194.418937 (Exim 4.92) (envelope-from ) id 1muuwv-000566-GO; Wed, 08 Dec 2021 11:17:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 242194.418937; Wed, 08 Dec 2021 11:17:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muuwv-00055z-BT; Wed, 08 Dec 2021 11:17:25 +0000 Received: by outflank-mailman (input) for mailman id 242194; Wed, 08 Dec 2021 11:17:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muupK-0006Yt-HI for xen-devel@lists.xenproject.org; Wed, 08 Dec 2021 11:09:34 +0000 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [2607:f8b0:4864:20::431]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 524ac4a9-5817-11ec-a831-37629979565c; Wed, 08 Dec 2021 12:09:33 +0100 (CET) Received: by mail-pf1-x431.google.com with SMTP id k64so2125210pfd.11 for ; Wed, 08 Dec 2021 03:09:33 -0800 (PST) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id u12sm3355395pfk.71.2021.12.08.03.09.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 03:09:32 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 524ac4a9-5817-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ZAl8F0tOkzqNpxvhUmIBbQ/2XyCnM6LrThKg9k5W8s=; b=XewnByTcwGZ5HuWSJOktdkA8rXnpKBKFuSg0cxOJL7s3BdUvTPdODuZfLIDeepUm4V +UFNS5kKkZ64h2+SLoku6yR1tR/0A+eaTTMV6wH4OAgYBCykpmcbSC84xrwGT8DK5z6I NAwcRUWRE5xi4yleywYOHQ3Z+PAuijS3/ucoUSnX0O8roEEkMd3TMCNQi4/Nee7ynLP8 YtGzd5gKmnV6H5WeuB2jtnHcA/FdVci05P8W9WFHdMj60WaDi0E67yIn6k7XYkXd2N/Q Pkh/hb3+/neA+1fwV3CX98BZZHeeXZYXum/i4O8YUwzfbt+j8AeThm8SubonZeZuOnPu cX4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2ZAl8F0tOkzqNpxvhUmIBbQ/2XyCnM6LrThKg9k5W8s=; b=kv374ynQI0pyIlCOzyxr+5oBLiXE81wJ3bq6fDQEQE8bx4Z7x6/3oe1kXlJLsYNDYH vUIH1GBIh5fqLOzVOkz0UTwlcaIHVw0evRpyesZRTBSFnQLJE1xZHgRTadlRKC7jIJx+ cMg1z2X/Lopglqqs/glVZhs09EcPmonObNrrDoIVC/wmZzlvHQVG135HuzfyirSBouEz HVEXQ42nusY3dbeBMQTla0H3PgJALnkotqOOoEOduTG/4H0GVuVGxHPbMxCqAuuAMA4v GH9SGvUev2JwlKa31yAIHvHjJszGG5jxKPxeFj2RaaP834byw/5c2r/D/CWSP+Aa853h TkRQ== X-Gm-Message-State: AOAM532T6wvRvpCrork+9Nv2pivEc6XpPv7fCgbQ9/sffqXyXIyQcG7B t6ateRPlL9gfTCBOiFxh/M0= X-Google-Smtp-Source: ABdhPJw1j8OimGYb+Vk6xtTFU75lvQF/n3cAmCvhA4Lo654aq4frrTPh1GDeEbLLUScPSozJ7D8kIA== X-Received: by 2002:a65:6a0b:: with SMTP id m11mr28632692pgu.372.1638961772554; Wed, 08 Dec 2021 03:09:32 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, xen-devel@lists.xenproject.org, Lai Jiangshan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Joerg Roedel , "Chang S. Bae" Subject: [PATCH 11/11] x86/entry: Remove the branch in sync_regs() Date: Wed, 8 Dec 2021 19:08:33 +0800 Message-Id: <20211208110833.65366-12-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211208110833.65366-1-jiangshanlai@gmail.com> References: <20211208110833.65366-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan In non-xenpv, the sp0 is the trampoline stack, and sync_regs() is called on non-xenpv only since error_entry is not called on xenpv, so the stack must be the trampoline stack or one of the IST stack and the check in sync_regs() is unneeded. Signed-off-by: Lai Jiangshan --- arch/x86/kernel/traps.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index a6c0bc9ee36f..63cdb7aedd67 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -708,13 +708,15 @@ DEFINE_IDTENTRY_RAW(exc_int3) /* * Help handler running on a per-cpu (IST or entry trampoline) stack * to switch to the normal thread stack if the interrupted code was in - * user mode. The actual stack switch is done in entry_64.S + * user mode. The actual stack switch is done in entry_64.S. It is not + * called from XENPV and the caller has ensured it is not on the thread + * stack. */ asmlinkage __visible noinstr struct pt_regs *sync_regs(struct pt_regs *eregs) { struct pt_regs *regs = (struct pt_regs *)this_cpu_read(cpu_current_top_of_stack) - 1; - if (regs != eregs) - *regs = *eregs; + + *regs = *eregs; return regs; }