1. 20 1月, 2022 1 次提交
    • A
      riscv: Implement sv48 support · e8a62cc2
      Alexandre Ghiti 提交于
      By adding a new 4th level of page table, give the possibility to 64bit
      kernel to address 2^48 bytes of virtual address: in practice, that offers
      128TB of virtual address space to userspace and allows up to 64TB of
      physical memory.
      
      If the underlying hardware does not support sv48, we will automatically
      fallback to a standard 3-level page table by folding the new PUD level into
      PGDIR level. In order to detect HW capabilities at runtime, we
      use SATP feature that ignores writes with an unsupported mode.
      Signed-off-by: NAlexandre Ghiti <alexandre.ghiti@canonical.com>
      Signed-off-by: NPalmer Dabbelt <palmer@rivosinc.com>
      e8a62cc2
  2. 07 3月, 2021 1 次提交
    • A
      efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table · 9e9888a0
      Ard Biesheuvel 提交于
      The EFI_RT_PROPERTIES_TABLE contains a mask of runtime services that are
      available after ExitBootServices(). This mostly does not concern the EFI
      stub at all, given that it runs before that. However, there is one call
      that is made at runtime, which is the call to SetVirtualAddressMap()
      (which is not even callable at boot time to begin with)
      
      So add the missing handling of the RT_PROP table to ensure that we only
      call SetVirtualAddressMap() if it is not being advertised as unsupported
      by the firmware.
      
      Cc: <stable@vger.kernel.org> # v5.10+
      Tested-by: NShawn Guo <shawn.guo@linaro.org>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      9e9888a0
  3. 09 12月, 2020 1 次提交
  4. 03 10月, 2020 1 次提交
  5. 16 9月, 2020 2 次提交
    • A
      efi/libstub: arm32: Use low allocation for the uncompressed kernel · 762cd288
      Ard Biesheuvel 提交于
      Before commit
      
        d0f9ca9b ("ARM: decompressor: run decompressor in place if loaded via UEFI")
      
      we were rather limited in the choice of base address for the uncompressed
      kernel, as we were relying on the logic in the decompressor that blindly
      rounds down the decompressor execution address to the next multiple of 128
      MiB, and decompresses the kernel there. For this reason, we have a lot of
      complicated memory region handling code, to ensure that this memory window
      is available, even though it could be occupied by reserved regions or
      other allocations that may or may not collide with the uncompressed image.
      
      Today, we simply pass the target address for the decompressed image to the
      decompressor directly, and so we can choose a suitable window just by
      finding a 16 MiB aligned region, while taking TEXT_OFFSET and the region
      for the swapper page tables into account.
      
      So let's get rid of the complicated logic, and instead, use the existing
      bottom up allocation routine to allocate a suitable window as low as
      possible, and carve out a memory region that has the right properties.
      
      Note that this removes any dependencies on the 'dram_base' argument to
      handle_kernel_image(), and so this is removed as well. Given that this
      was the only remaining use of dram_base, the code that produces it is
      removed entirely as well.
      Reviewed-by: NMaxim Uvarov <maxim.uvarov@linaro.org>
      Tested-by: NMaxim Uvarov <maxim.uvarov@linaro.org>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      762cd288
    • A
      efi/libstub: arm32: Base FDT and initrd placement on image address · 6208857b
      Ard Biesheuvel 提交于
      The way we use the base of DRAM in the EFI stub is problematic as it
      is ill defined what the base of DRAM actually means. There are some
      restrictions on the placement of FDT and initrd which are defined in
      terms of dram_base, but given that the placement of the kernel in
      memory is what defines these boundaries (as on ARM, this is where the
      linear region starts), it is better to use the image address in these
      cases, and disregard dram_base altogether.
      Reviewed-by: NMaxim Uvarov <maxim.uvarov@linaro.org>
      Tested-by: NMaxim Uvarov <maxim.uvarov@linaro.org>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      6208857b
  6. 09 7月, 2020 1 次提交
  7. 17 6月, 2020 1 次提交
    • A
      efi/libstub: arm: Print CPU boot mode and MMU state at boot · 2a55280a
      Ard Biesheuvel 提交于
      On 32-bit ARM, we may boot at HYP mode, or with the MMU and caches off
      (or both), even though the EFI spec does not actually support this.
      While booting at HYP mode is something we might tolerate, fiddling
      with the caches is a more serious issue, as disabling the caches is
      tricky to do safely from C code, and running without the Dcache makes
      it impossible to support unaligned memory accesses, which is another
      explicit requirement imposed by the EFI spec.
      
      So take note of the CPU mode and MMU state in the EFI stub diagnostic
      output so that we can easily diagnose any issues that may arise from
      this. E.g.,
      
        EFI stub: Entering in SVC mode with MMU enabled
      
      Also, capture the CPSR and SCTLR system register values at EFI stub
      entry, and after ExitBootServices() returns, and check whether the
      MMU and Dcache were disabled at any point. If this is the case, a
      diagnostic message like the following will be emitted:
      
        efi: [Firmware Bug]: EFI stub was entered with MMU and Dcache disabled, please fix your firmware!
        efi: CPSR at EFI stub entry        : 0x600001d3
        efi: SCTLR at EFI stub entry       : 0x00c51838
        efi: CPSR after ExitBootServices() : 0x600001d3
        efi: SCTLR after ExitBootServices(): 0x00c50838
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Reviewed-by: NLeif Lindholm <leif@nuviainc.com>
      2a55280a
  8. 23 5月, 2020 1 次提交
  9. 22 5月, 2020 1 次提交
  10. 01 5月, 2020 4 次提交
  11. 24 4月, 2020 4 次提交
  12. 23 4月, 2020 1 次提交
  13. 29 3月, 2020 1 次提交
    • A
      efi/libstub/arm: Fix spurious message that an initrd was loaded · 594e576d
      Ard Biesheuvel 提交于
      Commit:
      
        ec93fc37 ("efi/libstub: Add support for loading the initrd from a device path")
      
      added a diagnostic print to the ARM version of the EFI stub that
      reports whether an initrd has been loaded that was passed
      via the command line using initrd=.
      
      However, it failed to take into account that, for historical reasons,
      the file loading routines return EFI_SUCCESS when no file was found,
      and the only way to decide whether a file was loaded is to inspect
      the 'size' argument that is passed by reference. So let's inspect
      this returned size, to prevent the print from being emitted even if
      no initrd was loaded at all.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linux-efi@vger.kernel.org
      594e576d
  14. 24 2月, 2020 6 次提交
    • A
      efi/libstub: Take noinitrd cmdline argument into account for devpath initrd · 79d3219d
      Ard Biesheuvel 提交于
      One of the advantages of using what basically amounts to a callback
      interface into the bootloader for loading the initrd is that it provides
      a natural place for the bootloader or firmware to measure the initrd
      contents while they are being passed to the kernel.
      
      Unfortunately, this is not a guarantee that the initrd will in fact be
      loaded and its /init invoked by the kernel, since the command line may
      contain the 'noinitrd' option, in which case the initrd is ignored, but
      this will not be reflected in the PCR that covers the initrd measurement.
      
      This could be addressed by measuring the command line as well, and
      including that PCR in the attestation policy, but this locks down the
      command line completely, which may be too restrictive.
      
      So let's take the noinitrd argument into account in the stub, too. This
      forces any PCR that covers the initrd to assume a different value when
      noinitrd is passed, allowing an attestation policy to disregard the
      command line if there is no need to take its measurement into account
      for other reasons.
      
      As Peter points out, this would still require the agent that takes the
      measurements to measure a separator event into the PCR in question at
      ExitBootServices() time, to prevent replay attacks using the known
      measurement from the TPM log.
      
      Cc: Peter Jones <pjones@redhat.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      79d3219d
    • A
      efi/libstub: Add support for loading the initrd from a device path · ec93fc37
      Ard Biesheuvel 提交于
      There are currently two ways to specify the initrd to be passed to the
      Linux kernel when booting via the EFI stub:
      - it can be passed as a initrd= command line option when doing a pure PE
        boot (as opposed to the EFI handover protocol that exists for x86)
      - otherwise, the bootloader or firmware can load the initrd into memory,
        and pass the address and size via the bootparams struct (x86) or
        device tree (ARM)
      
      In the first case, we are limited to loading from the same file system
      that the kernel was loaded from, and it is also problematic in a trusted
      boot context, given that we cannot easily protect the command line from
      tampering without either adding complicated white/blacklisting of boot
      arguments or locking down the command line altogether.
      
      In the second case, we force the bootloader to duplicate knowledge about
      the boot protocol which is already encoded in the stub, and which may be
      subject to change over time, e.g., bootparams struct definitions, memory
      allocation/alignment requirements for the placement of the initrd etc etc.
      In the ARM case, it also requires the bootloader to modify the hardware
      description provided by the firmware, as it is passed in the same file.
      On systems where the initrd is measured after loading, it creates a time
      window where the initrd contents might be manipulated in memory before
      handing over to the kernel.
      
      Address these concerns by adding support for loading the initrd into
      memory by invoking the EFI LoadFile2 protocol installed on a vendor
      GUIDed device path that specifically designates a Linux initrd.
      This addresses the above concerns, by putting the EFI stub in charge of
      placement in memory and of passing the base and size to the kernel proper
      (via whatever means it desires) while still leaving it up to the firmware
      or bootloader to obtain the file contents, potentially from other file
      systems than the one the kernel itself was loaded from. On platforms that
      implement measured boot, it permits the firmware to take the measurement
      right before the kernel actually consumes the contents.
      Acked-by: NLaszlo Ersek <lersek@redhat.com>
      Tested-by: NIlias Apalodimas <ilias.apalodimas@linaro.org>
      Acked-by: NIlias Apalodimas <ilias.apalodimas@linaro.org>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      ec93fc37
    • A
      efi/libstub: Take soft and hard memory limits into account for initrd loading · 31f5e546
      Ard Biesheuvel 提交于
      On x86, the preferred load address of the initrd is still below 4 GB,
      even though in some cases, we can cope with an initrd that is loaded
      above that.
      
      To simplify the code, and to make it more straightforward to introduce
      other ways to load the initrd, pass the soft and hard memory limits at
      the same time, and let the code handling the initrd= command line option
      deal with this.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      31f5e546
    • A
      efi/libstub: Rewrite file I/O routine · 9302c1bb
      Ard Biesheuvel 提交于
      The file I/O routine that is used to load initrd or dtb files from
      the EFI system partition suffers from a few issues:
      - it converts the u8[] command line back to a UTF-16 string, which is
        pointless since we only handle initrd or dtb arguments provided via
        the loaded image protocol anyway, which is where we got the UTF-16[]
        command line from in the first place when booting via the PE entry
        point,
      - in the far majority of cases, only a single initrd= option is present,
        but it optimizes for multiple options, by going over the command line
        twice, allocating heap buffers for dynamically sized arrays, etc.
      - the coding style is hard to follow, with few comments, and all logic
        including string parsing etc all combined in a single routine.
      
      Let's fix this by rewriting most of it, based on the idea that in the
      case of multiple initrds, we can just allocate a new, bigger buffer
      and copy over the data before freeing the old one.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      9302c1bb
    • A
      efi/libstub: Move get_dram_base() into arm-stub.c · b8717454
      Ard Biesheuvel 提交于
      get_dram_base() is only called from arm-stub.c so move it into
      the same source file as its caller.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      b8717454
    • A
      efi/libstub/x86: Permit cmdline data to be allocated above 4 GB · 1e45bf73
      Ard Biesheuvel 提交于
      We now support cmdline data that is located in memory that is not
      32-bit addressable, so relax the allocation limit on systems where
      this feature is enabled.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      1e45bf73
  15. 23 2月, 2020 2 次提交
    • A
      efi/libstub/arm64: Use 1:1 mapping of RT services if property table exists · b92165d2
      Ard Biesheuvel 提交于
      The UEFI spec defines (and deprecates) a misguided and shortlived
      memory protection feature that is based on splitting memory regions
      covering PE/COFF executables into separate code and data regions,
      without annotating them as belonging to the same executable image.
      When the OS assigns the virtual addresses of these regions, it may
      move them around arbitrarily, without taking into account that the
      PE/COFF code sections may contain relative references into the data
      sections, which means the relative placement of these segments has
      to be preserved or the executable image will be corrupted.
      
      The original workaround on arm64 was to ensure that adjacent regions
      of the same type were mapped adjacently in the virtual mapping, but
      this requires sorting of the memory map, which we would prefer to
      avoid.
      
      Considering that the native physical mapping of the PE/COFF images
      does not suffer from this issue, let's preserve it at runtime, and
      install it as the virtual mapping as well.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      b92165d2
    • A
      efi/libstub/arm: Make efi_entry() an ordinary PE/COFF entrypoint · 9f922377
      Ard Biesheuvel 提交于
      Expose efi_entry() as the PE/COFF entrypoint directly, instead of
      jumping into a wrapper that fiddles with stack buffers and other
      stuff that the compiler is much better at. The only reason this
      code exists is to obtain a pointer to the base of the image, but
      we can get the same value from the loaded_image protocol, which
      we already need for other reasons anyway.
      
      Update the return type as well, to make it consistent with what
      is required for a PE/COFF executable entrypoint.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      9f922377
  16. 25 12月, 2019 7 次提交
  17. 07 11月, 2019 1 次提交
  18. 19 6月, 2019 1 次提交
  19. 16 2月, 2019 1 次提交
  20. 04 2月, 2019 1 次提交
    • A
      efi/arm/arm64: Allow SetVirtualAddressMap() to be omitted · 4e46c2a9
      Ard Biesheuvel 提交于
      The UEFI spec revision 2.7 errata A section 8.4 has the following to
      say about the virtual memory runtime services:
      
        "This section contains function definitions for the virtual memory
        support that may be optionally used by an operating system at runtime.
        If an operating system chooses to make EFI runtime service calls in a
        virtual addressing mode instead of the flat physical mode, then the
        operating system must use the services in this section to switch the
        EFI runtime services from flat physical addressing to virtual
        addressing."
      
      So it is pretty clear that calling SetVirtualAddressMap() is entirely
      optional, and so there is no point in doing so unless it achieves
      anything useful for us.
      
      This is not the case for 64-bit ARM. The identity mapping used by the
      firmware is arbitrarily converted into another permutation of userland
      addresses (i.e., bits [63:48] cleared), and the runtime code could easily
      deal with the original layout in exactly the same way as it deals with
      the converted layout. However, due to constraints related to page size
      differences if the OS is not running with 4k pages, and related to
      systems that may expose the individual sections of PE/COFF runtime
      modules as different memory regions, creating the virtual layout is a
      bit fiddly, and requires us to sort the memory map and reason about
      adjacent regions with identical memory types etc etc.
      
      So the obvious fix is to stop calling SetVirtualAddressMap() altogether
      on arm64 systems. However, to avoid surprises, which are notoriously
      hard to diagnose when it comes to OS<->firmware interactions, let's
      start by making it an opt-out feature, and implement support for the
      'efi=novamap' kernel command line parameter on ARM and arm64 systems.
      
      ( Note that 32-bit ARM generally does require SetVirtualAddressMap() to be
        used, given that the physical memory map and the kernel virtual address
        map are not guaranteed to be non-overlapping like on arm64. However,
        having support for efi=novamap,noruntime on 32-bit ARM, combined with
        the recently proposed support for earlycon=efifb, is likely to be useful
        to diagnose boot issues on such systems if they have no accessible serial
        port. )
      Tested-by: NJeffrey Hugo <jhugo@codeaurora.org>
      Tested-by: NBjorn Andersson <bjorn.andersson@linaro.org>
      Tested-by: NLee Jones <lee.jones@linaro.org>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
      Cc: Alexander Graf <agraf@suse.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20190202094119.13230-8-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      4e46c2a9
  21. 11 12月, 2018 1 次提交
    • S
      arm64: mm: Introduce DEFAULT_MAP_WINDOW · 363524d2
      Steve Capper 提交于
      We wish to introduce a 52-bit virtual address space for userspace but
      maintain compatibility with software that assumes the maximum VA space
      size is 48 bit.
      
      In order to achieve this, on 52-bit VA systems, we make mmap behave as
      if it were running on a 48-bit VA system (unless userspace explicitly
      requests a VA where addr[51:48] != 0).
      
      On a system running a 52-bit userspace we need TASK_SIZE to represent
      the 52-bit limit as it is used in various places to distinguish between
      kernelspace and userspace addresses.
      
      Thus we need a new limit for mmap, stack, ELF loader and EFI (which uses
      TTBR0) to represent the non-extended VA space.
      
      This patch introduces DEFAULT_MAP_WINDOW and DEFAULT_MAP_WINDOW_64 and
      switches the appropriate logic to use that instead of TASK_SIZE.
      Signed-off-by: NSteve Capper <steve.capper@arm.com>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      363524d2