From patchwork Tue Aug 8 08:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 132762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2332103vqr; Tue, 8 Aug 2023 12:01:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6TYQhZDWawRQxsbu+EzuaCcE7y0hCVw4NQKJNRZhmYYi5DbfM/iLNK/xZKyPwVmHdQRPE X-Received: by 2002:a5d:53cf:0:b0:313:e8bf:a6e with SMTP id a15-20020a5d53cf000000b00313e8bf0a6emr211352wrw.21.1691521298737; Tue, 08 Aug 2023 12:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691521298; cv=none; d=google.com; s=arc-20160816; b=iS8OAZga4++W/lUzmL/ij0LdnSkDN5cOJP7bTZlMWBl4SWsn3r/OIdsf+P4M+fdpu/ vKGavMUjXSCksoi3QdK+POtdANJ3akNPRXUpKxjn8rnC3wKwKP35/59Iagc2A8KALipn 5xyvTwnjCGxGBRngWjaeSNkJbZVKnr0w4lyjCcc8OORdLsnLhh0CroFAZ084HBabApVi 9QgRWjJYv82JaS8OO8+ge0FyEp3STNWJaLJd3oQBOlZFE6Le70QJo5v2nw0DEq+Yn+AI sqb+/3rLGg8kklN6Q90TNElOXZuTo1Yv4zmGU8pjsIJkpyTrX2LS+O51kpVGLwjUYelo 134A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=4FdDYtj/PJTr7QNgxSySfERBaEeNWE+ml2AZNGkpXbs=; fh=upm4t26Ojn/J6N+Q9k8Qqzx52VymNDAlYlARzLeNh5s=; b=ACS8G7WA7yZBCSzVEYSJ8xrMM1RABhCpasusJRp/rQNKiQZyIfgHZCkCNDE0SuquDv vV2/maAXTbeU0/2oEk6rrjMRNTDLAyX1nh82RK9ocB1h9A9BRXxgtbBfI3yxGMP3TPtj Im6l/ya6J+pZrlaI0ewnOqJel0YIBJZIhfU3okLAbw3+iCos3wSSNz07YpoRjP4LUjcX 1VpyZGFRzLSy7XHmjkVyiEp2eMrgztO2WM6XWDl49lMIXEof84McCOh0W5Iw6uZIzi1Q gcT6YpCkaemDmBNVM6WqrJhRAXnEHwPOL6IwJ+Wkv/3VeI+LtxIl7dS8ZI8ObVyH8/9t +0NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ex4e7Elt; dkim=neutral (no key) header.i=@linutronix.de header.b=FPz1UJY9; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq21-20020a170906d0d500b0099304c10fd0si8149772ejb.991.2023.08.08.12.00.59; Tue, 08 Aug 2023 12:01:38 -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=@linutronix.de header.s=2020 header.b=ex4e7Elt; dkim=neutral (no key) header.i=@linutronix.de header.b=FPz1UJY9; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232825AbjHHQcv (ORCPT + 99 others); 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 X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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: INBOX X-GMAIL-THRID: 1773590049956332506 X-GMAIL-MSGID: 1773688637317843360 The following commit has been merged into the x86/boot branch of tip: Commit-ID: d2d7a54f69b67cd0a30e0ebb5307cb2de625baac Gitweb: https://git.kernel.org/tip/d2d7a54f69b67cd0a30e0ebb5307cb2de625baac 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, 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");