Skip to content
Snippets Groups Projects
  1. Oct 08, 2019
  2. Oct 07, 2019
  3. Oct 04, 2019
    • James Morse's avatar
      arm64: ftrace: Ensure synchronisation in PLT setup for Neoverse-N1 #1542419 · dd8a1f13
      James Morse authored
      
      CPUs affected by Neoverse-N1 #1542419 may execute a stale instruction if
      it was recently modified. The affected sequence requires freshly written
      instructions to be executable before a branch to them is updated.
      
      There are very few places in the kernel that modify executable text,
      all but one come with sufficient synchronisation:
       * The module loader's flush_module_icache() calls flush_icache_range(),
         which does a kick_all_cpus_sync()
       * bpf_int_jit_compile() calls flush_icache_range().
       * Kprobes calls aarch64_insn_patch_text(), which does its work in
         stop_machine().
       * static keys and ftrace both patch between nops and branches to
         existing kernel code (not generated code).
      
      The affected sequence is the interaction between ftrace and modules.
      The module PLT is cleaned using __flush_icache_range() as the trampoline
      shouldn't be executable until we update the branch to it.
      
      Drop the double-underscore so that this path runs kick_all_cpus_sync()
      too.
      
      Signed-off-by: default avatarJames Morse <james.morse@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      dd8a1f13
    • James Morse's avatar
      arm64: Fix incorrect irqflag restore for priority masking for compat · f46f27a5
      James Morse authored
      
      Commit bd82d4bd ("arm64: Fix incorrect irqflag restore for priority
      masking") added a macro to the entry.S call paths that leave the
      PSTATE.I bit set. This tells the pPNMI masking logic that interrupts
      are masked by the CPU, not by the PMR. This value is read back by
      local_daif_save().
      
      Commit bd82d4bd added this call to el0_svc, as el0_svc_handler
      is called with interrupts masked. el0_svc_compat was missed, but should
      be covered in the same way as both of these paths end up in
      el0_svc_common(), which expects to unmask interrupts.
      
      Fixes: bd82d4bd ("arm64: Fix incorrect irqflag restore for priority masking")
      Signed-off-by: default avatarJames Morse <james.morse@arm.com>
      Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      f46f27a5
    • Julien Grall's avatar
      arm64: cpufeature: Effectively expose FRINT capability to userspace · 7230f7e9
      Julien Grall authored
      
      The HWCAP framework will detect a new capability based on the sanitized
      version of the ID registers.
      
      Sanitization is based on a whitelist, so any field not described will end
      up to be zeroed.
      
      At the moment, ID_AA64ISAR1_EL1.FRINTTS is not described in
      ftr_id_aa64isar1. This means the field will be zeroed and therefore the
      userspace will not be able to see the HWCAP even if the hardware
      supports the feature.
      
      This can be fixed by describing the field in ftr_id_aa64isar1.
      
      Fixes: ca9503fc ("arm64: Expose FRINT capabilities to userspace")
      Signed-off-by: default avatarJulien Grall <julien.grall@arm.com>
      Cc: mark.brown@arm.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      7230f7e9
  4. Oct 01, 2019
    • Masayoshi Mizuma's avatar
      arm64/sve: Fix wrong free for task->thread.sve_state · 4585fc59
      Masayoshi Mizuma authored
      
      The system which has SVE feature crashed because of
      the memory pointed by task->thread.sve_state was destroyed
      by someone.
      
      That is because sve_state is freed while the forking the
      child process. The child process has the pointer of sve_state
      which is same as the parent's because the child's task_struct
      is copied from the parent's one. If the copy_process()
      fails as an error on somewhere, for example, copy_creds(),
      then the sve_state is freed even if the parent is alive.
      The flow is as follows.
      
      copy_process
              p = dup_task_struct
                  => arch_dup_task_struct
                      *dst = *src;  // copy the entire region.
      :
              retval = copy_creds
              if (retval < 0)
                      goto bad_fork_free;
      :
      bad_fork_free:
      ...
              delayed_free_task(p);
                => free_task
                   => arch_release_task_struct
                      => fpsimd_release_task
                         => __sve_free
                            => kfree(task->thread.sve_state);
                               // free the parent's sve_state
      
      Move child's sve_state = NULL and clearing TIF_SVE flag
      to arch_dup_task_struct() so that the child doesn't free the
      parent's one.
      There is no need to wait until copy_process() to clear TIF_SVE for
      dst, because the thread flags for dst are initialized already by
      copying the src task_struct.
      This change simplifies the code, so get rid of comments that are no
      longer needed.
      
      As a note, arm64 used to have thread_info on the stack. So it
      would not be possible to clear TIF_SVE until the stack is initialized.
      From commit c02433dd ("arm64: split thread_info from task stack"),
      the thread_info is part of the task, so it should be valid to modify
      the flag from arch_dup_task_struct().
      
      Cc: stable@vger.kernel.org # 4.15.x-
      Fixes: bc0ee476 ("arm64/sve: Core task context handling")
      Signed-off-by: default avatarMasayoshi Mizuma <m.mizuma@jp.fujitsu.com>
      Reported-by: default avatarHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
      Suggested-by: default avatarDave Martin <Dave.Martin@arm.com>
      Reviewed-by: default avatarDave Martin <Dave.Martin@arm.com>
      Tested-by: default avatarJulien Grall <julien.grall@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      4585fc59
    • Thierry Reding's avatar
      arm64: errata: Update stale comment · 7a292b6c
      Thierry Reding authored
      
      Commit 73f38166 ("arm64: Advertise mitigation of Spectre-v2, or lack
      thereof") renamed the caller of the install_bp_hardening_cb() function
      but forgot to update a comment, which can be confusing when trying to
      follow the code flow.
      
      Fixes: 73f38166 ("arm64: Advertise mitigation of Spectre-v2, or lack thereof")
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      7a292b6c
  5. Sep 24, 2019
  6. Aug 27, 2019
  7. Aug 23, 2019
  8. Aug 21, 2019
    • James Morse's avatar
      arm64: entry: Move ct_user_exit before any other exception · 2671828c
      James Morse authored
      
      When taking an SError or Debug exception from EL0, we run the C
      handler for these exceptions before updating the context tracking
      code and unmasking lower priority interrupts.
      
      When booting with nohz_full lockdep tells us we got this wrong:
      | =============================
      | WARNING: suspicious RCU usage
      | 5.3.0-rc2-00010-gb4b5e9dcb11b-dirty #11271 Not tainted
      | -----------------------------
      | include/linux/rcupdate.h:643 rcu_read_unlock() used illegally wh!
      |
      | other info that might help us debug this:
      |
      |
      | RCU used illegally from idle CPU!
      | rcu_scheduler_active = 2, debug_locks = 1
      | RCU used illegally from extended quiescent state!
      | 1 lock held by a.out/432:
      |  #0: 00000000c7a79515 (rcu_read_lock){....}, at: brk_handler+0x00
      |
      | stack backtrace:
      | CPU: 1 PID: 432 Comm: a.out Not tainted 5.3.0-rc2-00010-gb4b5e9d1
      | Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno De8
      | Call trace:
      |  dump_backtrace+0x0/0x140
      |  show_stack+0x14/0x20
      |  dump_stack+0xbc/0x104
      |  lockdep_rcu_suspicious+0xf8/0x108
      |  brk_handler+0x164/0x1b0
      |  do_debug_exception+0x11c/0x278
      |  el0_dbg+0x14/0x20
      
      Moving the ct_user_exit calls to be before do_debug_exception() means
      they are also before trace_hardirqs_off() has been updated. Add a new
      ct_user_exit_irqoff macro to avoid the context-tracking code using
      irqsave/restore before we've updated trace_hardirqs_off(). To be
      consistent, do this everywhere.
      
      The C helper is called enter_from_user_mode() to match x86 in the hope
      we can merge them into kernel/context_tracking.c later.
      
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Fixes: 6c81fe79 ("arm64: enable context tracking")
      Signed-off-by: default avatarJames Morse <james.morse@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      2671828c
  9. Aug 20, 2019
  10. Aug 16, 2019
    • Will Deacon's avatar
      arm64: ftrace: Ensure module ftrace trampoline is coherent with I-side · b6143d10
      Will Deacon authored
      
      The initial support for dynamic ftrace trampolines in modules made use
      of an indirect branch which loaded its target from the beginning of
      a special section (e71a4e1b ("arm64: ftrace: add support for far
      branches to dynamic ftrace")). Since no instructions were being patched,
      no cache maintenance was needed. However, later in be0f272b ("arm64:
      ftrace: emit ftrace-mod.o contents through code") this code was reworked
      to output the trampoline instructions directly into the PLT entry but,
      unfortunately, the necessary cache maintenance was overlooked.
      
      Add a call to __flush_icache_range() after writing the new trampoline
      instructions but before patching in the branch to the trampoline.
      
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: James Morse <james.morse@arm.com>
      Cc: <stable@vger.kernel.org>
      Fixes: be0f272b ("arm64: ftrace: emit ftrace-mod.o contents through code")
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      b6143d10
  11. Aug 15, 2019
    • Sudeep Holla's avatar
      arm64: smp: disable hotplug on trusted OS resident CPU · d55c5f28
      Sudeep Holla authored
      
      The trusted OS may reject CPU_OFF calls to its resident CPU, so we must
      avoid issuing those. We never migrate a Trusted OS and we already take
      care to prevent CPU_OFF PSCI call. However, this is not reflected
      explicitly to the userspace. Any user can attempt to hotplug trusted OS
      resident CPU. The entire motion of going through the various state
      transitions in the CPU hotplug state machine gets executed and the
      PSCI layer finally refuses to make CPU_OFF call.
      
      This results is unnecessary unwinding of CPU hotplug state machine in
      the kernel. Instead we can mark the trusted OS resident CPU as not
      available for hotplug, so that the user attempt or request to do the
      same will get immediately rejected.
      
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      d55c5f28
  12. Aug 14, 2019
    • Kees Cook's avatar
      arm64/efi: Move variable assignments after SECTIONS · 90776dd1
      Kees Cook authored
      It seems that LLVM's linker does not correctly handle variable assignments
      involving section positions that are updated during the SECTIONS
      parsing. Commit aa69fb62 ("arm64/efi: Mark __efistub_stext_offset as
      an absolute symbol explicitly") ran into this too, but found a different
      workaround.
      
      However, this was not enough, as other variables were also miscalculated
      which manifested as boot failures under UEFI where __efistub__end was
      not taking the correct _end value (they should be the same):
      
      $ ld.lld -EL -maarch64elf --no-undefined -X -shared \
      	-Bsymbolic -z notext -z norelro --no-apply-dynamic-relocs \
      	-o vmlinux.lld -T poc.lds --whole-archive vmlinux.o && \
        readelf -Ws vmlinux.lld | egrep '\b(__efistub_|)_end\b'
      368272: ffff000002218000     0 NOTYPE  LOCAL  HIDDEN    38 __efistub__end
      368322: ffff000012318000     0 NOTYPE  GLOBAL DEFAULT   38 _end
      
      $ aarch64-linux-gnu-ld.bfd -EL -maarch64elf --no-undefined -X -shared \
      	-Bsymbolic -z notext -z norelro --no-apply-dynamic-relocs \
      	-o vmlinux.bfd -T poc.lds --whole-archive vmlinux.o && \
        readelf -Ws vmlinux.bfd | egrep '\b(__efistub_|)_end\b'
      338124: ffff000012318000     0 NOTYPE  LOCAL  DEFAULT  ABS __efistub__end
      383812: ffff000012318000     0 NOTYPE  GLOBAL DEFAULT 15325 _end
      
      To work around this, all of the __efistub_-prefixed variable assignments
      need to be moved after the linker script's SECTIONS entry. As it turns
      out, this also solves the problem fixed in commit aa69fb62, so those
      changes are reverted here.
      
      Link: https://github.com/ClangBuiltLinux/linux/issues/634
      Link: https://bugs.llvm.org/show_bug.cgi?id=42990
      
      
      Acked-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      90776dd1
    • Mark Rutland's avatar
      arm64: memory: rename VA_START to PAGE_END · 77ad4ce6
      Mark Rutland authored
      
      Prior to commit:
      
        14c127c9 ("arm64: mm: Flip kernel VA space")
      
      ... VA_START described the start of the TTBR1 address space for a given
      VA size described by VA_BITS, where all kernel mappings began.
      
      Since that commit, VA_START described a portion midway through the
      address space, where the linear map ends and other kernel mappings
      begin.
      
      To avoid confusion, let's rename VA_START to PAGE_END, making it clear
      that it's not the start of the TTBR1 address space and implying that
      it's related to PAGE_OFFSET. Comments and other mnemonics are updated
      accordingly, along with a typo fix in the decription of VMEMMAP_SIZE.
      
      There should be no functional change as a result of this patch.
      
      Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Tested-by: default avatarSteve Capper <steve.capper@arm.com>
      Reviewed-by: default avatarSteve Capper <steve.capper@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      77ad4ce6
  13. Aug 13, 2019
  14. Aug 12, 2019
  15. Aug 09, 2019
    • Lorenzo Pieralisi's avatar
      PSCI: cpuidle: Refactor CPU suspend power_state parameter handling · 9ffeb6d0
      Lorenzo Pieralisi authored
      
      Current PSCI code handles idle state entry through the
      psci_cpu_suspend_enter() API, that takes an idle state index as a
      parameter and convert the index into a previously initialized
      power_state parameter before calling the PSCI.CPU_SUSPEND() with it.
      
      This is unwieldly, since it forces the PSCI firmware layer to keep track
      of power_state parameter for every idle state so that the
      index->power_state conversion can be made in the PSCI firmware layer
      instead of the CPUidle driver implementations.
      
      Move the power_state handling out of drivers/firmware/psci
      into the respective ACPI/DT PSCI CPUidle backends and convert
      the psci_cpu_suspend_enter() API to get the power_state
      parameter as input, which makes it closer to its firmware
      interface PSCI.CPU_SUSPEND() API.
      
      A notable side effect is that the PSCI ACPI/DT CPUidle backends
      now can directly handle (and if needed update) power_state
      parameters before handing them over to the PSCI firmware
      interface to trigger PSCI.CPU_SUSPEND() calls.
      
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Acked-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Reviewed-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Ulf Hansson <ulf.hansson@linaro.org>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      9ffeb6d0
    • Lorenzo Pieralisi's avatar
      ARM: psci: cpuidle: Enable PSCI CPUidle driver · 78896146
      Lorenzo Pieralisi authored
      
      Allow selection of the PSCI CPUidle in the kernel by updating
      the respective Kconfig entry.
      
      Remove PSCI callbacks from ARM/ARM64 generic CPU ops
      to prevent the PSCI idle driver from clashing with the generic
      ARM CPUidle driver initialization, that relies on CPU ops
      to initialize and enter idle states.
      
      Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Cc: Will Deacon <will@kernel.org>
      Cc: Ulf Hansson <ulf.hansson@linaro.org>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      78896146
    • Steve Capper's avatar
      arm64: mm: Remove vabits_user · 2c624fe6
      Steve Capper authored
      
      Previous patches have enabled 52-bit kernel + user VAs and there is no
      longer any scenario where user VA != kernel VA size.
      
      This patch removes the, now redundant, vabits_user variable and replaces
      usage with vabits_actual where appropriate.
      
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      2c624fe6
    • Steve Capper's avatar
      arm64: mm: Introduce 52-bit Kernel VAs · b6d00d47
      Steve Capper authored
      
      Most of the machinery is now in place to enable 52-bit kernel VAs that
      are detectable at boot time.
      
      This patch adds a Kconfig option for 52-bit user and kernel addresses
      and plumbs in the requisite CONFIG_ macros as well as sets TCR.T1SZ,
      physvirt_offset and vmemmap at early boot.
      
      To simplify things this patch also removes the 52-bit user/48-bit kernel
      kconfig option.
      
      Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      b6d00d47
    • Steve Capper's avatar
      arm64: mm: Logic to make offset_ttbr1 conditional · c812026c
      Steve Capper authored
      
      When running with a 52-bit userspace VA and a 48-bit kernel VA we offset
      ttbr1_el1 to allow the kernel pagetables with a 52-bit PTRS_PER_PGD to
      be used for both userspace and kernel.
      
      Moving on to a 52-bit kernel VA we no longer require this offset to
      ttbr1_el1 should we be running on a system with HW support for 52-bit
      VAs.
      
      This patch introduces conditional logic to offset_ttbr1 to query
      SYS_ID_AA64MMFR2_EL1 whenever 52-bit VAs are selected. If there is HW
      support for 52-bit VAs then the ttbr1 offset is skipped.
      
      We choose to read a system register rather than vabits_actual because
      offset_ttbr1 can be called in places where the kernel data is not
      actually mapped.
      
      Calls to offset_ttbr1 appear to be made from rarely called code paths so
      this extra logic is not expected to adversely affect performance.
      
      Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      c812026c
    • Steve Capper's avatar
      arm64: mm: Introduce vabits_actual · 5383cc6e
      Steve Capper authored
      
      In order to support 52-bit kernel addresses detectable at boot time, one
      needs to know the actual VA_BITS detected. A new variable vabits_actual
      is introduced in this commit and employed for the KVM hypervisor layout,
      KASAN, fault handling and phys-to/from-virt translation where there
      would normally be compile time constants.
      
      In order to maintain performance in phys_to_virt, another variable
      physvirt_offset is introduced.
      
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      5383cc6e
    • Steve Capper's avatar
      arm64: mm: Introduce VA_BITS_MIN · 90ec95cd
      Steve Capper authored
      
      In order to support 52-bit kernel addresses detectable at boot time, the
      kernel needs to know the most conservative VA_BITS possible should it
      need to fall back to this quantity due to lack of hardware support.
      
      A new compile time constant VA_BITS_MIN is introduced in this patch and
      it is employed in the KASAN end address, KASLR, and EFI stub.
      
      For Arm, if 52-bit VA support is unavailable the fallback is to 48-bits.
      
      In other words: VA_BITS_MIN = min (48, VA_BITS)
      
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      90ec95cd
Loading