1. 21 11月, 2022 1 次提交
  2. 10 11月, 2022 1 次提交
  3. 26 10月, 2022 3 次提交
  4. 21 10月, 2022 1 次提交
  5. 30 7月, 2022 1 次提交
  6. 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
  7. 03 6月, 2022 2 次提交
  8. 11 4月, 2022 1 次提交
  9. 05 4月, 2022 1 次提交
  10. 11 3月, 2022 1 次提交
  11. 24 2月, 2022 1 次提交
  12. 03 2月, 2022 1 次提交
  13. 26 1月, 2022 1 次提交
  14. 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
  15. 13 1月, 2022 1 次提交
  16. 06 1月, 2022 1 次提交
  17. 11 12月, 2021 1 次提交
  18. 06 12月, 2021 1 次提交
    • A
      bpftool: Add debug mode for gen_loader. · 942df4dc
      Alexei Starovoitov 提交于
      Make -d flag functional for gen_loader style program loading.
      
      For example:
      $ bpftool prog load -L -d test_d_path.o
      ... // will print:
      libbpf: loading ./test_d_path.o
      libbpf: elf: section(3) fentry/security_inode_getattr, size 280, link 0, flags 6, type=1
      ...
      libbpf: prog 'prog_close': found data map 0 (test_d_p.bss, sec 7, off 0) for insn 30
      libbpf: gen: load_btf: size 5376
      libbpf: gen: map_create: test_d_p.bss idx 0 type 2 value_type_id 118
      libbpf: map 'test_d_p.bss': created successfully, fd=0
      libbpf: gen: map_update_elem: idx 0
      libbpf: sec 'fentry/filp_close': found 1 CO-RE relocations
      libbpf: record_relo_core: prog 1 insn[15] struct file 0:1 final insn_idx 15
      libbpf: gen: prog_load: type 26 insns_cnt 35 progi_idx 0
      libbpf: gen: find_attach_tgt security_inode_getattr 12
      libbpf: gen: prog_load: type 26 insns_cnt 37 progi_idx 1
      libbpf: gen: find_attach_tgt filp_close 12
      libbpf: gen: finish 0
      ... // at this point libbpf finished generating loader program
         0: (bf) r6 = r1
         1: (bf) r1 = r10
         2: (07) r1 += -136
         3: (b7) r2 = 136
         4: (b7) r3 = 0
         5: (85) call bpf_probe_read_kernel#113
         6: (05) goto pc+104
      ... // this is the assembly dump of the loader program
       390: (63) *(u32 *)(r6 +44) = r0
       391: (18) r1 = map[idx:0]+5584
       393: (61) r0 = *(u32 *)(r1 +0)
       394: (63) *(u32 *)(r6 +24) = r0
       395: (b7) r0 = 0
       396: (95) exit
      err 0  // the loader program was loaded and executed successfully
      (null)
      func#0 @0
      ...  // CO-RE in the kernel logs:
      CO-RE relocating STRUCT file: found target candidate [500]
      prog '': relo #0: kind <byte_off> (0), spec is [8] STRUCT file.f_path (0:1 @ offset 16)
      prog '': relo #0: matching candidate #0 [500] STRUCT file.f_path (0:1 @ offset 16)
      prog '': relo #0: patched insn #15 (ALU/ALU64) imm 16 -> 16
      vmlinux_cand_cache:[11]file(500),
      module_cand_cache:
      ... // verifier logs when it was checking test_d_path.o program:
      R1 type=ctx expected=fp
      0: R1=ctx(id=0,off=0,imm=0) R10=fp0
      ; int BPF_PROG(prog_close, struct file *file, void *id)
      0: (79) r6 = *(u64 *)(r1 +0)
      func 'filp_close' arg0 has btf_id 500 type STRUCT 'file'
      1: R1=ctx(id=0,off=0,imm=0) R6_w=ptr_file(id=0,off=0,imm=0) R10=fp0
      ; pid_t pid = bpf_get_current_pid_tgid() >> 32;
      1: (85) call bpf_get_current_pid_tgid#14
      
      ... // if there are multiple programs being loaded by the loader program
      ... // only the last program in the elf file will be printed, since
      ... // the same verifier log_buf is used for all PROG_LOAD commands.
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211204194623.27779-1-alexei.starovoitov@gmail.com
      942df4dc
  19. 15 11月, 2021 1 次提交
  20. 12 11月, 2021 1 次提交
  21. 04 11月, 2021 1 次提交
  22. 26 10月, 2021 3 次提交
    • Q
      bpftool: Switch to libbpf's hashmap for PIDs/names references · d6699f8e
      Quentin Monnet 提交于
      In order to show PIDs and names for processes holding references to BPF
      programs, maps, links, or BTF objects, bpftool creates hash maps to
      store all relevant information. This commit is part of a set that
      transitions from the kernel's hash map implementation to the one coming
      with libbpf.
      
      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 is the third and final step of the transition, in which we convert
      the hash maps used for storing the information about the processes
      holding references to BPF objects (programs, maps, links, BTF), and at
      last we drop the inclusion of tools/include/linux/hashtable.h.
      
      Note: Checkpatch complains about the use of __weak declarations, and the
      missing empty lines after the bunch of empty function declarations when
      compiling without the BPF skeletons (none of these were introduced in
      this patch). We want to keep things as they are, and the reports should
      be safe to ignore.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-6-quentin@isovalent.com
      d6699f8e
    • 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
    • Q
      bpftool: Do not expose and init hash maps for pinned path in main.c · 46241271
      Quentin Monnet 提交于
      BPF programs, maps, and links, can all be listed with their pinned paths
      by bpftool, when the "-f" option is provided. To do so, bpftool builds
      hash maps containing all pinned paths for each kind of objects.
      
      These three hash maps are always initialised in main.c, and exposed
      through main.h. There appear to be no particular reason to do so: we can
      just as well make them static to the files that need them (prog.c,
      map.c, and link.c respectively), and initialise them only when we want
      to show objects and the "-f" switch is provided.
      
      This may prevent unnecessary memory allocations if the implementation of
      the hash maps was to change in the future.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211023205154.6710-3-quentin@isovalent.com
      46241271
  23. 23 10月, 2021 1 次提交
  24. 09 10月, 2021 1 次提交
  25. 07 10月, 2021 1 次提交
  26. 31 7月, 2021 3 次提交
  27. 30 7月, 2021 2 次提交
  28. 25 5月, 2021 1 次提交
  29. 19 5月, 2021 1 次提交
    • A
      bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command. · d510296d
      Alexei Starovoitov 提交于
      Add -L flag to bpftool to use libbpf gen_trace facility and syscall/loader program
      for skeleton generation and program loading.
      
      "bpftool gen skeleton -L" command will generate a "light skeleton" or "loader skeleton"
      that is similar to existing skeleton, but has one major difference:
      $ bpftool gen skeleton lsm.o > lsm.skel.h
      $ bpftool gen skeleton -L lsm.o > lsm.lskel.h
      $ diff lsm.skel.h lsm.lskel.h
      @@ -5,34 +4,34 @@
       #define __LSM_SKEL_H__
      
       #include <stdlib.h>
      -#include <bpf/libbpf.h>
      +#include <bpf/bpf.h>
      
      The light skeleton does not use majority of libbpf infrastructure.
      It doesn't need libelf. It doesn't parse .o file.
      It only needs few sys_bpf wrappers. All of them are in bpf/bpf.h file.
      In future libbpf/bpf.c can be inlined into bpf.h, so not even libbpf.a would be
      needed to work with light skeleton.
      
      "bpftool prog load -L file.o" command is introduced for debugging of syscall/loader
      program generation. Just like the same command without -L it will try to load
      the programs from file.o into the kernel. It won't even try to pin them.
      
      "bpftool prog load -L -d file.o" command will provide additional debug messages
      on how syscall/loader program was generated.
      Also the execution of syscall/loader program will use bpf_trace_printk() for
      each step of loading BTF, creating maps, and loading programs.
      The user can do "cat /.../trace_pipe" for further debug.
      
      An example of fexit_sleep.lskel.h generated from progs/fexit_sleep.c:
      struct fexit_sleep {
      	struct bpf_loader_ctx ctx;
      	struct {
      		struct bpf_map_desc bss;
      	} maps;
      	struct {
      		struct bpf_prog_desc nanosleep_fentry;
      		struct bpf_prog_desc nanosleep_fexit;
      	} progs;
      	struct {
      		int nanosleep_fentry_fd;
      		int nanosleep_fexit_fd;
      	} links;
      	struct fexit_sleep__bss {
      		int pid;
      		int fentry_cnt;
      		int fexit_cnt;
      	} *bss;
      };
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210514003623.28033-18-alexei.starovoitov@gmail.com
      d510296d
  30. 02 4月, 2021 1 次提交
  31. 11 2月, 2021 1 次提交
  32. 20 11月, 2020 1 次提交
    • Y
      bpftool: Add {i,d}tlb_misses support for bpftool profile · 450d060e
      Yonghong Song 提交于
      Commit 47c09d6a("bpftool: Introduce "prog profile" command")
      introduced "bpftool prog profile" command which can be used
      to profile bpf program with metrics like # of instructions,
      
      This patch added support for itlb_misses and dtlb_misses.
      During an internal bpf program performance evaluation,
      I found these two metrics are also very useful. The following
      is an example output:
      
       $ bpftool prog profile id 324 duration 3 cycles itlb_misses
      
                 1885029 run_cnt
              5134686073 cycles
                  306893 itlb_misses
      
       $ bpftool prog profile id 324 duration 3 cycles dtlb_misses
      
                 1827382 run_cnt
              4943593648 cycles
                 5975636 dtlb_misses
      
       $ bpftool prog profile id 324 duration 3 cycles llc_misses
      
                 1836527 run_cnt
              5019612972 cycles
                 4161041 llc_misses
      
      From the above, we can see quite some dtlb misses, 3 dtlb misses
      perf prog run. This might be something worth further investigation.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20201119073039.4060095-1-yhs@fb.com
      450d060e