Skip to content

Improve stack depth verification stats output

Kumar Kartikeya Dwivedi bpf 8 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. v8 Latest6 patches 1 replyApplied 6/6
  2. v76 patches 6 repliesSuperseded
  3. v66 patches 4 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v53 patches2 repliesSuperseded
v43 patches2 repliesSuperseded
v33 patches0 repliesSuperseded
v23 patches2 repliesSuperseded
v13 patches8 repliesSuperseded

Changes in v8 from the cover letter

v7: https://lore.kernel.org/bpf/[email protected]

* Move the insns_total snapshot and delta for main and global roots into do_check_common() and explain why the override is needed for async subprograms. (Eduard)
* Avoid splitting __msg string literals in the stack-depth stats tests. (Eduard)
* Add a comment explaining why both the new per-subprogram records and the legacy one-line format are matched in veristat's parse_verif_log(). (Eduard)

Patches in v8 All 6 applied

#Subject and filesSizeRepliesApplied
1/6bpf: Track verifier instruction stats for each subprograminclude/linux/bpf_verifier.h kernel/bpf/verifier.c+50 -100 repliesApplied
2/6bpf: Attribute async callback instructions to verification rootskernel/bpf/verifier.c+10 -01 replyApplied
3/6bpf: Show more useful info in stack depth statskernel/bpf/verifier.c tools/testing/selftests/bpf/progs/verifier_basic_stack.c tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c +3 more+58 -250 repliesApplied
4/6selftests/bpf: Adjust veristat stack depth parsingtools/testing/selftests/bpf/veristat.c+19 -40 repliesApplied
5/6selftests/bpf: Test stack depth stats without BTF subprog namestools/testing/selftests/bpf/test_verifier.c tools/testing/selftests/bpf/verifier/calls.c+12 -20 repliesApplied
6/6selftests/bpf: Test subprogram instruction statisticstools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/verifier_subprog_insn_stats.c+225 -00 repliesApplied

Reviews trailers per patch

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

PatchEduard Zingerman
1/6A-b
2/6A-b
3/6A-b
4/6A-b
5/6A-b
6/6A-b

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

Read the v8 thread

Cover letter [PATCH bpf-next v8 0/6] Improve stack depth verification stats output

Some improvements for more clarity in the stack depth verification statistics output. See commit logs for details.

For example, ./test_progs -t subprogs/subprogs_alone loads prog4, which has a main program, two static subprograms, and two independently verified global subprograms. A sample run produces:

verification time 1765 usec
stack depth max 48
subprog 0 (prog4) main insns_self 29 insns_total 51 stack 8
subprog 1 (get_task_tgid) global insns_self 9 insns_total 9 stack 8
subprog 2 (sub4) static insns_self 15 insns_total 22 stack 8
subprog 3 (sub3) static insns_self 7 insns_total 7 stack 0
subprog 4 (sub1) global insns_self 10 insns_total 10 stack 8
processed 70 insns (limit 1000000) max_states_per_insn 0 total_states 7 peak_states 7 mark_read 0

The insns_self counts account for every processed instruction exactly once:

29 + 9 + 15 + 7 + 10 = 70

The main program and global subprograms are independent exploration roots, so their insns_total counts also account for the full processed budget:

51 + 9 + 10 = 70

Static subprogram totals provide a nested, top-down breakdown inside their root. In this example:

sub4: 22 = 15 self + 7 in sub3
prog4: 51 = 29 self + 22 in sub4

The global subprogram bodies are accounted in their own root totals rather than being included in prog4 or the static callees which call them.

Asynchronous callbacks start from fresh frame-zero verifier states, but the work remains part of the do_check_common() invocation for the main or global verification root under which it was scheduled. Running:

./test_progs -t verifier_subprog_insn_stats/stats_async_nested -v

produces the following stats:

