Skip to content

Commit 1279206

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/decompressor: Avoid magic offsets for EFI handover entrypoint
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 <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent df9215f commit 1279206

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

arch/x86/boot/compressed/efi_mixed.S

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ SYM_FUNC_START(__efi64_thunk)
140140
SYM_FUNC_END(__efi64_thunk)
141141

142142
.code32
143+
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
144+
SYM_FUNC_START(efi32_stub_entry)
145+
add $0x4, %esp /* Discard return address */
146+
popl %ecx
147+
popl %edx
148+
popl %esi
149+
jmp efi32_entry
150+
SYM_FUNC_END(efi32_stub_entry)
151+
#endif
152+
143153
/*
144154
* EFI service pointer must be in %edi.
145155
*
@@ -220,7 +230,7 @@ SYM_FUNC_END(efi_enter32)
220230
* stub may still exit and return to the firmware using the Exit() EFI boot
221231
* service.]
222232
*/
223-
SYM_FUNC_START(efi32_entry)
233+
SYM_FUNC_START_LOCAL(efi32_entry)
224234
call 1f
225235
1: pop %ebx
226236

@@ -320,6 +330,14 @@ SYM_FUNC_START(efi32_pe_entry)
320330
RET
321331
SYM_FUNC_END(efi32_pe_entry)
322332

333+
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
334+
.org efi32_stub_entry + 0x200
335+
.code64
336+
SYM_FUNC_START_NOALIGN(efi64_stub_entry)
337+
jmp efi_stub_entry
338+
SYM_FUNC_END(efi64_stub_entry)
339+
#endif
340+
323341
.section ".rodata"
324342
/* EFI loaded image protocol GUID */
325343
.balign 4

arch/x86/boot/compressed/head_64.S

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,6 @@ SYM_FUNC_START(startup_32)
294294
lret
295295
SYM_FUNC_END(startup_32)
296296

297-
#if IS_ENABLED(CONFIG_EFI_MIXED) && IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL)
298-
.org 0x190
299-
SYM_FUNC_START(efi32_stub_entry)
300-
add $0x4, %esp /* Discard return address */
301-
popl %ecx
302-
popl %edx
303-
popl %esi
304-
jmp efi32_entry
305-
SYM_FUNC_END(efi32_stub_entry)
306-
#endif
307-
308297
.code64
309298
.org 0x200
310299
SYM_CODE_START(startup_64)
@@ -542,13 +531,6 @@ trampoline_return:
542531
jmp *%rax
543532
SYM_CODE_END(startup_64)
544533

545-
#if IS_ENABLED(CONFIG_EFI_MIXED) && IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL)
546-
.org 0x390
547-
SYM_FUNC_START(efi64_stub_entry)
548-
jmp efi_stub_entry
549-
SYM_FUNC_END(efi64_stub_entry)
550-
#endif
551-
552534
.text
553535
SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
554536

0 commit comments

Comments
 (0)