From patchwork Mon May 22 07:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 97129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1272522vqo; Mon, 22 May 2023 00:45:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7zC7z2yDjpxYzA+C5Uu2bA4Lc7j0otViOzYgu1Cgg+Eb+dxB1+nmB4uUeboaNvTTZ0dG46 X-Received: by 2002:a05:6a20:3c91:b0:100:ed92:7d4d with SMTP id b17-20020a056a203c9100b00100ed927d4dmr11526250pzj.31.1684741526066; Mon, 22 May 2023 00:45:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684741526; cv=none; d=google.com; s=arc-20160816; b=IyLn1lFY1rQ7ZOL3CyK6s1DllP+FWG/CSNAPtqqpO0QlbbJlmK6y+lykUGNEBUivUo DZi0X6albSWCG+L0X4DcGcFvBf5x/9zGkjWV6su1gVMHkloosFtvBRBkUvJz5AEq8Bl6 PK4hkrKyH5NIUuY/F6z+EPXVvjW2cbbJYGRaM69sC6hw0G5vrutmimdQk/uemxYhyxeB cswAKhbTq/j+vuwM6aXVkv4d5mmwIY+Z1QSfnHIEQiDpAnqUIAta0uF5GtDlD3rumvoI XU3vH746o72SynVewaxJqoiLUyZMUG31dCtEtO1ob8YoI9gLgMlAWMzAzlpoo46g3ku/ LVbQ== 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=KeTPHj+I1fYwbE5NTuxo0fAziTIJ76oBXolfyY/XHLA=; b=JoXbh8wUwhvNhi1cbFRwwYacS2Ks9FH9JHTDIOvd58B7npnp9JIzF1Ow5UxlnLgzDi YE4bSJN66I+CgNG//EBvoDMHBRT6a7hY9e66zO2Ft3K1Yn7Bhfe5rn8N4Rdqu+vPAQbY V8PEhU7T4zc4SyBM9G4I3PXAWohRM2/UHB7JKPfBNjjTVI4POaecKgY6ambI3Ptv361/ fOD/LhEAUgTkRNZGuAycNrXzunHshNYje4ZfGVjSfB8BKXomIr8KpwvzIccUojjCbni2 SaCKHI0nO3K+SEm4cifRNQ/P7IALZe3Z5bbUtruw2Gbd9fsd4PJPQBMBNXi9ECfloCBL Wo0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cbZw27Yc; 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 i1-20020a639d01000000b005348464b81fsi2873837pgd.371.2023.05.22.00.45.13; Mon, 22 May 2023 00:45:26 -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=cbZw27Yc; 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 S232427AbjEVHPZ (ORCPT + 99 others); Mon, 22 May 2023 03:15:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232424AbjEVHOn (ORCPT ); Mon, 22 May 2023 03:14:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CA6E18C; Mon, 22 May 2023 00:14:39 -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 BCE5361DD9; Mon, 22 May 2023 07:14:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73E98C433A0; Mon, 22 May 2023 07:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684739678; bh=2ugw2aI3WS8XFLpq392iX/qheNdS02iXQMzmuFjsdqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cbZw27Ycs8S+dDX/2VuheOzDlMUCm1wZOt8RUWc+IP8kxfzR0U8iXHqIVeqhkLUxG Nc0gfiw/AyKvGwZ7GqUR5xZGagAdlZ22F1cnAEMSYtFyDHtm/v7hiiS0iN8un0pdtO HoBM0vU7Bm42jdFt/bhGATlwG4su4IXa1/sOpUtd6v5O1t5hCqc7Ni0dmgQoH2Jw1k iHKngvdziAtkRsHDHKFs8OBG6f+B5juNfs3HASC5cyc0q12eeQbqTVLnFjdgIVY2Kv /s5lMfZ1QfKHUDikhqjLfI5HlsxDlUIWc/nixFPhRgD20b0oiS+FucfaXTc4VLUpV5 6WZ2RRyFlyMAg== 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 v3 01/21] x86/efistub: Branch straight to kernel entry point from C code Date: Mon, 22 May 2023 09:13:55 +0200 Message-Id: <20230522071415.501717-2-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230522071415.501717-1-ardb@kernel.org> References: <20230522071415.501717-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1778; i=ardb@kernel.org; h=from:subject; bh=2ugw2aI3WS8XFLpq392iX/qheNdS02iXQMzmuFjsdqI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISVbTO+qocu11eWX0wLvqVVu3fSrSm7+6bl1WwxUFK4GT /zD8+BPRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjI/3ZGhq/ibDHmCYkrn+04 sDIi54ll3wfl0upKb/7r/Ld+rZgaXMfIMEH0pLX0TbWQuFm+F65WlXB2dixbmH9l1dPK2S9ZPrE Y8AAA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 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?1766579530789387476?= X-GMAIL-MSGID: =?utf-8?q?1766579530789387476?= Instead of returning to the calling code in assembler that does nothing more than perform an indirect call with the boot_params pointer in register ESI/RSI, perform the jump directly from the EFI stub C code. This will allow the asm entrypoint code to be dropped entirely in subsequent patches. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/x86-stub.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 8d17cee8b98e1a63..095aaa8b0ee30fb9 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -769,9 +769,17 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle) return EFI_SUCCESS; } +static void __noreturn enter_kernel(unsigned long kernel_addr, + struct boot_params *boot_params) +{ + /* enter decompressed kernel with boot_params pointer in RSI/ESI */ + asm("jmp *%0"::"r"(kernel_addr), "S"(boot_params)); + + unreachable(); +} + /* - * On success, we return the address of startup_32, which has potentially been - * relocated by efi_relocate_kernel. + * On success, we jump to the relocated kernel directly and never return. * On failure, we exit to the firmware via efi_exit instead of returning. */ asmlinkage unsigned long efi_main(efi_handle_t handle, @@ -914,7 +922,11 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, goto fail; } - return bzimage_addr; + if (IS_ENABLED(CONFIG_X86_64)) + /* add offset of startup_64() */ + bzimage_addr += 0x200; + + enter_kernel(bzimage_addr, boot_params); fail: efi_err("efi_main() failed!\n");