stack depth max 0
subprog 0 (stats_async_nested) main insns_self 9 insns_total 25 stack 0 subprog 1 (stats_async_nested_schedule) static insns_self 7 insns_total 7 stack 0 subprog 2 (stats_async_outer) static insns_self 7 insns_total 7 stack 0 subprog 3 (stats_async_nested_leaf) static insns_self 2 insns_total 2 stack 0 processed 25 insns

Here, 9 + 2 + 7 + 7 = 25. The main root total is the complete verifier budget for its do_check_common() invocation, including both directly and transitively scheduled asynchronous callbacks. Static subprogram and callback totals remain local to their synchronous paths.

Changelog:
----------
v7 -> v8
v7: https://lore.kernel.org/bpf/[email protected]

* Move the insns_total snapshot and delta for main and global roots into do_check_common() and explain why the override is needed for async subprograms. (Eduard)
* Avoid splitting __msg string literals in the stack-depth stats tests. (Eduard)
* Add a comment explaining why both the new per-subprogram records and the legacy one-line format are matched in veristat's parse_verif_log(). (Eduard)

v6 -> v7
v6: https://lore.kernel.org/bpf/[email protected]

* Rename insns_own to insns_self throughout. (Andrii)
* Drop the async accounting call stack and attribute callback work to the scheduling main or global verification root using its processed-insn delta. (Eduard, Andrii)
* Skip missing frames when folding instruction totals after a partial verifier state copy. (BPF CI Bot)
* Use explicit callback argument operands in deterministic instruction-count tests and update tests and examples for root attribution. (BPF CI Bot)

v5 -> v6
v5: https://lore.kernel.org/bpf/[email protected]

* Track self and inclusive instruction counts for main, global, and static subprograms. (Andrii, Eduard)
* Keep instruction subtotals path-local across verifier state copies.
* Propagate async callback budget through nested scheduling chains. (Andrii)
* Split per-subprogram instruction accounting into a preparatory patch.
* Add deterministic selftests with exact self, total, and processed counts.

v4 -> v5
v4: https://lore.kernel.org/bpf/[email protected]

* Change the format to combine instruction counts and stack depths into per-program records. (Andrii)
* Adjust veristat for the new format while retaining support for the legacy format.
* Explain why the legacy stack parsing buffer is zero-initialized. (BPF CI Bot)

v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]

* Read names from subprog_info directly to avoid an out-of-bounds access when func_info validation fails. (BPF CI Bot)

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

* Reuse subprog_name() to fetch subprogram names. (BPF CI Bot)

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

* Use multi-line format. (Eduard)
* Adjust veristat to work with old and new format.
* Adjust selftest log_level without new option. (Eduard)

Kumar Kartikeya Dwivedi (6):
bpf: Track verifier instruction stats for each subprogram
bpf: Attribute async callback instructions to verification roots
bpf: Show more useful info in stack depth stats selftests/bpf: Adjust veristat stack depth parsing selftests/bpf: Test stack depth stats without BTF subprog names selftests/bpf: Test subprogram instruction statistics

 include/linux/bpf_verifier.h                  |   5 +-
 kernel/bpf/verifier.c                         |  84 +++++--
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_basic_stack.c          |   6 +-
 .../bpf/progs/verifier_bpf_fastcall.c         |  28 ++-
 .../bpf/progs/verifier_global_subprogs.c      |   5 +-
 .../bpf/progs/verifier_private_stack.c        |  15 +-
 .../bpf/progs/verifier_subprog_insn_stats.c   | 223 ++++++++++++++++++
 .../selftests/bpf/progs/verifier_var_off.c    |   6 +-
 tools/testing/selftests/bpf/test_verifier.c   |   2 +-
 tools/testing/selftests/bpf/verifier/calls.c  |  12 +-
 tools/testing/selftests/bpf/veristat.c        |  23 +-
 12 files changed, 372 insertions(+), 39 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_subprog_insn_stats.c

base-commit: 3a59f11e0f989bdd637c87151992605a6559a7cb

Signature · 1 line
2.53.0