1. 24 8月, 2022 18 次提交
  2. 01 10月, 2020 1 次提交
  3. 29 9月, 2020 2 次提交
  4. 20 8月, 2020 3 次提交
    • A
      libbpf: Fix libbpf build on compilers missing __builtin_mul_overflow · dda1ec9f
      Andrii Nakryiko 提交于
      GCC compilers older than version 5 don't support __builtin_mul_overflow yet.
      Given GCC 4.9 is the minimal supported compiler for building kernel and the
      fact that libbpf is a dependency of resolve_btfids, which is dependency of
      CONFIG_DEBUG_INFO_BTF=y, this needs to be handled. This patch fixes the issue
      by falling back to slower detection of integer overflow in such cases.
      
      Fixes: 029258d7 ("libbpf: Remove any use of reallocarray() in libbpf")
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20200820061411.1755905-2-andriin@fb.com
      dda1ec9f
    • A
      libbpf: Implement enum value-based CO-RE relocations · eacaaed7
      Andrii Nakryiko 提交于
      Implement two relocations of a new enumerator value-based CO-RE relocation
      kind: ENUMVAL_EXISTS and ENUMVAL_VALUE.
      
      First, ENUMVAL_EXISTS, allows to detect the presence of a named enumerator
      value in the target (kernel) BTF. This is useful to do BPF helper/map/program
      type support detection from BPF program side. bpf_core_enum_value_exists()
      macro helper is provided to simplify built-in usage.
      
      Second, ENUMVAL_VALUE, allows to capture enumerator integer value and relocate
      it according to the target BTF, if it changes. This is useful to have
      a guarantee against intentional or accidental re-ordering/re-numbering of some
      of the internal (non-UAPI) enumerations, where kernel developers don't care
      about UAPI backwards compatiblity concerns. bpf_core_enum_value() allows to
      capture this succinctly and use correct enum values in code.
      
      LLVM uses ldimm64 instruction to capture enumerator value-based relocations,
      so add support for ldimm64 instruction patching as well.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20200819194519.3375898-5-andriin@fb.com
      eacaaed7
    • A
      libbpf: Implement type-based CO-RE relocations support · 3fc32f40
      Andrii Nakryiko 提交于
      Implement support for TYPE_EXISTS/TYPE_SIZE/TYPE_ID_LOCAL/TYPE_ID_REMOTE
      relocations. These are examples of type-based relocations, as opposed to
      field-based relocations supported already. The difference is that they are
      calculating relocation values based on the type itself, not a field within
      a struct/union.
      
      Type-based relos have slightly different semantics when matching local types
      to kernel target types, see comments in bpf_core_types_are_compat() for
      details. Their behavior on failure to find target type in kernel BTF also
      differs. Instead of "poisoning" relocatable instruction and failing load
      subsequently in kernel, they return 0 (which is rarely a valid return result,
      so user BPF code can use that to detect success/failure of the relocation and
      deal with it without extra "guarding" relocations). Also, it's always possible
      to check existence of the type in target kernel with TYPE_EXISTS relocation,
      similarly to a field-based FIELD_EXISTS.
      
      TYPE_ID_LOCAL relocation is a bit special in that it always succeeds (barring
      any libbpf/Clang bugs) and resolved to BTF ID using **local** BTF info of BPF
      program itself. Tests in subsequent patches demonstrate the usage and
      semantics of new relocations.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20200819194519.3375898-2-andriin@fb.com
      3fc32f40
  5. 19 8月, 2020 4 次提交
  6. 11 5月, 2020 1 次提交
    • G
      bpf, libbpf: Replace zero-length array with flexible-array · 385bbf7b
      Gustavo A. R. Silva 提交于
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20200507185057.GA13981@embeddedor
      385bbf7b
  7. 19 12月, 2019 1 次提交
  8. 16 12月, 2019 1 次提交
  9. 14 12月, 2019 1 次提交
  10. 04 11月, 2019 1 次提交
  11. 21 10月, 2019 1 次提交
  12. 16 10月, 2019 1 次提交
  13. 06 10月, 2019 1 次提交
    • A
      libbpf: add bpf_object__open_{file, mem} w/ extensible opts · 2ce8450e
      Andrii Nakryiko 提交于
      Add new set of bpf_object__open APIs using new approach to optional
      parameters extensibility allowing simpler ABI compatibility approach.
      
      This patch demonstrates an approach to implementing libbpf APIs that
      makes it easy to extend existing APIs with extra optional parameters in
      such a way, that ABI compatibility is preserved without having to do
      symbol versioning and generating lots of boilerplate code to handle it.
      To facilitate succinct code for working with options, add OPTS_VALID,
      OPTS_HAS, and OPTS_GET macros that hide all the NULL, size, and zero
      checks.
      
      Additionally, newly added libbpf APIs are encouraged to follow similar
      pattern of having all mandatory parameters as formal function parameters
      and always have optional (NULL-able) xxx_opts struct, which should
      always have real struct size as a first field and the rest would be
      optional parameters added over time, which tune the behavior of existing
      API, if specified by user.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      2ce8450e
  14. 01 10月, 2019 1 次提交
    • Y
      libbpf: handle symbol versioning properly for libbpf.a · 1bd63524
      Yonghong Song 提交于
      bcc uses libbpf repo as a submodule. It brings in libbpf source
      code and builds everything together to produce shared libraries.
      With latest libbpf, I got the following errors:
        /bin/ld: libbcc_bpf.so.0.10.0: version node not found for symbol xsk_umem__create@LIBBPF_0.0.2
        /bin/ld: failed to set dynamic section sizes: Bad value
        collect2: error: ld returned 1 exit status
        make[2]: *** [src/cc/libbcc_bpf.so.0.10.0] Error 1
      
      In xsk.c, we have
        asm(".symver xsk_umem__create_v0_0_2, xsk_umem__create@LIBBPF_0.0.2");
        asm(".symver xsk_umem__create_v0_0_4, xsk_umem__create@@LIBBPF_0.0.4");
      The linker thinks the built is for LIBBPF but cannot find proper version
      LIBBPF_0.0.2/4, so emit errors.
      
      I also confirmed that using libbpf.a to produce a shared library also
      has issues:
        -bash-4.4$ cat t.c
        extern void *xsk_umem__create;
        void * test() { return xsk_umem__create; }
        -bash-4.4$ gcc -c -fPIC t.c
        -bash-4.4$ gcc -shared t.o libbpf.a -o t.so
        /bin/ld: t.so: version node not found for symbol xsk_umem__create@LIBBPF_0.0.2
        /bin/ld: failed to set dynamic section sizes: Bad value
        collect2: error: ld returned 1 exit status
        -bash-4.4$
      
      Symbol versioning does happens in commonly used libraries, e.g., elfutils
      and glibc. For static libraries, for a versioned symbol, the old definitions
      will be ignored, and the symbol will be an alias to the latest definition.
      For example, glibc sched_setaffinity is versioned.
        -bash-4.4$ readelf -s /usr/lib64/libc.so.6 | grep sched_setaffinity
           756: 000000000013d3d0    13 FUNC    GLOBAL DEFAULT   13 sched_setaffinity@GLIBC_2.3.3
           757: 00000000000e2e70   455 FUNC    GLOBAL DEFAULT   13 sched_setaffinity@@GLIBC_2.3.4
          1800: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS sched_setaffinity.c
          4228: 00000000000e2e70   455 FUNC    LOCAL  DEFAULT   13 __sched_setaffinity_new
          4648: 000000000013d3d0    13 FUNC    LOCAL  DEFAULT   13 __sched_setaffinity_old
          7338: 000000000013d3d0    13 FUNC    GLOBAL DEFAULT   13 sched_setaffinity@GLIBC_2
          7380: 00000000000e2e70   455 FUNC    GLOBAL DEFAULT   13 sched_setaffinity@@GLIBC_
        -bash-4.4$
      For static library, the definition of sched_setaffinity aliases to the new definition.
        -bash-4.4$ readelf -s /usr/lib64/libc.a | grep sched_setaffinity
        File: /usr/lib64/libc.a(sched_setaffinity.o)
           8: 0000000000000000   455 FUNC    GLOBAL DEFAULT    1 __sched_setaffinity_new
          12: 0000000000000000   455 FUNC    WEAK   DEFAULT    1 sched_setaffinity
      
      For both elfutils and glibc, additional macros are used to control different handling
      of symbol versioning w.r.t static and shared libraries.
      For elfutils, the macro is SYMBOL_VERSIONING
      (https://sourceware.org/git/?p=elfutils.git;a=blob;f=lib/eu-config.h).
      For glibc, the macro is SHARED
      (https://sourceware.org/git/?p=glibc.git;a=blob;f=include/shlib-compat.h;hb=refs/heads/master)
      
      This patch used SHARED as the macro name. After this patch, the libbpf.a has
        -bash-4.4$ readelf -s libbpf.a | grep xsk_umem__create
           372: 0000000000017145  1190 FUNC    GLOBAL DEFAULT    1 xsk_umem__create_v0_0_4
           405: 0000000000017145  1190 FUNC    GLOBAL DEFAULT    1 xsk_umem__create
           499: 00000000000175eb   103 FUNC    GLOBAL DEFAULT    1 xsk_umem__create_v0_0_2
        -bash-4.4$
      No versioned symbols for xsk_umem__create.
      The libbpf.a can be used to build a shared library succesfully.
        -bash-4.4$ cat t.c
        extern void *xsk_umem__create;
        void * test() { return xsk_umem__create; }
        -bash-4.4$ gcc -c -fPIC t.c
        -bash-4.4$ gcc -shared t.o libbpf.a -o t.so
        -bash-4.4$
      
      Fixes: 10d30e30 ("libbpf: add flags to umem config")
      Cc: Kevin Laatz <kevin.laatz@intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Andrii Nakryiko <andriin@fb.com>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      1bd63524
  15. 08 8月, 2019 1 次提交
  16. 18 6月, 2019 1 次提交
  17. 01 6月, 2019 1 次提交
    • M
      libbpf: Return btf_fd for load_sk_storage_btf · cfd49210
      Michal Rostecki 提交于
      Before this change, function load_sk_storage_btf expected that
      libbpf__probe_raw_btf was returning a BTF descriptor, but in fact it was
      returning an information about whether the probe was successful (0 or
      1). load_sk_storage_btf was using that value as an argument of the close
      function, which was resulting in closing stdout and thus terminating the
      process which called that function.
      
      That bug was visible in bpftool. `bpftool feature` subcommand was always
      exiting too early (because of closed stdout) and it didn't display all
      requested probes. `bpftool -j feature` or `bpftool -p feature` were not
      returning a valid json object.
      
      This change renames the libbpf__probe_raw_btf function to
      libbpf__load_raw_btf, which now returns a BTF descriptor, as expected in
      load_sk_storage_btf.
      
      v2:
      - Fix typo in the commit message.
      
      v3:
      - Simplify BTF descriptor handling in bpf_object__probe_btf_* functions.
      - Rename libbpf__probe_raw_btf function to libbpf__load_raw_btf and
      return a BTF descriptor.
      
      v4:
      - Fix typo in the commit message.
      
      Fixes: d7c4b398 ("libbpf: detect supported kernel BTF features and sanitize BTF")
      Signed-off-by: NMichal Rostecki <mrostecki@opensuse.org>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      cfd49210