From nobody Thu Sep 11 21:17:48 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00BF4C41513 for ; Tue, 8 Aug 2023 16:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232830AbjHHQcv (ORCPT ); Tue, 8 Aug 2023 12:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232804AbjHHQbN (ORCPT ); Tue, 8 Aug 2023 12:31:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0E221395E; Tue, 8 Aug 2023 08:51:43 -0700 (PDT) Date: Tue, 08 Aug 2023 08:44:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691484246; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FdDYtj/PJTr7QNgxSySfERBaEeNWE+ml2AZNGkpXbs=; b=ex4e7Eltn1BuyK7KcsAk2jqK1UANcMjkFY9c4723AIBVHfksLOnOsonUQZcHDNuX7wPfYL xcHHxVGCDH2ZcYYCnHmqlP4zfqfCcnWQyBkHgGIVmseRLc1MdzH3HFtmQya3jgh5OGur6S W9XkqG+xrYlWFUWGKIO36Y8NpqF2rgKwAaeYmBXg/TOUTo72HB3/PfS1doA/K5oWa0smXx c6oZjCsbIqVVI5EC79lE3KcP1+yZ6CZKjc1I+U3NXMAPi4/x5HQgsBJs1dP/SJGyo2RmOZ BCG+HLow7lA507/mQUFystNS82WSeTeYz9jUoOw5VJCGHGEeNtMsg8PmUKXolw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691484246; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4FdDYtj/PJTr7QNgxSySfERBaEeNWE+ml2AZNGkpXbs=; b=FPz1UJY9TaCx3LFikMhIFzIAtmDjHI1DOdzf5piECiKyMaG0HAyfsSO2qaffF52WjeTXbz fYyQIreY85oOE+DA== From: "tip-bot2 for Ard Biesheuvel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/efistub: Branch straight to kernel entry point from C code Cc: Ard Biesheuvel , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230807162720.545787-4-ardb@kernel.org> References: <20230807162720.545787-4-ardb@kernel.org> MIME-Version: 1.0 Message-ID: <169148424606.27769.13302670504473669940.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/boot branch of tip: Commit-ID: d2d7a54f69b67cd0a30e0ebb5307cb2de625baac Gitweb: https://git.kernel.org/tip/d2d7a54f69b67cd0a30e0ebb5307cb2de= 625baac Author: Ard Biesheuvel AuthorDate: Mon, 07 Aug 2023 18:27:00 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 07 Aug 2023 20:36:06 +02:00 x86/efistub: Branch straight to kernel entry point from C code 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 Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20230807162720.545787-4-ardb@kernel.org --- drivers/firmware/efi/libstub/x86-stub.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index 220be75..40a10db 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -290,7 +290,7 @@ adjust_memory_range_protection(unsigned long start, uns= igned long size) #define TRAMPOLINE_PLACEMENT_BASE ((128 - 8)*1024) #define TRAMPOLINE_PLACEMENT_SIZE (640*1024 - (128 - 8)*1024) =20 -void startup_32(struct boot_params *boot_params); +extern const u8 startup_32[], startup_64[]; =20 static void setup_memory_protection(unsigned long image_base, unsigned long image_size) @@ -803,10 +803,19 @@ static efi_status_t exit_boot(struct boot_params *boo= t_params, void *handle) return EFI_SUCCESS; } =20 +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 failure, we exit to the firmware via efi_exit instead of returning. + * On success, this routine will jump to the relocated image directly and = never + * return. On failure, it will exit to the firmware via efi_exit() instea= d of + * returning. */ asmlinkage unsigned long efi_main(efi_handle_t handle, efi_system_table_t *sys_table_arg, @@ -950,7 +959,10 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, goto fail; } =20 - return bzimage_addr; + if (IS_ENABLED(CONFIG_X86_64)) + bzimage_addr +=3D startup_64 - startup_32; + + enter_kernel(bzimage_addr, boot_params); fail: efi_err("efi_main() failed!\n");