Skip to content

BPF verifier log improvements

Andrii Nakryiko bpf 3 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest8 patches 0 repliesApplied 8/8
  2. v28 patches 3 repliesSuperseded
  3. v18 patches 8 repliesSuperseded

Changes in v3 from the cover letter

- adjust reg_bounds tester to parse hex form of reg state as well;
- print reg->range as unsigned (Alexei);

Patches in v3 All 8 applied

#Subject and filesSizeRepliesApplied
1/8bpf: move verbose_linfo() into kernel/bpf/log.cinclude/linux/bpf_verifier.h kernel/bpf/log.c kernel/bpf/verifier.c+63 -570 repliesApplied
2/8bpf: move verifier state printing code to kernel/bpf/log.cinclude/linux/bpf_verifier.h kernel/bpf/log.c kernel/bpf/verifier.c+414 -4030 repliesApplied
3/8bpf: extract register state printingkernel/bpf/log.c+63 -570 repliesApplied
4/8bpf: print spilled register state in stack slotkernel/bpf/log.c+17 -190 repliesApplied
5/8bpf: emit map name in register state if applicable and availablekernel/bpf/log.c tools/testing/selftests/bpf/prog_tests/spin_lock.c+23 -110 repliesApplied
6/8bpf: omit default off=0 and imm=0 in register state logkernel/bpf/log.c tools/testing/selftests/bpf/prog_tests/align.c tools/testing/selftests/bpf/prog_tests/log_buf.c +2 more+39 -410 repliesApplied
7/8bpf: smarter verifier log number printing logickernel/bpf/log.c tools/testing/selftests/bpf/prog_tests/reg_bounds.c tools/testing/selftests/bpf/progs/exceptions_assert.c+118 -460 repliesApplied
8/8bpf: emit frameno for PTR_TO_STACK regs if it differs from current onekernel/bpf/log.c+14 -60 repliesApplied

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchEduard ZingermanStanislav Fomichev
1/8A-b A-b
2/8A-b A-b
3/8A-b A-b
4/8A-b A-b
5/8A-b A-b
6/8A-b A-b
7/8A-b A-b
8/8A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 bpf-next 0/8] BPF verifier log improvements

This patch set moves a big chunk of verifier log related code from gigantic verifier.c file into more focused kernel/bpf/log.c. This is not essential to the rest of functionality in this patch set, so I can undo it, but it felt like it's good to start chipping away from 20K+ verifier.c whenever we can.

The main purpose of the patch set, though, is in improving verifier log further.

Patches #3-#4 start printing out register state even if that register is spilled into stack slot. Previously we'd get only spilled register type, but no additional information, like SCALAR_VALUE's ranges. Super limiting during debugging. For cases of register spills smaller than 8 bytes, we also print out STACK_MISC/STACK_ZERO/STACK_INVALID markers. This, among other things, will make it easier to write tests for these mixed spill/misc cases.

Patch #5 prints map name for PTR_TO_MAP_VALUE/PTR_TO_MAP_KEY/CONST_PTR_TO_MAP registers. In big production BPF programs, it's important to map assembly to actual map, and it's often non-trivial. Having map name helps.

Patch #6 just removes visual noise in form of ubiquitous imm=0 and off=0. They are default values, omit them.

Patch #7 is probably the most controversial, but it reworks how verifier log prints numbers. For small valued integers we use decimals, but for large ones we switch to hexadecimal. From personal experience this is a much more useful convention. We can tune what consitutes "small value", for now it's 16-bit range.

Patch #8 prints frame number for PTR_TO_CTX registers, if that frame is different from the "current" one. This removes ambiguity and confusion, especially in complicated cases with multiple subprogs passing around pointers.

v2->v3:
- adjust reg_bounds tester to parse hex form of reg state as well;
- print reg->range as unsigned (Alexei);
v1->v2:
- use verbose_snum() for range and offset in register state (Eduard);
- fixed typos and added acks from Eduard and Stanislav.

Andrii Nakryiko (8):
bpf: move verbose_linfo() into kernel/bpf/log.c
bpf: move verifier state printing code to kernel/bpf/log.c
bpf: extract register state printing
bpf: print spilled register state in stack slot
bpf: emit map name in register state if applicable and available
bpf: omit default off=0 and imm=0 in register state log
bpf: smarter verifier log number printing logic
bpf: emit frameno for PTR_TO_STACK regs if it differs from current one

 include/linux/bpf_verifier.h                  |  76 +++
 kernel/bpf/log.c                              | 480 ++++++++++++++++++
 kernel/bpf/verifier.c                         | 460 -----------------
 .../testing/selftests/bpf/prog_tests/align.c  |  42 +-
 .../selftests/bpf/prog_tests/log_buf.c        |   4 +-
 .../selftests/bpf/prog_tests/reg_bounds.c     |  53 +-
 .../selftests/bpf/prog_tests/spin_lock.c      |  14 +-
 .../selftests/bpf/progs/exceptions_assert.c   |  40 +-
 8 files changed, 640 insertions(+), 529 deletions(-)
Signature · 1 line
2.34.1