From patchwork Mon May 8 07:03:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 90985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1966966vqo; Mon, 8 May 2023 00:16:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+mM579Dwmjs0iByVDNYxIKajVc2Xky3lAvF2TuuwWQ9pUFpe2LAHzJU7TzP9iKTs9O8vt X-Received: by 2002:a17:902:d4c7:b0:1a6:bc34:2ee with SMTP id o7-20020a170902d4c700b001a6bc3402eemr11269263plg.21.1683530166358; Mon, 08 May 2023 00:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683530166; cv=none; d=google.com; s=arc-20160816; b=umfGXCwzjj5i5OTSmLsfBA028Sf0XcRsuvh+blTOj7AeU/rQ3gSJ40k3JOIp4eqWSM sqggbS8HNepPbPCfbrP+NhaSOy70xm8lY36nzXe2PdWsdrhYX8tvy+0Y7KRR8+V79ExG 0pLEF9OhZvw+jObWB1sbDQzU0Dmt1IZ4vF3oN47vYqPYQJ3T7LCrn1m74zLF4WBQxm5q VV0y5X3RGxb8ycztzLOhqPyqV7DuCB6k7nfVYiD7xGHoEwqpaRIW+4R8R65AcvR2S771 qIBDCBUm84de3fUJshYkGwW5Pb2qOubEtJZ3UVzOcSYTAzU/inibQVlpsNCCLc9uNSn7 8o+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vhd7EyWJJ4Rb0UeAKGX8jfjggzmnQT1sq31Ba72S5TU=; b=H/hX//5ruyXsBsOHU/OColLiHCrBg0I9BMtryxhh/wanZez4aIchM2CSLB3TRd7zpp xjus8o7Y43jyAaPwtZvK9aD4qAw/Lly5BD1EUGPBOAhZyBcnKwJq+jOTJ37xH1FDpQ8F 0opavm/QiXFCxWYk8r+RQpBebahJNu/ZHuk/9U7jIFuvD5EeqfI0nv1MhRzFCtJE/19k Qhxta7gRRcs41/6JqHZd0nZ8FUNG/gKqnaVsqh+hGk0finnwGfONTO6s8M05nxVJ6UU6 K2yrpfcvrisHXuk3F/Yblsh3nhvxbXRbHvR5ERacM8CAkM+ZH+WLaoA4hDboAlMKnKNF 5Oyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lpAxgN8j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a170902d35300b001a656596b9esi7149650plk.608.2023.05.08.00.15.51; Mon, 08 May 2023 00:16:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lpAxgN8j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232938AbjEHHEH (ORCPT + 99 others); Mon, 8 May 2023 03:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232428AbjEHHDz (ORCPT ); Mon, 8 May 2023 03:03:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7F951A112; Mon, 8 May 2023 00:03:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7BF4561F8C; Mon, 8 May 2023 07:03:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24313C4339E; Mon, 8 May 2023 07:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683529432; bh=UygRvsEzWeCdWneVvfD1K/VpCrMByhROcGCs3aNJ6SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lpAxgN8jqzCo90JQr6MwZgUoWPmP3Kg/6DHBmLJLkpYmcJWqdRuCM2wcnmZ5RXMqG YE1Rr3N4tB85eff+lpdEJ3a8IKboGiKb1YoxKXFNbMHTCAHrzkoLr6IEpPHy5+s5Tq DTE5JB6xe/KTeqWQ70Km+Zo/QgdBWRq7OzRu9RYpsXvBCAagRq5jXtA1uBJO1g9/hY P32HfVkZLM89fFmDcjcwSGOSXoMjGT3OyBa86VrYSkChJ5lh/vxndlbWkkGXWJkhOx Y5WcKS3wYKlZQ5u0QLfr0R8C2UCAd3U03xKcCyItmw/c5meBsZJHCZuIJ0TUZiqIHL U/5K6vt3TFGvw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Linus Torvalds Subject: [PATCH v2 03/20] x86: decompressor: Call trampoline as a normal function Date: Mon, 8 May 2023 09:03:13 +0200 Message-Id: <20230508070330.582131-4-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508070330.582131-1-ardb@kernel.org> References: <20230508070330.582131-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2486; i=ardb@kernel.org; h=from:subject; bh=UygRvsEzWeCdWneVvfD1K/VpCrMByhROcGCs3aNJ6SY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISVi3hqjT1yTvBb/VbE9LOGpfbNW9DJD75bcqO0rryvO/ eMgefN0RykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIF1dGhvaPc3t2PrXfzBmQ o1u2Uu6YSaVGdOzq80v21i9d+PyBXDIjw5UvBi5rpYt5My4cyfjMHXNZ4sAJh19SxU6cKoZz0z9 1MgEA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765309327924358121?= X-GMAIL-MSGID: =?utf-8?q?1765309327924358121?= Move the long return to switch to 32-bit mode into the trampoline code so we can call it as an ordinary function. This will allow us to call it directly from C code in a subsequent patch. Signed-off-by: Ard Biesheuvel Acked-by: Kirill A. Shutemov --- arch/x86/boot/compressed/head_64.S | 25 +++++++++----------- arch/x86/boot/compressed/pgtable.h | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 59340e533dff8369..81b53b576cdd05ae 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -457,18 +457,9 @@ SYM_CODE_START(startup_64) /* Save the trampoline address in RCX */ movq %rax, %rcx - /* - * Load the address of trampoline_return() into RDI. - * It will be used by the trampoline to return to the main code. - */ - leaq trampoline_return(%rip), %rdi - - /* Switch to compatibility mode (CS.L = 0 CS.D = 1) via far return */ - pushq $__KERNEL32_CS leaq TRAMPOLINE_32BIT_CODE_OFFSET(%rax), %rax - pushq %rax - lretq -trampoline_return: + call *%rax + /* Restore the stack, the 32-bit trampoline uses its own stack */ leaq rva(boot_stack_end)(%rbx), %rsp @@ -566,16 +557,22 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) jmp *%rax SYM_FUNC_END(.Lrelocated) - .code32 /* * This is the 32-bit trampoline that will be copied over to low memory. * - * RDI contains the return address (might be above 4G). * ECX contains the base address of the trampoline memory. * Non zero RDX means trampoline needs to enable 5-level paging. */ SYM_CODE_START(trampoline_32bit_src) - /* Set up data and stack segments */ + popq %rdi + /* Switch to compatibility mode (CS.L = 0 CS.D = 1) via far return */ + pushq $__KERNEL32_CS + leaq 0f(%rip), %rax + pushq %rax + lretq + + .code32 +0: /* Set up data and stack segments */ movl $__KERNEL_DS, %eax movl %eax, %ds movl %eax, %ss diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h index cc9b2529a08634b4..91dbb99203fbce2d 100644 --- a/arch/x86/boot/compressed/pgtable.h +++ b/arch/x86/boot/compressed/pgtable.h @@ -6,7 +6,7 @@ #define TRAMPOLINE_32BIT_PGTABLE_OFFSET 0 #define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE -#define TRAMPOLINE_32BIT_CODE_SIZE 0x80 +#define TRAMPOLINE_32BIT_CODE_SIZE 0xA0 #define TRAMPOLINE_32BIT_STACK_END TRAMPOLINE_32BIT_SIZE