Skip to content

Commit 3b20d3c

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: declare a few utility functions as internal api
Namely, rename the following functions and add prototypes to bpf_verifier.h: - find_containing_subprog -> bpf_find_containing_subprog - insn_successors -> bpf_insn_successors - calls_callback -> bpf_calls_callback - fmt_stack_mask -> bpf_fmt_stack_mask Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/r/20250918-callchain-sensitive-liveness-v3-4-c3cd27bacc60@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 12a23f9 commit 3b20d3c

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

include/linux/bpf_verifier.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,4 +1065,9 @@ void print_verifier_state(struct bpf_verifier_env *env, const struct bpf_verifie
10651065
void print_insn_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,
10661066
u32 frameno);
10671067

1068+
struct bpf_subprog_info *bpf_find_containing_subprog(struct bpf_verifier_env *env, int off);
1069+
int bpf_insn_successors(struct bpf_prog *prog, u32 idx, u32 succ[2]);
1070+
void bpf_fmt_stack_mask(char *buf, ssize_t buf_sz, u64 stack_mask);
1071+
bool bpf_calls_callback(struct bpf_verifier_env *env, int insn_idx);
1072+
10681073
#endif /* _LINUX_BPF_VERIFIER_H */

kernel/bpf/verifier.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,7 +2979,7 @@ static int cmp_subprogs(const void *a, const void *b)
29792979
}
29802980

29812981
/* Find subprogram that contains instruction at 'off' */
2982-
static struct bpf_subprog_info *find_containing_subprog(struct bpf_verifier_env *env, int off)
2982+
struct bpf_subprog_info *bpf_find_containing_subprog(struct bpf_verifier_env *env, int off)
29832983
{
29842984
struct bpf_subprog_info *vals = env->subprog_info;
29852985
int l, r, m;
@@ -3004,7 +3004,7 @@ static int find_subprog(struct bpf_verifier_env *env, int off)
30043004
{
30053005
struct bpf_subprog_info *p;
30063006

3007-
p = find_containing_subprog(env, off);
3007+
p = bpf_find_containing_subprog(env, off);
30083008
if (!p || p->start != off)
30093009
return -ENOENT;
30103010
return p - env->subprog_info;
@@ -4211,7 +4211,7 @@ static void fmt_reg_mask(char *buf, ssize_t buf_sz, u32 reg_mask)
42114211
}
42124212
}
42134213
/* format stack slots bitmask, e.g., "-8,-24,-40" for 0x15 mask */
4214-
static void fmt_stack_mask(char *buf, ssize_t buf_sz, u64 stack_mask)
4214+
void bpf_fmt_stack_mask(char *buf, ssize_t buf_sz, u64 stack_mask)
42154215
{
42164216
DECLARE_BITMAP(mask, 64);
42174217
bool first = true;
@@ -4266,8 +4266,6 @@ static void bt_sync_linked_regs(struct backtrack_state *bt, struct bpf_jmp_histo
42664266
}
42674267
}
42684268

