]> Git Repo - linux.git/commitdiff
Merge branch 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <[email protected]>
Tue, 31 Mar 2020 17:28:35 +0000 (10:28 -0700)
committerLinus Torvalds <[email protected]>
Tue, 31 Mar 2020 17:28:35 +0000 (10:28 -0700)
Pull x86 boot updates from Ingo Molnar:
 "Misc cleanups and small enhancements all around the map"

* 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/boot/compressed: Fix debug_puthex() parameter type
  x86/setup: Fix static memory detection
  x86/vmlinux: Drop unneeded linker script discard of .eh_frame
  x86/*/Makefile: Use -fno-asynchronous-unwind-tables to suppress .eh_frame sections
  x86/boot/compressed: Remove .eh_frame section from bzImage
  x86/boot/compressed/64: Remove .bss/.pgtable from bzImage
  x86/boot/compressed/64: Use 32-bit (zero-extended) MOV for z_output_len
  x86/boot/compressed/64: Use LEA to initialize boot stack pointer

1  2 
arch/x86/boot/Makefile
arch/x86/boot/compressed/Makefile
arch/x86/boot/compressed/head_64.S
drivers/firmware/efi/libstub/Makefile

diff --combined arch/x86/boot/Makefile
index ef9e1f2c836c3cb4291ce72483f753156d2aae4e,24f011e0adf1089034aa652b1980a2addb2b6b2b..e17be90ab3129cda2d83047b644c31838048c5b6
@@@ -68,6 -68,7 +68,7 @@@ clean-files += cpustr.
  KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP
  KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
  KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  GCOV_PROFILE := n
  UBSAN_SANITIZE := n
  
@@@ -88,7 -89,7 +89,7 @@@ $(obj)/vmlinux.bin: $(obj)/compressed/v
  
  SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
  
 -sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p'
 +sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|efi32_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p'
  
  quiet_cmd_zoffset = ZOFFSET $@
        cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@
index e51879bdc51cffc2aa1bfc87da326328ba7b3a6a,c33111341325cb8a6784b1e2e265a49f5b0661f2..5f7c262bcc99aedcbc35f8abd1f3437fc70c6045
@@@ -39,6 -39,7 +39,7 @@@ KBUILD_CFLAGS += $(call cc-disable-warn
  KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
  KBUILD_CFLAGS += -Wno-pointer-sign
  KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  
  KBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
  GCOV_PROFILE := n
@@@ -87,7 -88,10 +88,7 @@@ endi
  
  vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
  
 -$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
 -
 -vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o \
 -      $(objtree)/drivers/firmware/efi/libstub/lib.a
 +vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
  
  # The compressed kernel is built with -fPIC/-fPIE so that a boot loader
index d4657d38e8846f40c7038afa0728599f7aef3aad,c8ee6eff13ef028cc91076551707cfe87ff36259..4f7e6b84be0703a62849ce1c3d1ecd9c6a29a325
@@@ -53,7 -53,19 +53,7 @@@ SYM_FUNC_START(startup_32
         * all need to be under the 4G limit.
         */
        cld
 -      /*
 -       * Test KEEP_SEGMENTS flag to see if the bootloader is asking
 -       * us to not reload segments
 -       */
 -      testb $KEEP_SEGMENTS, BP_loadflags(%esi)
 -      jnz 1f
 -
        cli
 -      movl    $(__BOOT_DS), %eax
 -      movl    %eax, %ds
 -      movl    %eax, %es
 -      movl    %eax, %ss
 -1:
  
  /*
   * Calculate the delta between where we were compiled to run
  1:    popl    %ebp
        subl    $1b, %ebp
  
 +      /* Load new GDT with the 64bit segments using 32bit descriptor */
 +      leal    gdt(%ebp), %eax
 +      movl    %eax, 2(%eax)
 +      lgdt    (%eax)
 +
 +      /* Load segment registers with our descriptors */
 +      movl    $__BOOT_DS, %eax
 +      movl    %eax, %ds
 +      movl    %eax, %es
 +      movl    %eax, %fs
 +      movl    %eax, %gs
 +      movl    %eax, %ss
 +
  /* setup a stack and make sure cpu supports long mode. */
        leal    boot_stack_end(%ebp), %esp
  
  
  #ifdef CONFIG_RELOCATABLE
        movl    %ebp, %ebx
 +
 +#ifdef CONFIG_EFI_STUB
 +/*
 + * If we were loaded via the EFI LoadImage service, startup_32 will be at an
 + * offset to the start of the space allocated for the image. efi_pe_entry will
 + * set up image_offset to tell us where the image actually starts, so that we
 + * can use the full available buffer.
 + *    image_offset = startup_32 - image_base
 + * Otherwise image_offset will be zero and has no effect on the calculations.
 + */
 +      subl    image_offset(%ebp), %ebx
 +#endif
 +
        movl    BP_kernel_alignment(%esi), %eax
        decl    %eax
        addl    %eax, %ebx
        notl    %eax
        andl    %eax, %ebx
        cmpl    $LOAD_PHYSICAL_ADDR, %ebx
 -      jge     1f
 +      jae     1f
  #endif
        movl    $LOAD_PHYSICAL_ADDR, %ebx
  1:
  
        /* Target address to relocate to for decompression */
 -      movl    BP_init_size(%esi), %eax
 -      subl    $_end, %eax
 -      addl    %eax, %ebx
 +      addl    BP_init_size(%esi), %ebx
 +      subl    $_end, %ebx
  
  /*
   * Prepare for entering 64 bit mode
   */
  
 -      /* Load new GDT with the 64bit segments using 32bit descriptor */
 -      addl    %ebp, gdt+2(%ebp)
 -      lgdt    gdt(%ebp)
 -
        /* Enable PAE mode */
        movl    %cr4, %eax
        orl     $X86_CR4_PAE, %eax
        cmp     $0, %edi
        jz      1f
        leal    efi64_stub_entry(%ebp), %eax
 -      movl    %esi, %edx
        movl    efi32_boot_args+4(%ebp), %esi
 +      movl    efi32_boot_args+8(%ebp), %edx   // saved bootparams pointer
 +      cmpl    $0, %edx
 +      jnz     1f
 +      leal    efi_pe_entry(%ebp), %eax
 +      movl    %edi, %ecx                      // MS calling convention
 +      movl    %esi, %edx
  1:
  #endif
        pushl   %eax
