1. 26 10月, 2022 2 次提交
  2. 05 8月, 2022 1 次提交
  3. 01 7月, 2022 1 次提交
  4. 30 6月, 2022 1 次提交
  5. 15 6月, 2022 1 次提交
    • Q
      Revert "bpftool: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK" · 6b4384ff
      Quentin Monnet 提交于
      This reverts commit a777e18f.
      
      In commit a777e18f ("bpftool: Use libbpf 1.0 API mode instead of
      RLIMIT_MEMLOCK"), we removed the rlimit bump in bpftool, because the
      kernel has switched to memcg-based memory accounting. Thanks to the
      LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK, we attempted to keep compatibility
      with other systems and ask libbpf to raise the limit for us if
      necessary.
      
      How do we know if memcg-based accounting is supported? There is a probe
      in libbpf to check this. But this probe currently relies on the
      availability of a given BPF helper, bpf_ktime_get_coarse_ns(), which
      landed in the same kernel version as the memory accounting change. This
      works in the generic case, but it may fail, for example, if the helper
      function has been backported to an older kernel. This has been observed
      for Google Cloud's Container-Optimized OS (COS), where the helper is
      available but rlimit is still in use. The probe succeeds, the rlimit is
      not raised, and probing features with bpftool, for example, fails.
      
      A patch was submitted [0] to update this probe in libbpf, based on what
      the cilium/ebpf Go library does [1]. It would lower the soft rlimit to
      0, attempt to load a BPF object, and reset the rlimit. But it may induce
      some hard-to-debug flakiness if another process starts, or the current
      application is killed, while the rlimit is reduced, and the approach was
      discarded.
      
      As a workaround to ensure that the rlimit bump does not depend on the
      availability of a given helper, we restore the unconditional rlimit bump
      in bpftool for now.
      
        [0] https://lore.kernel.org/bpf/20220609143614.97837-1-quentin@isovalent.com/
        [1] https://github.com/cilium/ebpf/blob/v0.9.0/rlimit/rlimit.go#L39Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Cc: Yafang Shao <laoar.shao@gmail.com>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/bpf/20220610112648.29695-2-quentin@isovalent.com
      6b4384ff
  6. 03 6月, 2022 1 次提交
    • D
      bpftool: Use libbpf_bpf_attach_type_str · 1ba5ad36
      Daniel Müller 提交于
      This change switches bpftool over to using the recently introduced
      libbpf_bpf_attach_type_str function instead of maintaining its own
      string representation for the bpf_attach_type enum.
      
      Note that contrary to other enum types, the variant names that bpftool
      maps bpf_attach_type to do not adhere a simple to follow rule. With
      bpf_prog_type, for example, the textual representation can easily be
      inferred by stripping the BPF_PROG_TYPE_ prefix and lowercasing the
      remaining string. bpf_attach_type violates this rule for various
      variants.
      We decided to fix up this deficiency with this change, meaning that
      bpftool uses the same textual representations as libbpf. Supporting
      tests, completion scripts, and man pages have been adjusted accordingly.
      However, we did add support for accepting (the now undocumented)
      original attach type names when they are provided by users.
      
      For the test (test_bpftool_synctypes.py), I have removed the enum
      representation checks, because we no longer mirror the various enum
      variant names in bpftool source code. For the man page, help text, and
      completion script checks we are now using enum definitions from
      uapi/linux/bpf.h as the source of truth directly.
      Signed-off-by: NDaniel Müller <deso@posteo.net>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Acked-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20220523230428.3077108-10-deso@posteo.net
      1ba5ad36
  7. 11 4月, 2022 1 次提交
  8. 19 3月, 2022 1 次提交
  9. 03 2月, 2022 1 次提交
  10. 20 1月, 2022 1 次提交
    • R
      bpftool: Adding support for BTF program names · b662000a
      Raman Shukhau 提交于
      `bpftool prog list` and other bpftool subcommands that show
      BPF program names currently get them from bpf_prog_info.name.
      That field is limited to 16 (BPF_OBJ_NAME_LEN) chars which leads
      to truncated names since many progs have much longer names.
      
      The idea of this change is to improve all bpftool commands that
      output prog name so that bpftool uses info from BTF to print
      program names if available.
      
      It tries bpf_prog_info.name first and fall back to btf only if
      the name is suspected to be truncated (has 15 chars length).
      
      Right now `bpftool p show id <id>` returns capped prog name
      
      <id>: kprobe  name example_cap_cap  tag 712e...
      ...
      
      With this change it would return
      
      <id>: kprobe  name example_cap_capable  tag 712e...
      ...
      
      Note, other commands that print prog names (e.g. "bpftool
      cgroup tree") are also addressed in this change.
      Signed-off-by: NRaman Shukhau <ramasha@fb.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20220119100255.1068997-1-ramasha@fb.com
      b662000a
  11. 15 11月, 2021 1 次提交
  12. 26 10月, 2021 1 次提交
    • Q
      bpftool: Switch to libbpf's hashmap for pinned paths of BPF objects · 8f184732
      Quentin Monnet 提交于
      In order to show pinned paths for BPF programs, maps, or links when
      listing them with the "-f" option, bpftool creates hash maps to store
      all relevant paths under the bpffs. So far, it would rely on the
      kernel implementation (from tools/include/linux/hashtable.h).
      
      We can make bpftool rely on libbpf's implementation instead. The
      motivation is to make bpftool less dependent of kernel headers, to ease
      the path to a potential out-of-tree mirror, like libbpf has.
      
      This commit is the first step of the conversion: the hash maps for
      pinned paths for programs, maps, and links are converted to libbpf's
      hashmap.{c,h}. Other hash maps used for the PIDs of process holding
      references to BPF objects are left unchanged for now. On the build side,
      this requires adding a dependency to a second header internal to libbpf,
      and making it a dependency for the bootstrap bpftool version as well.
      The rest of the changes are a rather straightforward conversion.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-4-quentin@isovalent.com
      8f184732
  13. 31 7月, 2021 1 次提交
  14. 16 7月, 2021 1 次提交
  15. 02 4月, 2021 1 次提交
  16. 22 7月, 2020 1 次提交
  17. 18 7月, 2020 1 次提交
  18. 08 7月, 2020 1 次提交
  19. 25 6月, 2020 1 次提交
  20. 23 6月, 2020 1 次提交
  21. 29 4月, 2020 1 次提交
    • A
      bpftool: Add bpf_link show and pin support · c5481f9a
      Andrii Nakryiko 提交于
      Add `bpftool link show` and `bpftool link pin` commands.
      
      Example plain output for `link show` (with showing pinned paths):
      
      [vmuser@archvm bpf]$ sudo ~/local/linux/tools/bpf/bpftool/bpftool -f link
      1: tracing  prog 12
              prog_type tracing  attach_type fentry
              pinned /sys/fs/bpf/my_test_link
              pinned /sys/fs/bpf/my_test_link2
      2: tracing  prog 13
              prog_type tracing  attach_type fentry
      3: tracing  prog 14
              prog_type tracing  attach_type fentry
      4: tracing  prog 15
              prog_type tracing  attach_type fentry
      5: tracing  prog 16
              prog_type tracing  attach_type fentry
      6: tracing  prog 17
              prog_type tracing  attach_type fentry
      7: raw_tracepoint  prog 21
              tp 'sys_enter'
      8: cgroup  prog 25
              cgroup_id 584  attach_type egress
      9: cgroup  prog 25
              cgroup_id 599  attach_type egress
      10: cgroup  prog 25
              cgroup_id 614  attach_type egress
      11: cgroup  prog 25
              cgroup_id 629  attach_type egress
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: NQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200429001614.1544-9-andriin@fb.com
      c5481f9a
  22. 14 3月, 2020 1 次提交
    • Q
      tools: bpftool: Restore message on failure to guess program type · 6ae32b29
      Quentin Monnet 提交于
      In commit 4a3d6c6a ("libbpf: Reduce log level for custom section
      names"), log level for messages for libbpf_attach_type_by_name() and
      libbpf_prog_type_by_name() was downgraded from "info" to "debug". The
      latter function, in particular, is used by bpftool when attempting to
      load programs, and this change caused bpftool to exit with no hint or
      error message when it fails to detect the type of the program to load
      (unless "-d" option was provided).
      
      To help users understand why bpftool fails to load the program, let's do
      a second run of the function with log level in "debug" mode in case of
      failure.
      
      Before:
      
          # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          # echo $?
          255
      
      Or really verbose with -d flag:
      
          # bpftool -d prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          libbpf: loading sample_ret0.o
          libbpf: section(1) .strtab, size 134, link 0, flags 0, type=3
          libbpf: skip section(1) .strtab
          libbpf: section(2) .text, size 16, link 0, flags 6, type=1
          libbpf: found program .text
          libbpf: section(3) .debug_abbrev, size 55, link 0, flags 0, type=1
          libbpf: skip section(3) .debug_abbrev
          libbpf: section(4) .debug_info, size 75, link 0, flags 0, type=1
          libbpf: skip section(4) .debug_info
          libbpf: section(5) .rel.debug_info, size 32, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_info(5) for section(4)
          libbpf: section(6) .debug_str, size 150, link 0, flags 30, type=1
          libbpf: skip section(6) .debug_str
          libbpf: section(7) .BTF, size 155, link 0, flags 0, type=1
          libbpf: section(8) .BTF.ext, size 80, link 0, flags 0, type=1
          libbpf: section(9) .rel.BTF.ext, size 32, link 14, flags 0, type=9
          libbpf: skip relo .rel.BTF.ext(9) for section(8)
          libbpf: section(10) .debug_frame, size 40, link 0, flags 0, type=1
          libbpf: skip section(10) .debug_frame
          libbpf: section(11) .rel.debug_frame, size 16, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_frame(11) for section(10)
          libbpf: section(12) .debug_line, size 74, link 0, flags 0, type=1
          libbpf: skip section(12) .debug_line
          libbpf: section(13) .rel.debug_line, size 16, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_line(13) for section(12)
          libbpf: section(14) .symtab, size 96, link 1, flags 0, type=2
          libbpf: looking for externs among 4 symbols...
          libbpf: collected 0 externs total
          libbpf: failed to guess program type from ELF section '.text'
          libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]
      
      After:
      
          # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          libbpf: failed to guess program type from ELF section '.text'
          libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20200311021205.9755-1-quentin@isovalent.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      6ae32b29
  23. 13 3月, 2020 1 次提交
  24. 21 1月, 2020 1 次提交
  25. 16 8月, 2019 1 次提交
  26. 09 8月, 2019 2 次提交
  27. 11 6月, 2019 1 次提交
  28. 29 1月, 2019 1 次提交
    • J
      tools: bpftool: fix crash with un-owned prog arrays · 8c79b356
      Jakub Kicinski 提交于
      Prog arrays don't have 'owner_prog_type' and 'owner_jited'
      fields in their fdinfo when they are created.  Those fields
      are set and reported when first program is checked for
      compatibility by bpf_prog_array_compatible().
      
      This means that bpftool cannot expect the fields to always
      be there.  Currently trying to show maps on a system with
      an un-owned prog array leads to a crash:
      
      $ bpftool map show
      389: prog_array  name tail_call_map  flags 0x0
      Error: key 'owner_prog_type' not found in fdinfo
      Error: key 'owner_jited' not found in fdinfo
             key 4B  value 4B  max_entries 4  memlock 4096B
             Segmentation fault (core dumped)
      
      We pass a NULL pointer to atoi().
      
      Remove the assumption that fdinfo keys are always present.
      Add missing validations and remove the p_err() calls which
      may lead to broken JSON output as caller will not propagate
      the failure.
      
      Fixes: 99a44bef ("tools: bpftool: add owner_prog_type and owner_jited to bpftool output")
      Signed-off-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      8c79b356
  29. 18 12月, 2018 2 次提交
  30. 15 12月, 2018 1 次提交
  31. 13 12月, 2018 1 次提交
  32. 01 12月, 2018 2 次提交
  33. 11 11月, 2018 1 次提交
  34. 09 11月, 2018 2 次提交
    • Q
      tools: bpftool: pass an argument to silence open_obj_pinned() · f120919f
      Quentin Monnet 提交于
      Function open_obj_pinned() prints error messages when it fails to open a
      link in the BPF virtual file system. However, in some occasions it is
      not desirable to print an error, for example when we parse all links
      under the bpffs root, and the error is due to some paths actually being
      symbolic links.
      
      Example output:
      
          # ls -l /sys/fs/bpf/
          lrwxrwxrwx 1 root root 0 Oct 18 19:00 ip -> /sys/fs/bpf/tc/
          drwx------ 3 root root 0 Oct 18 19:00 tc
          lrwxrwxrwx 1 root root 0 Oct 18 19:00 xdp -> /sys/fs/bpf/tc/
      
          # bpftool --bpffs prog show
          Error: bpf obj get (/sys/fs/bpf): Permission denied
          Error: bpf obj get (/sys/fs/bpf): Permission denied
      
          # strace -e bpf bpftool --bpffs prog show
          bpf(BPF_OBJ_GET, {pathname="/sys/fs/bpf/ip", bpf_fd=0}, 72) = -1 EACCES (Permission denied)
          Error: bpf obj get (/sys/fs/bpf): Permission denied
          bpf(BPF_OBJ_GET, {pathname="/sys/fs/bpf/xdp", bpf_fd=0}, 72) = -1 EACCES (Permission denied)
          Error: bpf obj get (/sys/fs/bpf): Permission denied
          ...
      
      To fix it, pass a bool as a second argument to the function, and prevent
      it from printing an error when the argument is set to true.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      f120919f
    • Q
      tools: bpftool: prevent infinite loop in get_fdinfo() · 53909030
      Quentin Monnet 提交于
      Function getline() returns -1 on failure to read a line, thus creating
      an infinite loop in get_fdinfo() if the key is not found. Fix it by
      calling the function only as long as we get a strictly positive return
      value.
      
      Found by copying the code for a key which is not always present...
      
      Fixes: 71bb428f ("tools: bpf: add bpftool")
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      53909030
  35. 08 11月, 2018 1 次提交
    • Q
      tools: bpftool: adjust rlimit RLIMIT_MEMLOCK when loading programs, maps · 8302b9bd
      Quentin Monnet 提交于
      The limit for memory locked in the kernel by a process is usually set to
      64 kbytes by default. This can be an issue when creating large BPF maps
      and/or loading many programs. A workaround is to raise this limit for
      the current process before trying to create a new BPF map. Changing the
      hard limit requires the CAP_SYS_RESOURCE and can usually only be done by
      root user (for non-root users, a call to setrlimit fails (and sets
      errno) and the program simply goes on with its rlimit unchanged).
      
      There is no API to get the current amount of memory locked for a user,
      therefore we cannot raise the limit only when required. One solution,
      used by bcc, is to try to create the map, and on getting a EPERM error,
      raising the limit to infinity before giving another try. Another
      approach, used in iproute2, is to raise the limit in all cases, before
      trying to create the map.
      
      Here we do the same as in iproute2: the rlimit is raised to infinity
      before trying to load programs or to create maps with bpftool.
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      8302b9bd