lkml.org 
[lkml]   [2022]   [Nov]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[tip: x86/boot] x86/boot/compressed: Move efi32_pe_entry() out of head_64.S
    The following commit has been merged into the x86/boot branch of tip:

    Commit-ID: 7f22ca396778fea9332d83ec2359dbe8396e9a06
    Gitweb: https://git.kernel.org/tip/7f22ca396778fea9332d83ec2359dbe8396e9a06
    Author: Ard Biesheuvel <ardb@kernel.org>
    AuthorDate: Tue, 22 Nov 2022 17:10:06 +01:00
    Committer: Borislav Petkov <bp@suse.de>
    CommitterDate: Tue, 22 Nov 2022 19:24:57 +01:00

    x86/boot/compressed: Move efi32_pe_entry() out of head_64.S

    Move the implementation of efi32_pe_entry() into efi-mixed.S, which is a
    more suitable location that only gets built if EFI mixed mode is
    actually enabled.

    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Link: https://lore.kernel.org/r/20221122161017.2426828-7-ardb@kernel.org
    ---
    arch/x86/boot/compressed/efi_mixed.S | 82 +++++++++++++++++++++++++-
    arch/x86/boot/compressed/head_64.S | 87 +---------------------------
    2 files changed, 83 insertions(+), 86 deletions(-)

    diff --git a/arch/x86/boot/compressed/efi_mixed.S b/arch/x86/boot/compressed/efi_mixed.S
    index 3487484..8844d8e 100644
    --- a/arch/x86/boot/compressed/efi_mixed.S
    +++ b/arch/x86/boot/compressed/efi_mixed.S
    @@ -257,6 +257,88 @@ SYM_FUNC_START(efi32_entry)
    jmp startup_32
    SYM_FUNC_END(efi32_entry)

    +#define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime)
    +#define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol)
    +#define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base)
    +
    +/*
    + * efi_status_t efi32_pe_entry(efi_handle_t image_handle,
    + * efi_system_table_32_t *sys_table)
    + */
    +SYM_FUNC_START(efi32_pe_entry)
    + pushl %ebp
    + movl %esp, %ebp
    + pushl %eax // dummy push to allocate loaded_image
    +
    + 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
    +
    + call 1f
    +1: pop %ebx
    +
    + /* Get the loaded image protocol pointer from the image handle */
    + leal -4(%ebp), %eax
    + pushl %eax // &loaded_image
    + leal (loaded_image_proto - 1b)(%ebx), %eax
    + pushl %eax // pass the GUID address
    + pushl 8(%ebp) // pass the image handle
    +
    + /*
    + * Note the alignment of the stack frame.
    + * sys_table
    + * handle <-- 16-byte aligned on entry by ABI
    + * return address
    + * frame pointer
    + * loaded_image <-- local variable
    + * saved %ebx <-- 16-byte aligned here
    + * saved %edi
    + * &loaded_image
    + * &loaded_image_proto
    + * handle <-- 16-byte aligned for call to handle_protocol
    + */
    +
    + movl 12(%ebp), %eax // sys_table
    + movl ST32_boottime(%eax), %eax // sys_table->boottime
    + call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol
    + addl $12, %esp // restore argument space
    + testl %eax, %eax
    + jnz 2f
    +
    + movl 8(%ebp), %ecx // image_handle
    + movl 12(%ebp), %edx // sys_table
    + movl -4(%ebp), %esi // loaded_image
    + movl LI32_image_base(%esi), %esi // loaded_image->image_base
    + leal (startup_32 - 1b)(%ebx), %ebp // runtime address of startup_32
    + /*
    + * We need to set the image_offset variable here since startup_32() will
    + * use it before we get to the 64-bit efi_pe_entry() in C code.
    + */
    + subl %esi, %ebp // calculate image_offset
    + movl %ebp, (image_offset - 1b)(%ebx) // save image_offset
    + xorl %esi, %esi
    + jmp efi32_entry // pass %ecx, %edx, %esi
    + // no other registers remain live
    +
    +2: popl %edi // restore callee-save registers
    + popl %ebx
    + leave
    + RET
    +SYM_FUNC_END(efi32_pe_entry)
    +
    + .section ".rodata"
    + /* EFI loaded image protocol GUID */
    + .balign 4
    +SYM_DATA_START_LOCAL(loaded_image_proto)
    + .long 0x5b1b31a1
    + .word 0x9562, 0x11d2
    + .byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b
    +SYM_DATA_END(loaded_image_proto)
    +
    .data
    .balign 8
    SYM_DATA_START_LOCAL(efi32_boot_gdt)
    diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
    index 9cd2a28..36f37f9 100644
    --- a/arch/x86/boot/compressed/head_64.S
    +++ b/arch/x86/boot/compressed/head_64.S
    @@ -673,6 +673,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lno_longmode)
    jmp 1b
    SYM_FUNC_END(.Lno_longmode)

    + .globl verify_cpu
    #include "../../kernel/verify_cpu.S"

    .data
    @@ -720,92 +721,6 @@ SYM_DATA_END_LABEL(boot32_idt, SYM_L_GLOBAL, boot32_idt_end)
    #ifdef CONFIG_EFI_STUB
    SYM_DATA(image_offset, .long 0)
    #endif
    -#ifdef CONFIG_EFI_MIXED
    -#define ST32_boottime 60 // offsetof(efi_system_table_32_t, boottime)
    -#define BS32_handle_protocol 88 // offsetof(efi_boot_services_32_t, handle_protocol)
    -#define LI32_image_base 32 // offsetof(efi_loaded_image_32_t, image_base)
    -
    - .text
    - .code32
    -SYM_FUNC_START(efi32_pe_entry)
    -/*
    - * efi_status_t efi32_pe_entry(efi_handle_t image_handle,
    - * efi_system_table_32_t *sys_table)
    - */
    -
    - pushl %ebp
    - movl %esp, %ebp
    - pushl %eax // dummy push to allocate loaded_image
    -
    - 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
    -
    - call 1f
    -1: pop %ebx
    -
    - /* Get the loaded image protocol pointer from the image handle */
    - leal -4(%ebp), %eax
    - pushl %eax // &loaded_image
    - leal (loaded_image_proto - 1b)(%ebx), %eax
    - pushl %eax // pass the GUID address
    - pushl 8(%ebp) // pass the image handle
    -
    - /*
    - * Note the alignment of the stack frame.
    - * sys_table
    - * handle <-- 16-byte aligned on entry by ABI
    - * return address
    - * frame pointer
    - * loaded_image <-- local variable
    - * saved %ebx <-- 16-byte aligned here
    - * saved %edi
    - * &loaded_image
    - * &loaded_image_proto
    - * handle <-- 16-byte aligned for call to handle_protocol
    - */
    -
    - movl 12(%ebp), %eax // sys_table
    - movl ST32_boottime(%eax), %eax // sys_table->boottime
    - call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol
    - addl $12, %esp // restore argument space
    - testl %eax, %eax
    - jnz 2f
    -
    - movl 8(%ebp), %ecx // image_handle
    - movl 12(%ebp), %edx // sys_table
    - movl -4(%ebp), %esi // loaded_image
    - movl LI32_image_base(%esi), %esi // loaded_image->image_base
    - leal (startup_32 - 1b)(%ebx), %ebp // runtime address of startup_32
    - /*
    - * We need to set the image_offset variable here since startup_32() will
    - * use it before we get to the 64-bit efi_pe_entry() in C code.
    - */
    - subl %esi, %ebp // calculate image_offset
    - movl %ebp, (image_offset - 1b)(%ebx) // save image_offset
    - xorl %esi, %esi
    - jmp efi32_entry // pass %ecx, %edx, %esi
    - // no other registers remain live
    -
    -2: popl %edi // restore callee-save registers
    - popl %ebx
    - leave
    - RET
    -SYM_FUNC_END(efi32_pe_entry)
    -
    - .section ".rodata"
    - /* EFI loaded image protocol GUID */
    - .balign 4
    -SYM_DATA_START_LOCAL(loaded_image_proto)
    - .long 0x5b1b31a1
    - .word 0x9562, 0x11d2
    - .byte 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b
    -SYM_DATA_END(loaded_image_proto)
    -#endif

    #ifdef CONFIG_AMD_MEM_ENCRYPT
    __HEAD
    \
     
     \ /
      Last update: 2022-11-24 09:15    [W:4.200 / U:0.252 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site