]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: share several utility functions as internal API
authorEduard Zingerman <eddyz87@gmail.com>
Fri, 10 Apr 2026 20:55:52 +0000 (13:55 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 10 Apr 2026 22:01:55 +0000 (15:01 -0700)
Namely:
- bpf_subprog_is_global
- bpf_vlog_alignment

Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20260410-patch-set-v4-1-5d4eecb343db@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf_verifier.h
kernel/bpf/log.c
kernel/bpf/verifier.c

index 36bfd96d4563087209d73dfcfe43786df0184256..15f7f9f35be98f6f30c46cdf03cf5c0249a8ac38 100644 (file)
@@ -1121,12 +1121,14 @@ void print_verifier_state(struct bpf_verifier_env *env, const struct bpf_verifie
                          u32 frameno, bool print_all);
 void print_insn_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,
                      u32 frameno);
+u32 bpf_vlog_alignment(u32 pos);
 
 struct bpf_subprog_info *bpf_find_containing_subprog(struct bpf_verifier_env *env, int off);
 int bpf_jmp_offset(struct bpf_insn *insn);
 struct bpf_iarray *bpf_insn_successors(struct bpf_verifier_env *env, u32 idx);
 void bpf_fmt_stack_mask(char *buf, ssize_t buf_sz, u64 stack_mask);
 bool bpf_calls_callback(struct bpf_verifier_env *env, int insn_idx);
+bool bpf_subprog_is_global(const struct bpf_verifier_env *env, int subprog);
 
 int bpf_find_subprog(struct bpf_verifier_env *env, int off);
 int bpf_compute_const_regs(struct bpf_verifier_env *env);
index 6fd030fd6eeb9db04f256d23bbc2703d300a16d4..803f21e61d9299fff5c31fb603b77b4c75ba13d1 100644 (file)
@@ -806,7 +806,7 @@ void print_verifier_state(struct bpf_verifier_env *env, const struct bpf_verifie
                mark_verifier_state_clean(env);
 }
 
-static inline u32 vlog_alignment(u32 pos)
+u32 bpf_vlog_alignment(u32 pos)
 {
        return round_up(max(pos + BPF_LOG_MIN_ALIGNMENT / 2, BPF_LOG_ALIGNMENT),
                        BPF_LOG_MIN_ALIGNMENT) - pos - 1;
@@ -818,7 +818,7 @@ void print_insn_state(struct bpf_verifier_env *env, const struct bpf_verifier_st
        if (env->prev_log_pos && env->prev_log_pos == env->log.end_pos) {
                /* remove new line character */
                bpf_vlog_reset(&env->log, env->prev_log_pos - 1);
-               verbose(env, "%*c;", vlog_alignment(env->prev_insn_print_pos), ' ');
+               verbose(env, "%*c;", bpf_vlog_alignment(env->prev_insn_print_pos), ' ');
        } else {
                verbose(env, "%d:", env->insn_idx);
        }
index 9c1135d373e246ea9cc6dfd97bf96664151a5270..c422f1142b99fab80f453910a858c3519a3014c4 100644 (file)
@@ -423,7 +423,7 @@ static struct btf_record *reg_btf_record(const struct bpf_reg_state *reg)
        return rec;
 }
 
-static bool subprog_is_global(const struct bpf_verifier_env *env, int subprog)
+bool bpf_subprog_is_global(const struct bpf_verifier_env *env, int subprog)
 {
        struct bpf_func_info_aux *aux = env->prog->aux->func_info_aux;
 
@@ -4631,7 +4631,7 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,
                        if (subprog < 0)
                                return -EFAULT;
 
-                       if (subprog_is_global(env, subprog)) {
+                       if (bpf_subprog_is_global(env, subprog)) {
                                /* check that jump history doesn't have any
                                 * extra instructions from subprog; the next
                                 * instruction after call to global subprog
@@ -7032,7 +7032,7 @@ continue_func:
                if (subprog[idx].has_tail_call)
                        tail_call_reachable = true;
 
-               frame = subprog_is_global(env, idx) ? 0 : frame + 1;
+               frame = bpf_subprog_is_global(env, idx) ? 0 : frame + 1;
                if (frame >= MAX_CALL_FRAMES) {
                        verbose(env, "the call stack of %d frames is too deep !\n",
                                frame);
@@ -11107,7 +11107,7 @@ static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
        err = btf_check_subprog_call(env, subprog, caller->regs);
        if (err == -EFAULT)
                return err;
-       if (subprog_is_global(env, subprog)) {
+       if (bpf_subprog_is_global(env, subprog)) {
                const char *sub_name = subprog_name(env, subprog);
 
                if (env->cur_state->active_locks) {
@@ -25299,7 +25299,7 @@ static int do_check_subprogs(struct bpf_verifier_env *env)
 again:
        new_cnt = 0;
        for (i = 1; i < env->subprog_cnt; i++) {
-               if (!subprog_is_global(env, i))
+               if (!bpf_subprog_is_global(env, i))
                        continue;
 
                sub_aux = subprog_aux(env, i);