diff mbox series

[3/6] x86/efi/mixed: Don't bother preserving 64-bit mode segment selectors

Message ID 20250108182218.1453754-11-ardb+git@google.com
State New
Headers show
Series x86/efi/mixed: Decouple from legacy decompressor | expand

Commit Message

Ard Biesheuvel Jan. 8, 2025, 6:22 p.m. UTC
From: Ard Biesheuvel <ardb@kernel.org>

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 <ardb@kernel.org>
---
 arch/x86/boot/compressed/efi_mixed.S | 24 ++++++--------------
 1 file changed, 7 insertions(+), 17 deletions(-)
diff mbox series

Patch

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