Skip to content

Improve verifier log readability

Christy Lee bpf 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 3 repliesIn review
  2. v23 patches 6 repliesSuperseded
  3. v13 patches 3 repliesSuperseded

Changes in v3 from the cover letter

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3Only print scratched registers and stack slots to verifier logsinclude/linux/bpf_verifier.h kernel/bpf/verifier.c tools/testing/selftests/bpf/prog_tests/align.c+90 -281 reply
2/3Right align verifier states in verifier logsinclude/linux/bpf_verifier.h kernel/bpf/verifier.c tools/testing/selftests/bpf/prog_tests/align.c+147 -1132 replies
3/3Only output backtracking information in log level 2kernel/bpf/verifier.c+3 -30 replies

Reviews trailers per patch

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

PatchAndrii Nakryiko
1/3A-b
2/3A-b
3/3A-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/3] Improve verifier log readability

Simplify verifier logs and improve readability.

Changelog:
----------
v2 -> v3:
v2: https://lore.kernel.org/all/[email protected]/

Patch 1:
* Fixed typo
* Added print_all bool arg to print_verifier_state()

Patch 2:
* Changed alignment from 32 to 40, fixed off-by-one error
* Renamed print_prev_insn_state() to print_insn_state()
* Fixed formatting to make the code more readable

v1 -> v2:
v1: https://lore.kernel.org/bpf/[email protected]/

Patch 2/3:
* Verifier will skip insn_idx when the insn is longer than 8 bytes, example:
0000000000000000 <good_prog>:

       0:	18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00	r2 = 0 ll
       2:	63 12 00 00 00 00 00 00	*(u32 *)(r2 + 0) = r1
       3:	61 20 04 00 00 00 00 00	r0 = *(u32 *)(r2 + 4)
       4:	95 00 00 00 00 00 00 00	exit

It's incorrect to check that prev_insn_idx = insn_idx - 1, skip this check and print the verifier state on the correct line.
Before:
0: R1=ctx(id=0,off=0,imm=0) R10=fp0
; a[0] = (int)(long)ctx;
0: (18) r2 = 0xffffc900006de000
2: R2_w=map_value(id=0,off=0,ks=4,vs=16,imm=0)
2: (63) *(u32 *)(r2 +0) = r1
After:
0: R1=ctx(id=0,off=0,imm=0) R10=fp0
; a[0] = (int)(long)ctx;
0: (18) r2 = 0xffffc900006de000 ; R2_w=map_value(id=0,off=0,ks=4,vs=16,imm=0) 2: (63) *(u32 *)(r2 +0) = r1
* Track previous line logging length in env, allow aligning intsruction from anywhere in the verifier
* Fixed bug where the verifier printed verifier state after checking source memory access but before check destination memory access, this ensures the aligned verifier state contains all scratched registers

Patch 3/3:
* Added one more case where we should only log in log_level=2

Christy Lee (3):
Only print scratched registers and stack slots to verifier logs Right align verifier states in verifier logs
Only output backtracking information in log level 2

 include/linux/bpf_verifier.h                  |  10 +
 kernel/bpf/verifier.c                         | 130 ++++++++---
 .../testing/selftests/bpf/prog_tests/align.c  | 214 +++++++++---------
 3 files changed, 225 insertions(+), 129 deletions(-)

--
2.30.2