4269-
static bool calls_callback(struct bpf_verifier_env *env, int insn_idx);
4270-
42714269
/* For given verifier state backtrack_insn() is called from the last insn to
42724270
* the first insn. Its purpose is to compute a bitmask of registers and
42734271
* stack slots that needs precision in the parent verifier state.
@@ -4294,7 +4292,7 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,
42944292
fmt_reg_mask(env->tmp_str_buf, TMP_STR_BUF_LEN, bt_reg_mask(bt));
42954293
verbose(env, "mark_precise: frame%d: regs=%s ",
42964294
bt->frame, env->tmp_str_buf);
4297-
fmt_stack_mask(env->tmp_str_buf, TMP_STR_BUF_LEN, bt_stack_mask(bt));
4295+
bpf_fmt_stack_mask(env->tmp_str_buf, TMP_STR_BUF_LEN, bt_stack_mask(bt));
42984296
verbose(env, "stack=%s before ", env->tmp_str_buf);
42994297
verbose(env, "%d: ", idx);
43004298
verbose_insn(env, insn);
@@ -4495,7 +4493,7 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,
44954493
* backtracking, as these registers are set by the function
44964494
* invoking callback.
44974495
*/
4498-
if (subseq_idx >= 0 && calls_callback(env, subseq_idx))
4496+
if (subseq_idx >= 0 && bpf_calls_callback(env, subseq_idx))
44994497
for (i = BPF_REG_1; i <= BPF_REG_5; i++)
45004498
bt_clear_reg(bt, i);
45014499
if (bt_reg_mask(bt) & BPF_REGMASK_ARGS) {
@@ -4934,7 +4932,7 @@ static int __mark_chain_precision(struct bpf_verifier_env *env,
49344932
bt_frame_reg_mask(bt, fr));
49354933
verbose(env, "mark_precise: frame%d: parent state regs=%s ",
49364934
fr, env->tmp_str_buf);
4937-
fmt_stack_mask(env->tmp_str_buf, TMP_STR_BUF_LEN,
4935+
bpf_fmt_stack_mask(env->tmp_str_buf, TMP_STR_BUF_LEN,
49384936
bt_frame_stack_mask(bt, fr));
49394937
verbose(env, "stack=%s: ", env->tmp_str_buf);
49404938
print_verifier_state(env, st, fr, true);
@@ -11023,7 +11021,7 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
1102311021
"At callback return", "R0");
1102411022
return -EINVAL;
1102511023
}
11026-
if (!calls_callback(env, callee->callsite)) {
11024+
if (!bpf_calls_callback(env, callee->callsite)) {
1102711025
verifier_bug(env, "in callback at %d, callsite %d !calls_callback",
1102811026
*insn_idx, callee->callsite);
1102911027
return -EFAULT;
@@ -17298,15 +17296,15 @@ static void mark_subprog_changes_pkt_data(struct bpf_verifier_env *env, int off)
1729817296
{
1729917297
struct bpf_subprog_info *subprog;
1730017298

17301-
subprog = find_containing_subprog(env, off);
17299+
subprog = bpf_find_containing_subprog(env, off);
1730217300
subprog->changes_pkt_data = true;
1730317301
}
1730417302

1730517303
static void mark_subprog_might_sleep(struct bpf_verifier_env *env, int off)
1730617304
{
1730717305
struct bpf_subprog_info *subprog;
1730817306

17309-
subprog = find_containing_subprog(env, off);
17307+
subprog = bpf_find_containing_subprog(env, off);
1731017308
subprog->might_sleep = true;
1731117309
}
1731217310

@@ -17320,8 +17318,8 @@ static void merge_callee_effects(struct bpf_verifier_env *env, int t, int w)
1732017318
{
1732117319
struct bpf_subprog_info *caller, *callee;
1732217320

17323-
caller = find_containing_subprog(env, t);
17324-
callee = find_containing_subprog(env, w);
17321+
caller = bpf_find_containing_subprog(env, t);
17322+
callee = bpf_find_containing_subprog(env, w);
1732517323
caller->changes_pkt_data |= callee->changes_pkt_data;
1732617324
caller->might_sleep |= callee->might_sleep;
1732717325
}
@@ -17391,7 +17389,7 @@ static void mark_calls_callback(struct bpf_verifier_env *env, int idx)
1739117389
env->insn_aux_data[idx].calls_callback = true;
1739217390
}
1739317391

17394-
static bool calls_callback(struct bpf_verifier_env *env, int insn_idx)
17392+
bool bpf_calls_callback(struct bpf_verifier_env *env, int insn_idx)
1739517393
{
1739617394
return env->insn_aux_data[insn_idx].calls_callback;
1739717395
}
@@ -19439,7 +19437,7 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
1943919437
goto hit;
1944019438
}
1944119439
}
19442-
if (calls_callback(env, insn_idx)) {
19440+
if (bpf_calls_callback(env, insn_idx)) {
1944319441
if (states_equal(env, &sl->state, cur, RANGE_WITHIN))
1944419442
goto hit;
1944519443
goto skip_inf_loop_check;
@@ -24171,7 +24169,7 @@ static bool can_jump(struct bpf_insn *insn)
2417124169
return false;
2417224170
}
2417324171

24174-
static int insn_successors(struct bpf_prog *prog, u32 idx, u32 succ[2])
24172+
int bpf_insn_successors(struct bpf_prog *prog, u32 idx, u32 succ[2])
2417524173
{
2417624174
struct bpf_insn *insn = &prog->insnsi[idx];
2417724175
int i = 0, insn_sz;
@@ -24387,7 +24385,7 @@ static int compute_live_registers(struct bpf_verifier_env *env)
2438724385
u16 new_out = 0;
2438824386
u16 new_in = 0;
2438924387

24390-
succ_num = insn_successors(env->prog, insn_idx, succ);
24388+
succ_num = bpf_insn_successors(env->prog, insn_idx, succ);
2439124389
for (int s = 0; s < succ_num; ++s)
2439224390
new_out |= state[succ[s]].in;
2439324391
new_in = (new_out & ~live->def) | live->use;
@@ -24556,7 +24554,7 @@ static int compute_scc(struct bpf_verifier_env *env)
2455624554
stack[stack_sz++] = w;
2455724555
}
2455824556
/* Visit 'w' successors */
24559-
succ_cnt = insn_successors(env->prog, w, succ);
24557+
succ_cnt = bpf_insn_successors(env->prog, w, succ);
2456024558
for (j = 0; j < succ_cnt; ++j) {
2456124559
if (pre[succ[j]]) {
2456224560
low[w] = min(low[w], low[succ[j]]);

0 commit comments

Comments
 (0)