Skip to content
  1. Dec 11, 2021
  2. Dec 10, 2021
  3. Dec 09, 2021
  4. Dec 07, 2021
  5. Dec 06, 2021
    • Kajol Jain's avatar
      bpf: Remove config check to enable bpf support for branch records · db52f572
      Kajol Jain authored
      Branch data available to BPF programs can be very useful to get stack traces
      out of userspace application.
      
      Commit fff7b643 ("bpf: Add bpf_read_branch_records() helper") added BPF
      support to capture branch records in x86. Enable this feature also for other
      architectures as well by removing checks specific to x86.
      
      If an architecture doesn't support branch records, bpf_read_branch_records()
      still has appropriate checks and it will return an -EINVAL in that scenario.
      Based on UAPI helper doc in include/uapi/linux/bpf.h, unsupported architectures
      should return -ENOENT in such case. Hence, update the appropriate check to
      return -ENOENT instead.
      
      Selftest 'perf_branches' result on power9 machine which has the branch stacks
      support:
      
       - Before this patch:
      
        [command]# ./test_progs -t perf_branches
         #88/1 perf_branches/perf_branches_hw:FAIL
         #88/2 perf_branches/perf_branches_no_hw:OK
         #88 perf_branches:FAIL
        Summary: 0/1 PASSED, 0 SKIPPED, 1 FAILED
      
       - After this patch:
      
        [command]# ./test_progs -t perf_branches
         #88/1 perf_branches/perf_branches_hw:OK
         #88/2 perf_branches/perf_branches_no_hw:OK
         #88 perf_branches:OK
        Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
      
      Selftest 'perf_branches' result on power9 machine which doesn't have branch
      stack report:
      
       - After this patch:
      
        [command]# ./test_progs -t perf_branches
         #88/1 perf_branches/perf_branches_hw:SKIP
         #88/2 perf_branches/perf_branches_no_hw:OK
         #88 perf_branches:OK
        Summary: 1/1 PASSED, 1 SKIPPED, 0 FAILED
      
      Fixes: fff7b643
      
       ("bpf: Add bpf_read_branch_records() helper")
      Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20211206073315.77432-1-kjain@linux.ibm.com
      db52f572
    • Alexei Starovoitov's avatar
      bpftool: Add debug mode for gen_loader. · 942df4dc
      Alexei Starovoitov authored
      
      
      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: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211204194623.27779-1-alexei.starovoitov@gmail.com
      942df4dc
  6. Dec 05, 2021
  7. Dec 04, 2021
  8. Dec 03, 2021