bpf, docs: structured overview of verifier
Subsystems (2)
cover bpf, docs: structured overview of verifier
This is an RFC for adding overview documentation for the BPF verifier.
The existing verifier.rst has detail but IMHO it lacks structure and background. Here is my humble proposal to make the verifier docs more helpful for newcomers.
Finding a balance between overview and detail in documentation is never easy. The idea here is to describe abstract interpretation and have enough information that anyone interested can learn what is going on.
Please let me know what you think. I used Gemini 3 to get a first draft, which I then checked word-for-word and reworked.
Burak Emir (1):
bpf, docs: structured docs for the verifier
Documentation/bpf/index.rst | 1 + .../bpf/verifier-overview-1-abstr-interp.rst | 74 +++++++++++++++ .../bpf/verifier-overview-2-domain.rst | 91 +++++++++++++++++++ .../bpf/verifier-overview-3-dataflow.rst | 83 +++++++++++++++++ .../bpf/verifier-overview-4-pruning.rst | 59 ++++++++++++ .../bpf/verifier-overview-5-advanced.rst | 70 ++++++++++++++ Documentation/bpf/verifier-overview-index.rst | 17 ++++ 7 files changed, 395 insertions(+) create mode 100644 Documentation/bpf/verifier-overview-1-abstr-interp.rst create mode 100644 Documentation/bpf/verifier-overview-2-domain.rst create mode 100644 Documentation/bpf/verifier-overview-3-dataflow.rst create mode 100644 Documentation/bpf/verifier-overview-4-pruning.rst create mode 100644 Documentation/bpf/verifier-overview-5-advanced.rst create mode 100644 Documentation/bpf/verifier-overview-index.rst
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
RFC PATCH 1/1 bpf, docs: structured docs for the verifier
Multi-part docseries (verifier-formal-*.rst) for BPF verifier.
Provides some background that helps get a structured overview of the static analysis that happens in the verifier.
The documentation covers:
* Part 1: Abstract Interpretation
* Part 2: Abstract Domain (Value lattices, tnum, pointer provenance)
* Part 3: Data Flow (Transfer functions, ALU ops, bounds tracking)
* Part 4: Pruning (State equivalence, subsumption, liveness)
* Part 5: Advanced Contexts (BTF, concurrency, reference tracking)
--- Documentation/bpf/index.rst | 1 + .../bpf/verifier-overview-1-abstr-interp.rst | 74 +++++++++++++++ .../bpf/verifier-overview-2-domain.rst | 91 +++++++++++++++++++ .../bpf/verifier-overview-3-dataflow.rst | 83 +++++++++++++++++ .../bpf/verifier-overview-4-pruning.rst | 59 ++++++++++++ .../bpf/verifier-overview-5-advanced.rst | 70 ++++++++++++++ Documentation/bpf/verifier-overview-index.rst | 17 ++++ 7 files changed, 395 insertions(+) create mode 100644 Documentation/bpf/verifier-overview-1-abstr-interp.rst create mode 100644 Documentation/bpf/verifier-overview-2-domain.rst create mode 100644 Documentation/bpf/verifier-overview-3-dataflow.rst create mode 100644 Documentation/bpf/verifier-overview-4-pruning.rst create mode 100644 Documentation/bpf/verifier-overview-5-advanced.rst create mode 100644 Documentation/bpf/verifier-overview-index.rst
Documentation/bpf/index.rst +1 -0
@@ -13,6 +13,7 @@ that goes into great technical depth about the BPF Architecture. :maxdepth: 1 verifier + verifier-overview-index libbpf/index standardization/index btf
Documentation/bpf/verifier-overview-1-abstr-interp.rst new file +74 -0
74 lines not on this page · raw message
Documentation/bpf/verifier-overview-2-domain.rst new file +91 -0
91 lines not on this page · raw message
Documentation/bpf/verifier-overview-3-dataflow.rst new file +83 -0
83 lines not on this page · raw message
Documentation/bpf/verifier-overview-4-pruning.rst new file +59 -0
59 lines not on this page · raw message
Documentation/bpf/verifier-overview-5-advanced.rst new file +70 -0
70 lines not on this page · raw message
Documentation/bpf/verifier-overview-index.rst new file +17 -0
@@ -0,0 +1,17 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================ +Overview of the BPF Verifier +============================ + +This is an index to multi-part documentation that gives an overview of the +eBPF verifier. + +.. toctree:: + :maxdepth: 2 + + verifier-overview-1-abstr-interp + verifier-overview-2-domain + verifier-overview-3-dataflow + verifier-overview-4-pruning + verifier-overview-5-advanced
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
[email protected]
AI reviewRe: [RFC PATCH 1/1] bpf, docs: structured docs for the verifier
The files are named verifier-overview-*.rst, not verifier-formal-*.rst.
Quoted 1 line
Multi-part docseries (verifier-formal-*.rst) for BPF verifier.
The files are named verifier-overview-*.rst, not
verifier-formal-*.rst.
Quoted 5 lines
Documentation/bpf/verifier-overview-2-domain.rst new file +0
-0
[ ... ]
Documentation/bpf/verifier-overview-2-domain.rst line 18
Quoted 3 lines
Documentation/bpf/verifier-overview-2-domain.rst new file +3
-0+* **Top ($\top$)**: The most general state. It represents *any* possible value. The verifier has zero knowledge. In the code, this is represented by the ``tnum_unknown`` bitmask and the widest possible numeric bounds (``umin_value = 0``, ``umax_value = U64_MAX``, ``smin_value = S64_MIN``, ``smax_value = S64_MAX``), applied via functions like ``__mark_reg_unknown()`` and ``__mark_reg_unbounded()``. +* **Intermediate Values**: Partial knowledge (e.g., "the value is between 5 and 10," or "the lower 3 bits are 0"). +* **Bottom ($\bot$)**: The most specific state. It represents an impossible or contradictory state (e.g., a value that must be simultaneously > 10 and < 5). The verifier does not have an explicit ``struct`` for Bottom; instead, it manifests as contradictory bounds (e.g., ``umin_value > umax_value``). When the verifier encounters this, it identifies the execution path as dead code and stops exploring it.
The $\top$ and $\bot$ LaTeX notations will not render in Sphinx RST. The kernel documentation build uses Sphinx with mathjax as the math renderer, but dollar-sign delimiters are not enabled by default. These will appear literally as "$\top$" and "$\bot$" in the generated HTML.
The standard RST inline math syntax would be :math:\top and :math:\bot. The same issue appears in a few other places across Parts 2, 3, and 4 (e.g. the $\top$ in the tnum_unknown example and in Part 3's overflow section and Part 4's subsumption examples).
Quoted 5 lines
Documentation/bpf/verifier-overview-4-pruning.rst new file +0
-0
[ ... ]
Quoted 1 line
+The verifier tracks this using ``REG_LIVE_READ`` and ``REG_LIVE_WRITTEN`` flags. During the ``states_equal()`` check, if a register is marked as dead in the *existing state*, the verifier knows that this register will remain dead regardless of how the current path is explored. As a result, it completely ignores the value of that register in the *current state*.
REG_LIVE_READ and REG_LIVE_WRITTEN do not exist anywhere in the current kernel tree. The actual liveness mechanism is implemented in compute_live_registers(), which uses bitmask-based insn_live_regs structs with in/out/use/def fields, and stores the results as insn_aux[i].live_regs_before.
Could these references be updated to describe the actual implementation?
Quoted 5 lines
Documentation/bpf/verifier-overview-5-advanced.rst new file +0
-0
[ ... ]
Documentation/bpf/verifier-overview-5-advanced.rst line 42
Quoted 3 lines
Documentation/bpf/verifier-overview-5-advanced.rst new file +3
-0+The ``struct bpf_verifier_state`` includes fields like ``active_spin_lock`` and ``active_rcu_lock``. + +* **Spinlocks**: When a program calls the helper ``bpf_spin_lock(map_value)``, the verifier's transfer function asserts that no lock is currently held. It then updates ``active_spin_lock`` with the identity of the map value.
The field active_spin_lock does not exist in struct bpf_verifier_state. The actual fields are active_locks (u32), active_lock_id (u32), and active_lock_ptr (void *).
Similarly, active_rcu_lock should be active_rcu_locks (plural) to match the actual field name in the struct.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22853419607
Re: [RFC PATCH 1/1] bpf, docs: structured docs for the verifier
In reply to Burak EmirQuoted 13 lines · Burak Emir
Multi-part docseries (verifier-formal-*.rst) for BPF verifier.
Provides some background that helps get a structured overview of the static analysis that happens in the verifier.
The documentation covers:
* Part 1: Abstract Interpretation
* Part 2: Abstract Domain (Value lattices, tnum, pointer provenance)
* Part 3: Data Flow (Transfer functions, ALU ops, bounds tracking)
* Part 4: Pruning (State equivalence, subsumption, liveness)
* Part 5: Advanced Contexts (BTF, concurrency, reference tracking)
Quoted 2 lines
Signed-off-by Burak Emir <[email protected]>Assisted-by Gemini:gemini-3.1-pro,gemini-3-flash
Pls don't waste the maintainer's time with this.
pw-bot: cr