From patchwork Tue Aug 8 03:59:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Lutomirski X-Patchwork-Id: 9886475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F0C1360352 for ; Tue, 8 Aug 2017 04:02:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE432287A9 for ; Tue, 8 Aug 2017 04:02:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D241C287AC; Tue, 8 Aug 2017 04:02:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 09556287A9 for ; Tue, 8 Aug 2017 04:02:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1devg0-0002ml-1Y; Tue, 08 Aug 2017 03:59:28 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1devfy-0002mf-PZ for xen-devel@lists.xenproject.org; Tue, 08 Aug 2017 03:59:26 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id CF/BB-03406-E1739895; Tue, 08 Aug 2017 03:59:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRWlGSWpSXmKPExsVybKJssq6seWe kwcLdchbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8biP99ZClbLV2za4djAOF2qi5GLQ0hgFpNE 78cvbF2MnBwsAg4SeyacYuli5OBgFIiRePDDGiTMKOAvMe1NBxNImE1AXaKl0xckLCJgK7Hn1 DoWEJtZ4B+jxLneMhBbGCh+/dAqqImqEhe3fGUEsXkFQiVWzlwIVi8hIC8xsXca4wRG7gWMDK sYNYpTi8pSi3SNzPSSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxKTivWS83M3MQI9ywAEOxjPLAg 8xCjJwaQkyrtJuzNSiC8pP6UyI7E4I76oNCe1+BCjDAeHkgTvDFOgnGBRanpqRVpmDjDEYNIS HDxKIrwnQdK8xQWJucWZ6RCpU4zGHEdmbf3CxPFqwv9vTEIsefl5qVLivO0gpQIgpRmleXCDY KF/iVFWSpiXEeg0IZ6C1KLczBJU+VeM4hyMSsK8k0Gm8GTmlcDtewV0ChPQKW8SW0FOKUlESE k1MIZkaC/lW5QSHLHm17SG/o9/rVPncfod7GrMWecnPZlLd/rhC1mvf/syz57Lu3DKVKHDpiZ V5ZZ/V0+04F9yzj/vWt3XQ5eN3eVcJp65HnL17VzLqpulPVN8zn1vMU2Z29ep3aKbOO1peLtA 1GKnadKiR6+cWPt71cq/ir2Fwv13Jmfk3FDvq1diKc5INNRiLipOBACWqJlfeAIAAA== X-Env-Sender: luto@kernel.org X-Msg-Ref: server-10.tower-27.messagelabs.com!1502164764!87562398!1 X-Originating-IP: [198.145.29.99] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57967 invoked from network); 8 Aug 2017 03:59:25 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-10.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Aug 2017 03:59:25 -0000 Received: from localhost (c-71-202-137-17.hsd1.ca.comcast.net [71.202.137.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F2D422B60; Tue, 8 Aug 2017 03:59:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F2D422B60 From: Andy Lutomirski To: X86 ML , Juergen Gross Date: Mon, 7 Aug 2017 20:59:21 -0700 Message-Id: <7c88ed36805d36841ab03ec3b48b4122c4418d71.1502164668.git.luto@kernel.org> X-Mailer: git-send-email 2.13.3 Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , "H. Peter Anvin" , "xen-devel@lists.xenproject.org" , Boris Ostrovsky , Borislav Petkov Subject: [Xen-devel] [PATCH v2] x86/xen/64: Rearrange the SYSCALL entries X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Xen's raw SYSCALL entries are much less weird than native. Rather than fudging them to look like native entries, use the Xen-provided stack frame directly. This lets us eliminate entry_SYSCALL_64_after_swapgs and two uses of the SWAPGS_UNSAFE_STACK paravirt hook. The SYSENTER code would benefit from similar treatment. This makes one change to the native code path: the compat instruction that clears the high 32 bits of %rax is moved slightly later. I'd be surprised if this affects performance at all. Signed-off-by: Andy Lutomirski Reviewed-by: Juergen Gross Tested-by: Juergen Gross --- Changes from v1 (which I never actually emailed): - Fix zero-extension in the compat case. arch/x86/entry/entry_64.S | 9 ++------- arch/x86/entry/entry_64_compat.S | 7 +++---- arch/x86/xen/xen-asm_64.S | 23 +++++++++-------------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index aa58155187c5..7cee92cf807f 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -142,14 +142,8 @@ ENTRY(entry_SYSCALL_64) * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, * it is too small to ever cause noticeable irq latency. */ - SWAPGS_UNSAFE_STACK - /* - * A hypervisor implementation might want to use a label - * after the swapgs, so that it can do the swapgs - * for the guest and jump here on syscall. - */ -GLOBAL(entry_SYSCALL_64_after_swapgs) + swapgs movq %rsp, PER_CPU_VAR(rsp_scratch) movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp @@ -161,6 +155,7 @@ GLOBAL(entry_SYSCALL_64_after_swapgs) pushq %r11 /* pt_regs->flags */ pushq $__USER_CS /* pt_regs->cs */ pushq %rcx /* pt_regs->ip */ +GLOBAL(entry_SYSCALL_64_after_hwframe) pushq %rax /* pt_regs->orig_ax */ pushq %rdi /* pt_regs->di */ pushq %rsi /* pt_regs->si */ diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S index e1721dafbcb1..5314d7b8e5ad 100644 --- a/arch/x86/entry/entry_64_compat.S +++ b/arch/x86/entry/entry_64_compat.S @@ -183,21 +183,20 @@ ENDPROC(entry_SYSENTER_compat) */ ENTRY(entry_SYSCALL_compat) /* Interrupts are off on entry. */ - SWAPGS_UNSAFE_STACK + swapgs /* Stash user ESP and switch to the kernel stack. */ movl %esp, %r8d movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp - /* Zero-extending 32-bit regs, do not remove */ - movl %eax, %eax - /* Construct struct pt_regs on stack */ pushq $__USER32_DS /* pt_regs->ss */ pushq %r8 /* pt_regs->sp */ pushq %r11 /* pt_regs->flags */ pushq $__USER32_CS /* pt_regs->cs */ pushq %rcx /* pt_regs->ip */ +GLOBAL(entry_SYSCALL_compat_after_hwframe) + movl %eax, %eax /* discard orig_ax high bits */ pushq %rax /* pt_regs->orig_ax */ pushq %rdi /* pt_regs->di */ pushq %rsi /* pt_regs->si */ diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S index c3df43141e70..a8a4f4c460a6 100644 --- a/arch/x86/xen/xen-asm_64.S +++ b/arch/x86/xen/xen-asm_64.S @@ -82,34 +82,29 @@ RELOC(xen_sysret64, 1b+1) * rip * r11 * rsp->rcx - * - * In all the entrypoints, we undo all that to make it look like a - * CPU-generated syscall/sysenter and jump to the normal entrypoint. */ -.macro undo_xen_syscall - mov 0*8(%rsp), %rcx - mov 1*8(%rsp), %r11 - mov 5*8(%rsp), %rsp -.endm - /* Normal 64-bit system call target */ ENTRY(xen_syscall_target) - undo_xen_syscall - jmp entry_SYSCALL_64_after_swapgs + popq %rcx + popq %r11 + jmp entry_SYSCALL_64_after_hwframe ENDPROC(xen_syscall_target) #ifdef CONFIG_IA32_EMULATION /* 32-bit compat syscall target */ ENTRY(xen_syscall32_target) - undo_xen_syscall - jmp entry_SYSCALL_compat + popq %rcx + popq %r11 + jmp entry_SYSCALL_compat_after_hwframe ENDPROC(xen_syscall32_target) /* 32-bit compat sysenter target */ ENTRY(xen_sysenter_target) - undo_xen_syscall + mov 0*8(%rsp), %rcx + mov 1*8(%rsp), %r11 + mov 5*8(%rsp), %rsp jmp entry_SYSENTER_compat ENDPROC(xen_sysenter_target)