Skip to content

Commit df9215f

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/efistub: Simplify and clean up handover entry code
Now that the EFI entry code in assembler is only used by the optional and deprecated EFI handover protocol, and given that the EFI stub C code no longer returns to it, most of it can simply be dropped. While at it, clarify the symbol naming, by merging efi_main() and efi_stub_entry(), making the latter the shared entry point for all different boot modes that enter via the EFI stub. The efi32_stub_entry() and efi64_stub_entry() names are referenced explicitly by the tooling that populates the setup header, so these must be retained, but can be emitted as aliases of efi_stub_entry() where appropriate. 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 d2d7a54 commit df9215f

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

Documentation/arch/x86/boot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ execution context provided by the EFI firmware.
14171417

14181418
The function prototype for the handover entry point looks like this::
14191419

1420-
efi_main(void *handle, efi_system_table_t *table, struct boot_params *bp)
1420+
efi_stub_entry(void *handle, efi_system_table_t *table, struct boot_params *bp)
14211421
14221422
'handle' is the EFI image handle passed to the boot loader by the EFI
14231423
firmware, 'table' is the EFI system table - these are the first two

arch/x86/boot/compressed/efi_mixed.S

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* When booting in 64-bit mode on 32-bit EFI firmware, startup_64_mixed_mode()
2727
* is the first thing that runs after switching to long mode. Depending on
2828
* whether the EFI handover protocol or the compat entry point was used to
29-
* enter the kernel, it will either branch to the 64-bit EFI handover
30-
* entrypoint at offset 0x390 in the image, or to the 64-bit EFI PE/COFF
29+
* enter the kernel, it will either branch to the common 64-bit EFI stub
30+
* entrypoint efi_stub_entry() directly, or via the 64-bit EFI PE/COFF
3131
* entrypoint efi_pe_entry(). In the former case, the bootloader must provide a
3232
* struct bootparams pointer as the third argument, so the presence of such a
3333
* pointer is used to disambiguate.
@@ -37,21 +37,23 @@
3737
* | efi32_pe_entry |---->| | | +-----------+--+
3838
* +------------------+ | | +------+----------------+ |
3939
* | startup_32 |---->| startup_64_mixed_mode | |
40-
* +------------------+ | | +------+----------------+ V
41-
* | efi32_stub_entry |---->| | | +------------------+
42-
* +------------------+ +------------+ +---->| efi64_stub_entry |
43-
* +-------------+----+
44-
* +------------+ +----------+ |
45-
* | startup_64 |<----| efi_main |<--------------+
46-
* +------------+ +----------+
40+
* +------------------+ | | +------+----------------+ |
41+
* | efi32_stub_entry |---->| | | |
42+
* +------------------+ +------------+ | |
43+
* V |
44+
* +------------+ +----------------+ |
45+
* | startup_64 |<----| efi_stub_entry |<--------+
46+
* +------------+ +----------------+
4747
*/
4848
SYM_FUNC_START(startup_64_mixed_mode)
4949
lea efi32_boot_args(%rip), %rdx
5050
mov 0(%rdx), %edi
5151
mov 4(%rdx), %esi
52+
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
5253
mov 8(%rdx), %edx // saved bootparams pointer
5354
test %edx, %edx
54-
jnz efi64_stub_entry
55+
jnz efi_stub_entry
56+
#endif
5557
/*
5658
* efi_pe_entry uses MS calling convention, which requires 32 bytes of
5759
* shadow space on the stack even if all arguments are passed in

arch/x86/boot/compressed/head_32.S

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,6 @@ SYM_FUNC_START(startup_32)
150150
jmp *%eax
151151
SYM_FUNC_END(startup_32)
152152

153-
#ifdef CONFIG_EFI_STUB
154-
SYM_FUNC_START(efi32_stub_entry)
155-
add $0x4, %esp
156-
movl 8(%esp), %esi /* save boot_params pointer */
157-
call efi_main
158-
/* efi_main returns the possibly relocated address of startup_32 */
159-
jmp *%eax
160-
SYM_FUNC_END(efi32_stub_entry)
161-
SYM_FUNC_ALIAS(efi_stub_entry, efi32_stub_entry)
162-
#endif
163-
164153
.text
165154
SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
166155

arch/x86/boot/compressed/head_64.S

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,19 +542,11 @@ trampoline_return:
542542
jmp *%rax
543543
SYM_CODE_END(startup_64)
544544

545-
#ifdef CONFIG_EFI_STUB
546-
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
545+
#if IS_ENABLED(CONFIG_EFI_MIXED) && IS_ENABLED(CONFIG_EFI_HANDOVER_PROTOCOL)
547546
.org 0x390
548-
#endif
549547
SYM_FUNC_START(efi64_stub_entry)
550-
and $~0xf, %rsp /* realign the stack */
551-
movq %rdx, %rbx /* save boot_params pointer */
552-
call efi_main
553-
movq %rbx,%rsi
554-
leaq rva(startup_64)(%rax), %rax
555-
jmp *%rax
548+
jmp efi_stub_entry
556549
SYM_FUNC_END(efi64_stub_entry)
557-
SYM_FUNC_ALIAS(efi_stub_entry, efi64_stub_entry)
558550
#endif
559551

560552
.text

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,9 @@ static void __noreturn enter_kernel(unsigned long kernel_addr,
817817
* return. On failure, it will exit to the firmware via efi_exit() instead of
818818
* returning.
819819
*/
820-
asmlinkage unsigned long efi_main(efi_handle_t handle,
821-
efi_system_table_t *sys_table_arg,
822-
struct boot_params *boot_params)
820+
void __noreturn efi_stub_entry(efi_handle_t handle,
821+
efi_system_table_t *sys_table_arg,
822+
struct boot_params *boot_params)
823823
{
824824
unsigned long bzimage_addr = (unsigned long)startup_32;
825825
unsigned long buffer_start, buffer_end;
@@ -964,7 +964,19 @@ asmlinkage unsigned long efi_main(efi_handle_t handle,
964964

965965
enter_kernel(bzimage_addr, boot_params);
966966
fail:
967-
efi_err("efi_main() failed!\n");
967+
efi_err("efi_stub_entry() failed!\n");
968968

969969
efi_exit(handle, status);
970970
}
971+
972+
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
973+
#ifndef CONFIG_EFI_MIXED
974+
extern __alias(efi_stub_entry)
975+
void efi32_stub_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg,
976+
struct boot_params *boot_params);
977+
978+
extern __alias(efi_stub_entry)
979+
void efi64_stub_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg,
980+
struct boot_params *boot_params);
981+
#endif
982+
#endif

0 commit comments

Comments
 (0)