From patchwork Thu Mar 3 03:54:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12767000 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 B4F1FC433EF for ; Thu, 3 Mar 2022 03:54:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.282733.481541 (Exim 4.92) (envelope-from ) id 1nPcY0-0006Ae-0R; Thu, 03 Mar 2022 03:54:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 282733.481541; Thu, 03 Mar 2022 03:54:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nPcXz-0006AX-Tp; Thu, 03 Mar 2022 03:54:35 +0000 Received: by outflank-mailman (input) for mailman id 282733; Thu, 03 Mar 2022 03:54:35 +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 1nPcXy-0006AR-SR for xen-devel@lists.xenproject.org; Thu, 03 Mar 2022 03:54:35 +0000 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [2607:f8b0:4864:20::102e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a174f243-9aa5-11ec-8539-5f4723681683; Thu, 03 Mar 2022 04:54:32 +0100 (CET) Received: by mail-pj1-x102e.google.com with SMTP id k5-20020a17090a3cc500b001befa0d3102so2383137pjd.1 for ; Wed, 02 Mar 2022 19:54:31 -0800 (PST) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id mu1-20020a17090b388100b001bedddf2000sm537800pjb.14.2022.03.02.19.54.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Mar 2022 19:54:30 -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: a174f243-9aa5-11ec-8539-5f4723681683 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=V2/ej5DrRdUXhbTtL7As/s+7H+Hg/qh6D0nKyde9b4I=; b=Cf6C+jFzvaQJqp+87aHDyXKn1AnopM3mxsZXXVve5nRwKAHyoEW6RWZ82BxB1/MpAs YBeLSbTIABdPihhCBaQaZsH8HO4BpyuxMiloaRGq75Q5JXATrMsGuFrephWtRRSjs0d0 AP8Ob0+dxLcisk1yC6u47FptP4V+sB38bpPne1a+RruGrkn+5HAvkGofli4prSWlKBOk VY/TjCZNnz8fjIVkgNqx9yrwJT2Df9mWqoPIpIhEMtK4vr/RX1QVkozI+4TLCweH6z0C 6S5+8I7OuILJGTyjV4G8zHIXKeFnGVL+oaiF5ViG74XDU5C/o5tq6C3NiluQPvx+9TjH 10+Q== 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=V2/ej5DrRdUXhbTtL7As/s+7H+Hg/qh6D0nKyde9b4I=; b=c6uSIUARr3PpdfesYws6uJOnwhLcFMuoNilyjTXivDvypdhrCR33Ij+NUTwpfPPC5b 7I7X1oiNnRD2D0JDmZb8Dme7KqBQkALJZZwSWHUOXv+Kc1qAXiuVCkEY64HJ2NR6idMO ZRT/qb4pWq9MTVfdNsHQsypIfMfTchX9TV4Ug0fyRPOIQWkLzeS77R/7IY/nw48RLKDe v1k7KOt3jdFpf+fG54px2orCFdd60iInDoC/zJLOlxbBKGOOzTqlDdPC8DA8pQTp7JyO lChztkutO+nu84eQx+4XV9ieAFnxigXfpKdEUoBqxoggpcuB+sdHpHYlYfQfizJU8Kd6 pUrQ== X-Gm-Message-State: AOAM531Av+6dgPTD9G0JidMbxfXIfIRVZ0Pa7gYr+JWlbzh4NZXR/9v4 cCVo99Pzt6slsGlyImMvMik= X-Google-Smtp-Source: ABdhPJwMqYGzS+07MgSD+XrJLZC6tb4GmJcD1c0Voe27uz+8Clqe4zPHlwkCb0iXztvSKqT4uzsfvw== X-Received: by 2002:a17:902:e945:b0:14e:b8d9:aa07 with SMTP id b5-20020a170902e94500b0014eb8d9aa07mr33517195pll.163.1646279670545; Wed, 02 Mar 2022 19:54:30 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Lai Jiangshan , xen-devel@lists.xenproject.org, Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH V2 5/7] x86/entry: Don't call error_entry for XENPV Date: Thu, 3 Mar 2022 11:54:32 +0800 Message-Id: <20220303035434.20471-6-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20220303035434.20471-1-jiangshanlai@gmail.com> References: <20220303035434.20471-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. Cc: xen-devel@lists.xenproject.org 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 630bf8164a09..adc9f7619d1b 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 Thu Mar 3 03:54:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12767001 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 3A965C433F5 for ; Thu, 3 Mar 2022 03:55:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.282734.481552 (Exim 4.92) (envelope-from ) id 1nPcYE-0006Uf-8P; Thu, 03 Mar 2022 03:54:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 282734.481552; Thu, 03 Mar 2022 03:54:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nPcYE-0006UY-5I; Thu, 03 Mar 2022 03:54:50 +0000 Received: by outflank-mailman (input) for mailman id 282734; Thu, 03 Mar 2022 03:54:49 +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 1nPcYD-0006U6-Ej for xen-devel@lists.xenproject.org; Thu, 03 Mar 2022 03:54:49 +0000 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [2607:f8b0:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ab1d001e-9aa5-11ec-8eba-a37418f5ba1a; Thu, 03 Mar 2022 04:54:48 +0100 (CET) Received: by mail-pg1-x52e.google.com with SMTP id w37so3419279pga.7 for ; Wed, 02 Mar 2022 19:54:48 -0800 (PST) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id u9-20020a17090a450900b001b9b5ca299esm6563740pjg.54.2022.03.02.19.54.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Mar 2022 19:54:46 -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: ab1d001e-9aa5-11ec-8eba-a37418f5ba1a 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=AOa0Ei1g6e4VlPBDw15RL007lSMOSrMvUzhJPGj9XAI=; b=eCXzMPrvm0QclKJ/8ESlhGV7ol/xxd0jxpeS+MvgphVnb3ojFQ+gK3KpzVzxxo+qxL bSwolL7L4dDMj29c6jcEc1th4JLA9CD7t1+M9csTffdIwf8P2wU9ny44rUGuPNQniOI1 pnMvB/X0OUgGWfcOq34wjA3TelHnDUsNdSgJySjD8a/FFtMMAYcsRWDohcAX9uOVozdE QrdI+LUylMbE4ZX7ar5lagHtuezvvHoHZ3nhwbj9fTS2Y5BS9QJyh0TX3yGTc18iUKBh 5WIINkssRb+sUqfobVqg4UU1pYTHt8iJmT0HEoIu94SMlrTbnDDdR9kGa4WLB7noP1qy HDTA== 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=AOa0Ei1g6e4VlPBDw15RL007lSMOSrMvUzhJPGj9XAI=; b=hSLXxBw3Rpd9h9BO89ImV38vboK6TS0UPI+K87bMh/U5BHTA/JPfv0Cit9dxCeh3qz 3t6IsX9krF6bxLMB61r4z09rHkgvxjVyt0rR971U1qx63tOyHjI1v9/3v9qXhgyuBOlr nARkMqLmdCk18O2E/o4QUpf04Eymi5GxBmM9Ft2k5bRCPs7swd0qnt2kVUez+Uriyh/C /SBj6JvTHEa1N9YHZ9cYzWhpDseapARrrIX/4Etcz49j0bEWA8OG6UICySXHriOClEQG CpuOlwibxOQJQxkob6YYxuYSbbz2wrxgw3zWHvMLgR/zJcdi41XHkuquyYRDW9Svyp9o kbIw== X-Gm-Message-State: AOAM532yhGiS2hFJev2kcpBfJ0XopBFi8TmT2x47ReBo5DXy0Y3SYwQd Sb/iF13Xk36JwXjeSei4Skc= X-Google-Smtp-Source: ABdhPJwuPPW+OW04xR5tRD6ZiwBqHBvxNWZMWDjet+tD/wstzrZ9p5WcmL5uWKiurXsOsVmlNtqIuQ== X-Received: by 2002:a63:6b42:0:b0:37c:4e5c:a903 with SMTP id g63-20020a636b42000000b0037c4e5ca903mr2183734pgc.463.1646279686726; Wed, 02 Mar 2022 19:54:46 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Lai Jiangshan , xen-devel@lists.xenproject.org, Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Juergen Gross , "Peter Zijlstra (Intel)" , "Kirill A. Shutemov" Subject: [PATCH V2 7/7] x86/entry: Convert SWAPGS to swapgs and remove the definition of SWAPGS Date: Thu, 3 Mar 2022 11:54:34 +0800 Message-Id: <20220303035434.20471-8-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20220303035434.20471-1-jiangshanlai@gmail.com> References: <20220303035434.20471-1-jiangshanlai@gmail.com> MIME-Version: 1.0 From: Lai Jiangshan XENPV doesn't use swapgs_restore_regs_and_return_to_usermode(), error_entry() and entry_SYSENTER_compat(), so the PV-awared SWAPGS in them can be changed to swapgs. There is no user of the SWAPGS anymore after this change. The INTERRUPT_RETURN in swapgs_restore_regs_and_return_to_usermode() is also converted. Cc: xen-devel@lists.xenproject.org Reviewed-by: Juergen Gross Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 10 +++++----- arch/x86/entry/entry_64_compat.S | 2 +- arch/x86/include/asm/irqflags.h | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 88b61f310289..d9c885400034 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -644,8 +644,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) @@ -1007,7 +1007,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 @@ -1039,7 +1039,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 @@ -1060,7 +1060,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 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 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