1. 03 Feb, 2023 7 commits
  2. 02 Feb, 2023 2 commits
  3. 01 Feb, 2023 24 commits
  4. 30 Jan, 2023 7 commits
    • Alexei Starovoitov's avatar
      Merge branch 'Support bpf trampoline for s390x' · c1a3daf7
      Alexei Starovoitov authored
      Ilya Leoshkevich says:
      
      ====================
      
      v2: https://lore.kernel.org/bpf/20230128000650.1516334-1-iii@linux.ibm.com/#t
      v2 -> v3:
      - Make __arch_prepare_bpf_trampoline static.
        (Reported-by: kernel test robot <lkp@intel.com>)
      - Support both old- and new- style map definitions in sk_assign. (Alexei)
      - Trim DENYLIST.s390x. (Alexei)
      - Adjust s390x vmlinux path in vmtest.sh.
      - Drop merged fixes.
      
      v1: https://lore.kernel.org/bpf/20230125213817.1424447-1-iii@linux.ibm.com/#t
      v1 -> v2:
      - Fix core_read_macros, sk_assign, test_profiler, test_bpffs (24/31;
        I'm not quite happy with the fix, but don't have better ideas),
        and xdp_synproxy. (Andrii)
      - Prettify liburandom_read and verify_pkcs7_sig fixes. (Andrii)
      - Fix bpf_usdt_arg using barrier_var(); prettify barrier_var(). (Andrii)
      - Change BPF_MAX_TRAMP_LINKS to enum and query it using BTF. (Andrii)
      - Improve bpf_jit_supports_kfunc_call() description. (Alexei)
      - Always check sign_extend() return value.
      - Cc: Alexander Gordeev.
      
      Hi,
      
      This series implements poke, trampoline, kfunc, and mixing subprogs
      and tailcalls on s390x.
      
      The following failures still remain:
      
      #82      get_stack_raw_tp:FAIL
      get_stack_print_output:FAIL:user_stack corrupted user stack
      Known issue:
      We cannot reliably unwind userspace on s390x without DWARF.
      
      #101     ksyms_module:FAIL
      address of kernel function bpf_testmod_test_mod_kfunc is out of range
      Known issue:
      Kernel and modules are too far away from each other on s390x.
      
      #190     stacktrace_build_id:FAIL
      Known issue:
      We cannot reliably unwind userspace on s390x without DWARF.
      
      #281     xdp_metadata:FAIL
      See patch 6.
      
      None of these seem to be due to the new changes.
      
      Best regards,
      Ilya
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      c1a3daf7
    • Ilya Leoshkevich's avatar
      selftests/bpf: Trim DENYLIST.s390x · ee105d5a
      Ilya Leoshkevich authored
      Now that trampoline is implemented, enable a number of tests on s390x.
      18 of the remaining failures have to do with either lack of rethook
      (fixed by [1]) or syscall symbols missing from BTF (fixed by [2]).
      
      Do not re-classify the remaining failures for now; wait until the
      s390/for-next fixes are merged and re-classify only the remaining few.
      
      [1] https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=for-next&id=1a280f48c0e403903cf0b4231c95b948e664f25a
      [2] https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=for-next&id=2213d44e140f979f4b60c3c0f8dd56d151cc8692Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-9-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      ee105d5a
    • Ilya Leoshkevich's avatar
      selftests/bpf: Fix s390x vmlinux path · af320fb7
      Ilya Leoshkevich authored
      After commit edd4a866 ("s390/boot: get rid of startup archive")
      there is no more compressed/ subdirectory.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-8-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      af320fb7
    • Ilya Leoshkevich's avatar
      s390/bpf: Implement bpf_jit_supports_kfunc_call() · 63d7b53a
      Ilya Leoshkevich authored
      Implement calling kernel functions from eBPF. In general, the eBPF ABI
      is fairly close to that of s390x, with one important difference: on
      s390x callers should sign-extend signed arguments. Handle that by using
      information returned by bpf_jit_find_kfunc_model().
      
      Here is an example of how sign extensions works. Suppose we need to
      call the following function from BPF:
      
          ; long noinline bpf_kfunc_call_test4(signed char a, short b, int c,
      long d)
          0000000000936a78 <bpf_kfunc_call_test4>:
          936a78:       c0 04 00 00 00 00       jgnop bpf_kfunc_call_test4
          ;     return (long)a + (long)b + (long)c + d;
          936a7e:       b9 08 00 45             agr     %r4,%r5
          936a82:       b9 08 00 43             agr     %r4,%r3
          936a86:       b9 08 00 24             agr     %r2,%r4
          936a8a:       c0 f4 00 1e 3b 27       jg      <__s390_indirect_jump_r14>
      
      As per the s390x ABI, bpf_kfunc_call_test4() has the right to assume
      that a, b and c are sign-extended by the caller, which results in using
      64-bit additions (agr) without any additional conversions. Without sign
      extension we would have the following on the JITed code side:
      
          ; tmp = bpf_kfunc_call_test4(-3, -30, -200, -1000);
          ;        5:       b4 10 00 00 ff ff ff fd w1 = -3
          0x3ff7fdcdad4:       llilf   %r2,0xfffffffd
          ;        6:       b4 20 00 00 ff ff ff e2 w2 = -30
          0x3ff7fdcdada:       llilf   %r3,0xffffffe2
          ;        7:       b4 30 00 00 ff ff ff 38 w3 = -200
          0x3ff7fdcdae0:       llilf   %r4,0xffffff38
          ;       8:       b7 40 00 00 ff ff fc 18 r4 = -1000
          0x3ff7fdcdae6:       lgfi    %r5,-1000
          0x3ff7fdcdaec:       mvc     64(4,%r15),160(%r15)
          0x3ff7fdcdaf2:       lgrl    %r1,bpf_kfunc_call_test4@GOT
          0x3ff7fdcdaf8:       brasl   %r14,__s390_indirect_jump_r1
      
      This first 3 llilfs are 32-bit loads, that need to be sign-extended
      to 64 bits.
      
      Note: at the moment bpf_jit_find_kfunc_model() does not seem to play
      nicely with XDP metadata functions: add_kfunc_call() adds an "abstract"
      bpf_*() version to kfunc_btf_tab, but then fixup_kfunc_call() puts the
      concrete version into insn->imm, which bpf_jit_find_kfunc_model() cannot
      find. But this seems to be a common code problem.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-7-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      63d7b53a
    • Ilya Leoshkevich's avatar
      s390/bpf: Implement bpf_jit_supports_subprog_tailcalls() · dd691e84
      Ilya Leoshkevich authored
      Allow mixing subprogs and tail calls by passing the current tail
      call count to subprogs.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-6-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      dd691e84
    • Ilya Leoshkevich's avatar
      s390/bpf: Implement arch_prepare_bpf_trampoline() · 528eb2cb
      Ilya Leoshkevich authored
      arch_prepare_bpf_trampoline() is used for direct attachment of eBPF
      programs to various places, bypassing kprobes. It's responsible for
      calling a number of eBPF programs before, instead and/or after
      whatever they are attached to.
      
      Add a s390x implementation, paying attention to the following:
      
      - Reuse the existing JIT infrastructure, where possible.
      - Like the existing JIT, prefer making multiple passes instead of
        backpatching. Currently 2 passes is enough. If literal pool is
        introduced, this needs to be raised to 3. However, at the moment
        adding literal pool only makes the code larger. If branch
        shortening is introduced, the number of passes needs to be
        increased even further.
      - Support both regular and ftrace calling conventions, depending on
        the trampoline flags.
      - Use expolines for indirect calls.
      - Handle the mismatch between the eBPF and the s390x ABIs.
      - Sign-extend fmod_ret return values.
      
      invoke_bpf_prog() produces about 120 bytes; it might be possible to
      slightly optimize this, but reaching 50 bytes, like on x86_64, looks
      unrealistic: just loading cookie, __bpf_prog_enter, bpf_func, insnsi
      and __bpf_prog_exit as literals already takes at least 5 * 12 = 60
      bytes, and we can't use relative addressing for most of them.
      Therefore, lower BPF_MAX_TRAMP_LINKS on s390x.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-5-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      528eb2cb
    • Ilya Leoshkevich's avatar
      s390/bpf: Implement bpf_arch_text_poke() · f1d5df84
      Ilya Leoshkevich authored
      bpf_arch_text_poke() is used to hotpatch eBPF programs and trampolines.
      s390x has a very strict hotpatching restriction: the only thing that is
      allowed to be hotpatched is conditional branch mask.
      
      Take the same approach as commit de5012b4 ("s390/ftrace: implement
      hotpatching"): create a conditional jump to a "plt", which loads the
      target address from memory and jumps to it; then first patch this
      address, and then the mask.
      
      Trampolines (introduced in the next patch) respect the ftrace calling
      convention: the return address is in %r0, and %r1 is clobbered. With
      that in mind, bpf_arch_text_poke() does not differentiate between jumps
      and calls.
      
      However, there is a simple optimization for jumps (for the epilogue_ip
      case): if a jump already points to the destination, then there is no
      "plt" and we can just flip the mask.
      
      For simplicity, the "plt" template is defined in assembly, and its size
      is used to define C arrays. There doesn't seem to be a way to convey
      this size to C as a constant, so it's hardcoded and double-checked
      during runtime.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Link: https://lore.kernel.org/r/20230129190501.1624747-4-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      f1d5df84