1. 09 9月, 2016 17 次提交
    • A
      efi/arm64: Treat regions with WT/WC set but WB cleared as memory · cb82cce7
      Ard Biesheuvel 提交于
      Currently, memory regions are only recorded in the memblock memory table
      if they have the EFI_MEMORY_WB memory type attribute set. In case the
      region is of a reserved type, it is also marked as MEMBLOCK_NOMAP, which
      will leave it out of the linear mapping.
      
      However, memory regions may legally have the EFI_MEMORY_WT or EFI_MEMORY_WC
      attributes set, and the EFI_MEMORY_WB cleared, in which case the region in
      question is obviously backed by normal memory, but is not recorded in the
      memblock memory table at all. Since it would be useful to be able to
      identify any UEFI reported memory region using memblock_is_memory(), it
      makes sense to add all memory to the memblock memory table, and simply mark
      it as MEMBLOCK_NOMAP if it lacks the EFI_MEMORY_WB attribute.
      
      While implementing this, let's refactor the code slightly to make it easier
      to understand: replace is_normal_ram() with is_memory(), and make it return
      true for each region that has any of the WB|WT|WC bits set. (This follows
      the AArch64 bindings in the UEFI spec, which state that those are the
      attributes that map to normal memory)
      
      Also, replace is_reserve_region() with is_usable_memory(), and only invoke
      it if the region in question was identified as memory by is_memory() in the
      first place. The net result is the same (only reserved regions that are
      backed by memory end up in the memblock memory table with the MEMBLOCK_NOMAP
      flag set) but carried out in a more straightforward way.
      
      Finally, we remove the trailing asterisk in the EFI debug output. Keeping it
      clutters the code, and it serves no real purpose now that we no longer
      temporarily reserve BootServices code and data regions like we did in the
      early days of EFI support on arm64 Linux (which it inherited from the x86
      implementation)
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reviewed-by: NLeif Lindholm <leif.lindholm@linaro.org>
      Tested-by: NJames Morse <james.morse@arm.com>
      Reviewed-by: NJames Morse <james.morse@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      cb82cce7
    • I
      efi: Add efi_test driver for exporting UEFI runtime service interfaces · ff6301da
      Ivan Hu 提交于
      This driver is used by the Firmware Test Suite (FWTS) for testing the UEFI
      runtime interfaces readiness of the firmware.
      
      This driver exports UEFI runtime service interfaces into userspace,
      which allows to use and test UEFI runtime services provided by the
      firmware.
      
      This driver uses the efi.<service> function pointers directly instead of
      going through the efivar API to allow for direct testing of the UEFI
      runtime service interfaces provided by the firmware.
      
      Details for FWTS are available from,
      <https://wiki.ubuntu.com/FirmwareTestSuite>
      Signed-off-by: NIvan Hu <ivan.hu@canonical.com>
      Cc: joeyli <jlee@suse.com>
      Cc: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      ff6301da
    • A
      efi/arm64: Add debugfs node to dump UEFI runtime page tables · 9d80448a
      Ard Biesheuvel 提交于
      Register the debugfs node 'efi_page_tables' to allow the UEFI runtime
      page tables to be inspected. Note that ARM does not have 'asm/ptdump.h'
      [yet] so for now, this is arm64 only.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Acked-by: NMark Rutland <mark.rutland@arm.com>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      9d80448a
    • A
      efi: Replace runtime services spinlock with semaphore · dce48e35
      Ard Biesheuvel 提交于
      The purpose of the efi_runtime_lock is to prevent concurrent calls into
      the firmware. There is no need to use spinlocks here, as long as we ensure
      that runtime service invocations from an atomic context (i.e., EFI pstore)
      cannot block.
      
      So use a semaphore instead, and use down_trylock() in the nonblocking case.
      We don't use a mutex here because the mutex_trylock() function must not
      be called from interrupt context, whereas the down_trylock() can.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Sylvain Chouleur <sylvain.chouleur@gmail.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      dce48e35
    • S
      efi: Don't use spinlocks for efi vars · 21b3ddd3
      Sylvain Chouleur 提交于
      All efivars operations are protected by a spinlock which prevents
      interruptions and preemption. This is too restricted, we just need a
      lock preventing concurrency.
      The idea is to use a semaphore of count 1 and to have two ways of
      locking, depending on the context:
      - In interrupt context, we call down_trylock(), if it fails we return
        an error
      - In normal context, we call down_interruptible()
      
      We don't use a mutex here because the mutex_trylock() function must not
      be called from interrupt context, whereas the down_trylock() can.
      Signed-off-by: NSylvain Chouleur <sylvain.chouleur@intel.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Sylvain Chouleur <sylvain.chouleur@gmail.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      21b3ddd3
    • S
      efi: Use a file local lock for efivars · 217b27d4
      Sylvain Chouleur 提交于
      This patch replaces the spinlock in the efivars struct with a single lock
      for the whole vars.c file.  The goal of this lock is to protect concurrent
      calls to efi variable services, registering and unregistering. This allows
      us to register new efivars operations without having in-progress call.
      Signed-off-by: NSylvain Chouleur <sylvain.chouleur@intel.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Sylvain Chouleur <sylvain.chouleur@gmail.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      217b27d4
    • A
      efi/arm*: esrt: Add missing call to efi_esrt_init() · 2ead3084
      Ard Biesheuvel 提交于
      ESRT support is built by default for all architectures that define
      CONFIG_EFI. However, this support was not wired up yet for ARM/arm64,
      since efi_esrt_init() was never called. So add the missing call.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Jones <pjones@redhat.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      2ead3084
    • A
      efi/esrt: Use memremap not ioremap to access ESRT table in memory · f58a37b2
      Ard Biesheuvel 提交于
      On ARM and arm64, ioremap() and memremap() are not interchangeable like
      on x86, and the use of ioremap() on ordinary RAM is typically flagged
      as an error if the memory region being mapped is also covered by the
      linear mapping, since that would lead to aliases with conflicting
      cacheability attributes.
      
      Since what we are dealing with is not an I/O region with side effects,
      using ioremap() here is arguably incorrect anyway, so let's replace
      it with memremap() instead.
      Acked-by: NPeter Jones <pjones@redhat.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      f58a37b2
    • M
      efi/esrt: Use efi_mem_reserve() and avoid a kmalloc() · 8e80632f
      Matt Fleming 提交于
      We can use the new efi_mem_reserve() API to mark the ESRT table as
      reserved forever and save ourselves the trouble of copying the data
      out into a kmalloc buffer.
      
      The added advantage is that now the ESRT driver will work across
      kexec reboot.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      8e80632f
    • M
      efi/runtime-map: Use efi.memmap directly instead of a copy · 31ce8cc6
      Matt Fleming 提交于
      Now that efi.memmap is available all of the time there's no need to
      allocate and build a separate copy of the EFI memory map.
      
      Furthermore, efi.memmap contains boot services regions but only those
      regions that have been reserved via efi_mem_reserve(). Using
      efi.memmap allows us to pass boot services across kexec reboot so that
      the ESRT and BGRT drivers will now work.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      31ce8cc6
    • M
      efi: Allow drivers to reserve boot services forever · 816e7612
      Matt Fleming 提交于
      Today, it is not possible for drivers to reserve EFI boot services for
      access after efi_free_boot_services() has been called on x86. For
      ARM/arm64 it can be done simply by calling memblock_reserve().
      
      Having this ability for all three architectures is desirable for a
      couple of reasons,
      
        1) It saves drivers copying data out of those regions
        2) kexec reboot can now make use of things like ESRT
      
      Instead of using the standard memblock_reserve() which is insufficient
      to reserve the region on x86 (see efi_reserve_boot_services()), a new
      API is introduced in this patch; efi_mem_reserve().
      
      efi.memmap now always represents which EFI memory regions are
      available. On x86 the EFI boot services regions that have not been
      reserved via efi_mem_reserve() will be removed from efi.memmap during
      efi_free_boot_services().
      
      This has implications for kexec, since it is not possible for a newly
      kexec'd kernel to access the same boot services regions that the
      initial boot kernel had access to unless they are reserved by every
      kexec kernel in the chain.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      816e7612
    • M
      efi: Add efi_memmap_install() for installing new EFI memory maps · c45f4da3
      Matt Fleming 提交于
      While efi_memmap_init_{early,late}() exist for architecture code to
      install memory maps from firmware data and for the virtual memory
      regions respectively, drivers don't care which stage of the boot we're
      at and just want to swap the existing memmap for a modified one.
      
      efi_memmap_install() abstracts the details of how the new memory map
      should be mapped and the existing one unmapped.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Taku Izumi <izumi.taku@jp.fujitsu.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      c45f4da3
    • M
      efi: Split out EFI memory map functions into new file · 60863c0d
      Matt Fleming 提交于
      Also move the functions from the EFI fake mem driver since future
      patches will require access to the memmap insertion code even if
      CONFIG_EFI_FAKE_MEM isn't enabled.
      
      This will be useful when we need to build custom EFI memory maps to
      allow drivers to mark regions as reserved.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Taku Izumi <izumi.taku@jp.fujitsu.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      60863c0d
    • M
      efi/fake_mem: Refactor main two code chunks into functions · c8c1a4c5
      Matt Fleming 提交于
      There is a whole load of generic EFI memory map code inside of the
      fake_mem driver which is better suited to being grouped with the rest
      of the generic EFI code for manipulating EFI memory maps.
      
      In preparation for that, this patch refactors the core code, so that
      it's possible to move entire functions later.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Taku Izumi <izumi.taku@jp.fujitsu.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      c8c1a4c5
    • M
      efi: Add efi_memmap_init_late() for permanent EFI memmap · dca0f971
      Matt Fleming 提交于
      Drivers need a way to access the EFI memory map at runtime. ARM and
      arm64 currently provide this by remapping the EFI memory map into the
      vmalloc space before setting up the EFI virtual mappings.
      
      x86 does not provide this functionality which has resulted in the code
      in efi_mem_desc_lookup() where it will manually map individual EFI
      memmap entries if the memmap has already been torn down on x86,
      
        /*
         * If a driver calls this after efi_free_boot_services,
         * ->map will be NULL, and the target may also not be mapped.
         * So just always get our own virtual map on the CPU.
         *
         */
        md = early_memremap(p, sizeof (*md));
      
      There isn't a good reason for not providing a permanent EFI memory map
      for runtime queries, especially since the EFI regions are not mapped
      into the standard kernel page tables.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      dca0f971
    • M
      efi: Refactor efi_memmap_init_early() into arch-neutral code · 9479c7ce
      Matt Fleming 提交于
      Every EFI architecture apart from ia64 needs to setup the EFI memory
      map at efi.memmap, and the code for doing that is essentially the same
      across all implementations. Therefore, it makes sense to factor this
      out into the common code under drivers/firmware/efi/.
      
      The only slight variation is the data structure out of which we pull
      the initial memory map information, such as physical address, memory
      descriptor size and version, etc. We can address this by passing a
      generic data structure (struct efi_memory_map_data) as the argument to
      efi_memmap_init_early() which contains the minimum info required for
      initialising the memory map.
      
      In the process, this patch also fixes a few undesirable implementation
      differences:
      
       - ARM and arm64 were failing to clear the EFI_MEMMAP bit when
         unmapping the early EFI memory map. EFI_MEMMAP indicates whether
         the EFI memory map is mapped (not the regions contained within) and
         can be traversed.  It's more correct to set the bit as soon as we
         memremap() the passed in EFI memmap.
      
       - Rename efi_unmmap_memmap() to efi_memmap_unmap() to adhere to the
         regular naming scheme.
      
      This patch also uses a read-write mapping for the memory map instead
      of the read-only mapping currently used on ARM and arm64. x86 needs
      the ability to update the memory map in-place when assigning virtual
      addresses to regions (efi_map_region()) and tagging regions when
      reserving boot services (efi_reserve_boot_services()).
      
      There's no way for the generic fake_mem code to know which mapping to
      use without introducing some arch-specific constant/hook, so just use
      read-write since read-only is of dubious value for the EFI memory map.
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      9479c7ce
    • M
      x86/efi: Test for EFI_MEMMAP functionality when iterating EFI memmap · 4971531a
      Matt Fleming 提交于
      Both efi_find_mirror() and efi_fake_memmap() really want to know
      whether the EFI memory map is available, not just whether the machine
      was booted using EFI. efi_fake_memmap() even has a check for
      EFI_MEMMAP at the start of the function.
      
      Since we've already got other code that has this dependency, merge
      everything under one if() conditional, and remove the now superfluous
      check from efi_fake_memmap().
      
      Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump]
      Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm]
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Taku Izumi <izumi.taku@jp.fujitsu.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Xishi Qiu <qiuxishi@huawei.com>
      Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      4971531a
  2. 05 9月, 2016 4 次提交
    • J
      efi/libstub: Use efi_exit_boot_services() in FDT · ed9cc156
      Jeffrey Hugo 提交于
      The FDT code directly calls ExitBootServices.  This is inadvisable as the
      UEFI spec details a complex set of errors, race conditions, and API
      interactions that the caller of ExitBootServices must get correct.  The
      FDT code does not handle EFI_INVALID_PARAMETER as required by the spec,
      which causes intermittent boot failures on the Qualcomm Technologies
      QDF2432.  Call the efi_exit_boot_services() helper intead, which handles
      the EFI_INVALID_PARAMETER scenario properly.
      Signed-off-by: NJeffrey Hugo <jhugo@codeaurora.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      ed9cc156
    • J
      efi/libstub: Introduce ExitBootServices helper · fc07716b
      Jeffrey Hugo 提交于
      The spec allows ExitBootServices to fail with EFI_INVALID_PARAMETER if a
      race condition has occurred where the EFI has updated the memory map after
      the stub grabbed a reference to the map.  The spec defines a retry
      proceedure with specific requirements to handle this scenario.
      
      This scenario was previously observed on x86 - commit d3768d88 ("x86,
      efi: retry ExitBootServices() on failure") but the current fix is not spec
      compliant and the scenario is now observed on the Qualcomm Technologies
      QDF2432 via the FDT stub which does not handle the error and thus causes
      boot failures.  The user will notice the boot failure as the kernel is not
      executed and the system may drop back to a UEFI shell, but will be
      unresponsive to input and the system will require a power cycle to recover.
      
      Add a helper to the stub library that correctly adheres to the spec in the
      case of EFI_INVALID_PARAMETER from ExitBootServices and can be universally
      used across all stub implementations.
      Signed-off-by: NJeffrey Hugo <jhugo@codeaurora.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      fc07716b
    • J
      efi/libstub: Allocate headspace in efi_get_memory_map() · dadb57ab
      Jeffrey Hugo 提交于
      efi_get_memory_map() allocates a buffer to store the memory map that it
      retrieves.  This buffer may need to be reused by the client after
      ExitBootServices() is called, at which point allocations are not longer
      permitted.  To support this usecase, provide the allocated buffer size back
      to the client, and allocate some additional headroom to account for any
      reasonable growth in the map that is likely to happen between the call to
      efi_get_memory_map() and the client reusing the buffer.
      Signed-off-by: NJeffrey Hugo <jhugo@codeaurora.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      dadb57ab
    • A
      efi: Fix handling error value in fdt_find_uefi_params · 4af9ed57
      Andrzej Hajda 提交于
      of_get_flat_dt_subnode_by_name can return negative value in case of error.
      Assigning the result to unsigned variable and checking if the variable
      is lesser than zero is incorrect and always false.
      The patch fixes it by using signed variable to check the result.
      
      The problem has been detected using semantic patch
      scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci
      Signed-off-by: NAndrzej Hajda <a.hajda@samsung.com>
      Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Cc: Marek Szyprowski <m.szyprowski@samsung.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Shawn Lin <shawn.lin@rock-chips.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      4af9ed57
  3. 11 8月, 2016 1 次提交
  4. 09 7月, 2016 1 次提交
  5. 06 7月, 2016 1 次提交
    • S
      Xen: EFI: Parse DT parameters for Xen specific UEFI · 0cac5c30
      Shannon Zhao 提交于
      The EFI DT parameters for bare metal are located under /chosen node,
      while for Xen Dom0 they are located under /hyperviosr/uefi node. These
      parameters under /chosen and /hyperviosr/uefi are not expected to appear
      at the same time.
      
      Parse these EFI parameters and initialize EFI like the way for bare
      metal except the runtime services because the runtime services for Xen
      Dom0 are available through hypercalls and they are always enabled. So it
      sets the EFI_RUNTIME_SERVICES flag if it finds /hyperviosr/uefi node and
      bails out in arm_enable_runtime_services() when EFI_RUNTIME_SERVICES
      flag is set already.
      Signed-off-by: NShannon Zhao <shannon.zhao@linaro.org>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      0cac5c30
  6. 27 6月, 2016 2 次提交
    • A
      efi: Convert efi_call_virt() to efi_call_virt_pointer() · 80e75596
      Alex Thorlton 提交于
      This commit makes a few slight modifications to the efi_call_virt() macro
      to get it to work with function pointers that are stored in locations
      other than efi.systab->runtime, and renames the macro to
      efi_call_virt_pointer().  The majority of the changes here are to pull
      these macros up into header files so that they can be accessed from
      outside of drivers/firmware/efi/runtime-wrappers.c.
      
      The most significant change not directly related to the code move is to
      add an extra "p" argument into the appropriate efi_call macros, and use
      that new argument in place of the, formerly hard-coded,
      efi.systab->runtime pointer.
      
      The last piece of the puzzle was to add an efi_call_virt() macro back into
      drivers/firmware/efi/runtime-wrappers.c to wrap around the new
      efi_call_virt_pointer() macro - this was mainly to keep the code from
      looking too cluttered by adding a bunch of extra references to
      efi.systab->runtime everywhere.
      
      Note that I also broke up the code in the efi_call_virt_pointer() macro a
      bit in the process of moving it.
      Signed-off-by: NAlex Thorlton <athorlton@sgi.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Dimitri Sivanich <sivanich@sgi.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Roy Franz <roy.franz@linaro.org>
      Cc: Russ Anderson <rja@sgi.com>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/1466839230-12781-5-git-send-email-matt@codeblueprint.co.ukSigned-off-by: NIngo Molnar <mingo@kernel.org>
      80e75596
    • C
      efibc: Report more information in the error messages · 5356c327
      Compostella, Jeremy 提交于
      Report the name of the EFI variable if the value size is too large,
      or if efibc_set_variable() fails to allocate the 'struct efivar_entry'
      object.
      
      If efibc_set_variable() fails because the 'size' value is too
      large, it also reports this value in the error message.
      Reported-by: NRobert Elliott <elliott@hpe.com>
      Signed-off-by: NJeremy Compostella <jeremy.compostella@intel.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      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: http://lkml.kernel.org/r/1466839230-12781-2-git-send-email-matt@codeblueprint.co.uk
      [ Minor readability edits. ]
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      5356c327
  7. 03 6月, 2016 3 次提交
    • D
      efi/arm: Fix the format of EFI debug messages · c7534397
      Dennis Chen 提交于
      When both EFI and memblock debugging is enabled on the kernel command line:
      
        'efi=debug memblock=debug'
      
      .. the debug messages for early_con look the following way:
      
       [    0.000000] efi:   0x0000e1050000-0x0000e105ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
       [    0.000000] efi:   0x0000e1300000-0x0000e1300fff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
       [    0.000000] efi:   0x0000e8200000-0x0000e827ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
       [    0.000000] efi:   0x008000000000-0x008001e7ffff [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC]
       [    0.000000] memblock_add: [0x00008000000000-0x00008001e7ffff] flags 0x0 early_init_dt_add_memory_arch+0x54/0x5c
       [    0.000000] *
       ...
      
      Note the misplaced '*' line, which happened because the memblock debug message
      was printed while the EFI debug message was still being constructed..
      
      This patch fixes the output to be the expected:
      
       [    0.000000] efi:   0x0000e1050000-0x0000e105ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
       [    0.000000] efi:   0x0000e1300000-0x0000e1300fff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
       [    0.000000] efi:   0x0000e8200000-0x0000e827ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
       [    0.000000] efi:   0x008000000000-0x008001e7ffff [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC]*
       [    0.000000] memblock_add: [0x00008000000000-0x00008001e7ffff] flags 0x0 early_init_dt_add_memory_arch+0x54/0x5c
       ...
      
      Note how the '*' is now in the proper EFI debug message line.
      Signed-off-by: NDennis Chen <dennis.chen@arm.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Acked-by: NMark Rutland <mark.rutland@arm.com>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mark Salter <msalter@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steve Capper <steve.capper@arm.com>
      Cc: Steve McIntyre <steve@einval.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/1464690224-4503-3-git-send-email-matt@codeblueprint.co.uk
      [ Made the changelog more readable. ]
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      c7534397
    • G
      efi-pstore: implement efivars_pstore_exit() · cae73167
      Geliang Tang 提交于
      The original efivars_pstore_exit() is empty. I
       1) add a bufsize check statement.
       2) call pstore_unregister as it is defined now.
       3) free the memory and set bufsize to 0.
      Signed-off-by: NGeliang Tang <geliangtang@163.com>
      Acked-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      cae73167
    • G
      pstore: add lzo/lz4 compression support · 8cfc8ddc
      Geliang Tang 提交于
      Like zlib compression in pstore, this patch added lzo and lz4
      compression support so that users can have more options and better
      compression ratio.
      
      The original code treats the compressed data together with the
      uncompressed ECC correction notice by using zlib decompress. The
      ECC correction notice is missing in the decompression process. The
      treatment also makes lzo and lz4 not working. So I treat them
      separately by using pstore_decompress() to treat the compressed
      data, and memcpy() to treat the uncompressed ECC correction notice.
      Signed-off-by: NGeliang Tang <geliangtang@163.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      8cfc8ddc
  8. 07 5月, 2016 4 次提交
    • J
      efi: Merge boolean flag arguments · 1cfd6316
      Julia Lawall 提交于
      The parameters atomic and duplicates of efivar_init always have opposite
      values.  Drop the parameter atomic, replace the uses of !atomic with
      duplicates, and update the call sites accordingly.
      
      The code using duplicates is slightly reorganized with an 'else', to avoid
      duplicating the lock code.
      Signed-off-by: NJulia Lawall <Julia.Lawall@lip6.fr>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Jeremy Kerr <jk@ozlabs.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matthew Garrett <mjg59@srcf.ucam.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Saurabh Sengar <saurabh.truth@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vaishali Thakkar <vaishali.thakkar@oracle.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/1462570771-13324-5-git-send-email-matt@codeblueprint.co.ukSigned-off-by: NIngo Molnar <mingo@kernel.org>
      1cfd6316
    • M
      efi/capsule: Move 'capsule' to the stack in efi_capsule_supported() · fb7a84ca
      Matt Fleming 提交于
      Dan Carpenter reports that passing the address of the pointer to the
      kmalloc()'d memory for 'capsule' is dangerous:
      
       "drivers/firmware/efi/capsule.c:109 efi_capsule_supported()
        warn: did you mean to pass the address of 'capsule'
      
         108
         109          status = efi.query_capsule_caps(&capsule, 1, &max_size, reset);
                                                      ^^^^^^^^
        If we modify capsule inside this function call then at the end of the
        function we aren't freeing the original pointer that we allocated."
      
      Ard Biesheuvel noted that we don't even need to call kmalloc() since the
      object we allocate isn't very big and doesn't need to persist after the
      function returns.
      
      Place 'capsule' on the stack instead.
      Suggested-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Bryan O'Donoghue <pure.logic@nexus-software.ie>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Kweh Hock Leong <hock.leong.kweh@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: joeyli <jlee@suse.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/1462570771-13324-4-git-send-email-matt@codeblueprint.co.ukSigned-off-by: NIngo Molnar <mingo@kernel.org>
      fb7a84ca
    • J
      efibc: Fix excessive stack footprint warning · 2e121d71
      Jeremy Compostella 提交于
      GCC complains about a newly added file for the EFI Bootloader Control:
      
        drivers/firmware/efi/efibc.c: In function 'efibc_set_variable':
        drivers/firmware/efi/efibc.c:53:1: error: the frame size of 2272 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
      
      The problem is the declaration of a local variable of type struct
      efivar_entry, which is by itself larger than the warning limit of 1024
      bytes.
      
      Use dynamic memory allocation instead of stack memory for the entry
      object.
      
      This patch also fixes a potential buffer overflow.
      Reported-by: NIngo Molnar <mingo@kernel.org>
      Reported-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NJeremy Compostella <jeremy.compostella@intel.com>
      [ Updated changelog to include GCC error ]
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.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: http://lkml.kernel.org/r/1462570771-13324-3-git-send-email-matt@codeblueprint.co.ukSigned-off-by: NIngo Molnar <mingo@kernel.org>
      2e121d71
    • M
      efi/capsule: Make efi_capsule_pending() lockless · 62075e58
      Matt Fleming 提交于
      Taking a mutex in the reboot path is bogus because we cannot sleep
      with interrupts disabled, such as when rebooting due to panic(),
      
        BUG: sleeping function called from invalid context at kernel/locking/mutex.c:97
        in_atomic(): 0, irqs_disabled(): 1, pid: 7, name: rcu_sched
        Call Trace:
          dump_stack+0x63/0x89
          ___might_sleep+0xd8/0x120
          __might_sleep+0x49/0x80
          mutex_lock+0x20/0x50
          efi_capsule_pending+0x1d/0x60
          native_machine_emergency_restart+0x59/0x280
          machine_emergency_restart+0x19/0x20
          emergency_restart+0x18/0x20
          panic+0x1ba/0x217
      
      In this case all other CPUs will have been stopped by the time we
      execute the platform reboot code, so 'capsule_pending' cannot change
      under our feet. We wouldn't care even if it could since we cannot wait
      for it complete.
      
      Also, instead of relying on the external 'system_state' variable just
      use a reboot notifier, so we can set 'stop_capsules' while holding
      'capsule_mutex', thereby avoiding a race where system_state is updated
      while we're in the middle of efi_capsule_update_locked() (since CPUs
      won't have been stopped at that point).
      Signed-off-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Bryan O'Donoghue <pure.logic@nexus-software.ie>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Kweh Hock Leong <hock.leong.kweh@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: joeyli <jlee@suse.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/1462570771-13324-2-git-send-email-matt@codeblueprint.co.ukSigned-off-by: NIngo Molnar <mingo@kernel.org>
      62075e58
  9. 29 4月, 2016 1 次提交
    • A
      arm64: kaslr: increase randomization granularity · 6f26b367
      Ard Biesheuvel 提交于
      Currently, our KASLR implementation randomizes the placement of the core
      kernel at 2 MB granularity. This is based on the arm64 kernel boot
      protocol, which mandates that the kernel is loaded TEXT_OFFSET bytes above
      a 2 MB aligned base address. This requirement is a result of the fact that
      the block size used by the early mapping code may be 2 MB at the most (for
      a 4 KB granule kernel)
      
      But we can do better than that: since a KASLR kernel needs to be relocated
      in any case, we can tolerate a physical misalignment as long as the virtual
      misalignment relative to this 2 MB block size is equal in size, and code to
      deal with this is already in place.
      
      Since we align the kernel segments to 64 KB, let's randomize the physical
      offset at 64 KB granularity as well (unless CONFIG_DEBUG_ALIGN_RODATA is
      enabled). This way, the page table and TLB footprint is not affected.
      
      The higher granularity allows for 5 bits of additional entropy to be used.
      Reviewed-by: NMatt Fleming <matt@codeblueprint.co.uk>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      6f26b367
  10. 28 4月, 2016 6 次提交