Skip to content

Scc instead of loop entry #8852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: bpf-next_base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions include/linux/bpf_verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,6 @@ struct bpf_verifier_state {
/* first and last insn idx of this verifier state */
u32 first_insn_idx;
u32 last_insn_idx;
/* If this state is a part of states loop this field points to some
* parent of this state such that:
* - it is also a member of the same states loop;
* - DFS states traversal starting from initial state visits loop_entry
* state before this state.
* Used to compute topmost loop entry for state loops.
* State loops might appear because of open coded iterators logic.
* See get_loop_entry() for more information.
*/
struct bpf_verifier_state *loop_entry;
/* Sub-range of env->insn_hist[] corresponding to this state's
* instruction history.
* Backtracking is using it to go from last to first.
Expand All @@ -466,11 +456,11 @@ struct bpf_verifier_state {
u32 dfs_depth;
u32 callback_unroll_depth;
u32 may_goto_depth;
/* If this state was ever pointed-to by other state's loop_entry field
* this flag would be set to true. Used to avoid freeing such states
* while they are still in use.
/*
* If this state is a checkpoint at insn_idx that belongs to an SCC,
* record the SCC epoch at the time of checkpoint creation.
*/
u32 used_as_loop_entry;
u32 scc_epoch;
};

#define bpf_get_spilled_reg(slot, frame, mask) \
Expand Down Expand Up @@ -604,6 +594,11 @@ struct bpf_insn_aux_data {
* accepts callback function as a parameter.
*/
bool calls_callback;
/*
* CFG strongly connected component this instruction belongs to,
* zero if it is a singleton SCC.
*/
u32 scc;
/* registers alive before this instruction. */
u16 live_regs_before;
};
Expand Down Expand Up @@ -713,6 +708,25 @@ struct bpf_idset {
u32 ids[BPF_ID_MAP_SIZE];
};

/* Information tracked for CFG strongly connected components */
struct bpf_scc_info {
/*
* Set to true when is_state_visited() detected convergence of
* open coded iterator for a state with insn_idx within this SCC.
* Indicates that read and precision marks are incomplete for
* states with insn_idx in this SCC.
*/
bool state_loops_possible;
/*
* Number of times this SCC was entered by some verifier state
* and that state was fully explored.
* In other words, number of times .branches became non-zero
* and then zero again.
*/
u32 scc_epoch;
struct bpf_verifier_state *entry_state;
};

/* single container for all structs
* one verifier_env per bpf_check() call
*/
Expand Down Expand Up @@ -805,6 +819,8 @@ struct bpf_verifier_env {
u64 prev_log_pos, prev_insn_print_pos;
/* buffer used to temporary hold constants as scalar registers */
struct bpf_reg_state fake_reg[2];
struct bpf_scc_info *scc_info;
u32 num_sccs;
/* buffer used to generate temporary string representations,
* e.g., in reg_type_str() to generate reg_type string
*/
Expand Down
Loading
Loading