Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp956522rwb; Fri, 28 Jul 2023 02:26:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlHBK90vnCtuWe5FDdw0ucwIN2JovlphFqbYaxJfG5R9WOGZL47y9/SFlg9oaP3KaC87CCzN X-Received: by 2002:a05:6402:219:b0:522:2c36:4c59 with SMTP id t25-20020a056402021900b005222c364c59mr1401019edv.4.1690536401770; Fri, 28 Jul 2023 02:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690536401; cv=none; d=google.com; s=arc-20160816; b=pwGrYdLOPlU5FFBekJ3hBkMVYFJINiUG770DuVYNM90s4eskXF6N/IrB8ZBIecj/7q 7LRHpJi7M5aBrHi8TiWSu87Nr1CJ6qP9u6IYnSSPHLkNUvYxIqjZ7g0jyf1jUXofrJCT Hy4QLXu8qJNDGWFY3Fbw5IESLIE+X0dcX0Wuaba8BpAgcAGpWY7xOmLYi87somiPi1lg NIVyTuFz1YJVaLpd1tHVFK1ba3MNPezDeAqbiapHw1TYT7U/++/KBseW9Eb2xQn5ZPxA 2QlYFhbr4QNKvQumYzmxgW4+aY+6uaVLacXBQE6ssvfNmd3KTTEflhr3mOOeCnate7B9 Lxpg== 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=xR2HOf6GeBCw2JCfm2++uf8C3R9G5WCemKhaXpDO69Q=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=FtMPukgf+5Y7I4m7W0K+PEiuU02wxgRJZ3ZopOjg6KdlwAoNVcSkSfzeDZMdn+d7dh mqU5CkkQgAr4QL6zWocRSQxwoi4tE/4ey2KfjlbX9qtu9DXF7VBEV0zaACr/ANv+V6Uw UIPWFVTWI76nBNR1RSvQbw3qe7NzHIDvdeFc74IwaeC2A70XeM318vP0NceDAlJyT6wo lB2H4cY+EVTqDknrsKLuvxB56XE+ieGTXJ+hfvJ6XOnwxLkeTAUKMbBC4uCq7eoZoJ4d Mfo8xaPHh0B8gW+JBawOj9FivHwitk3IbxrY8w3jxrLc96XD6f1cS68Fw5Sqw+Vsotm0 yMng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NmWI9oIl; 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 b15-20020aa7cd0f000000b005227e4f12fdsi2312919edw.237.2023.07.28.02.26.16; Fri, 28 Jul 2023 02:26:41 -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=NmWI9oIl; 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 S235221AbjG1JOO (ORCPT + 99 others); Fri, 28 Jul 2023 05:14:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235349AbjG1JMm (ORCPT ); Fri, 28 Jul 2023 05:12:42 -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 AB60A3A9F; Fri, 28 Jul 2023 02:10:56 -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 292BC62065; Fri, 28 Jul 2023 09:10:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE4D7C433CB; Fri, 28 Jul 2023 09:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690535455; bh=cnIFjVPlRuij4fslmOFx/et3lCiQLNIXYxYzvqFRV/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NmWI9oIl2fQVGb+U5t+NW5jpiJ5DOuC+pIcrCgc50GOPoau92ZulpPKdo58Cz/MgC J6x77G2hDLaEkKh66x/DjEs/UTMb8HH32I0I+pKjW9Sz0ZO4eK5XZ++zSAsPSp1ke6 AxqyN/XliTjZ6oCfQzoR3XisdC5cIdEai2hR7tiTcoT7+WAciCXVblh70gn9qGJGw3 guL823nc4GDMH3dbrAsB+r5AblCqoLmKXIHsoC3M43u+saU7DJ78PgPxnUofuPzGzR XQ5nLmbBfFRkZKB7b9FCgjsqtgqRXFo9+GbgJkkG05ZkqA/AvQC5/mcUvXXVJf8lth SSwrqiUUkMp4Q== 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 v7 03/22] x86/efistub: Branch straight to kernel entry point from C code Date: Fri, 28 Jul 2023 11:08:57 +0200 Message-Id: <20230728090916.1538550-4-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230728090916.1538550-1-ardb@kernel.org> References: <20230728090916.1538550-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2316; i=ardb@kernel.org; h=from:subject; bh=cnIFjVPlRuij4fslmOFx/et3lCiQLNIXYxYzvqFRV/o=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIeVw6xIzkcU6N3d885t/yXpv6mHmaUYrs3U5Pxr/2idrb +vJF8DVUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZS+YiRYVoxv4LxGf65tXzL He6kZNT8llwT/0eStUaKp0UzVq85ieGfzu48o0/6j+Q1/9gbPvzC7T/Hu5d36X3e+zNiZS7zrWf mBwA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit 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 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..09c4210e4ef33864 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 char 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