Simplify verifier logs and improve readability. Changelog: ---------- v2 -> v3: v2: https://lore.kernel.org/all/20211215192225.1278237-1-christylee@xxxxxx/ 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/20211213182117.682461-1-christylee@xxxxxx/ 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