From patchwork Mon Aug 5 12:42:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11076831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE3EF18A6 for ; Mon, 5 Aug 2019 12:45:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAAC520072 for ; Mon, 5 Aug 2019 12:45:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF73828905; Mon, 5 Aug 2019 12:45:20 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B0E32860C for ; Mon, 5 Aug 2019 12:45:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hucKX-0000c9-K8; Mon, 05 Aug 2019 12:43:13 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hucKW-0000bs-Ir for xen-devel@lists.xenproject.org; Mon, 05 Aug 2019 12:43:12 +0000 X-Inumbo-ID: 95bc5cbc-b77e-11e9-a59d-033b08eeb3fc Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 95bc5cbc-b77e-11e9-a59d-033b08eeb3fc; Mon, 05 Aug 2019 12:43:11 +0000 (UTC) Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: SPjANT231gLeC0zLsrMZINjukTPdia3+ffk1aqdFLwe8lhgB3ZMtq4RkWs0OdIuFCjpSebFfnN jmuxqD3k4KvbLWQxuKGJvBx/EXwWvxqXF3ITHCshnLTiQahSt6SrJ2EWYH0AYf2Dky8YcPB5jf bwRqTatJNNuJN5AuwtG3A+dcTTtnK9w6MQMH09N8FgukaJok0zEmLVn0efhJg/bfACNPxwCNmH AWsBl3mScLdPKGuISngKMBjxSw3geRnc3vwL12qL9ZYAhn9p8Q6T466PNR1KTTeduWMCTd+Wb3 XNg= X-SBRS: 2.7 X-MesageID: 3859933 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,349,1559534400"; d="scan'208";a="3859933" From: Andrew Cooper To: Xen-devel Date: Mon, 5 Aug 2019 13:42:59 +0100 Message-ID: <20190805124301.12887-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805124301.12887-1-andrew.cooper3@citrix.com> References: <20190805124301.12887-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/4] x86/boot: Minor improvements to efi_arch_post_exit_boot() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Split up the long asm block by commenting the logical subsections. The movabs for obtaining __start_xen can be a rip-relative lea instead. This has the added advantage that objdump can now cross reference it during disassembly. The stack handing is confusing to follow. %rsp is set up by reading stack_start which is a pointer to cpu0_stack, then constructing an lret frame under %rsp (to avoid clobbering whatever is adjacent to cpu0_stack), and uses the Pascal form of lret to move %rsp to the base of cpu0_stack. Remove stack_start from the mix and use a single lea to load cpu0_stack base directly, and use the more common push/push/lretq sequence for reloading %cs. Use unreachable() rather than an infinite for loop, which lets the compiler discard all the epilogue code that it inserted previously. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné Overall, the asm block is 10 bytes shorter, not that this was the point of the change. In principle, the constraints for [cs] and [ds] could be relaxed to include "m", but Clang decided to insert 5 rip-relative memory operands for the segment loads, which isn't a clever optimisation to make. --- xen/arch/x86/efi/efi-boot.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 7a13a30bc0..2f59d8bdbd 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -249,17 +249,20 @@ static void __init noreturn efi_arch_post_exit_boot(void) "or $"__stringify(X86_CR4_PGE)", %[cr4]\n\t" "mov %[cr4], %%cr4\n\t" #endif - "movabs $__start_xen, %[rip]\n\t" + /* Load data segments. */ "lgdt gdt_descr(%%rip)\n\t" - "mov stack_start(%%rip), %%rsp\n\t" "mov %[ds], %%ss\n\t" "mov %[ds], %%ds\n\t" "mov %[ds], %%es\n\t" "mov %[ds], %%fs\n\t" "mov %[ds], %%gs\n\t" - "movl %[cs], 8(%%rsp)\n\t" - "mov %[rip], (%%rsp)\n\t" - "lretq %[stkoff]-16" + + /* Switch stack, reload %cs and jump. */ + "lea %c[stkoff] + cpu0_stack(%%rip), %%rsp\n\t" + "lea __start_xen(%%rip), %[rip]\n\t" + "push %[cs]\n\t" + "push %[rip]\n\t" + "lretq" : [rip] "=&r" (efer/* any dead 64-bit variable */), [cr4] "+&r" (cr4) : [cr3] "r" (idle_pg_table), @@ -268,7 +271,7 @@ static void __init noreturn efi_arch_post_exit_boot(void) [stkoff] "i" (STACK_SIZE - sizeof(struct cpu_info)), "D" (&mbi) : "memory" ); - for( ; ; ); /* not reached */ + unreachable(); } static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, char *section)