Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1117234rwo; Wed, 2 Aug 2023 08:59:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlExIRyEVo0C1B6kInCz0T1x+tyoHsPGsITBj+Uqdhuw9rF5LyMKWO+TsgCjrvsl+mDWtfKE X-Received: by 2002:a05:651c:90:b0:2b9:da28:c50b with SMTP id 16-20020a05651c009000b002b9da28c50bmr5052042ljq.16.1690991963916; Wed, 02 Aug 2023 08:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690991963; cv=none; d=google.com; s=arc-20160816; b=Y/j7WpDHskIxR+67h0Mh3teTToJwN8LF4VrE7ve1GuTDsbAgBeQVhUdZMupioUq6vK 815R/Jlxjss/+DfYyAGLVRilKEcw++V+PS+QLi0aHIOYpvtUlpQZ4RokBVpg0/1DaKjp y/wtC5nom7wRPMqma9hXB4GIeYWyP+RN/zUepgA3q9dTLpxH/VjcmZW7AozS34bffzfq bl8jHOdV3neHWPkIn92LvRnyQQgBabImjv+8k+nq7lD1J3sSSwMmUu8F1kUzXZVQGWpU tgy4fJwAgdg++JQ9o758gUOLg/In+alKgVep6Q4ZFLpF9fZKNZ7yCFQ74O+0EkQ1SG+G 0a4g== 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=QW8QUAj+RhkUtt6iXvDM2oIQqHUmF22qa90GRR0nIKI=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=HeOkre5NnCavWtWcpQV2tHmGr03v1twuAER13UhIKLcLi49M73ypnvvqld+JGM4/qO D7GwNkmqlST6QzXk8BeFLRd++lV/FSbEVxZgFWy3b7gHnf1BmPs8jk+jiMFVKNYSA8/v tKhdzRXOjNjPUQ2hVZ5oYTBHYPf3fHiW4A7xBYpnLFoU6d88J4ZI65sEwJY8hkFaLkkr h4eqBbybKjWOE4wFcfGfZsV+6go0+9ER6AtsFMvYYcRyuf0BO9CncbkFB/88cw+ZX7Po y0A4MjC55dKZVqIhXQYptLMKdsqUvDcRb8IwXG6ov+Zc8WoyHUlY+6RNcqouMTdO9y9Z UagA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AM2uM0td; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ci18-20020a170906c35200b009932d8a227asi6031589ejb.277.2023.08.02.08.58.59; Wed, 02 Aug 2023 08:59:23 -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=AM2uM0td; 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 S234740AbjHBPtS (ORCPT + 99 others); Wed, 2 Aug 2023 11:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234674AbjHBPtO (ORCPT ); Wed, 2 Aug 2023 11:49:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5621E1BFD; Wed, 2 Aug 2023 08:49:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E72D361A21; Wed, 2 Aug 2023 15:49:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 701F2C433CB; Wed, 2 Aug 2023 15:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690991345; bh=rZ4dagtCLM4Dd3aSWI/Kh+e/QUOV/FZ3MiPjfd5ziT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AM2uM0tdXJjnFlCX9fmag9J8PvgeGk7XR4vtBYMCqv/NnWHytYejcIu3X7fsMIvQC HlJifk/O0xEHNuzPMtH7c7ZPhqxLUfi8tnRjPm0CJXOXkxxEcaJHcnIxZI0yrDSefL JgEZrD//cTiqULSSgvrZq0SqLL1cIuLN5sv5x62VhuNixoWajMz/2mTpaqbxBkvrvh PIQmNuucPGSTw/bO1bOjXDZR8cX9FZcb0408PL8/iKj9VD5GeZwkj7T+Jiky0nLpTT bvbMeGixKNNBylgMO5cdWuJCX/HrV1Y0rnvdJFD+FcGODPla5grgcScUPnmlvKUYmY A2cy7JudwqM8A== 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 v8 03/23] x86/efistub: Branch straight to kernel entry point from C code Date: Wed, 2 Aug 2023 17:48:11 +0200 Message-Id: <20230802154831.2147855-4-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230802154831.2147855-1-ardb@kernel.org> References: <20230802154831.2147855-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2314; i=ardb@kernel.org; h=from:subject; bh=rZ4dagtCLM4Dd3aSWI/Kh+e/QUOV/FZ3MiPjfd5ziT8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIeVU1RYVrmPHwpLuTli1USK+et5SNf9pLldVhFIapY/Pm JmmZ3awo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzEQYuR4fzcM89niCeWLzy9 +U3Xo1IFU8vFas/ubPnvt672reKWimyG/w4zFmiY9c+RmSSlu9NjyhytWakct4Xifxe67d1i3tW zlAkA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit 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 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 | 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 220be75a5cdc1f4c..40a10db2d85e7942 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, unsigned long size) #define TRAMPOLINE_PLACEMENT_BASE ((128 - 8)*1024) #define TRAMPOLINE_PLACEMENT_SIZE (640*1024 - (128 - 8)*1024) -void startup_32(struct boot_params *boot_params); +extern const u8 startup_32[], startup_64[]; 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 *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 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() instead 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; } - return bzimage_addr; + if (IS_ENABLED(CONFIG_X86_64)) + bzimage_addr += startup_64 - startup_32; + + enter_kernel(bzimage_addr, boot_params); fail: efi_err("efi_main() failed!\n"); -- 2.39.2