From patchwork Fri Jun 2 10:12:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 102455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp926477vqr; Fri, 2 Jun 2023 03:32:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mSGcnEGf3RwbDXWnWwfwXRw4f9ZC8f7o6p6p1OC7StLXpSBjiGVGI+a5MbgzTaNZeE+Hn X-Received: by 2002:a05:6a20:4283:b0:10c:90ac:442d with SMTP id o3-20020a056a20428300b0010c90ac442dmr9651776pzj.13.1685701952390; Fri, 02 Jun 2023 03:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685701952; cv=none; d=google.com; s=arc-20160816; b=L8zq2DpBUaRt2NR7hSvqAKDfiYpOjltVa1/60f7SxsI3XjD3SvgkylunjLRhUiaEir JKmClT5yYb7UjOkRoLxXtxFy58KBerTncrYxzvtWCWt95QTtjyNji+qEnMhR1NQFayir sxZlLSwKRJRJ4UqQf7c6VlgtdUEaox5d65zQIXAe+/gdQkuwMv0muhPDIYYHAu5+f0G2 47bCLc/ZF2WrFvnE9rYJM5lBTtGC0gxws590/Gaktw9isG0k64fs1UyLPCH0xik9OvZs iwSirFIvAuVmngeexbpaNuJ8wCXaDUErb4MPHApKzeuLo6oN5xzWjNJkSKW9Fv3+Tc3O 48Tw== 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=sQZhXDdW/Pt1TLOgC10hAFzrGwzWSSI2c8Hy68wku88=; b=dfIyqhOb7xf8N5XiHsGyoHbjNZEjXtjY43Vc5GxaUxuEQamaGxBCYutnqGKVNL34k8 ffz9Wnnjc649iSL5DPTv6mQIL316IkMtSQHn75uiKtMSmLz6jnRKLfebXPHYrSdmRFhM SBLRZCVLfORFG/psETx5mrLqJy8IorZfGdjPURlh3lIEWON0+Rnf1XRa5BRJpPuqYkz+ 6fEkXnmTGbgB700P8Nt8sUq4w6pt3J38YYt6H3FIfYOdmRoid8m7hiAaWA/mQeko04od hNUrWmoCsUvEJTemxptZX3qtZTFG7uGDDCtz1zsIXcek72HIPGFzFf54i9BrcjYcaZjW BqnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="geZ/QPOO"; 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 w4-20020a170902904400b001b18ec6ddfcsi678816plz.294.2023.06.02.03.32.10; Fri, 02 Jun 2023 03:32:32 -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="geZ/QPOO"; 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 S235414AbjFBKXr (ORCPT + 99 others); Fri, 2 Jun 2023 06:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235275AbjFBKWt (ORCPT ); Fri, 2 Jun 2023 06:22:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F215210C6; Fri, 2 Jun 2023 03:22:38 -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 7FC7D64E4E; Fri, 2 Jun 2023 10:22:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06598C4339E; Fri, 2 Jun 2023 10:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685701357; bh=4Bh3UcI6mBb60v5tgLvoAeGffUld7BrhFCXiRmmP3sE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=geZ/QPOOKIpEeGzmFOkHVZ1D8zL1xKTkxEVDKssO4q1c7HqrdjTON3rt+Sy2PqtCf stx9KDftl3r7NLYiVvEpL09K/njN+Qzhbm2tULVn0cXX1TuVTDfKbJ9zPDUwfA8juj ruitBx7gywBEfdCqPDTFyRGMeyYNR46Hfra1dOBGlQKdPaTso0QAcaXZaB92/mPq5K CtdM5lhmpSUQ1tkgeYaGjmIaXhTPPZX28lS2hJWAPXrKAome8t/GVxwW5u4qWCfEPB j2oFsEB08YZWTlbx52KXqF5ZLw70By4GIYoqQN3XpqiTB3/tTdAlMSQXr2+Gnb15ll fILd++h7RhN2A== 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 , Joerg Roedel Subject: [PATCH v4 07/21] x86/decompressor: Call trampoline as a normal function Date: Fri, 2 Jun 2023 12:12:59 +0200 Message-Id: <20230602101313.3557775-8-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230602101313.3557775-1-ardb@kernel.org> References: <20230602101313.3557775-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2554; i=ardb@kernel.org; h=from:subject; bh=4Bh3UcI6mBb60v5tgLvoAeGffUld7BrhFCXiRmmP3sE=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIaXywIrLdwW/ut2TuTv3OdMUt6AgAyV9Lx3bgpTZ36+3b mVxKwnpKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABO5YM3wV/yCv0jOD32zyzGW NT//+SmuNHt0vb6u+Iz0LY8dEzL3xzMyLJxyS/unhU/uq1VyDMvSQ10nTAj75LBjX1Ifk/uLmqL NXAA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1767586610357133081?= X-GMAIL-MSGID: =?utf-8?q?1767586610357133081?= Move the long return to switch to 32-bit mode into the trampoline code so it can be called as an ordinary function. This will allow it to be called directly from C code in a subsequent patch. Acked-by: Kirill A. Shutemov Signed-off-by: Ard Biesheuvel --- 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 2d1b0ee94929f7ec..af45ddd8297a4a07 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -446,18 +446,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 @@ -540,16 +531,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