1. 12 7月, 2018 4 次提交
    • M
      arm64: implement syscall wrappers · 4378a7d4
      Mark Rutland 提交于
      To minimize the risk of userspace-controlled values being used under
      speculation, this patch adds pt_regs based syscall wrappers for arm64,
      which pass the minimum set of required userspace values to syscall
      implementations. For each syscall, a wrapper which takes a pt_regs
      argument is automatically generated, and this extracts the arguments
      before calling the "real" syscall implementation.
      
      Each syscall has three functions generated:
      
      * __do_<compat_>sys_<name> is the "real" syscall implementation, with
        the expected prototype.
      
      * __se_<compat_>sys_<name> is the sign-extension/narrowing wrapper,
        inherited from common code. This takes a series of long parameters,
        casting each to the requisite types required by the "real" syscall
        implementation in __do_<compat_>sys_<name>.
      
        This wrapper *may* not be necessary on arm64 given the AAPCS rules on
        unused register bits, but it seemed safer to keep the wrapper for now.
      
      * __arm64_<compat_>_sys_<name> takes a struct pt_regs pointer, and
        extracts *only* the relevant register values, passing these on to the
        __se_<compat_>sys_<name> wrapper.
      
      The syscall invocation code is updated to handle the calling convention
      required by __arm64_<compat_>_sys_<name>, and passes a single struct
      pt_regs pointer.
      
      The compiler can fold the syscall implementation and its wrappers, such
      that the overhead of this approach is minimized.
      
      Note that we play games with sys_ni_syscall(). It can't be defined with
      SYSCALL_DEFINE0() because we must avoid the possibility of error
      injection. Additionally, there are a couple of locations where we need
      to call it from C code, and we don't (currently) have a
      ksys_ni_syscall().  While it has no wrapper, passing in a redundant
      pt_regs pointer is benign per the AAPCS.
      
      When ARCH_HAS_SYSCALL_WRAPPER is selected, no prototype is defines for
      sys_ni_syscall(). Since we need to treat it differently for in-kernel
      calls and the syscall tables, the prototype is defined as-required.
      
      The wrappers are largely the same as their x86 counterparts, but
      simplified as we don't have a variety of compat calling conventions that
      require separate stubs. Unlike x86, we have some zero-argument compat
      syscalls, and must define COMPAT_SYSCALL_DEFINE0() to ensure that these
      are also given an __arm64_compat_sys_ prefix.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Reviewed-by: NDominik Brodowski <linux@dominikbrodowski.net>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      4378a7d4
    • M
      arm64: convert native/compat syscall entry to C · 3b714275
      Mark Rutland 提交于
      Now that the syscall invocation logic is in C, we can migrate the rest
      of the syscall entry logic over, so that the entry assembly needn't look
      at the register values at all.
      
      The SVE reset across syscall logic now unconditionally clears TIF_SVE,
      but sve_user_disable() will only write back to CPACR_EL1 when SVE is
      actually enabled.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Reviewed-by: NDave Martin <dave.martin@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      3b714275
    • M
      arm64: convert syscall trace logic to C · f37099b6
      Mark Rutland 提交于
      Currently syscall tracing is a tricky assembly state machine, which can
      be rather difficult to follow, and even harder to modify. Before we
      start fiddling with it for pt_regs syscalls, let's convert it to C.
      
      This is not intended to have any functional change.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      f37099b6
    • M
      arm64: convert raw syscall invocation to C · 4141c857
      Mark Rutland 提交于
      As a first step towards invoking syscalls with a pt_regs argument,
      convert the raw syscall invocation logic to C. We end up with a bit more
      register shuffling, but the unified invocation logic means we can unify
      the tracing paths, too.
      
      Previously, assembly had to open-code calls to ni_sys() when the system
      call number was out-of-bounds for the relevant syscall table. This case
      is now handled by invoke_syscall(), and the assembly no longer need to
      handle this case explicitly. This allows the tracing paths to be
      simplified and unified, as we no longer need the __ni_sys_trace path and
      the __sys_trace_return label.
      
      This only converts the invocation of the syscall. The rest of the
      syscall triage and tracing is left in assembly for now, and will be
      converted in subsequent patches.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      4141c857