Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp957586rwb; Fri, 28 Jul 2023 02:27:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlFqt9XQ0uq5dJo531zrMk9THBPPvcnh5ukrpkzuqHDyXjfDe/cZ8nFaNyWWvYbkLArY8xl6 X-Received: by 2002:ac2:4f0c:0:b0:4f9:5ca5:f1a6 with SMTP id k12-20020ac24f0c000000b004f95ca5f1a6mr1834011lfr.17.1690536478818; Fri, 28 Jul 2023 02:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690536478; cv=none; d=google.com; s=arc-20160816; b=Pe1Ckdrdpn2AkYqlNfyDK6kKdhXrUWAlP78hUBp/lHJLPYxapoVnUaUWelkD9dHQuf mJ/kRpaPazQsr8d5i45ayR91ljKjOhSa/EfeYXFuaNiYwAzRRTAAAgGiYVoMs4zK3lYa 5xag9gPgKVSySNqTCcg2SVmHyXTMDDNyJOyrMkeb1YloXAc/FjCrmqjHcJTb4o7cQLA8 H3kp+WgkhPy1Eq1eMP2rPvUpSkcyrG6ZQAm3S/wzP3zKuiFfkV7QpK+175E4D99lywuq gmmwWKXfEf1SehmkQLA8is7ldBEOrG9LGz1M5R6JIRXVty+Y0j8np3djm0Ipxr7w535E Z3Fg== 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=yozfjZh1VW9LJIzbO5jL3n09WquFpLKdj78Ockuwjsg=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=Xq+WKP/jOHgIPtjLZqv8/nPJIVZC1aZXzamZEMfaGoi+3fpT8EzWafp7VgRI5knYFW ZKpSYmCjPkUQ1OtXC694DLrj35SXqN4PjacklChOS2NeAbovvu/udp4WidY6ZlujQslc rP2T2IVddu8Tp6duxwUOPeSDjrdAXyjjc4IaiGWhfNZsCYFCevY4Z2mgdQJURBtLa78l A5IOXZMdowGUxUvKwwVzuAMCdnYDei3pdWii5BoKlpzQvQklBFMoJR3+D2USfceGcrkm zaJ8KHuNOtBSBv2LKg9Hdv8e8uf3wE1Y8qZ9FhgQ51QHboP89spq4AfeFMH8pOBO8dkJ XQeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O5QYVuov; 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 l13-20020a056402028d00b0051e05fbbc31si2252108edv.56.2023.07.28.02.27.28; Fri, 28 Jul 2023 02:27:58 -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=O5QYVuov; 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 S235444AbjG1JOk (ORCPT + 99 others); Fri, 28 Jul 2023 05:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235353AbjG1JMn (ORCPT ); Fri, 28 Jul 2023 05:12:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB3023AA5; Fri, 28 Jul 2023 02:11:04 -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 8783162065; Fri, 28 Jul 2023 09:11:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38832C433C8; Fri, 28 Jul 2023 09:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690535464; bh=xUjiZ9CTB36hToIiK/jDOw5AzOSt60/p72hz0Htkw5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O5QYVuov01U/jIMdXbjCIO8LLEdSk8MDlLuwOOnRFAjdPXQK6u9SNMk6m1jxnmYtR dj7ZNHaLj5+xrrkH14OijSyOEOFx1XFCfgDA63+EyqO4IaW+TYQf7luh7Zl6KdyQov YaO5WZj9T3TrJSmwJ/s5gIgN4rBk0YkQ9RX7kEU5b2txHkWX/uKNbDHBxU5+y1m3XQ Ua4oBM1txODP4P/K8FeClVgoDUYYS5EVroT2T6Y4aKjKhwLfWdKbSaRd3ddaMlxLd3 vcwtmohVxsqcnupr3Zwo1yQGatvx0e8Oc85NQ9QcAXNgaik950bh/v3BZOBtMjux69 Y+HLZKBT7hJUQ== 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 05/22] x86/decompressor: Avoid magic offsets for EFI handover entrypoint Date: Fri, 28 Jul 2023 11:08:59 +0200 Message-Id: <20230728090916.1538550-6-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=3376; i=ardb@kernel.org; h=from:subject; bh=xUjiZ9CTB36hToIiK/jDOw5AzOSt60/p72hz0Htkw5Y=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIeVw6/J18nZ/HfJLHRd1OH9TS3DZ0nZ0R7PDo1/vhGfIq 7CvTt7ZUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACaS68fw34HzzbwXb6bPdLJZ zbBafNKEDdWXhW/M9LnAvHJa5ZUPMnsZ/vtcmJaddVb2qk9U0p9Hwt8Z//fYrbomkr/UVEe1qt9 kHhMA 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 The native 32-bit or 64-bit EFI handover protocol entrypoint offset relative to the respective startup_32/64 address is described in boot_params as handover_offset, so that the special Linux/x86 aware EFI loader can find it there. When mixed mode is enabled, this single field has to describe this offset for both the 32-bit and 64-bit entrypoints, so their respective relative offsets have to be identical. Given that startup_32 and startup_64 are 0x200 bytes apart, and the EFI handover entrypoint resides at a fixed offset, the 32-bit and 64-bit versions of those entrypoints must be exactly 0x200 bytes apart as well. Currently, hard-coded fixed offsets are used to ensure this, but it is sufficient to emit the 64-bit entrypoint 0x200 bytes after the 32-bit one, wherever it happens to reside. This allows this code (which is now EFI mixed mode specific) to be moved into efi_mixed.S and out of the startup code in head_64.S. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 20 +++++++++++++++++++- arch/x86/boot/compressed/head_64.S | 18 ------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index dcc562c8f7f35162..9308b595f6f0a5de 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -140,6 +140,16 @@ SYM_FUNC_START(__efi64_thunk) SYM_FUNC_END(__efi64_thunk) .code32 +#ifdef CONFIG_EFI_HANDOVER_PROTOCOL +SYM_FUNC_START(efi32_stub_entry) + add $0x4, %esp /* Discard return address */ + popl %ecx + popl %edx + popl %esi + jmp efi32_entry +SYM_FUNC_END(efi32_stub_entry) +#endif + /* * EFI service pointer must be in %edi. * @@ -220,7 +230,7 @@ SYM_FUNC_END(efi_enter32) * stub may still exit and return to the firmware using the Exit() EFI boot * service.] */ -SYM_FUNC_START(efi32_entry) +SYM_FUNC_START_LOCAL(efi32_entry) call 1f 1: pop %ebx @@ -320,6 +330,14 @@ SYM_FUNC_START(efi32_pe_entry) RET SYM_FUNC_END(efi32_pe_entry) +#ifdef CONFIG_EFI_HANDOVER_PROTOCOL + .org efi32_stub_entry + 0x200 + .code64 +SYM_FUNC_START_NOALIGN(efi64_stub_entry) + jmp efi_stub_entry +SYM_FUNC_END(efi64_stub_entry) +#endif + .section ".rodata" /* EFI loaded image protocol GUID */ .balign 4 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 279c2675883c6a0f..b1367f34e2881fc7 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -294,17 +294,6 @@ SYM_FUNC_START(startup_32) lret SYM_FUNC_END(startup_32) -#if IS_ENABLED(CONFIG_EFI_MIXED) && IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL) - .org 0x190 -SYM_FUNC_START(efi32_stub_entry) - add $0x4, %esp /* Discard return address */ - popl %ecx - popl %edx - popl %esi - jmp efi32_entry -SYM_FUNC_END(efi32_stub_entry) -#endif - .code64 .org 0x200 SYM_CODE_START(startup_64) @@ -534,13 +523,6 @@ trampoline_return: jmp *%rax SYM_CODE_END(startup_64) -#if IS_ENABLED(CONFIG_EFI_MIXED) && IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL) - .org 0x390 -SYM_FUNC_START(efi64_stub_entry) - jmp efi_stub_entry -SYM_FUNC_END(efi64_stub_entry) -#endif - .text SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) -- 2.39.2