Skip to content

Commit c1d95a0

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-simple-dfa-based-live-registers-analysis'
Eduard Zingerman says: ==================== bpf: simple DFA-based live registers analysis This patch-set introduces a simple live registers DFA analysis. Analysis is done as a separate step before main verification pass. Results are stored in the env->insn_aux_data for each instruction. The change helps with iterator/callback based loops handling, as regular register liveness marks are not finalized while loops are processed. See veristat results in patch #2. Note: for regular subprogram calls analysis conservatively assumes that r1-r5 are used, and r0 is used at each 'exit' instruction. Experiments show that adding logic handling these cases precisely has no impact on verification performance. The patch set was tested by disabling the current register parentage chain liveness computation, using DFA-based liveness for registers while assuming all stack slots as live. See discussion in [1]. Changes v2 -> v3: - added support for BPF_LOAD_ACQ, BPF_STORE_REL atomics (Alexei); - correct use marks for r0 for BPF_CMPXCHG. Changes v1 -> v2: - added a refactoring commit extracting utility functions: jmp_offset(), verbose_insn() (Alexei); - added a refactoring commit extracting utility function get_call_summary() in order to share helper/kfunc related code with mark_fastcall_pattern_for_call() (Alexei); - comment in the compute_insn_live_regs() extended (Alexei). Changes RFC -> v1: - parameter count for helpers and kfuncs is taken into account; - copy_verifier_state() bugfix had been merged as a separate patch-set and is no longer a part of this patch set. RFC: https://lore.kernel.org/bpf/[email protected]/ v1: https://lore.kernel.org/bpf/[email protected]/ v2: https://lore.kernel.org/bpf/[email protected]/ [1] https://lore.kernel.org/bpf/[email protected]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 5bde575 + 2ea8f6a commit c1d95a0

File tree

9 files changed

+875
-106
lines changed

9 files changed

+875
-106
lines changed

include/linux/bpf_verifier.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ struct bpf_insn_aux_data {
591591
* accepts callback function as a parameter.
592592
*/
593593
bool calls_callback;
594+
/* registers alive before this instruction. */
595+
u16 live_regs_before;
594596
};
595597

596598
#define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */
@@ -748,7 +750,11 @@ struct bpf_verifier_env {
748750
struct {
749751
int *insn_state;
750752
int *insn_stack;
753+
/* vector of instruction indexes sorted in post-order */
754+
int *insn_postorder;
751755
int cur_stack;
756+
/* current position in the insn_postorder vector */
757+
int cur_postorder;
752758
} cfg;
753759
struct backtrack_state bt;
754760
struct bpf_insn_hist_entry *insn_hist;

0 commit comments

Comments
 (0)