1. 25 1月, 2020 1 次提交
  2. 20 1月, 2020 2 次提交
  3. 11 1月, 2020 2 次提交
    • A
      efi/x86: Allow translating 64-bit arguments for mixed mode calls · ea7d87f9
      Arvind Sankar 提交于
      Introduce the ability to define macros to perform argument translation
      for the calls that need it, and define them for the boot services that
      we currently use.
      
      When calling 32-bit firmware methods in mixed mode, all output
      parameters that are 32-bit according to the firmware, but 64-bit in the
      kernel (ie OUT UINTN * or OUT VOID **) must be initialized in the
      kernel, or the upper 32 bits may contain garbage. Define macros that
      zero out the upper 32 bits of the output before invoking the firmware
      method.
      
      When a 32-bit EFI call takes 64-bit arguments, the mixed-mode call must
      push the two 32-bit halves as separate arguments onto the stack. This
      can be achieved by splitting the argument into its two halves when
      calling the assembler thunk. Define a macro to do this for the
      free_pages boot service.
      Signed-off-by: NArvind Sankar <nivedita@alum.mit.edu>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Matthew Garrett <mjg59@google.com>
      Cc: linux-efi@vger.kernel.org
      Link: https://lkml.kernel.org/r/20200103113953.9571-17-ardb@kernel.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      ea7d87f9
    • A
      efi/libstub/x86: Force 'hidden' visibility for extern declarations · bc7c9d62
      Ard Biesheuvel 提交于
      Commit c3710de5 ("efi/libstub/x86: Drop __efi_early() export and
      efi_config struct") introduced a reference from C code in eboot.c to
      the startup_32 symbol defined in the .S startup code. This results in
      a GOT based reference to startup_32, and since GOT entries carry
      absolute addresses, they need to be fixed up before they can be used.
      
      On modern toolchains (binutils 2.26 or later), this reference is
      relaxed into a R_386_GOTOFF relocation (or the analogous X86_64 one)
      which never uses the absolute address in the entry, and so we get
      away with not fixing up the GOT table before calling the EFI entry
      point. However, GCC 4.6 combined with a binutils of the era (2.24)
      will produce a true GOT indirected reference, resulting in a wrong
      value to be returned for the address of startup_32() if the boot
      code is not running at the address it was linked at.
      
      Fortunately, we can easily override this behavior, and force GCC to
      emit the GOTOFF relocations explicitly, by setting the visibility
      pragma 'hidden'.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Arvind Sankar <nivedita@alum.mit.edu>
      Cc: Matthew Garrett <mjg59@google.com>
      Cc: linux-efi@vger.kernel.org
      Link: https://lkml.kernel.org/r/20200103113953.9571-3-ardb@kernel.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      bc7c9d62
  4. 25 12月, 2019 13 次提交
  5. 07 11月, 2019 2 次提交
    • D
      x86/efi: EFI soft reservation to E820 enumeration · 262b45ae
      Dan Williams 提交于
      UEFI 2.8 defines an EFI_MEMORY_SP attribute bit to augment the
      interpretation of the EFI Memory Types as "reserved for a specific
      purpose".
      
      The proposed Linux behavior for specific purpose memory is that it is
      reserved for direct-access (device-dax) by default and not available for
      any kernel usage, not even as an OOM fallback.  Later, through udev
      scripts or another init mechanism, these device-dax claimed ranges can
      be reconfigured and hot-added to the available System-RAM with a unique
      node identifier. This device-dax management scheme implements "soft" in
      the "soft reserved" designation by allowing some or all of the
      reservation to be recovered as typical memory. This policy can be
      disabled at compile-time with CONFIG_EFI_SOFT_RESERVE=n, or runtime with
      efi=nosoftreserve.
      
      This patch introduces 2 new concepts at once given the entanglement
      between early boot enumeration relative to memory that can optionally be
      reserved from the kernel page allocator by default. The new concepts
      are:
      
      - E820_TYPE_SOFT_RESERVED: Upon detecting the EFI_MEMORY_SP
        attribute on EFI_CONVENTIONAL memory, update the E820 map with this
        new type. Only perform this classification if the
        CONFIG_EFI_SOFT_RESERVE=y policy is enabled, otherwise treat it as
        typical ram.
      
      - IORES_DESC_SOFT_RESERVED: Add a new I/O resource descriptor for
        a device driver to search iomem resources for application specific
        memory. Teach the iomem code to identify such ranges as "Soft Reserved".
      
      Note that the comment for do_add_efi_memmap() needed refreshing since it
      seemed to imply that the efi map might overflow the e820 table, but that
      is not an issue as of commit 7b6e4ba3 "x86/boot/e820: Clean up the
      E820_X_MAX definition" that removed the 128 entry limit for
      e820__range_add().
      
      A follow-on change integrates parsing of the ACPI HMAT to identify the
      node and sub-range boundaries of EFI_MEMORY_SP designated memory. For
      now, just identify and reserve memory of this type.
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Reviewed-by: NDave Hansen <dave.hansen@linux.intel.com>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      Acked-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      262b45ae
    • D
      x86: efi/random: Invoke EFI_RNG_PROTOCOL to seed the UEFI RNG table · 0d959814
      Dominik Brodowski 提交于
      Invoke the EFI_RNG_PROTOCOL protocol in the context of the x86 EFI stub,
      same as is done on arm/arm64 since commit 568bc4e8 ("efi/arm*/libstub:
      Invoke EFI_RNG_PROTOCOL to seed the UEFI RNG table"). Within the stub,
      a Linux-specific RNG seed UEFI config table will be seeded. The EFI routines
      in the core kernel will pick that up later, yet still early during boot,
      to seed the kernel entropy pool. If CONFIG_RANDOM_TRUST_BOOTLOADER, entropy
      is credited for this seed.
      Signed-off-by: NDominik Brodowski <linux@dominikbrodowski.net>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      0d959814
  6. 31 10月, 2019 1 次提交
    • K
      x86, efi: Never relocate kernel below lowest acceptable address · 220dd769
      Kairui Song 提交于
      Currently, kernel fails to boot on some HyperV VMs when using EFI.
      And it's a potential issue on all x86 platforms.
      
      It's caused by broken kernel relocation on EFI systems, when below three
      conditions are met:
      
      1. Kernel image is not loaded to the default address (LOAD_PHYSICAL_ADDR)
         by the loader.
      2. There isn't enough room to contain the kernel, starting from the
         default load address (eg. something else occupied part the region).
      3. In the memmap provided by EFI firmware, there is a memory region
         starts below LOAD_PHYSICAL_ADDR, and suitable for containing the
         kernel.
      
      EFI stub will perform a kernel relocation when condition 1 is met. But
      due to condition 2, EFI stub can't relocate kernel to the preferred
      address, so it fallback to ask EFI firmware to alloc lowest usable memory
      region, got the low region mentioned in condition 3, and relocated
      kernel there.
      
      It's incorrect to relocate the kernel below LOAD_PHYSICAL_ADDR. This
      is the lowest acceptable kernel relocation address.
      
      The first thing goes wrong is in arch/x86/boot/compressed/head_64.S.
      Kernel decompression will force use LOAD_PHYSICAL_ADDR as the output
      address if kernel is located below it. Then the relocation before
      decompression, which move kernel to the end of the decompression buffer,
      will overwrite other memory region, as there is no enough memory there.
      
      To fix it, just don't let EFI stub relocate the kernel to any address
      lower than lowest acceptable address.
      
      [ ardb: introduce efi_low_alloc_above() to reduce the scope of the change ]
      Signed-off-by: NKairui Song <kasong@redhat.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Acked-by: NJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: https://lkml.kernel.org/r/20191029173755.27149-6-ardb@kernel.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      220dd769
  7. 19 7月, 2019 1 次提交
    • Z
      x86/boot/efi: Remove unused variables · cd6697b8
      Zhenzhong Duan 提交于
      Fix gcc warnings:
      
      arch/x86/boot/compressed/eboot.c: In function 'make_boot_params':
      arch/x86/boot/compressed/eboot.c:394:6: warning: unused variable 'i' [-Wunused-variable]
        int i;
            ^
      arch/x86/boot/compressed/eboot.c:393:6: warning: unused variable 's1' [-Wunused-variable]
        u8 *s1;
            ^
      arch/x86/boot/compressed/eboot.c:392:7: warning: unused variable 's2' [-Wunused-variable]
        u16 *s2;
             ^
      arch/x86/boot/compressed/eboot.c:387:8: warning: unused variable 'options' [-Wunused-variable]
        void *options, *handle;
              ^
      arch/x86/boot/compressed/eboot.c: In function 'add_e820ext':
      arch/x86/boot/compressed/eboot.c:498:16: warning: unused variable 'size' [-Wunused-variable]
        unsigned long size;
                      ^
      arch/x86/boot/compressed/eboot.c:497:15: warning: unused variable 'status' [-Wunused-variable]
        efi_status_t status;
                     ^
      arch/x86/boot/compressed/eboot.c: In function 'exit_boot_func':
      arch/x86/boot/compressed/eboot.c:681:15: warning: unused variable 'status' [-Wunused-variable]
        efi_status_t status;
                     ^
      arch/x86/boot/compressed/eboot.c:680:8: warning: unused variable 'nr_desc' [-Wunused-variable]
        __u32 nr_desc;
              ^
      arch/x86/boot/compressed/eboot.c: In function 'efi_main':
      arch/x86/boot/compressed/eboot.c:750:22: warning: unused variable 'image' [-Wunused-variable]
        efi_loaded_image_t *image;
                            ^
      Signed-off-by: NZhenzhong Duan <zhenzhong.duan@oracle.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Link: https://lkml.kernel.org/r/1563282957-26898-1-git-send-email-zhenzhong.duan@oracle.com
      cd6697b8
  8. 19 6月, 2019 1 次提交
  9. 30 11月, 2018 1 次提交
    • E
      x86/efi: Allocate e820 buffer before calling efi_exit_boot_service · b84a64fa
      Eric Snowberg 提交于
      The following commit:
      
        d6493401 ("x86/efi: Use efi_exit_boot_services()")
      
      introduced a regression on systems with large memory maps causing them
      to hang on boot. The first "goto get_map" that was removed from
      exit_boot() ensured there was enough room for the memory map when
      efi_call_early(exit_boot_services) was called. This happens when
      (nr_desc > ARRAY_SIZE(params->e820_table).
      
      Chain of events:
      
        exit_boot()
          efi_exit_boot_services()
            efi_get_memory_map                  <- at this point the mm can't grow over 8 desc
            priv_func()
              exit_boot_func()
                allocate_e820ext()              <- new mm grows over 8 desc from e820 alloc
            efi_call_early(exit_boot_services)  <- mm key doesn't match so retry
            efi_call_early(get_memory_map)      <- not enough room for new mm
            system hangs
      
      This patch allocates the e820 buffer before calling efi_exit_boot_services()
      and fixes the regression.
      
       [ mingo: minor cleanliness edits. ]
      Signed-off-by: NEric Snowberg <eric.snowberg@oracle.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: <stable@vger.kernel.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arend van Spriel <arend.vanspriel@broadcom.com>
      Cc: Bhupesh Sharma <bhsharma@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Hans de Goede <hdegoede@redhat.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Jon Hunter <jonathanh@nvidia.com>
      Cc: Julien Thierry <julien.thierry@arm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Nathan Chancellor <natechancellor@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Sedat Dilek <sedat.dilek@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: YiFei Zhu <zhuyifei1999@gmail.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20181129171230.18699-2-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      b84a64fa
  10. 26 9月, 2018 1 次提交
    • H
      efi/x86: Call efi_parse_options() from efi_main() · c33ce984
      Hans de Goede 提交于
      Before this commit we were only calling efi_parse_options() from
      make_boot_params(), but make_boot_params() only gets called if the
      kernel gets booted directly as an EFI executable. So when booted through
      e.g. grub we ended up not parsing the commandline in the boot code.
      
      This makes the drivers/firmware/efi/libstub code ignore the "quiet"
      commandline argument resulting in the following message being printed:
      "EFI stub: UEFI Secure Boot is enabled."
      
      Despite the quiet request. This commits adds an extra call to
      efi_parse_options() to efi_main() to make sure that the options are
      always processed. This fixes quiet not working.
      
      This also fixes the libstub code ignoring nokaslr and efi=nochunk.
      Reported-by: NPeter Robinson <pbrobinson@redhat.com>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      c33ce984
  11. 22 7月, 2018 6 次提交
  12. 16 7月, 2018 1 次提交
  13. 11 7月, 2018 1 次提交
    • A
      efi/x86: Fix mixed mode reboot loop by removing pointless call to PciIo->Attributes() · e2967018
      Ard Biesheuvel 提交于
      Hans de Goede reported that his mixed EFI mode Bay Trail tablet
      would not boot at all any more, but enter a reboot loop without
      any logs printed by the kernel.
      
      Unbreak 64-bit Linux/x86 on 32-bit UEFI:
      
      When it was first introduced, the EFI stub code that copies the
      contents of PCI option ROMs originally only intended to do so if
      the EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM attribute was *not* set.
      
      The reason was that the UEFI spec permits PCI option ROM images
      to be provided by the platform directly, rather than via the ROM
      BAR, and in this case, the OS can only access them at runtime if
      they are preserved at boot time by copying them from the areas
      described by PciIo->RomImage and PciIo->RomSize.
      
      However, it implemented this check erroneously, as can be seen in
      commit:
      
        dd5fc854 ("EFI: Stash ROMs if they're not in the PCI BAR")
      
      which introduced:
      
          if (!attributes & EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM)
                  continue;
      
      and given that the numeric value of EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM
      is 0x4000, this condition never becomes true, and so the option ROMs
      were copied unconditionally.
      
      This was spotted and 'fixed' by commit:
      
        886d751a ("x86, efi: correct precedence of operators in setup_efi_pci")
      
      but inadvertently inverted the logic at the same time, defeating
      the purpose of the code, since it now only preserves option ROM
      images that can be read from the ROM BAR as well.
      
      Unsurprisingly, this broke some systems, and so the check was removed
      entirely in the following commit:
      
        73970188 ("x86, efi: remove attribute check from setup_efi_pci")
      
      It is debatable whether this check should have been included in the
      first place, since the option ROM image provided to the UEFI driver by
      the firmware may be different from the one that is actually present in
      the card's flash ROM, and so whatever PciIo->RomImage points at should
      be preferred regardless of whether the attribute is set.
      
      As this was the only use of the attributes field, we can remove
      the call to PciIo->Attributes() entirely, which is especially
      nice because its prototype involves uint64_t type by-value
      arguments which the EFI mixed mode has trouble dealing with.
      
      Any mixed mode system with PCI is likely to be affected.
      Tested-by: NWilfried Klaebe <linux-kernel@lebenslange-mailadresse.de>
      Tested-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180711090235.9327-2-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      e2967018
  14. 24 6月, 2018 1 次提交
    • A
      efi/x86: Fix incorrect invocation of PciIo->Attributes() · 2e6eb40c
      Ard Biesheuvel 提交于
      The following commit:
      
        2c3625cb ("efi/x86: Fold __setup_efi_pci32() and __setup_efi_pci64() into one function")
      
      ... merged the two versions of __setup_efi_pciXX(), without taking into
      account that the 32-bit version used a rather dodgy trick to pass an
      immediate 0 constant as argument for a uint64_t parameter.
      
      The issue is caused by the fact that on x86, UEFI protocol method calls
      are redirected via struct efi_config::call(), which is a variadic function,
      and so the compiler has to infer the types of the parameters from the
      arguments rather than from the prototype.
      
      As the 32-bit x86 calling convention passes arguments via the stack,
      passing the unqualified constant 0 twice is the same as passing 0ULL,
      which is why the 32-bit code in __setup_efi_pci32() contained the
      following call:
      
        status = efi_early->call(pci->attributes, pci,
                                 EfiPciIoAttributeOperationGet, 0, 0,
                                 &attributes);
      
      to invoke this UEFI protocol method:
      
        typedef
        EFI_STATUS
        (EFIAPI *EFI_PCI_IO_PROTOCOL_ATTRIBUTES) (
          IN  EFI_PCI_IO_PROTOCOL                     *This,
          IN  EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation,
          IN  UINT64                                  Attributes,
          OUT UINT64                                  *Result OPTIONAL
          );
      
      After the merge, we inadvertently ended up with this version for both
      32-bit and 64-bit builds, breaking the latter.
      
      So replace the two zeroes with the explicitly typed constant 0ULL,
      which works as expected on both 32-bit and 64-bit builds.
      
      Wilfried tested the 64-bit build, and I checked the generated assembly
      of a 32-bit build with and without this patch, and they are identical.
      Reported-by: NWilfried Klaebe <linux-kernel@lebenslange-mailadresse.de>
      Tested-by: NWilfried Klaebe <linux-kernel@lebenslange-mailadresse.de>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: hdegoede@redhat.com
      Cc: linux-efi@vger.kernel.org
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      2e6eb40c
  15. 14 5月, 2018 4 次提交
  16. 12 3月, 2018 1 次提交
  17. 09 3月, 2018 1 次提交