@@@ -250,17 -236,11 +250,17 @@@ SYM_FUNC_START(efi32_stub_entry
  1:    pop     %ebp
        subl    $1b, %ebp
  
 +      movl    %esi, efi32_boot_args+8(%ebp)
 +SYM_INNER_LABEL(efi32_pe_stub_entry, SYM_L_LOCAL)
        movl    %ecx, efi32_boot_args(%ebp)
        movl    %edx, efi32_boot_args+4(%ebp)
 -      sgdtl   efi32_boot_gdt(%ebp)
        movb    $0, efi_is64(%ebp)
  
 +      /* Save firmware GDTR and code/data selectors */
 +      sgdtl   efi32_boot_gdt(%ebp)
 +      movw    %cs, efi32_boot_cs(%ebp)
 +      movw    %ds, efi32_boot_ds(%ebp)
 +
        /* Disable paging */
        movl    %cr0, %eax
        btrl    $X86_CR0_PG_BIT, %eax
@@@ -284,9 -264,6 +284,9 @@@ SYM_CODE_START(startup_64
         * and command line.
         */
  
 +      cld
 +      cli
 +
        /* Setup data segments. */
        xorl    %eax, %eax
        movl    %eax, %ds
        /* Start with the delta to where the kernel will run at. */
  #ifdef CONFIG_RELOCATABLE
        leaq    startup_32(%rip) /* - $startup_32 */, %rbp
 +
 +#ifdef CONFIG_EFI_STUB
 +/*
 + * If we were loaded via the EFI LoadImage service, startup_32 will be at an
 + * offset to the start of the space allocated for the image. efi_pe_entry will
 + * set up image_offset to tell us where the image actually starts, so that we
 + * can use the full available buffer.
 + *    image_offset = startup_32 - image_base
 + * Otherwise image_offset will be zero and has no effect on the calculations.
 + */
 +      movl    image_offset(%rip), %eax
 +      subq    %rax, %rbp
 +#endif
 +
        movl    BP_kernel_alignment(%rsi), %eax
        decl    %eax
        addq    %rax, %rbp
        notq    %rax
        andq    %rax, %rbp
        cmpq    $LOAD_PHYSICAL_ADDR, %rbp
 -      jge     1f
 +      jae     1f
  #endif
        movq    $LOAD_PHYSICAL_ADDR, %rbp
  1:
         */
  
        /* Make sure we have GDT with 32-bit code segment */
 -      leaq    gdt(%rip), %rax
 -      movq    %rax, gdt64+2(%rip)
 -      lgdt    gdt64(%rip)
 +      leaq    gdt64(%rip), %rax
 +      addq    %rax, 2(%rax)
 +      lgdt    (%rax)
  
        /*
         * paging_prepare() sets up the trampoline and checks if we need to
@@@ -476,16 -439,6 +476,16 @@@ trampoline_return
        cld
        popq    %rsi
  
 +      /*
 +       * The GDT may get overwritten either during the copy we just did or
 +       * during extract_kernel below. To avoid any issues, repoint the GDTR
 +       * to the new copy of the GDT.
 +       */
 +      leaq    gdt64(%rbx), %rax
 +      leaq    gdt(%rbx), %rdx
 +      movq    %rdx, 2(%rax)
 +      lgdt    (%rax)
 +
  /*
   * Jump to the relocated address.
   */
@@@ -498,9 -451,9 +498,9 @@@ SYM_CODE_END(startup_64
  SYM_FUNC_START(efi64_stub_entry)
  SYM_FUNC_START_ALIAS(efi_stub_entry)
        and     $~0xf, %rsp                     /* realign the stack */
 +      movq    %rdx, %rbx                      /* save boot_params pointer */
        call    efi_main
 -      movq    %rax,%rsi
 -      movl    BP_code32_start(%esi), %eax
 +      movq    %rbx,%rsi
        leaq    startup_64(%rax), %rax
        jmp     *%rax
  SYM_FUNC_END(efi64_stub_entry)
@@@ -529,7 -482,7 +529,7 @@@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocate
        leaq    input_data(%rip), %rdx  /* input_data */
        movl    $z_input_len, %ecx      /* input_len */
        movq    %rbp, %r8               /* output target address */
-       movq    $z_output_len, %r9      /* decompressed length, end of relocs */
+       movl    $z_output_len, %r9d     /* decompressed length, end of relocs */
        call    extract_kernel          /* returns kernel location in %rax */
        popq    %rsi
  
@@@ -658,13 -611,13 +658,13 @@@ SYM_FUNC_END(.Lno_longmode
  
        .data
  SYM_DATA_START_LOCAL(gdt64)
 -      .word   gdt_end - gdt
 -      .quad   0
 +      .word   gdt_end - gdt - 1
 +      .quad   gdt - gdt64
  SYM_DATA_END(gdt64)
        .balign 8
  SYM_DATA_START_LOCAL(gdt)
 -      .word   gdt_end - gdt
 -      .long   gdt
 +      .word   gdt_end - gdt - 1
 +      .long   0
        .word   0
        .quad   0x00cf9a000000ffff      /* __KERNEL32_CS */
        .quad   0x00af9a000000ffff      /* __KERNEL_CS */
        .quad   0x0000000000000000      /* TS continued */
  SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end)
  
 +#ifdef CONFIG_EFI_STUB
 +SYM_DATA(image_offset, .long 0)
 +#endif
 +
  #ifdef CONFIG_EFI_MIXED
 -SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0)
 +SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0)
  SYM_DATA(efi_is64, .byte 1)
 +
 +#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
 +      subl    $1b, %ebx
 +
 +      /* Get the loaded image protocol pointer from the image handle */
 +      leal    -4(%ebp), %eax
 +      pushl   %eax                            // &loaded_image
 +      leal    loaded_image_proto(%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
 +      movl    %ebx, %ebp                      // startup_32 for efi32_pe_stub_entry
 +      /*
 +       * 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, %ebx
 +      movl    %ebx, image_offset(%ebp)        // save image_offset
 +      jmp     efi32_pe_stub_entry
 +
 +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
  
  /*
@@@ -780,7 -645,7 +780,7 @@@ SYM_DATA_END_LABEL(boot_stack, SYM_L_LO
  /*
   * Space for page tables (not in .bss so not zeroed)
   */
-       .section ".pgtable","a",@nobits
+       .section ".pgtable","aw",@nobits
        .balign 4096
  SYM_DATA_LOCAL(pgtable,               .fill BOOT_PGT_SIZE, 1, 0)
  
index 4d6246c6f651a7605a56b6375850fc7f379abd14,a1140c4ee478e3be6dfd727b6b87e3339eebc27f..094eabdecfe61fa5a8707d5ec787019b5b42fd3b
@@@ -12,7 -12,8 +12,8 @@@ cflags-$(CONFIG_X86)          += -m$(BITS) -D__
                                   -mno-mmx -mno-sse -fshort-wchar \
                                   -Wno-pointer-sign \
                                   $(call cc-disable-warning, address-of-packed-member) \
-                                  $(call cc-disable-warning, gnu)
+                                  $(call cc-disable-warning, gnu) \
+                                  -fno-asynchronous-unwind-tables
  
  # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
  # disable the stackleak plugin
@@@ -25,7 -26,6 +26,7 @@@ cflags-$(CONFIG_ARM)          := $(subst $(CC_F
  cflags-$(CONFIG_EFI_ARMSTUB)  += -I$(srctree)/scripts/dtc/libfdt
  
  KBUILD_CFLAGS                 := $(cflags-y) -DDISABLE_BRANCH_PROFILING \
 +                                 -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \
                                   -D__NO_FORTIFY \
                                   $(call cc-option,-ffreestanding) \
                                   $(call cc-option,-fno-stack-protector) \
@@@ -40,11 -40,11 +41,11 @@@ OBJECT_FILES_NON_STANDARD  := 
  KCOV_INSTRUMENT                       := n
  
  lib-y                         := efi-stub-helper.o gop.o secureboot.o tpm.o \
 -                                 random.o pci.o
 +                                 file.o mem.o random.o randomalloc.o pci.o \
 +                                 skip_spaces.o lib-cmdline.o lib-ctype.o
  
  # include the stub's generic dependencies from lib/ when building for ARM/arm64
  arm-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c
 -arm-deps-$(CONFIG_ARM64) += sort.c
  
  $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE
        $(call if_changed_rule,cc_o_c)
@@@ -54,7 -54,6 +55,7 @@@ lib-$(CONFIG_EFI_ARMSTUB)     += arm-stub.
  
  lib-$(CONFIG_ARM)             += arm32-stub.o
  lib-$(CONFIG_ARM64)           += arm64-stub.o
 +lib-$(CONFIG_X86)             += x86-stub.o
  CFLAGS_arm32-stub.o           := -DTEXT_OFFSET=$(TEXT_OFFSET)
  CFLAGS_arm64-stub.o           := -DTEXT_OFFSET=$(TEXT_OFFSET)
  
This page took 0.097716 seconds and 4 git commands to generate.