1. 01 May, 2019 2 commits
  2. 30 Apr, 2019 4 commits
  3. 29 Apr, 2019 3 commits
  4. 26 Apr, 2019 5 commits
    • Will Deacon's avatar
      futex: Update comments and docs about return values of arch futex code · 42750351
      Will Deacon authored
      The architecture implementations of 'arch_futex_atomic_op_inuser()' and
      'futex_atomic_cmpxchg_inatomic()' are permitted to return only -EFAULT,
      -EAGAIN or -ENOSYS in the case of failure.
      
      Update the comments in the asm-generic/ implementation and also a stray
      reference in the robust futex documentation.
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      42750351
    • Will Deacon's avatar
      arm64: futex: Avoid copying out uninitialised stack in failed cmpxchg() · 8e4e0ac0
      Will Deacon authored
      Returning an error code from futex_atomic_cmpxchg_inatomic() indicates
      that the caller should not make any use of *uval, and should instead act
      upon on the value of the error code. Although this is implemented
      correctly in our futex code, we needlessly copy uninitialised stack to
      *uval in the error case, which can easily be avoided.
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      8e4e0ac0
    • Will Deacon's avatar
      arm64: futex: Bound number of LDXR/STXR loops in FUTEX_WAKE_OP · 03110a5c
      Will Deacon authored
      Our futex implementation makes use of LDXR/STXR loops to perform atomic
      updates to user memory from atomic context. This can lead to latency
      problems if we end up spinning around the LL/SC sequence at the expense
      of doing something useful.
      
      Rework our futex atomic operations so that we return -EAGAIN if we fail
      to update the futex word after 128 attempts. The core futex code will
      reschedule if necessary and we'll try again later.
      
      Cc: <stable@kernel.org>
      Fixes: 6170a974 ("arm64: Atomic operations")
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      03110a5c
    • Will Deacon's avatar
      locking/futex: Allow low-level atomic operations to return -EAGAIN · 6b4f4bc9
      Will Deacon authored
      Some futex() operations, including FUTEX_WAKE_OP, require the kernel to
      perform an atomic read-modify-write of the futex word via the userspace
      mapping. These operations are implemented by each architecture in
      arch_futex_atomic_op_inuser() and futex_atomic_cmpxchg_inatomic(), which
      are called in atomic context with the relevant hash bucket locks held.
      
      Although these routines may return -EFAULT in response to a page fault
      generated when accessing userspace, they are expected to succeed (i.e.
      return 0) in all other cases. This poses a problem for architectures
      that do not provide bounded forward progress guarantees or fairness of
      contended atomic operations and can lead to starvation in some cases.
      
      In these problematic scenarios, we must return back to the core futex
      code so that we can drop the hash bucket locks and reschedule if
      necessary, much like we do in the case of a page fault.
      
      Allow architectures to return -EAGAIN from their implementations of
      arch_futex_atomic_op_inuser() and futex_atomic_cmpxchg_inatomic(), which
      will cause the core futex code to reschedule if necessary and return
      back to the architecture code later on.
      
      Cc: <stable@kernel.org>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      6b4f4bc9
    • Will Deacon's avatar
      arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value · 84ff7a09
      Will Deacon authored
      Rather embarrassingly, our futex() FUTEX_WAKE_OP implementation doesn't
      explicitly set the return value on the non-faulting path and instead
      leaves it holding the result of the underlying atomic operation. This
      means that any FUTEX_WAKE_OP atomic operation which computes a non-zero
      value will be reported as having failed. Regrettably, I wrote the buggy
      code back in 2011 and it was upstreamed as part of the initial arm64
      support in 2012.
      
      The reasons we appear to get away with this are:
      
        1. FUTEX_WAKE_OP is rarely used and therefore doesn't appear to get
           exercised by futex() test applications
      
        2. If the result of the atomic operation is zero, the system call
           behaves correctly
      
        3. Prior to version 2.25, the only operation used by GLIBC set the
           futex to zero, and therefore worked as expected. From 2.25 onwards,
           FUTEX_WAKE_OP is not used by GLIBC at all.
      
      Fix the implementation by ensuring that the return value is either 0
      to indicate that the atomic operation completed successfully, or -EFAULT
      if we encountered a fault when accessing the user mapping.
      
      Cc: <stable@kernel.org>
      Fixes: 6170a974 ("arm64: Atomic operations")
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      84ff7a09
  5. 25 Apr, 2019 1 commit
    • Kees Cook's avatar
      arm64: sysreg: Make mrs_s and msr_s macros work with Clang and LTO · be604c61
      Kees Cook authored
      Clang's integrated assembler does not allow assembly macros defined
      in one inline asm block using the .macro directive to be used across
      separate asm blocks. LLVM developers consider this a feature and not a
      bug, recommending code refactoring:
      
        https://bugs.llvm.org/show_bug.cgi?id=19749
      
      As binutils doesn't allow macros to be redefined, this change uses
      UNDEFINE_MRS_S and UNDEFINE_MSR_S to define corresponding macros
      in-place and workaround gcc and clang limitations on redefining macros
      across different assembler blocks.
      
      Specifically, the current state after preprocessing looks like this:
      
      asm volatile(".macro mXX_s ... .endm");
      void f()
      {
      	asm volatile("mXX_s a, b");
      }
      
      With GCC, it gives macro redefinition error because sysreg.h is included
      in multiple source files, and assembler code for all of them is later
      combined for LTO (I've seen an intermediate file with hundreds of
      identical definitions).
      
      With clang, it gives macro undefined error because clang doesn't allow
      sharing macros between inline asm statements.
      
      I also seem to remember catching another sort of undefined error with
      GCC due to reordering of macro definition asm statement and generated
      asm code for function that uses the macro.
      
      The solution with defining and undefining for each use, while certainly
      not elegant, satisfies both GCC and clang, LTO and non-LTO.
      Co-developed-by: default avatarAlex Matveev <alxmtvv@gmail.com>
      Co-developed-by: default avatarYury Norov <ynorov@caviumnetworks.com>
      Co-developed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarMark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      be604c61
  6. 23 Apr, 2019 6 commits
  7. 16 Apr, 2019 11 commits
  8. 12 Apr, 2019 1 commit
  9. 11 Apr, 2019 1 commit
    • Masahiro Yamada's avatar
      arm64: vdso: use $(LD) instead of $(CC) to link VDSO · 691efbed
      Masahiro Yamada authored
      We use $(LD) to link vmlinux, modules, decompressors, etc.
      
      VDSO is the only exceptional case where $(CC) is used as the linker
      driver, but I do not know why we need to do so. VDSO uses a special
      linker script, and does not link standard libraries at all.
      
      I changed the Makefile to use $(LD) rather than $(CC). I tested this,
      and VDSO worked for me.
      
      Users will be able to use their favorite linker (e.g. lld instead of
      of bfd) by passing LD= from the command line.
      
      My plan is to rewrite all VDSO Makefiles to use $(LD), then delete
      cc-ldoption.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      691efbed
  10. 10 Apr, 2019 1 commit
    • Vincenzo Frascino's avatar
      arm64: compat: Reduce address limit · d2631193
      Vincenzo Frascino authored
      Currently, compat tasks running on arm64 can allocate memory up to
      TASK_SIZE_32 (UL(0x100000000)).
      
      This means that mmap() allocations, if we treat them as returning an
      array, are not compliant with the sections 6.5.8 of the C standard
      (C99) which states that: "If the expression P points to an element of
      an array object and the expression Q points to the last element of the
      same array object, the pointer expression Q+1 compares greater than P".
      
      Redefine TASK_SIZE_32 to address the issue.
      
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarJann Horn <jannh@google.com>
      Signed-off-by: default avatarVincenzo Frascino <vincenzo.frascino@arm.com>
      [will: fixed typo in comment]
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      d2631193
  11. 09 Apr, 2019 5 commits