1. 09 2月, 2022 2 次提交
  2. 08 2月, 2022 1 次提交
  3. 05 2月, 2022 1 次提交
    • Y
      libbpf: Fix build issue with llvm-readelf · 0908a66a
      Yonghong Song 提交于
      There are cases where clang compiler is packaged in a way
      readelf is a symbolic link to llvm-readelf. In such cases,
      llvm-readelf will be used instead of default binutils readelf,
      and the following error will appear during libbpf build:
      
        Warning: Num of global symbols in
         /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/sharedobjs/libbpf-in.o (367)
         does NOT match with num of versioned symbols in
         /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.so libbpf.map (383).
         Please make sure all LIBBPF_API symbols are versioned in libbpf.map.
        --- /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_global_syms.tmp ...
        +++ /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_versioned_syms.tmp ...
        @@ -324,6 +324,22 @@
         btf__str_by_offset
         btf__type_by_id
         btf__type_cnt
        +LIBBPF_0.0.1
        +LIBBPF_0.0.2
        +LIBBPF_0.0.3
        +LIBBPF_0.0.4
        +LIBBPF_0.0.5
        +LIBBPF_0.0.6
        +LIBBPF_0.0.7
        +LIBBPF_0.0.8
        +LIBBPF_0.0.9
        +LIBBPF_0.1.0
        +LIBBPF_0.2.0
        +LIBBPF_0.3.0
        +LIBBPF_0.4.0
        +LIBBPF_0.5.0
        +LIBBPF_0.6.0
        +LIBBPF_0.7.0
         libbpf_attach_type_by_name
         libbpf_find_kernel_btf
         libbpf_find_vmlinux_btf_id
        make[2]: *** [Makefile:184: check_abi] Error 1
        make[1]: *** [Makefile:140: all] Error 2
      
      The above failure is due to different printouts for some ABS
      versioned symbols. For example, with the same libbpf.so,
        $ /bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
           134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.5.0
           202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.6.0
           ...
        $ /opt/llvm/bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
           134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.5.0@@LIBBPF_0.5.0
           202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.6.0@@LIBBPF_0.6.0
           ...
      The binutils readelf doesn't print out the symbol LIBBPF_* version and llvm-readelf does.
      Such a difference caused libbpf build failure with llvm-readelf.
      
      The proposed fix filters out all ABS symbols as they are not part of the comparison.
      This works for both binutils readelf and llvm-readelf.
      Reported-by: NDelyan Kratunov <delyank@fb.com>
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20220204214355.502108-1-yhs@fb.com
      0908a66a
  4. 04 2月, 2022 2 次提交
  5. 03 2月, 2022 2 次提交
  6. 02 2月, 2022 3 次提交
  7. 01 2月, 2022 1 次提交
  8. 26 1月, 2022 3 次提交
  9. 25 1月, 2022 4 次提交
  10. 22 1月, 2022 1 次提交
  11. 21 1月, 2022 2 次提交
    • A
      libbpf: streamline low-level XDP APIs · c359821a
      Andrii Nakryiko 提交于
      Introduce 4 new netlink-based XDP APIs for attaching, detaching, and
      querying XDP programs:
        - bpf_xdp_attach;
        - bpf_xdp_detach;
        - bpf_xdp_query;
        - bpf_xdp_query_id.
      
      These APIs replace bpf_set_link_xdp_fd, bpf_set_link_xdp_fd_opts,
      bpf_get_link_xdp_id, and bpf_get_link_xdp_info APIs ([0]). The latter
      don't follow a consistent naming pattern and some of them use
      non-extensible approaches (e.g., struct xdp_link_info which can't be
      modified without breaking libbpf ABI).
      
      The approach I took with these low-level XDP APIs is similar to what we
      did with low-level TC APIs. There is a nice duality of bpf_tc_attach vs
      bpf_xdp_attach, and so on. I left bpf_xdp_attach() to support detaching
      when -1 is specified for prog_fd for generality and convenience, but
      bpf_xdp_detach() is preferred due to clearer naming and associated
      semantics. Both bpf_xdp_attach() and bpf_xdp_detach() accept the same
      opts struct allowing to specify expected old_prog_fd.
      
      While doing the refactoring, I noticed that old APIs require users to
      specify opts with old_fd == -1 to declare "don't care about already
      attached XDP prog fd" condition. Otherwise, FD 0 is assumed, which is
      essentially never an intended behavior. So I made this behavior
      consistent with other kernel and libbpf APIs, in which zero FD means "no
      FD". This seems to be more in line with the latest thinking in BPF land
      and should cause less user confusion, hopefully.
      
      For querying, I left two APIs, both more generic bpf_xdp_query()
      allowing to query multiple IDs and attach mode, but also
      a specialization of it, bpf_xdp_query_id(), which returns only requested
      prog_id. Uses of prog_id returning bpf_get_link_xdp_id() were so
      prevalent across selftests and samples, that it seemed a very common use
      case and using bpf_xdp_query() for doing it felt very cumbersome with
      a highly branches if/else chain based on flags and attach mode.
      
      Old APIs are scheduled for deprecation in libbpf 0.8 release.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/309Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Acked-by: NToke Høiland-Jørgensen <toke@redhat.com>
      Link: https://lore.kernel.org/r/20220120061422.2710637-2-andrii@kernel.orgSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      c359821a
    • A
      libbpf: deprecate legacy BPF map definitions · 93b8952d
      Andrii Nakryiko 提交于
      Enact deprecation of legacy BPF map definition in SEC("maps") ([0]). For
      the definitions themselves introduce LIBBPF_STRICT_MAP_DEFINITIONS flag
      for libbpf strict mode. If it is set, error out on any struct
      bpf_map_def-based map definition. If not set, libbpf will print out
      a warning for each legacy BPF map to raise awareness that it goes away.
      
      For any use of BPF_ANNOTATE_KV_PAIR() macro providing a legacy way to
      associate BTF key/value type information with legacy BPF map definition,
      warn through libbpf's pr_warn() error message (but don't fail BPF object
      open).
      
      BPF-side struct bpf_map_def is marked as deprecated. User-space struct
      bpf_map_def has to be used internally in libbpf, so it is left
      untouched. It should be enough for bpf_map__def() to be marked
      deprecated to raise awareness that it goes away.
      
      bpftool is an interesting case that utilizes libbpf to open BPF ELF
      object to generate skeleton. As such, even though bpftool itself uses
      full on strict libbpf mode (LIBBPF_STRICT_ALL), it has to relax it a bit
      for BPF map definition handling to minimize unnecessary disruptions. So
      opt-out of LIBBPF_STRICT_MAP_DEFINITIONS for bpftool. User's code that
      will later use generated skeleton will make its own decision whether to
      enforce LIBBPF_STRICT_MAP_DEFINITIONS or not.
      
      There are few tests in selftests/bpf that are consciously using legacy
      BPF map definitions to test libbpf functionality. For those, temporary
      opt out of LIBBPF_STRICT_MAP_DEFINITIONS mode for the duration of those
      tests.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/272Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20220120060529.1890907-4-andrii@kernel.orgSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      93b8952d
  12. 20 1月, 2022 1 次提交
  13. 19 1月, 2022 1 次提交
  14. 13 1月, 2022 4 次提交
  15. 07 1月, 2022 1 次提交
  16. 06 1月, 2022 5 次提交
  17. 29 12月, 2021 3 次提交
  18. 24 12月, 2021 1 次提交
  19. 18 12月, 2021 1 次提交
    • A
      libbpf: Rework feature-probing APIs · 878d8def
      Andrii Nakryiko 提交于
      Create three extensible alternatives to inconsistently named
      feature-probing APIs:
      
        - libbpf_probe_bpf_prog_type() instead of bpf_probe_prog_type();
        - libbpf_probe_bpf_map_type() instead of bpf_probe_map_type();
        - libbpf_probe_bpf_helper() instead of bpf_probe_helper().
      
      Set up return values such that libbpf can report errors (e.g., if some
      combination of input arguments isn't possible to validate, etc), in
      addition to whether the feature is supported (return value 1) or not
      supported (return value 0).
      
      Also schedule deprecation of those three APIs. Also schedule deprecation
      of bpf_probe_large_insn_limit().
      
      Also fix all the existing detection logic for various program and map
      types that never worked:
      
        - BPF_PROG_TYPE_LIRC_MODE2;
        - BPF_PROG_TYPE_TRACING;
        - BPF_PROG_TYPE_LSM;
        - BPF_PROG_TYPE_EXT;
        - BPF_PROG_TYPE_SYSCALL;
        - BPF_PROG_TYPE_STRUCT_OPS;
        - BPF_MAP_TYPE_STRUCT_OPS;
        - BPF_MAP_TYPE_BLOOM_FILTER.
      
      Above prog/map types needed special setups and detection logic to work.
      Subsequent patch adds selftests that will make sure that all the
      detection logic keeps working for all current and future program and map
      types, avoiding otherwise inevitable bit rot.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/312Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NDave Marchevsky <davemarchevsky@fb.com>
      Cc: Julia Kartseva <hex@fb.com>
      Link: https://lore.kernel.org/bpf/20211217171202.3352835-2-andrii@kernel.org
      878d8def
  20. 17 12月, 2021 1 次提交