From patchwork Wed Jan 8 18:22:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 855775 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4803F201016 for ; Wed, 8 Jan 2025 18:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360567; cv=none; b=CipuvMTfoEMWN5CkKepwiA0CUE9PN92rSTG279/lv4Yum01fiY6uYoPPxNzkehdpO35apLeGWfVzfOZAeQINLrbKnDPhpRy+E3nJObpd6Dv/+DdtOGO6lhAunSMwBeXEuS1ny6rnimlUJSfcJRTGFDV+b3M5Cz305F3f/ybo0gU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360567; c=relaxed/simple; bh=c5n7Z3abIRGd7MR68fFwDHml88PuxivLHK+FOz6bahM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kcVFP7FEBOEG/DElO+Ue5mhAfYACjzb7ZnzT3zbJNiyFFJy9WXdZyPxU6FKYpvXh8cXAoMRSnAOweeGPcz3unA8szYl7zA+EU8v+BglSqOj0/x31l/stqZoOZ8VDslqb1DoJla+df+AaDOXXP2+mzGA1N+0wqerWE8RppoHmewg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jix/gzmO; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jix/gzmO" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4361a8fc3bdso573445e9.2 for ; Wed, 08 Jan 2025 10:22:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736360564; x=1736965364; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4jijnO+/vwt5TKuw0t4KuJDIurPSMvqe04KWFl33HmU=; b=Jix/gzmOF/k5t27gD4BEi1xuaarf/ehlgq2U63/ZO7KOmkwnQar1IlDNk5EXhhiIGW 3/LzkwjlFMoiV8wGoC1bxJb5dx9BV0FOmcA2ong4H1yp08YhqiF1NpFaqfZTa/0YF3UK YcWzBn7/WssfDbCT5nyTpy3cOW9tjOnbqhxfaa9v+y7eNnDMUk+eznuHnIpUTrTb9e5E RX+vGpKpaUJxzXqWPkk0wLH4LrRqz/sqULS/6k7Uk7bfQG80zZh4RFzNet17qvAUbzBk wLcJ0jC2SWWdEQ6TGc37Jpnzk/Nxc86Ip+XVHBxD8FJM6ydphll4OImPptO2ZeY98MAw 0lpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736360564; x=1736965364; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4jijnO+/vwt5TKuw0t4KuJDIurPSMvqe04KWFl33HmU=; b=QFijOD6GKKeCv2/D6qTleH64PtlA3q9VjC7QlHsy8QcRwuKl0ULK16qQ7poWtEz3Ph 44Cmn5OhP6CDJRlTf4h2YlkFOBN13LdJuHJNa4yBqX4Znfw07uodkxSfd1as5twZbzqn Z148Xig/88Q3e7og44mSz4fbfuAFJI70SL36jS9cSdT3XPnxAf6SZo0n9ht7XuJvMzsa uRaIbyB4Sn6cH0TbqijZzlp7mng3AIebuYxV0sWtyscWMKZ4iEdPXbj8PV0PHsmLAow3 R47VEbF97AafcfRLz09FRI7uk8wA54/b89N/gAW+XwKieShtJKHp/az9VWeB13PeadLW EghA== X-Gm-Message-State: AOJu0Yz7zVzChD3/BXZ4Vj1SKj6FVGF9CmKh3ZS2/1fdn404CQGqaFS7 ZLQ3OrDRPyobJoe1YLXOecx697VnCvC/OTd5N+aaDlUYMYIUaQJl0ghPSR/79u5K5RYQoa1kFQd 0OewDWgGVTSjZWpyszd1tVE/9F69MvvodNjPfrugEnHQxVv0iymOBCp5rUwNZV47EzX4EZJGSA4 1J+O0MiKmXINhXPXkaZFFzaGxA4w== X-Google-Smtp-Source: AGHT+IGsWWOOSsGzdHXgbonkA2unx1gvF35gsxnWe+/5Cdm+oQJdMRSriAFbRZRqPIPuudPDtnoy6aZb X-Received: from wmbay2.prod.google.com ([2002:a05:600c:1e02:b0:436:e67f:5b4c]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3514:b0:434:a367:2bd9 with SMTP id 5b1f17b1804b1-436e26a607fmr36080415e9.14.1736360564695; Wed, 08 Jan 2025 10:22:44 -0800 (PST) Date: Wed, 8 Jan 2025 19:22:20 +0100 In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108182218.1453754-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1856; i=ardb@kernel.org; h=from:subject; bh=B7tjid52pXcEHwxSjXgczIOJflt5UduLd+Wztt1NSa0=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb3uUAyjgLf3nTpelz3LQjM3n+83rqnRufqn2fT9zkrmW 5uPO87sKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABO5fIaRYWr33fcPJVe15GyZ /WCVs6Wq889lpa82B/EpVb9ZwvprYiMjw9/uqDDuchdPRkWZ+uvcTXGGSnc/uCZGzJr8Nn1W2T4 +JgA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108182218.1453754-9-ardb+git@google.com> Subject: [PATCH 1/6] x86/efi/mixed: Check CPU compatibility without relying on verify_cpu() From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel From: Ard Biesheuvel In order for the EFI mixed mode startup code to be reusable in a context where the legacy decompressor is not used, replace the call to verify_cpu() [which performs an elaborate set of checks] with a simple check against the 'long mode' bit in the appropriate CPUID leaf. This is reasonable, given that EFI support is implied when booting in this manner, and so there is no need to consider very old CPUs when performing this check. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 22 ++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 876fc6d46a13..067e10eb7897 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -293,24 +293,20 @@ SYM_FUNC_END(efi32_entry) * efi_system_table_32_t *sys_table) */ SYM_FUNC_START(efi32_pe_entry) - pushl %ebp - movl %esp, %ebp pushl %ebx // save callee-save registers - pushl %edi - - call verify_cpu // check for long mode support - testl %eax, %eax - movl $0x80000003, %eax // EFI_UNSUPPORTED - jnz 2f - movl 8(%ebp), %ecx // image_handle - movl 12(%ebp), %edx // sys_table + /* Check whether the CPU supports long mode */ + movl $0x80000001, %eax // assume extended info support + cpuid + btl $29, %edx // check long mode bit + jnc 1f + leal 8(%esp), %esp // preserve stack alignment + movl (%esp), %ecx // image_handle + movl 4(%esp), %edx // sys_table jmp efi32_entry // pass %ecx, %edx // no other registers remain live - -2: popl %edi // restore callee-save registers +1: movl $0x80000003, %eax // EFI_UNSUPPORTED popl %ebx - leave RET SYM_FUNC_END(efi32_pe_entry) From patchwork Wed Jan 8 18:22:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 856040 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 647DA1FF7BE for ; Wed, 8 Jan 2025 18:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360570; cv=none; b=M+5IZfbrX2fB+cuNJKp12Ip3h73BxyPIpY28K1a4ng6l9dQtDt4d7eyieof+dXfYMSg2dg4TEkaVaIDNQYN5oyqHnOjyVinqDHs/dHxGTUqKmJL96uLmXbCIr74MWrENeAZh/ojdZaYIhftUc6goqZiZbGDOg8FNC+Qyjxyyk2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360570; c=relaxed/simple; bh=jx4bUGPsr+9JVsCuAZLXge19kkt5W9Q3cPtdscYk5zk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PPb556yz9L6+LZpoOPUebzqLXUUYrdiLz74+E9T/9q/s9OOy1cMPM3YYdyGYwDRFk/SY53cH2fQ1QjdvU5z+nf3W5g+y15jJ/9BneIGsfFQQ4XEiBM9Nnohf/1yecyIkSPAX6mEj+8VKQdP8lpZ0TzfkBVp5WnvI6QPJQ3qsjzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QjD/uHLN; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QjD/uHLN" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-385dcadffebso44718f8f.0 for ; Wed, 08 Jan 2025 10:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736360567; x=1736965367; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qNVfr096nJGxcAFzzBLTLfvTxGz5JlZ2yViC6UqrtIk=; b=QjD/uHLNO9l37vi0OPVk71Z1+KML/dDL9dRYNVQdGUT+1T6Jp1SgcxSvsmsliqj5Aj czerNieW1SXQyd9sYZh7SxrqWh5mpa0AdIWcAZp6xzV277bAbIMBDZ84SEIMoiNwzoga Tahw2n0BKwuOTsfYB70roe7IuRISJHD1VMIb5V7VZMjVKheY5pHzedQFG3qAQpGK3TV0 ncVhDJFKWzwHM+DGKzx4kiDPy5/HHnwurgwv2JpbcI/DenYqiMZKhtPX/eNqQnxEdcMr vslc8zV6hhKgV0YYuH8pTFVpyk5uku1mqBjQc1cEXeE7uAcbCdHPtiz8aIWEWD5Qii5g MY7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736360567; x=1736965367; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qNVfr096nJGxcAFzzBLTLfvTxGz5JlZ2yViC6UqrtIk=; b=nKhYbJP1982cApkAAOD/3mu7jSLy2M0mvZCAj+TDFV6VUfIm1T2tAZOd42UjYtdJ+E Y4C7qU1eb2MUj/1XukBOpAjjhk4m70OXghLBQSVfGewNrukngesxDhgiJJdHVVCRi9O/ zmWDkYyEtPEhdilMVJfDeDglBKiitcX3Xh8vLEKv3UT2DWB4ZUMkECmZnrwAFeeAK1uC lPxkvBLltwXM+sGVYvJ9MLyewq8Ty5Dcx8F6CAWRmnWDlcv1uh95paBb4gxr9H54AFoo nmqw6lud4mmcU7bJPvAIIdrFUF1e/wQdnJiyIq2YjfeSnTObC8Ijv64637DVmL4+dRnh 1N1A== X-Gm-Message-State: AOJu0Yx9ei4HOLf9XFo5hJ/Yd0Dy5GR6B6Iv2dk/24cF2yr4TBV2Brb2 TiaKBm8/imt5Nzu7FOlQvzgYEimcfM+yMEgfmVnKIsO0kn2LyCKHBwIVPHutHoJ8/pCap1z2arF MZF+eAs0BwrtSSkpyBRHhit2FFNIcu2zYf1oslCJnVqTZE3xgr9ZfhHdvvfWHtlCEoyYrQuUCgl rFVYstHSuYjAX+mt+8OmtB9E97sg== X-Google-Smtp-Source: AGHT+IFYxTSxNQ5yr95KCS/7/y8oRKBY/qpFax6EkY97FYcVer4GH/WLxeA1GI1NOowxPYyBRlp0SOhl X-Received: from wrd20.prod.google.com ([2002:a05:6000:4a14:b0:386:2ebe:be29]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4023:b0:385:f7a3:fed1 with SMTP id ffacd0b85a97d-38a87336e53mr2913655f8f.44.1736360566688; Wed, 08 Jan 2025 10:22:46 -0800 (PST) Date: Wed, 8 Jan 2025 19:22:21 +0100 In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108182218.1453754-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=8939; i=ardb@kernel.org; h=from:subject; bh=RX1/qLs48jU+AD6m8d23gxWs8NQmh0fm6jguKjbYvHI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb3uUNzeGyU9xV+/9IuIvp24aknAj1+/vKLP/rb+vcPq8 vtJWk+CO0pZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBEoo8wMrzK+tlc5qC+T3jW dP5XLlu6Vt5ekLX7sfqJ9Ms/o18fLRdlZDj620Dom0xq5I5HL/o/vc9Yu59h5+HVRlfqWN13Sdq 4O3IBAA== X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108182218.1453754-10-ardb+git@google.com> Subject: [PATCH 2/6] x86/efi/mixed: Remove dependency on legacy startup_32 code From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel From: Ard Biesheuvel The EFI mixed mode startup code calls into startup_32 in the legacy decompressor with a mocked up boot_params struct, only to get it to set up the 1:1 mapping of the lower 4 GiB of memory and switch to a GDT that supports 64-bit mode. In order to be able to reuse the EFI mixed mode startup code in EFI zboot images, which do not incorporate the legacy decompressor code, decouple it, by building the 1:1 map and installing the GDT directly. This also removes the need to preserve and restore the stack pointer and the arguments passed to the entrypoint, and instead, the firmware stack can be retained, and the arguments can be loaded from it at the point where they are needed, i.e., before calling into the EFI stub C code. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 143 ++++++++++++-------- arch/x86/boot/compressed/head_64.S | 7 - 2 files changed, 86 insertions(+), 64 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 067e10eb7897..c010aba7a0d0 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -15,15 +15,18 @@ */ #include -#include #include #include +#include #include #include -#include .code64 .text + .balign 8 +SYM_DATA_LOCAL(gdt, .quad 0x0, 0x0, 0xaf9a000000ffff) /* __KERNEL_CS */ + .set gdt_size, . - gdt + /* * When booting in 64-bit mode on 32-bit EFI firmware, startup_64_mixed_mode() * is the first thing that runs after switching to long mode. Depending on @@ -35,30 +38,34 @@ * pointer is used to disambiguate. * * +--------------+ - * +------------------+ +------------+ +------>| efi_pe_entry | - * | efi32_pe_entry |---->| | | +-----------+--+ - * +------------------+ | | +------+----------------+ | - * | startup_32 |---->| startup_64_mixed_mode | | - * +------------------+ | | +------+----------------+ | - * | efi32_stub_entry |---->| | | | - * +------------------+ +------------+ | | + * +------------------+ +-------------+ +------>| efi_pe_entry | + * | efi32_pe_entry |--->| | | +-----------+--+ + * +------------------+ | | +------+----------------+ | + * | efi32_entry |---->| startup_64_mixed_mode | | + * +------------------+ | | +------+----------------+ | + * | efi32_stub_entry |--->| | | | + * +------------------+ +-------------+ | | * V | - * +------------+ +----------------+ | - * | startup_64 |<----| efi_stub_entry |<--------+ - * +------------+ +----------------+ + * +-------------+ +----------------+ | + * | vmlinux |<----| efi_stub_entry |<--------+ + * +-------------+ +----------------+ */ -SYM_FUNC_START(startup_64_mixed_mode) - lea efi32_boot_args(%rip), %rdx - mov 0(%rdx), %edi - mov 4(%rdx), %esi +SYM_FUNC_START_LOCAL_NOALIGN(startup_64_mixed_mode) + xorl %eax, %eax + movl %eax, %ds + movl %eax, %es + movl %eax, %ss + movl %eax, %fs + movl %eax, %gs - /* Switch to the firmware's stack */ - movl efi32_boot_sp(%rip), %esp - andl $~7, %esp + movl 0(%rsp), %ecx // MS calling convention + movl 4(%rsp), %edx #ifdef CONFIG_EFI_HANDOVER_PROTOCOL - mov 8(%rdx), %edx // saved bootparams pointer - test %edx, %edx + test %edi, %edi // struct boot_params provided? + movl %edx, %esi // SysV calling convention + cmovnzl %edi, %edx + movl %ecx, %edi jnz efi_stub_entry #endif /* @@ -69,8 +76,6 @@ SYM_FUNC_START(startup_64_mixed_mode) * the correct stack alignment for entry. */ sub $40, %rsp - mov %rdi, %rcx // MS calling convention - mov %rsi, %rdx jmp efi_pe_entry SYM_FUNC_END(startup_64_mixed_mode) @@ -151,7 +156,6 @@ SYM_FUNC_END(__efi64_thunk) SYM_FUNC_START(efi32_stub_entry) call 1f 1: popl %ecx - leal (efi32_boot_args - 1b)(%ecx), %ebx /* Clear BSS */ xorl %eax, %eax @@ -163,10 +167,7 @@ SYM_FUNC_START(efi32_stub_entry) rep stosl add $0x4, %esp /* Discard return address */ - popl %ecx - popl %edx - popl %esi - movl %esi, 8(%ebx) + movl 8(%esp), %edi /* struct boot_params pointer */ jmp efi32_entry SYM_FUNC_END(efi32_stub_entry) #endif @@ -241,8 +242,9 @@ SYM_FUNC_END(efi_enter32) /* * This is the common EFI stub entry point for mixed mode. * - * Arguments: %ecx image handle - * %edx EFI system table pointer + * Arguments: 0(%esp) image handle + * 4(%esp) EFI system table pointer + * %edi struct boot_params pointer (or NULL) * * Since this is the point of no return for ordinary execution, no registers * are considered live except for the function parameters. [Note that the EFI @@ -261,31 +263,58 @@ SYM_FUNC_START_LOCAL(efi32_entry) /* Store firmware IDT descriptor */ sidtl (efi32_boot_idt - 1b)(%ebx) - /* Store firmware stack pointer */ - movl %esp, (efi32_boot_sp - 1b)(%ebx) - - /* Store boot arguments */ - leal (efi32_boot_args - 1b)(%ebx), %ebx - movl %ecx, 0(%ebx) - movl %edx, 4(%ebx) - movb $0x0, 12(%ebx) // efi_is64 - - /* - * Allocate some memory for a temporary struct boot_params, which only - * needs the minimal pieces that startup_32() relies on. - */ - subl $PARAM_SIZE, %esp - movl %esp, %esi - movl $PAGE_SIZE, BP_kernel_alignment(%esi) - movl $_end - 1b, BP_init_size(%esi) - subl $startup_32 - 1b, BP_init_size(%esi) + /* Record mixed mode entry */ + movb $0x0, (efi_is64 - 1b)(%ebx) /* Disable paging */ movl %cr0, %eax btrl $X86_CR0_PG_BIT, %eax movl %eax, %cr0 - jmp startup_32 + /* Set up 1:1 mapping */ + leal (pte - 1b)(%ebx), %eax + movl $_PAGE_PRESENT | _PAGE_RW | _PAGE_PSE, %ecx + leal (_PAGE_PRESENT | _PAGE_RW)(%eax), %edx +2: movl %ecx, (%eax) + addl $8, %eax + addl $PMD_SIZE, %ecx + jnc 2b + + xor %ecx, %ecx + movl $PAGE_SIZE, %esi +3: movl %edx, (%eax,%ecx,8) + addl %esi, %edx + inc %ecx + cmp $4, %ecx + jl 3b + + addl %esi, %eax + movl %edx, (%eax) + movl %eax, %cr3 + + movl %cr4, %eax + orl $X86_CR4_PAE, %eax + movl %eax, %cr4 + + movl $MSR_EFER, %ecx + rdmsr + btsl $_EFER_LME, %eax + wrmsr + + leal (gdt - 1b)(%ebx), %ecx + pushl %ecx + pushw $gdt_size - 1 + lgdtl (%esp) + lea 6(%esp), %esp + + /* Enable paging and jump to long mode */ + leal (startup_64_mixed_mode - 1b)(%ebx), %ecx + pushl $__KERNEL_CS + pushl %ecx + movl %cr0, %eax + btsl $X86_CR0_PG_BIT, %eax + movl %eax, %cr0 + lret SYM_FUNC_END(efi32_entry) /* @@ -301,10 +330,8 @@ SYM_FUNC_START(efi32_pe_entry) btl $29, %edx // check long mode bit jnc 1f leal 8(%esp), %esp // preserve stack alignment - movl (%esp), %ecx // image_handle - movl 4(%esp), %edx // sys_table - jmp efi32_entry // pass %ecx, %edx - // no other registers remain live + xor %edi, %edi // no struct boot_params in EDI + jmp efi32_entry // only ESP and EDI remain live 1: movl $0x80000003, %eax // EFI_UNSUPPORTED popl %ebx RET @@ -318,8 +345,10 @@ SYM_FUNC_START_NOALIGN(efi64_stub_entry) SYM_FUNC_END(efi64_stub_entry) #endif - .data - .balign 8 + .bss + .balign PAGE_SIZE +SYM_DATA_LOCAL(pte, .fill 6 * PAGE_SIZE, 1, 0) + SYM_DATA_START_LOCAL(efi32_boot_gdt) .word 0 .quad 0 @@ -330,8 +359,8 @@ SYM_DATA_START_LOCAL(efi32_boot_idt) .quad 0 SYM_DATA_END(efi32_boot_idt) + .data + .balign 4 SYM_DATA_LOCAL(efi32_boot_cs, .word 0) SYM_DATA_LOCAL(efi32_boot_ds, .word 0) -SYM_DATA_LOCAL(efi32_boot_sp, .long 0) -SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0) SYM_DATA(efi_is64, .byte 1) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 1dcb794c5479..5db6495a3bb9 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -263,13 +263,6 @@ SYM_FUNC_START(startup_32) * used to perform that far jump. */ leal rva(startup_64)(%ebp), %eax -#ifdef CONFIG_EFI_MIXED - cmpb $1, rva(efi_is64)(%ebp) - je 1f - leal rva(startup_64_mixed_mode)(%ebp), %eax -1: -#endif - pushl $__KERNEL_CS pushl %eax From patchwork Wed Jan 8 18:22:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 855774 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2F4A201002 for ; Wed, 8 Jan 2025 18:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360572; cv=none; b=gLDtF26qO8VNg6G+BA3iccbR7IpLy1Lx1l1k7tNXtyN07zjKnKOFDi1C4QnIIs9Isqsi7G5nM7MJlI14zACB1pUaP1j3RmJAz71xbSeqdW/JrEkG+SZMVL/4lXvZERHRECb5BVyRB25xEUgHC1Wgd2+yNjM3F7Neyz31GPQcbkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360572; c=relaxed/simple; bh=SLVCqnZOPTlF7lPP3mZgvL9YfZxpx7l4xVoZ1DQSXfs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cSxUCKNUUu4Ge/P3PXzzE125a5IVhAMYQk9Oz+luIxb5OJduya1PTQ22TFQD/lil9lkzNQQMqooQKUP7BZ8zJZBCxCihZAag1DlR9Qo7haamPNLQfTSGbYtEVJZCcEJt6VQfosei3yeLIASffR4/FP+1H9KfKz9JVJasp/IXjuc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=adCRRusW; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="adCRRusW" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43673af80a6so837225e9.1 for ; Wed, 08 Jan 2025 10:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736360569; x=1736965369; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hbPTlmytNWKUoOoC51RgPxgmKvrqZNo9QyU8n/XLuQw=; b=adCRRusWLWSZaVtsoVgxdHQF568L54ejTRzp8WJUk8QibHMFs+5Q4RtKmphgtwZGJT ly3zMR6LU3FwF5nlU2qQ+AqNyKAUOVCzSj+XGURr6L5cSLCEMTaeRcbj45EZ+cSRoFyo p7TNSrqnDSAvdOeIp6c4iWd/6l3BY0+ANk7cwZ2UVf2fbCZkCciGjr5dbuvYGBNF+Lxn 9inhUGFmWC018UtMKuqk2hBf9MJajFpyEVmbb+k2bEixpjDcunveofuJmpwJflKT4zfS vfnsSQ6VJKhmnvvvPwaKDG3nJKgRb+3feGlZe4RI+x0sIQMTD7P+nVRos7ZWu/dvQUgz FPZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736360569; x=1736965369; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hbPTlmytNWKUoOoC51RgPxgmKvrqZNo9QyU8n/XLuQw=; b=P5BkYGOUtfYQLiwzD7sAMGsFCOGE9PHs5IHhALU8c3SeHmpbPP0Z1LQlhlNu20PqyM SAPIB1QzRkHzwCc30VuUDt02iQrMSyQ3rz3iYkajDD74+1grKQwhDsyNtCEqvIn3y9RE NeRZXTyh5VpwlYX65ld0AOZAW+LCRTE5pTtW42bdEmyJOK9qCMKDNSz5IiiHvuBz+rXI VGN/UnLaGKhJbRc/8NR2hYhlJnenTMXc9QcFMs7qccFh0dDnQKKbFtvdibarF3T7KL0c hIhyXwA6wQZzvNvYNjsQAJPda0Ek4oFwvp3Ngwb8qa0NP/tcxyjddFvc7P4yUbAmxfjg UE/Q== X-Gm-Message-State: AOJu0YwGgkD8aPBXDfrhNxS0Uc7WFQ8ZjmYK1C7u+suhl63b9UwGvXOJ YC/ldnxZjxyxm1wRNQRmdt3V3CyG8CgkA03CrZWNv0I+6eM82KMsZWFS+pnvpLi+nWebMbY30sW CfipZfMs6lHeXu9YKpu/Ic/0/l/jg/T4QSAjCPWDFnD5/s1hU4/d7m4a5FBM/JIA7wvVKLWVLyL J/zaJr+CgSvJ1JcfMa7rBOXQLATw== X-Google-Smtp-Source: AGHT+IHeeTo02Cq9pv4ZYdtm9WaozBbVbAy/bjSMvFSfPhrOeYQ2g+MbjsQ+TZ3pNbbAu93U9XKU2qof X-Received: from wmbfj5.prod.google.com ([2002:a05:600c:c85:b0:434:a9bd:e68c]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f06:b0:431:12a8:7f1a with SMTP id 5b1f17b1804b1-436e26d018emr38216315e9.16.1736360569091; Wed, 08 Jan 2025 10:22:49 -0800 (PST) Date: Wed, 8 Jan 2025 19:22:22 +0100 In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108182218.1453754-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2119; i=ardb@kernel.org; h=from:subject; bh=u33yVDr1ep+Jh3oT0UHzraXfOa6OSpZltgKwiAbbxx0=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb3uUPw8xvXzlghpXuQ+v01pw4aENanzzu18Jbhs1u8ld jd6cuebdZSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJXKhh+Gcdf/TU6QnhAgzR N4LXCDyft+csb3XP5MelGd8/bYkLvCnAyNCVYntw8/9F9fWZ7yNrjV+tnhkayPBcJXlp/s20CfO /5XMCAA== X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108182218.1453754-11-ardb+git@google.com> Subject: [PATCH 3/6] x86/efi/mixed: Don't bother preserving 64-bit mode segment selectors From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel From: Ard Biesheuvel Commit e10848a26a96 ("x86/efi: Preserve segment registers in mixed mode") added code to preserve and restore the caller's data segment selector values when temporarily switching back to the firmware's GDT and segment layout to perform an EFI runtime call. At that point, this code was shared between the boot-time and runtime mixed mode implementations, and the issue this commit aimed to address only affected the latter. Since commit 96738c69a7fc ("x86/efi: Avoid triple faults during EFI mixed mode calls") the runtime version of the mixed mode handling is entirely separate, and relies on IA-32e compatibility mode to call into the 32-bit firmware while retaining the OS's GDT/IDT and segment layout. At boot-time, preserving/restoring the values is pointless, and the data segment selectors can now simply be zeroed after (re)entering 64-bit mode. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 24 ++++++-------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index c010aba7a0d0..066f4365af4f 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -83,17 +83,10 @@ SYM_FUNC_START(__efi64_thunk) push %rbp push %rbx - movl %ds, %eax - push %rax - movl %es, %eax - push %rax - movl %ss, %eax - push %rax - /* Copy args passed on stack */ - movq 0x30(%rsp), %rbp - movq 0x38(%rsp), %rbx - movq 0x40(%rsp), %rax + movq 0x18(%rsp), %rbp + movq 0x20(%rsp), %rbx + movq 0x28(%rsp), %rax /* * Convert x86-64 ABI params to i386 ABI @@ -135,14 +128,11 @@ SYM_FUNC_START(__efi64_thunk) 1: addq $64, %rsp movq %rdi, %rax - pop %rbx - movl %ebx, %ss - pop %rbx - movl %ebx, %es - pop %rbx - movl %ebx, %ds - /* Clear out 32-bit selector from FS and GS */ + /* Clear out 32-bit segment selectors */ xorl %ebx, %ebx + movl %ebx, %ds + movl %ebx, %es + movl %ebx, %ss movl %ebx, %fs movl %ebx, %gs From patchwork Wed Jan 8 18:22:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 856039 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86813201026 for ; Wed, 8 Jan 2025 18:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360574; cv=none; b=l166L5OTB60Xha/FT/ZnmZ6y+QDRuagDJ4ZSmdSvBSNXEa7ehrUOdx2xxhNgTIdE/S3HnV4aNKyAC8TaQsEpU/0q8Wp+INFCF1Mz8pSYTwXpKQkr0qH8A8kp1WZjFinHgmxbAq004tN5C5NEv+J0jvC0wqfOP2PPc4iZpESv5hU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360574; c=relaxed/simple; bh=JqScNhNP0EUKwyQdwToGmexv4nL2LEtECSplL/i5GW0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u+Fx+UyKMMnCdOif0bursrInBaUTHnTu2Z9ZUBNQTMU2dLkyNavuUtwkoUv7PvxVo6ng0+cB9mFHEOQ/5CXiTBhfMc/uPc4RBrr+BHgqihXF6+6Atta4Mse7Bf/9CKcMxcBIQdEBSu76aduqucKo/talpYzUSYcPVraD85Uw8mg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=meUEjksK; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="meUEjksK" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-385e1339790so47623f8f.2 for ; Wed, 08 Jan 2025 10:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736360571; x=1736965371; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7MULeU0q87nEZRKiBNEJIYAO905XkZ1RQoCMPLQGBYs=; b=meUEjksKIF3Jtke62TZltar4nG/hecTx8rMnxc6PPwV9BhMWjT1IjY2xpptSkDIMOU oKOpff8WXJawZozigBlwDsfZRCnFvT4NKztpiqx7t5FJW2fAC8qcAIQYo38GQfFIr6Hf SmvFCWfnsUb745I2CUqVFYX0n38dBAmG2J4nYMRn5coxwJB2w1wfbxyDdJ4V/AEnFx0z JFg4bFnWD4CxD958MPOaeNBa9vxuVnRJU/Dkss6mvVKpnqsD/xr1waGg9jcrfrhFA9Q4 yM8I3lG1eq2/opK/tP9I5Bwh1WG4EtZI3/iY058K5mC0Rfo86XNwjdnb7woWGbZjFbuX OlsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736360571; x=1736965371; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7MULeU0q87nEZRKiBNEJIYAO905XkZ1RQoCMPLQGBYs=; b=Zxeg8LfDCEcPL7udpGG4eM2NEeYuczQwsPwccnsI2IpJk/8NJr02LkAmrdSt3Sv8nU ZNzu7XLWS342+0nnDHWIWi0wf80AJNmkPxSQ2ZWMdj3/BDASUoCsAJZHqKsEmvhv7hS0 qiT25zT53lKmAR3nISQnBUQzXMxwTYYrtCTelDe7bvKKyC9JMBY9sq3yfUHzUFmVR7mU ZtwuiP2jtxY5QG3LavZ4Je4iAXoCD14bAOSIy84vAO8XsWkzUxJ+6HNLYLXLNHb976am Rqrr8C1LqAKx++x8Eo/V/8qTr3c2oCRl44OAmb8cMShWkNvX1vsYALvxTIwsKG8LzN9K aaSQ== X-Gm-Message-State: AOJu0Yyqufl4qXo5CUpQjxZVCtuJcwdjnzaoe5lp9T6ZUZx9TkR+Drf5 MSqlqd+Y1S2y7EeslYziihMhcvqd67VptCyUs7S4ryLR8UdPZ2/XYDM1AX5cQVljpGjlVNgyaWW jTEIBEKI3wBb6ZnOtrjfT3vdwMq5yd2PrQ5ku7FmQ9Z1/TnEdg+WAl3qUZDa5Q3v05J1MATWR+O eCfODASw86ack6kygBo0YAyNoBAQ== X-Google-Smtp-Source: AGHT+IEYNlwtXpUorAnTQlC3S22npDjNWQv+6V7VBok5jHS/n9p8/gNP2Qrygdmzc4UDo3ad0Z6GInlD X-Received: from wmbg19.prod.google.com ([2002:a05:600c:a413:b0:436:1abf:b8fe]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4802:b0:385:e877:c037 with SMTP id ffacd0b85a97d-38a87338d79mr2764515f8f.42.1736360571107; Wed, 08 Jan 2025 10:22:51 -0800 (PST) Date: Wed, 8 Jan 2025 19:22:23 +0100 In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108182218.1453754-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5149; i=ardb@kernel.org; h=from:subject; bh=06SD9I9ktyMI33HZ8zlJt/DZZorIDT/UL8orpVh2Jq8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb3uUOJ2HT7XF++8P1j8ZQwIqdbYls+ZzuW3qfSvwiJVw dmFa906SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwERKNRgZ+uwEL+yqOSC6Waro V17zxQXh1TePFAnIyEc0XjzZv87EjuGv+MS/nsKsi9ieZZplpvsYaosYKbleLeComS/x6cDzT7c ZAA== X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108182218.1453754-12-ardb+git@google.com> Subject: [PATCH 4/6] x86/efi/mixed: Simplify and document thunking logic From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel From: Ard Biesheuvel The current boot-time version of the thunk into 32-bit mode, to invoke EFI services and protocols using the 32-bit calling convention, is a jumble of argument marshalling code and GDT/IDT and segment register handling, with an undocumented de facto calling convention that passes the data segment descriptor, the return address and the GDT/IDT base pointer for the return in registers EDX, EBP and EBX respectively. Let's clean this up, and replace this with documented logic that separates the handling of the segment registers into the 64-bit caller, and the marshalling of the arguments into the 32-bit callee. Also, replace the open coded far call with an actual one, removing the need to pass the return address via a register. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 92 ++++++++++---------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index 066f4365af4f..a44e522bbbed 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -80,52 +80,36 @@ SYM_FUNC_START_LOCAL_NOALIGN(startup_64_mixed_mode) SYM_FUNC_END(startup_64_mixed_mode) SYM_FUNC_START(__efi64_thunk) - push %rbp push %rbx - /* Copy args passed on stack */ - movq 0x18(%rsp), %rbp - movq 0x20(%rsp), %rbx - movq 0x28(%rsp), %rax - - /* - * Convert x86-64 ABI params to i386 ABI - */ - subq $64, %rsp - movl %esi, 0x0(%rsp) - movl %edx, 0x4(%rsp) - movl %ecx, 0x8(%rsp) - movl %r8d, 0xc(%rsp) - movl %r9d, 0x10(%rsp) - movl %ebp, 0x14(%rsp) - movl %ebx, 0x18(%rsp) - movl %eax, 0x1c(%rsp) - - leaq 0x20(%rsp), %rbx - sgdt (%rbx) - sidt 16(%rbx) - - leaq 1f(%rip), %rbp + /* Store live GDT and IDT descriptors */ + subq $16, %rsp + sgdt (%rsp) + sidt 6(%rsp) /* * Switch to IDT and GDT with 32-bit segments. These are the firmware * GDT and IDT that were installed when the kernel started executing. * The pointers were saved by the efi32_entry() routine below. - * - * Pass the saved DS selector to the 32-bit code, and use far return to - * restore the saved CS selector. */ lidt efi32_boot_idt(%rip) lgdt efi32_boot_gdt(%rip) - movzwl efi32_boot_ds(%rip), %edx - movzwq efi32_boot_cs(%rip), %rax - pushq %rax - leaq efi_enter32(%rip), %rax - pushq %rax - lretq + /* Reload firmware's data segment selectors */ + movw efi32_boot_ds(%rip), %bx + movl %ebx, %ds + movl %ebx, %es + movl %ebx, %ss + movl %ebx, %fs + movl %ebx, %gs + + /* Move args #5 and #6 into 32-bit accessible registers */ + movl %r8d, %eax + movl %r9d, %ebx -1: addq $64, %rsp + lcalll *efi32_thunk(%rip) + + addq $16, %rsp movq %rdi, %rax /* Clear out 32-bit segment selectors */ @@ -137,7 +121,6 @@ SYM_FUNC_START(__efi64_thunk) movl %ebx, %gs pop %rbx - pop %rbp RET SYM_FUNC_END(__efi64_thunk) @@ -163,17 +146,27 @@ SYM_FUNC_END(efi32_stub_entry) #endif /* - * EFI service pointer must be in %edi. + * Called using a far call from 64-bit code, using the x86_64 SysV ABI (except + * for R8/R9 which are inaccessible to 32-bit code - EAX/EBX are used instead). + * + * The first argument (EDI) is a pointer to the boot service or protocol, to + * which the remaining arguments are passed, each truncated to 32 bits. * - * The stack should represent the 32-bit calling convention. + * Entered with ESP+40 pointing to the arguments passed via the stack, and with + * the 64-bit mode GDT and IDT descriptors at ESP+8 and ESP+14, respectively. */ SYM_FUNC_START_LOCAL(efi_enter32) - /* Load firmware selector into data and stack segment registers */ - movl %edx, %ds - movl %edx, %es - movl %edx, %fs - movl %edx, %gs - movl %edx, %ss + /* + * Convert x86-64 SysV ABI params to i386 ABI + */ + pushl 56(%esp) /* Up to 3 args passed via the caller's stack */ + pushl 52(%esp) + pushl 48(%esp) + pushl %ebx /* R9 */ + pushl %eax /* R8 */ + pushl %ecx + pushl %edx + pushl %esi /* Reload pgtables */ movl %cr3, %eax @@ -201,8 +194,9 @@ SYM_FUNC_START_LOCAL(efi_enter32) */ cli - lidtl 16(%ebx) - lgdtl (%ebx) + addl $32, %esp + lidtl 14(%esp) + lgdtl 8(%esp) movl %cr4, %eax btsl $(X86_CR4_PAE_BIT), %eax @@ -219,9 +213,6 @@ SYM_FUNC_START_LOCAL(efi_enter32) xorl %eax, %eax lldt %ax - pushl $__KERNEL_CS - pushl %ebp - /* Enable paging */ movl %cr0, %eax btsl $X86_CR0_PG_BIT, %eax @@ -250,6 +241,10 @@ SYM_FUNC_START_LOCAL(efi32_entry) movw %cs, (efi32_boot_cs - 1b)(%ebx) movw %ds, (efi32_boot_ds - 1b)(%ebx) + /* Fix up absolute reference */ + leal (efi32_thunk - 1b)(%ebx), %eax + addl %eax, (%eax) + /* Store firmware IDT descriptor */ sidtl (efi32_boot_idt - 1b)(%ebx) @@ -351,6 +346,7 @@ SYM_DATA_END(efi32_boot_idt) .data .balign 4 +SYM_DATA_LOCAL(efi32_thunk, .long efi_enter32 - .) SYM_DATA_LOCAL(efi32_boot_cs, .word 0) SYM_DATA_LOCAL(efi32_boot_ds, .word 0) SYM_DATA(efi_is64, .byte 1) From patchwork Wed Jan 8 18:22:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 855773 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B93DA201026 for ; Wed, 8 Jan 2025 18:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360576; cv=none; b=kDOtH9E3BJMypPNFdIiF+VdigcbbzVkjRkpPNcei8nY19m9dWytFOslyB31g/yfzOGBj2gZEqME6ER8DCyGMhf2AU/O6jTXqQziqVCXFrC2r3IZBeWWTtgz817L+GCkBxWO6EDT8I1pBgUAFU9cAUq0lRomJn1XFB/9/0opkHkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360576; c=relaxed/simple; bh=cHdxDG+CZLPQVM0hykUhARikRkONgl0Kis3lMtVaXe4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fVpWT12O2gA+p7PRp7spzEJUqXt8xorPowzt0P9J0FLELb8sq+JmabmvWgwIRppa8uI3glQADmkfUp8rO80uLWI1dNLs24PDciQNnLA2bJK0S+Vawj0kIckIsKVaKfRhesPPklfYjoa2A1MYq1ZzQX/ZCUTEHbUMGgokZrA+Fak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zFdl2XcJ; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zFdl2XcJ" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-385e1fd40acso41073f8f.3 for ; Wed, 08 Jan 2025 10:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736360573; x=1736965373; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jMNqoigFiWM5TbLMD0Xi2MHr+lE9/rI9qjc7yUxHIVg=; b=zFdl2XcJNNWAOrg44c68Ayy32jbKkQPMEqrg8wiNu/HbcEeYjWECYVzByNm+6AZSGD kuvb3OPQDV8yevyBlgFhBmQUEgbHu6noy+hnSx2nbj9SWZyidvt/aF1bvEcyoFZA8BvY Fb6Iau/aTrOr+4cX4jsBX3UO5405AmcIX0tlqv7bZ649nxRvlpZZiO5QDlD+3NR6hG+B Q2QyNOgV/GQoGQnbydNOHdPCjRlSMzOZPDbqVej5jPnFgFHZZ5inOiMG9FmSCDTOHjnD SdhsBAvNuEPRUeQiLmsdYh5lYBknjhfHYA2ircGqbGtveVlFOLl01sKn3hjeR7QGqvM7 cFoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736360573; x=1736965373; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jMNqoigFiWM5TbLMD0Xi2MHr+lE9/rI9qjc7yUxHIVg=; b=tKGQTTlMlAOSpTJUjW4NyM3cpwQHFaJO/HDranCLMQb8giDI2H9WTUwa5rymHz+G9O Yd1Zp+Bup9rvK+IZwJliDgHKNt8lh2pTdbXvEJw/dZmSApceT3eftA37uFscBhT0Nqrx 3Jw0KzBUwiGll0rYobUtNwyO9zewPd6Ch/KC+WA2dl+PKS/gQDC5u4qNfSylBP1CZZfU Jn/lvoKM/DP0fk3N2M4m6TVycgqNWGBSVrzdJNnGHZO9E10K2GE9NbghVjugcNYsgRlG dBamkhZJHJRbsXLEaZZtvc4QN7XxqjEft8o5nma08XGzgfYHe3M6gdeHXFDQ2/SI5Kbi BOXw== X-Gm-Message-State: AOJu0Yz5KU8gFtotYUHxrP1e1jaD+9ZiNbPprsK7emdqE7zglbwtEiiv AI/OHhar5yQQw3HaVzNbwSJzq0unVL3abdbIkZIwDTDnPWCJh2mFKNWtitpdJZCge1WqC03bfOV P+Yg2Vt9TIeM9QRsm4Dl/skAfzQ4LJmJhYa4T353olOaKGaItwUe3feBAjyWR9ZZzA4/IE+JnXF TM49k6+Qfjpr31fO3SY03l0xZZdQ== X-Google-Smtp-Source: AGHT+IF5FxHo/GxUg3M9bFpnWUOS3dfV3YLDhvFEBW4ZokvEkI7JN0wADt0+mqzGvEDzIXQxewD2mXEf X-Received: from wmbay14.prod.google.com ([2002:a05:600c:1e0e:b0:434:a2c3:d51b]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1aca:b0:385:fa3d:1988 with SMTP id ffacd0b85a97d-38a872fc2d2mr3347130f8f.8.1736360573138; Wed, 08 Jan 2025 10:22:53 -0800 (PST) Date: Wed, 8 Jan 2025 19:22:24 +0100 In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108182218.1453754-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3975; i=ardb@kernel.org; h=from:subject; bh=OYEz/LdyZY7FNclv23VBaoW3nBN5gwqCUebHiTAjWjo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb3uUNImbxO/ZUb6TyTW7Dypmnz5xRMd3coGbqET6ze/k XE6yny2o5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEwk6jHDX/HPNmb5nvn6lfHP PwQqRh3Y+Otx/dJb/+6m/Zy3on12xCGGX0y3HgtGzhYtmyCwfzJXQ/GppfHp077X8s+vV9hwUI3 lFy8A X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108182218.1453754-13-ardb+git@google.com> Subject: [PATCH 5/6] x86/efi/mixed: Reduce padding by moving some code around From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel From: Ard Biesheuvel The 32-bit and 64-bit entrypoints for the EFI handover protocol need to be exactly 0x200 bytes apart, and so the 64-bit version is placed at the end, using padding to move it into place. This padding can be reduced now, since the code in between has reduced in size as well. So move efi32_stub_entry() to the beginning of the source file. Note that this code is outside of the compressed kernel image, and so the padding is not compressed. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/efi_mixed.S | 51 ++++++++++---------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S index a44e522bbbed..b5a46a4ce083 100644 --- a/arch/x86/boot/compressed/efi_mixed.S +++ b/arch/x86/boot/compressed/efi_mixed.S @@ -21,12 +21,32 @@ #include #include - .code64 .text .balign 8 SYM_DATA_LOCAL(gdt, .quad 0x0, 0x0, 0xaf9a000000ffff) /* __KERNEL_CS */ .set gdt_size, . - gdt +#ifdef CONFIG_EFI_HANDOVER_PROTOCOL + .code32 +SYM_FUNC_START_NOALIGN(efi32_stub_entry) + call 1f +1: popl %ecx + + /* Clear BSS */ + xorl %eax, %eax + leal (_bss - 1b)(%ecx), %edi + leal (_ebss - 1b)(%ecx), %ecx + subl %edi, %ecx + shrl $2, %ecx + cld + rep stosl + + add $0x4, %esp /* Discard return address */ + movl 8(%esp), %edi /* struct boot_params pointer */ + jmp efi32_entry +SYM_FUNC_END(efi32_stub_entry) +#endif + /* * When booting in 64-bit mode on 32-bit EFI firmware, startup_64_mixed_mode() * is the first thing that runs after switching to long mode. Depending on @@ -50,6 +70,7 @@ SYM_DATA_LOCAL(gdt, .quad 0x0, 0x0, 0xaf9a000000ffff) /* __KERNEL_CS */ * | vmlinux |<----| efi_stub_entry |<--------+ * +-------------+ +----------------+ */ + .code64 SYM_FUNC_START_LOCAL_NOALIGN(startup_64_mixed_mode) xorl %eax, %eax movl %eax, %ds @@ -79,7 +100,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(startup_64_mixed_mode) jmp efi_pe_entry SYM_FUNC_END(startup_64_mixed_mode) -SYM_FUNC_START(__efi64_thunk) +SYM_FUNC_START_NOALIGN(__efi64_thunk) push %rbx /* Store live GDT and IDT descriptors */ @@ -125,26 +146,6 @@ SYM_FUNC_START(__efi64_thunk) SYM_FUNC_END(__efi64_thunk) .code32 -#ifdef CONFIG_EFI_HANDOVER_PROTOCOL -SYM_FUNC_START(efi32_stub_entry) - call 1f -1: popl %ecx - - /* Clear BSS */ - xorl %eax, %eax - leal (_bss - 1b)(%ecx), %edi - leal (_ebss - 1b)(%ecx), %ecx - subl %edi, %ecx - shrl $2, %ecx - cld - rep stosl - - add $0x4, %esp /* Discard return address */ - movl 8(%esp), %edi /* struct boot_params pointer */ - jmp efi32_entry -SYM_FUNC_END(efi32_stub_entry) -#endif - /* * Called using a far call from 64-bit code, using the x86_64 SysV ABI (except * for R8/R9 which are inaccessible to 32-bit code - EAX/EBX are used instead). @@ -155,7 +156,7 @@ SYM_FUNC_END(efi32_stub_entry) * Entered with ESP+40 pointing to the arguments passed via the stack, and with * the 64-bit mode GDT and IDT descriptors at ESP+8 and ESP+14, respectively. */ -SYM_FUNC_START_LOCAL(efi_enter32) +SYM_FUNC_START_LOCAL_NOALIGN(efi_enter32) /* * Convert x86-64 SysV ABI params to i386 ABI */ @@ -232,7 +233,7 @@ SYM_FUNC_END(efi_enter32) * stub may still exit and return to the firmware using the Exit() EFI boot * service.] */ -SYM_FUNC_START_LOCAL(efi32_entry) +SYM_FUNC_START_LOCAL_NOALIGN(efi32_entry) call 1f 1: pop %ebx @@ -306,7 +307,7 @@ SYM_FUNC_END(efi32_entry) * efi_status_t efi32_pe_entry(efi_handle_t image_handle, * efi_system_table_32_t *sys_table) */ -SYM_FUNC_START(efi32_pe_entry) +SYM_FUNC_START_NOALIGN(efi32_pe_entry) pushl %ebx // save callee-save registers /* Check whether the CPU supports long mode */ From patchwork Wed Jan 8 18:22:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 856038 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA0191FF7BE for ; Wed, 8 Jan 2025 18:22:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360578; cv=none; b=cm/Kkg9rsInjWMdIjruMOuk9+jQy0PrXeHkCe/BmcO9nm6hz/Hc2ogoB7tbyRY8J57Y/rfGxswEi4GAttB0cXcEKSLLLSTxjU2h9GyUqzGw2WS84cywNYs5FfByYEScwEMjmEZp6IHBuhGxoTnGDloKAHgDw1lyNgtXfKPYbbj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736360578; c=relaxed/simple; bh=5aZsSKDqucBQ6tFp0pxoZMte3MmpDtZA7VB/THD1IXs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TZh872ByAGxn1+wAm0IEhSG0Hj4yzZ009VvFtrLZKzXMyYQfQypxb+rdCBldiWfWyJg6uY1HGQ7/LmktLFQZ7voA/L2Dq59WDDIpUh6rMc/1tM+DiOR29mdmaypeg8A96+mhMwXFTaeGTj3wQL2cziLE77/pnGiw1vMje4XFz68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GFe7vx6a; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GFe7vx6a" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-43621907030so988845e9.1 for ; Wed, 08 Jan 2025 10:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736360575; x=1736965375; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=a7cVtdq5SKa/m4ejGzp2zpEWpp87o08TE6jwR8+FTF8=; b=GFe7vx6avnh0uOq/pS+/wAh2TkLTL85+m8H9a5D+wQNKbHxGbv+g8oha7foEMG4zDS iGlekzGfHgnTE1VTyLttB8aYQe0KxvFZTIrRLG7P1MqaXUT6UXr4en5gHgVJysPMBGuU mW8lmLBxKNli4ZthrysBq79pVVljWwrPntkmHhxs5HEv0Ombo2jvrM/WhXT/lyZqzc9Z 8+QcscNGapcuDGaSAd3TCFAMv3u4NsSdUbkv3hKSFZv6TPO6L7xLRJePWv3EEWUTvKln Xz/XkEoO30N/U21VenqU4Ry8roK6wrtnxC5jjcRqvJKWxS7U9vQPpb5WbXWdBpJxEhux G1QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736360575; x=1736965375; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a7cVtdq5SKa/m4ejGzp2zpEWpp87o08TE6jwR8+FTF8=; b=msqVLbT6AU/uEkwLgYJpKXCJGNFCd/LaYqpO0i8Lm5JbEljbsoRcFYZAOXvTGvMg+/ VJ6QRWYY50JdUP2h1M3wkjsgzHTnmuhJbrXmokUZN/ZdhYqgahPCQbwkO9HLrsVjEGwE e4NYoWalA5Ya8IlGj9QI7snXMyAgvgIL/LHTK0eknmRcuev/XXzE63PuxN8PGbB8HRrT x573nF6MEhskWDAWZE2YGKfm52GXIjsMJhrl7aVDV1abIMVcra1AN3wHG1KWsErHAJCc dQQulgn4XyKnfAAYUvkuQ0tfVeBdQey4T5KpJd9bKRGTFvTuNJH3cd9Tg+r0E9H0SOmI CV8g== X-Gm-Message-State: AOJu0YxNZP71zOB5s9WyHjoYHkiKhK5HOdlUqTQlNGkKa4SV4+bxzm2V LsZ7/fBASYPlUaCraQXEKIOLvu5Nr36ve8GLznzzcu6rmtPskcb0YAZYX0ZAZ8K66fDNDgdgZEF rOKbsdRrwviXxCCd4kd7rI/CazULOJ45NkT7bFHc12Cjm2TkwfwDne2I2Jmk6eJp3h5PeLLj0sa 8KUzxhPA57uV+yoo9UtfFGF4mI2Q== X-Google-Smtp-Source: AGHT+IEsbHg1DvvUyMgsdAz+afibrxWfkaiRXKvHW83Gd38cBmoNRQuFKDRc6S9YmcjoiQy/SaVyLC+Z X-Received: from wmbbd18.prod.google.com ([2002:a05:600c:1f12:b0:436:1796:9989]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1ace:b0:38a:4184:152a with SMTP id ffacd0b85a97d-38a87314dabmr3424920f8f.28.1736360575044; Wed, 08 Jan 2025 10:22:55 -0800 (PST) Date: Wed, 8 Jan 2025 19:22:25 +0100 In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108182218.1453754-8-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2573; i=ardb@kernel.org; h=from:subject; bh=HpiQLIH+SBXUhj6Ia655frB2mrG7GycBSMSfn8QP/Dk=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb3uUPKFdR/nHFkX5OFxRefdmQtcd+dqbwxTOrs44dKNt 1LnclQedJSyMIhxMMiKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJ8Lgw/Hdb08exUv9duYxD KX/y3SKdGE735yVJGxXnlU0J6n1e5cXIMD9MTumYrrjGoh0Vanz5YQbzZ16P3TPHeEdk096bCy5 o8AIA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108182218.1453754-14-ardb+git@google.com> Subject: [PATCH 6/6] x86/efi/mixed: Move mixed mode startup code into libstub From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel From: Ard Biesheuvel The EFI mixed mode code has been decoupled from the legacy decompressor, in order to be able to reuse it with generic EFI zboot images for x86. Move the source file into the libstub source directory to facilitate this. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/Makefile | 1 - drivers/firmware/efi/libstub/Makefile | 3 +++ arch/x86/boot/compressed/efi_mixed.S => drivers/firmware/efi/libstub/x86-mixed.S | 0 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index f2051644de94..fc5563704466 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -104,7 +104,6 @@ vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o $(obj)/td vmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/mem.o vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o -vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a $(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index e04285a7a6b9..f8cbd4557131 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -62,6 +62,8 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS)) # `-fdata-sections` flag from KBUILD_CFLAGS_KERNEL KBUILD_CFLAGS_KERNEL := $(filter-out -fdata-sections, $(KBUILD_CFLAGS_KERNEL)) +KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ + lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \ file.o mem.o random.o randomalloc.o pci.o \ skip_spaces.o lib-cmdline.o lib-ctype.o \ @@ -83,6 +85,7 @@ lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o string.o intrinsics.o systable.o \ lib-$(CONFIG_ARM) += arm32-stub.o lib-$(CONFIG_ARM64) += kaslr.o arm64.o arm64-stub.o smbios.o lib-$(CONFIG_X86) += x86-stub.o smbios.o +lib-$(CONFIG_EFI_MIXED) += x86-mixed.o lib-$(CONFIG_X86_64) += x86-5lvl.o lib-$(CONFIG_RISCV) += kaslr.o riscv.o riscv-stub.o lib-$(CONFIG_LOONGARCH) += loongarch.o loongarch-stub.o diff --git a/arch/x86/boot/compressed/efi_mixed.S b/drivers/firmware/efi/libstub/x86-mixed.S similarity index 100% rename from arch/x86/boot/compressed/efi_mixed.S rename to drivers/firmware/efi/libstub/x86-mixed.S