1. 11 6月, 2016 1 次提交
    • Z
      arm64: bpf: implement bpf_tail_call() helper · ddb55992
      Zi Shen Lim 提交于
      Add support for JMP_CALL_X (tail call) introduced by commit 04fd61ab
      ("bpf: allow bpf programs to tail-call other bpf programs").
      
      bpf_tail_call() arguments:
        ctx   - context pointer passed to next program
        array - pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
        index - index inside array that selects specific program to run
      
      In this implementation arm64 JIT jumps into callee program after prologue,
      so callee program reuses the same stack. For tail_call_cnt, we use the
      callee-saved R26 (which was already saved/restored but previously unused
      by JIT).
      
      With this patch a tail call generates the following code on arm64:
      
        if (index >= array->map.max_entries)
            goto out;
      
        34:   mov     x10, #0x10                      // #16
        38:   ldr     w10, [x1,x10]
        3c:   cmp     w2, w10
        40:   b.ge    0x0000000000000074
      
        if (tail_call_cnt > MAX_TAIL_CALL_CNT)
            goto out;
        tail_call_cnt++;
      
        44:   mov     x10, #0x20                      // #32
        48:   cmp     x26, x10
        4c:   b.gt    0x0000000000000074
        50:   add     x26, x26, #0x1
      
        prog = array->ptrs[index];
        if (prog == NULL)
            goto out;
      
        54:   mov     x10, #0x68                      // #104
        58:   ldr     x10, [x1,x10]
        5c:   ldr     x11, [x10,x2]
        60:   cbz     x11, 0x0000000000000074
      
        goto *(prog->bpf_func + prologue_size);
      
        64:   mov     x10, #0x20                      // #32
        68:   ldr     x10, [x11,x10]
        6c:   add     x10, x10, #0x20
        70:   br      x10
        74:
      Signed-off-by: NZi Shen Lim <zlim.lnx@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ddb55992
  2. 18 5月, 2016 1 次提交
  3. 17 5月, 2016 3 次提交
  4. 15 5月, 2016 1 次提交
    • Z
      arm64: bpf: jit JMP_JSET_{X,K} · 98397fc5
      Zi Shen Lim 提交于
      Original implementation commit e54bcde3 ("arm64: eBPF JIT compiler")
      had the relevant code paths, but due to an oversight always fail jiting.
      
      As a result, we had been falling back to BPF interpreter whenever a BPF
      program has JMP_JSET_{X,K} instructions.
      
      With this fix, we confirm that the corresponding tests in lib/test_bpf
      continue to pass, and also jited.
      
      ...
      [    2.784553] test_bpf: #30 JSET jited:1 188 192 197 PASS
      [    2.791373] test_bpf: #31 tcpdump port 22 jited:1 325 677 625 PASS
      [    2.808800] test_bpf: #32 tcpdump complex jited:1 323 731 991 PASS
      ...
      [    3.190759] test_bpf: #237 JMP_JSET_K: if (0x3 & 0x2) return 1 jited:1 110 PASS
      [    3.192524] test_bpf: #238 JMP_JSET_K: if (0x3 & 0xffffffff) return 1 jited:1 98 PASS
      [    3.211014] test_bpf: #249 JMP_JSET_X: if (0x3 & 0x2) return 1 jited:1 120 PASS
      [    3.212973] test_bpf: #250 JMP_JSET_X: if (0x3 & 0xffffffff) return 1 jited:1 89 PASS
      ...
      
      Fixes: e54bcde3 ("arm64: eBPF JIT compiler")
      Signed-off-by: NZi Shen Lim <zlim.lnx@gmail.com>
      Acked-by: NWill Deacon <will.deacon@arm.com>
      Acked-by: NYang Shi <yang.shi@linaro.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      98397fc5
  5. 18 1月, 2016 1 次提交
  6. 19 12月, 2015 1 次提交
    • D
      bpf: move clearing of A/X into classic to eBPF migration prologue · 8b614aeb
      Daniel Borkmann 提交于
      Back in the days where eBPF (or back then "internal BPF" ;->) was not
      exposed to user space, and only the classic BPF programs internally
      translated into eBPF programs, we missed the fact that for classic BPF
      A and X needed to be cleared. It was fixed back then via 83d5b7ef
      ("net: filter: initialize A and X registers"), and thus classic BPF
      specifics were added to the eBPF interpreter core to work around it.
      
      This added some confusion for JIT developers later on that take the
      eBPF interpreter code as an example for deriving their JIT. F.e. in
      f75298f5 ("s390/bpf: clear correct BPF accumulator register"), at
      least X could leak stack memory. Furthermore, since this is only needed
      for classic BPF translations and not for eBPF (verifier takes care
      that read access to regs cannot be done uninitialized), more complexity
      is added to JITs as they need to determine whether they deal with
      migrations or native eBPF where they can just omit clearing A/X in
      their prologue and thus reduce image size a bit, see f.e. cde66c2d
      ("s390/bpf: Only clear A and X for converted BPF programs"). In other
      cases (x86, arm64), A and X is being cleared in the prologue also for
      eBPF case, which is unnecessary.
      
      Lets move this into the BPF migration in bpf_convert_filter() where it
      actually belongs as long as the number of eBPF JITs are still few. It
      can thus be done generically; allowing us to remove the quirk from
      __bpf_prog_run() and to slightly reduce JIT image size in case of eBPF,
      while reducing code duplication on this matter in current(/future) eBPF
      JITs.
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NMichael Holzheu <holzheu@linux.vnet.ibm.com>
      Tested-by: NMichael Holzheu <holzheu@linux.vnet.ibm.com>
      Cc: Zi Shen Lim <zlim.lnx@gmail.com>
      Cc: Yang Shi <yang.shi@linaro.org>
      Acked-by: NYang Shi <yang.shi@linaro.org>
      Acked-by: NZi Shen Lim <zlim.lnx@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      8b614aeb
  7. 04 12月, 2015 1 次提交
  8. 19 11月, 2015 1 次提交
  9. 18 11月, 2015 1 次提交
    • Y
      arm64: bpf: make BPF prologue and epilogue align with ARM64 AAPCS · ec0738db
      Yang Shi 提交于
      Save and restore FP/LR in BPF prog prologue and epilogue, save SP to FP
      in prologue in order to get the correct stack backtrace.
      
      However, ARM64 JIT used FP (x29) as eBPF fp register, FP is subjected to
      change during function call so it may cause the BPF prog stack base address
      change too.
      
      Use x25 to replace FP as BPF stack base register (fp). Since x25 is callee
      saved register, so it will keep intact during function call.
      It is initialized in BPF prog prologue when BPF prog is started to run
      everytime. Save and restore x25/x26 in BPF prologue and epilogue to keep
      them intact for the outside of BPF. Actually, x26 is unnecessary, but SP
      requires 16 bytes alignment.
      
      So, the BPF stack layout looks like:
      
                                       high
               original A64_SP =>   0:+-----+ BPF prologue
                                      |FP/LR|
               current A64_FP =>  -16:+-----+
                                      | ... | callee saved registers
                                      +-----+
                                      |     | x25/x26
               BPF fp register => -80:+-----+
                                      |     |
                                      | ... | BPF prog stack
                                      |     |
                                      |     |
               current A64_SP =>      +-----+
                                      |     |
                                      | ... | Function call stack
                                      |     |
                                      +-----+
                                        low
      
      CC: Zi Shen Lim <zlim.lnx@gmail.com>
      CC: Xi Wang <xi.wang@gmail.com>
      Signed-off-by: NYang Shi <yang.shi@linaro.org>
      Acked-by: NZi Shen Lim <zlim.lnx@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ec0738db
  10. 17 11月, 2015 2 次提交
  11. 07 11月, 2015 2 次提交
  12. 03 10月, 2015 1 次提交
  13. 26 6月, 2015 1 次提交
  14. 25 6月, 2015 1 次提交
    • X
      arm64: bpf: fix out-of-bounds read in bpf2a64_offset() · 8eee539d
      Xi Wang 提交于
      Problems occur when bpf_to or bpf_from has value prog->len - 1 (e.g.,
      "Very long jump backwards" in test_bpf where the last instruction is a
      jump): since ctx->offset has length prog->len, ctx->offset[bpf_to + 1]
      or ctx->offset[bpf_from + 1] will cause an out-of-bounds read, leading
      to a bogus jump offset and kernel panic.
      
      This patch moves updating ctx->offset to after calling build_insn(),
      and changes indexing to use bpf_to and bpf_from without + 1.
      
      Fixes: e54bcde3 ("arm64: eBPF JIT compiler")
      Cc: <stable@vger.kernel.org> # 3.18+
      Cc: Zi Shen Lim <zlim.lnx@gmail.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Acked-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NXi Wang <xi.wang@gmail.com>
      Signed-off-by: NCatalin Marinas <catalin.marinas@arm.com>
      8eee539d
  15. 08 5月, 2015 1 次提交
    • X
      arm64: bpf: fix signedness bug in loading 64-bit immediate · 1e4df6b7
      Xi Wang 提交于
      Consider "(u64)insn1.imm << 32 | imm" in the arm64 JIT.  Since imm is
      signed 32-bit, it is sign-extended to 64-bit, losing the high 32 bits.
      The fix is to convert imm to u32 first, which will be zero-extended to
      u64 implicitly.
      
      Cc: Zi Shen Lim <zlim.lnx@gmail.com>
      Cc: Alexei Starovoitov <ast@plumgrid.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: <stable@vger.kernel.org>
      Fixes: 30d3d94c ("arm64: bpf: add 'load 64-bit immediate' instruction")
      Signed-off-by: NXi Wang <xi.wang@gmail.com>
      [will: removed non-arm64 bits and redundant casting]
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      1e4df6b7
  16. 04 12月, 2014 1 次提交
  17. 21 10月, 2014 4 次提交
  18. 12 9月, 2014 1 次提交
  19. 08 9月, 2014 1 次提交