linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: x86@kernel.org, kees@kernel.org, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 5/6] x86/efi/mixed: Reduce padding by moving some code around
Date: Wed,  8 Jan 2025 19:22:24 +0100	[thread overview]
Message-ID: <20250108182218.1453754-13-ardb+git@google.com> (raw)
In-Reply-To: <20250108182218.1453754-8-ardb+git@google.com>

From: Ard Biesheuvel <ardb@kernel.org>

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 <ardb@kernel.org>
---
 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 <asm/processor-flags.h>
 #include <asm/segment.h>
 
-	.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 */
-- 
2.47.1.613.gc27f4b7a9f-goog


  parent reply	other threads:[~2025-01-08 18:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08 18:22 [PATCH 0/6] x86/efi/mixed: Decouple from legacy decompressor Ard Biesheuvel
2025-01-08 18:22 ` [PATCH 1/6] x86/efi/mixed: Check CPU compatibility without relying on verify_cpu() Ard Biesheuvel
2025-01-08 18:22 ` [PATCH 2/6] x86/efi/mixed: Remove dependency on legacy startup_32 code Ard Biesheuvel
2025-01-08 18:22 ` [PATCH 3/6] x86/efi/mixed: Don't bother preserving 64-bit mode segment selectors Ard Biesheuvel
2025-01-08 18:22 ` [PATCH 4/6] x86/efi/mixed: Simplify and document thunking logic Ard Biesheuvel
2025-01-08 18:22 ` Ard Biesheuvel [this message]
2025-01-08 18:22 ` [PATCH 6/6] x86/efi/mixed: Move mixed mode startup code into libstub Ard Biesheuvel
2025-02-25 20:56 ` [PATCH 0/6] x86/efi/mixed: Decouple from legacy decompressor Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250108182218.1453754-13-ardb+git@google.com \
    --to=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).