From patchwork Fri Jun 2 10:12:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 102453 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp926371vqr; Fri, 2 Jun 2023 03:32:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/fM69xMu+adnIv9DnMryvvyXak8d0jxtlMkM0fIJc+vOSuo9EQr08VfgBEXeiNvYDdrXY X-Received: by 2002:a05:622a:10a:b0:3f6:aff0:6dfe with SMTP id u10-20020a05622a010a00b003f6aff06dfemr13357507qtw.37.1685701939920; Fri, 02 Jun 2023 03:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685701939; cv=none; d=google.com; s=arc-20160816; b=ue5uaxGxE9cutxxCKntm1I9+cj8Cf/rc1jb/Q3iMYFycRXMAd8rNVxPb7G78fT6dag XGvZEkUgwT+TTo5PkImVJcSP2KLqPjq46BXv4/vBz8jIIvz/Fl1VYzieCD2cqLBtIrxI atRvzm+d0oV1+sJb7KILrNQITXrOVlXwfrXI2r02hxDSkQlc3GlKzrK4UaM5KhjHCZPj SUhxuKyJ//d9lWNRHFyACRcAwUXqe3xWmusdBv8KyLPk6lOj8VdbjaaFGBhmyV1TNLVN awz1z9evQnRAso2CBHINBWGhDEzQ/vNMiFwVteyaJB6vo4sRnOzP1UujyybezMwKKeLR dtCw== 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=LByMT2Ga14pQcWsADFCNUtp+CNHrRJUszQgPgjixMV5sIRKBNbaeIVRrqtRh68RFjr LXIy/YPUjC7Qb9XmRKX5FSmvV+1ld5LNMqxm5d1An27nsENeNgWZqO1fWzUUvBTXwKgy snt9czOinBrB2V8cyQPg+a1MnK4xbnhlt2Elbyq1BdN/It3qMsnOfFAlH2dJYO5ziB3u 6omNk64kIzMKy/0KZVaPNLcxUS+fVKkfOXrSFtUzRi2nBJAqvlnwc6jNowunlmcXRimF xYGjDlGx75ug/BxD7L27Ucmi8UJXJPdHkV9wKoEZ1CRvS5em2+NasJuB2FIjQZe7UpiQ p+bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K2u71tj2; 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 l62-20020a638841000000b005362a6e5395si836507pgd.229.2023.06.02.03.32.05; Fri, 02 Jun 2023 03:32:19 -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=K2u71tj2; 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 S235444AbjFBKXJ (ORCPT + 99 others); Fri, 2 Jun 2023 06:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235377AbjFBKWO (ORCPT ); Fri, 2 Jun 2023 06:22:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E5E51A7; Fri, 2 Jun 2023 03:22:12 -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 3BA4364E77; Fri, 2 Jun 2023 10:22:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC33DC433D2; Fri, 2 Jun 2023 10:22:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685701331; bh=2ugw2aI3WS8XFLpq392iX/qheNdS02iXQMzmuFjsdqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K2u71tj2CtRCMgj8JKI0rybfZ5Qn7hS9qJVCdQZcd2kt0ypXAbHBekGJyMIRwRSr1 1iQqYieUF7zYnbAlhIz+2cDP6gMjjdZRTiKVvCMH+FLd+FL/kU6avIoWPCKKEDpEXC /lXwDojb2VykTcf2Vu6lQpUVQ4A7uOIqAmO0kuhmnReuuN8rrDfKw46IcYHHRjCVyu 1C1pQZrCCOPQNwiMTbxRr+kCaxCr+HRf18Slv934O4rcNhhIIZMe/XTwBU8DuHCOTx bd/nZ0BIHtmiptb3okFsRCbflPMOLYD0oo5qEnY/rZjIhjtDXbz+PiLFuVSnvn0OMx nLx+Cq4Fiv3jA== 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 01/21] x86/efistub: Branch straight to kernel entry point from C code Date: Fri, 2 Jun 2023 12:12:53 +0200 Message-Id: <20230602101313.3557775-2-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=1778; i=ardb@kernel.org; h=from:subject; bh=2ugw2aI3WS8XFLpq392iX/qheNdS02iXQMzmuFjsdqI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIaXywIKrhi7XVpdfTgu8p1a5ddOvKrn5p+fWbTFQUbgaP PEPz4M/HaUsDGIcDLJiiiwCs/++23l6olSt8yxZmDmsTCBDGLg4BWAi+XcZGdZHROwtufPF4oSU 4hadjQKn7+TV9U/9oNL/7sHMEyWBBpEMf+XsN5qEaiwT5NSzecemE+4q/p7pTxxjUG32wqctL19 P4gQA 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?1767586597544281750?= X-GMAIL-MSGID: =?utf-8?q?1767586597544281750?= 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");