1. 03 6月, 2022 2 次提交
  2. 11 4月, 2022 1 次提交
  3. 05 4月, 2022 1 次提交
  4. 11 3月, 2022 1 次提交
  5. 24 2月, 2022 1 次提交
  6. 03 2月, 2022 1 次提交
  7. 26 1月, 2022 1 次提交
  8. 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
  9. 13 1月, 2022 1 次提交
  10. 06 1月, 2022 1 次提交
  11. 11 12月, 2021 1 次提交
  12. 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
  13. 15 11月, 2021 1 次提交
  14. 12 11月, 2021 1 次提交
  15. 04 11月, 2021 1 次提交
  16. 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
  17. 23 10月, 2021 1 次提交
  18. 09 10月, 2021 1 次提交
  19. 07 10月, 2021 1 次提交
  20. 31 7月, 2021 3 次提交
  21. 30 7月, 2021 2 次提交
  22. 25 5月, 2021 1 次提交
  23. 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
  24. 02 4月, 2021 1 次提交
  25. 11 2月, 2021 1 次提交
  26. 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
  27. 06 11月, 2020 1 次提交
  28. 16 9月, 2020 1 次提交
  29. 04 9月, 2020 1 次提交
  30. 14 8月, 2020 1 次提交
  31. 28 7月, 2020 1 次提交
  32. 18 7月, 2020 1 次提交
  33. 25 6月, 2020 1 次提交
  34. 23 6月, 2020 1 次提交
    • A
      tools/bpftool: Show info for processes holding BPF map/prog/link/btf FDs · d53dee3f
      Andrii Nakryiko 提交于
      Add bpf_iter-based way to find all the processes that hold open FDs against
      BPF object (map, prog, link, btf). bpftool always attempts to discover this,
      but will silently give up if kernel doesn't yet support bpf_iter BPF programs.
      Process name and PID are emitted for each process (task group).
      
      Sample output for each of 4 BPF objects:
      
      $ sudo ./bpftool prog show
      2694: cgroup_device  tag 8c42dee26e8cd4c2  gpl
              loaded_at 2020-06-16T15:34:32-0700  uid 0
              xlated 648B  jited 409B  memlock 4096B
              pids systemd(1)
      2907: cgroup_skb  name egress  tag 9ad187367cf2b9e8  gpl
              loaded_at 2020-06-16T18:06:54-0700  uid 0
              xlated 48B  jited 59B  memlock 4096B  map_ids 2436
              btf_id 1202
              pids test_progs(2238417), test_progs(22384459)
      
      $ sudo ./bpftool map show
      2436: array  name test_cgr.bss  flags 0x400
              key 4B  value 8B  max_entries 1  memlock 8192B
              btf_id 1202
              pids test_progs(2238417), test_progs(22384459)
      2445: array  name pid_iter.rodata  flags 0x480
              key 4B  value 4B  max_entries 1  memlock 8192B
              btf_id 1214  frozen
              pids bpftool(2239612)
      
      $ sudo ./bpftool link show
      61: cgroup  prog 2908
              cgroup_id 375301  attach_type egress
              pids test_progs(2238417), test_progs(22384459)
      62: cgroup  prog 2908
              cgroup_id 375344  attach_type egress
              pids test_progs(2238417), test_progs(22384459)
      
      $ sudo ./bpftool btf show
      1202: size 1527B  prog_ids 2908,2907  map_ids 2436
              pids test_progs(2238417), test_progs(22384459)
      1242: size 34684B
              pids bpftool(2258892)
      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/20200619231703.738941-9-andriin@fb.com
      d53dee3f