1. 05 2月, 2019 15 次提交
    • B
      bpf, riscv: add BPF JIT for RV64G · 2353ecc6
      Björn Töpel 提交于
      This commit adds a BPF JIT for RV64G.
      
      The JIT is a two-pass JIT, and has a dynamic prolog/epilogue (similar
      to the MIPS64 BPF JIT) instead of static ones (e.g. x86_64).
      
      At the moment the RISC-V Linux port does not support
      CONFIG_HAVE_KPROBES, which means that CONFIG_BPF_EVENTS is not
      supported. Thus, no tests involving BPF_PROG_TYPE_TRACEPOINT,
      BPF_PROG_TYPE_PERF_EVENT, BPF_PROG_TYPE_KPROBE and
      BPF_PROG_TYPE_RAW_TRACEPOINT passes.
      
      The implementation does not support "far branching" (>4KiB).
      
      Test results:
        # modprobe test_bpf
        test_bpf: Summary: 378 PASSED, 0 FAILED, [366/366 JIT'ed]
      
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier
        ...
        Summary: 761 PASSED, 507 SKIPPED, 2 FAILED
      
      Note that "test_verifier" was run with one build with
      CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y and one without, otherwise
      many of the the tests that require unaligned access were skipped.
      
      CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y:
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier | grep -c 'NOTE.*unknown align'
        0
      
      No CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS:
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier | grep -c 'NOTE.*unknown align'
        59
      
      The two failing test_verifier tests are:
        "ld_abs: vlan + abs, test 1"
        "ld_abs: jump around ld_abs"
      
      This is due to that "far branching" involved in those tests.
      
      All tests where done on QEMU (QEMU emulator version 3.1.50
      (v3.1.0-688-g8ae951fbc106)).
      Signed-off-by: NBjörn Töpel <bjorn.topel@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      2353ecc6
    • D
      Merge branch 'bpf-btf-dedup' · 31de3897
      Daniel Borkmann 提交于
      Andrii Nakryiko says:
      
      ====================
      This patch series adds BTF deduplication algorithm to libbpf. This algorithm
      allows to take BTF type information containing duplicate per-compilation unit
      information and reduce it to equivalent set of BTF types with no duplication without
      loss of information. It also deduplicates strings and removes those strings that
      are not referenced from any BTF type (and line information in .BTF.ext section,
      if any).
      
      Algorithm also resolves struct/union forward declarations into concrete BTF types
      across multiple compilation units to facilitate better deduplication ratio. If
      undesired, this resolution can be disabled through specifying corresponding options.
      
      When applied to BTF data emitted by pahole's DWARF->BTF converter, it reduces
      the overall size of .BTF section by about 65x, from about 112MB to 1.75MB, leaving
      only 29247 out of initial 3073497 BTF type descriptors.
      
      Algorithm with minor differences and preliminary results before FUNC/FUNC_PROTO
      support is also described more verbosely at:
      
      https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.html
      
      v1->v2:
      - rebase on latest bpf-next
      - err_log/elog -> pr_debug
      - btf__dedup, btf__get_strings, btf__get_nr_types listed under 0.0.2 version
      ====================
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      31de3897
    • A
      selftests/btf: add initial BTF dedup tests · 9c651127
      Andrii Nakryiko 提交于
      This patch sets up a new kind of tests (BTF dedup tests) and tests few aspects of
      BTF dedup algorithm. More complete set of tests will come in follow up patches.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      9c651127
    • A
      btf: add BTF types deduplication algorithm · d5caef5b
      Andrii Nakryiko 提交于
      This patch implements BTF types deduplication algorithm. It allows to
      greatly compress typical output of pahole's DWARF-to-BTF conversion or
      LLVM's compilation output by detecting and collapsing identical types emitted in
      isolation per compilation unit. Algorithm also resolves struct/union forward
      declarations into concrete BTF types representing referenced struct/union. If
      undesired, this resolution can be disabled through specifying corresponding options.
      
      Algorithm itself and its application to Linux kernel's BTF types is
      described in details at:
      https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.htmlSigned-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      d5caef5b
    • A
      btf: extract BTF type size calculation · 69eaab04
      Andrii Nakryiko 提交于
      This pre-patch extracts calculation of amount of space taken by BTF type descriptor
      for later reuse by btf_dedup functionality.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      69eaab04
    • S
      libbpf: fix libbpf_print · a8a1f7d0
      Stanislav Fomichev 提交于
      With the recent print rework we now have the following problem:
      pr_{warning,info,debug} expand to __pr which calls libbpf_print.
      libbpf_print does va_start and calls __libbpf_pr with va_list argument.
      In __base_pr we again do va_start. Because the next argument is a
      va_list, we don't get correct pointer to the argument (and print noting
      in my case, I don't know why it doesn't crash tbh).
      
      Fix this by changing libbpf_print_fn_t signature to accept va_list and
      remove unneeded calls to va_start in the existing users.
      
      Alternatively, this can we solved by exporting __libbpf_pr and
      changing __pr macro to (and killing libbpf_print):
      {
      	if (__libbpf_pr)
      		__libbpf_pr(level, "libbpf: " fmt, ##__VA_ARGS__)
      }
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      a8a1f7d0
    • A
      Merge branch 'libbpf-btf_ext' · 1728b111
      Alexei Starovoitov 提交于
      Yonghong Song says:
      
      ====================
      This patch set exposed a few functions in libbpf.
      All these newly added API functions are helpful for
      JIT based bpf compilation where .BTF and .BTF.ext
      are available as in-memory data blobs.
      
      Patch #1 exposed several btf_ext__* API functions which
      are used to handle .BTF.ext ELF sections.
      Patch #2 refactored the function bpf_map_find_btf_info()
      and exposed API function btf__get_map_kv_tids() to
      retrieve the map key/value type id's generated by
      bpf program through BPF_ANNOTATE_KV_PAIR macro.
      ====================
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      1728b111
    • Y
      tools/bpf: implement libbpf btf__get_map_kv_tids() API function · 96408c43
      Yonghong Song 提交于
      Currently, to get map key/value type id's, the macro
        BPF_ANNOTATE_KV_PAIR(<map_name>, <key_type>, <value_type>)
      needs to be defined in the bpf program for the
      corresponding map.
      
      During program/map loading time,
      the local static function bpf_map_find_btf_info()
      in libbpf.c is implemented to retrieve the key/value
      type ids given the map name.
      
      The patch refactored function bpf_map_find_btf_info()
      to create an API btf__get_map_kv_tids() which includes
      the bulk of implementation for the original function.
      The API btf__get_map_kv_tids() can be used by bcc,
      a JIT based bpf compilation system, which uses the
      same BPF_ANNOTATE_KV_PAIR to record map key/value types.
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      96408c43
    • Y
      tools/bpf: expose functions btf_ext__* as API functions · b8dcf8d1
      Yonghong Song 提交于
      The following set of functions, which manipulates .BTF.ext
      section, are exposed as API functions:
        . btf_ext__new
        . btf_ext__free
        . btf_ext__reloc_func_info
        . btf_ext__reloc_line_info
        . btf_ext__func_info_rec_size
        . btf_ext__line_info_rec_size
      
      These functions are useful for JIT based bpf codegen, e.g.,
      bcc, to manipulate in-memory .BTF.ext sections.
      
      The signature of function btf_ext__reloc_func_info()
      is also changed to be the same as its definition in btf.c.
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      b8dcf8d1
    • S
      selftests/bpf: use localhost in tcp_{server,client}.py · 7e8a5903
      Stanislav Fomichev 提交于
      Bind and connect to localhost. There is no reason for this test to
      use non-localhost interface. This lets us run this test in a network
      namespace.
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      7e8a5903
    • H
      s390: bpf: fix JMP32 code-gen · ecc15f11
      Heiko Carstens 提交于
      Commit 626a5f66 ("s390: bpf: implement jitting of JMP32") added
      JMP32 code-gen support for s390. However it triggers the warning below
      due to some unusual gotos in the original s390 bpf jit code.
      
      Add a couple of additional "is_jmp32" initializations to fix this.
      Also fix the wrong opcode for the "llilf" instruction that was
      introduced with the same commit.
      
      arch/s390/net/bpf_jit_comp.c: In function 'bpf_jit_insn':
      arch/s390/net/bpf_jit_comp.c:248:55: warning: 'is_jmp32' may be used uninitialized in this function [-Wmaybe-uninitialized]
        _EMIT6(op1 | reg(b1, b2) << 16 | (rel & 0xffff), op2 | mask); \
                                                             ^
      arch/s390/net/bpf_jit_comp.c:1211:8: note: 'is_jmp32' was declared here
         bool is_jmp32 = BPF_CLASS(insn->code) == BPF_JMP32;
      
      Fixes: 626a5f66 ("s390: bpf: implement jitting of JMP32")
      Cc: Jiong Wang <jiong.wang@netronome.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: NHeiko Carstens <heiko.carstens@de.ibm.com>
      Acked-by: NJiong Wang <jiong.wang@netronome.com>
      Acked-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      ecc15f11
    • A
      Merge branch 'change-libbpf-print-api' · 9fa3b473
      Alexei Starovoitov 提交于
      Yonghong Song says:
      
      ====================
      These are patches responding to my comments for
      Magnus's patch (https://patchwork.ozlabs.org/patch/1032848/).
      The goal is to make pr_* macros available to other C files
      than libbpf.c, and to simplify API function libbpf_set_print().
      
      Specifically, Patch #1 used global functions
      to facilitate pr_* macros in the header files so they
      are available in different C files.
      Patch #2 removes the global function libbpf_print_level_available()
      which is added in Patch 1.
      Patch #3 simplified libbpf_set_print() which takes only one print
      function with a debug level argument among others.
      
      Changelogs:
       v3 -> v4:
         . rename libbpf internal header util.h to libbpf_util.h
         . rename libbpf internal function libbpf_debug_print() to libbpf_print()
       v2 -> v3:
         . bailed out earlier in libbpf_debug_print() if __libbpf_pr is NULL
         . added missing LIBBPF_DEBUG level check in libbpf.c __base_pr().
       v1 -> v2:
         . Renamed global function libbpf_dprint() to libbpf_debug_print()
           to be more expressive.
         . Removed libbpf_dprint_level_available() as it is used only
           once in btf.c and we can remove it by optimizing for common cases.
      ====================
      Acked-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      9fa3b473
    • Y
      tools/bpf: simplify libbpf API function libbpf_set_print() · 6f1ae8b6
      Yonghong Song 提交于
      Currently, the libbpf API function libbpf_set_print()
      takes three function pointer parameters for warning, info
      and debug printout respectively.
      
      This patch changes the API to have just one function pointer
      parameter and the function pointer has one additional
      parameter "debugging level". So if in the future, if
      the debug level is increased, the function signature
      won't change.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      6f1ae8b6
    • Y
      tools/bpf: print out btf log at LIBBPF_WARN level · 9d100a19
      Yonghong Song 提交于
      Currently, the btf log is allocated and printed out in case
      of error at LIBBPF_DEBUG level.
      Such logs from kernel are very important for debugging.
      For example, bpf syscall BPF_PROG_LOAD command can get
      verifier logs back to user space. In function load_program()
      of libbpf.c, the log buffer is allocated unconditionally
      and printed out at pr_warning() level.
      
      Let us do the similar thing here for btf. Allocate buffer
      unconditionally and print out error logs at pr_warning() level.
      This can reduce one global function and
      optimize for common situations where pr_warning()
      is activated either by default or by user supplied
      debug output function.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      9d100a19
    • Y
      tools/bpf: move libbpf pr_* debug print functions to headers · 8461ef8b
      Yonghong Song 提交于
      A global function libbpf_print, which is invisible
      outside the shared library, is defined to print based
      on levels. The pr_warning, pr_info and pr_debug
      macros are moved into the newly created header
      common.h. So any .c file including common.h can
      use these macros directly.
      
      Currently btf__new and btf_ext__new API has an argument getting
      __pr_debug function pointer into btf.c so the debugging information
      can be printed there. This patch removed this parameter
      from btf__new and btf_ext__new and directly using pr_debug in btf.c.
      
      Another global function libbpf_print_level_available, also
      invisible outside the shared library, can test
      whether a particular level debug printing is
      available or not. It is used in btf.c to
      test whether DEBUG level debug printing is availabl or not,
      based on which the log buffer will be allocated when loading
      btf to the kernel.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      8461ef8b
  2. 04 2月, 2019 25 次提交