Re: [PATCH bpf-next v1 10/14] bpf: Correct Program Structure diagnostic context

Eduard Zingerman <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <[email protected]>
On Sun, 2026-08-16 at 03:57 +0200, Kumar Kartikeya Dwivedi wrote:

Acked-by: Eduard Zingerman <[email protected]>

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 3de9e4f617b6..d2f08c6612c6 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -2995,15 +2995,13 @@ static int add_kfuncs(struct bpf_verifier_env *env)
>  	return 0;
>  }
>  
> -static int check_subprogs(struct bpf_verifier_env *env)
> +static void find_subprog_properties(struct bpf_verifier_env *env)
>  {
> -	int i, subprog_start, subprog_end, off, cur_subprog = 0;
> +	int i, subprog_end, cur_subprog = 0;
>  	struct bpf_subprog_info *subprog = env->subprog_info;
>  	struct bpf_insn *insn = env->prog->insnsi;
>  	int insn_cnt = env->prog->len;
>  
> -	/* now check that all jumps are within the same subprog */
> -	subprog_start = subprog[cur_subprog].start;
>  	subprog_end = subprog[cur_subprog + 1].start;
>  	for (i = 0; i < insn_cnt; i++) {
>  		u8 code = insn[i].code;
> @@ -3017,6 +3015,27 @@ static int check_subprogs(struct bpf_verifier_env *env)
>  		if (BPF_CLASS(code) == BPF_LD &&
>  		    (BPF_MODE(code) == BPF_ABS || BPF_MODE(code) == BPF_IND))
>  			subprog[cur_subprog].has_ld_abs = true;
> +		if (i == subprog_end - 1) {
> +			cur_subprog++;
> +			if (cur_subprog < env->subprog_cnt)
> +				subprog_end = subprog[cur_subprog + 1].start;
> +		}

Nit: in situations like this doing two nested loops reads much better:
     for each subprog:
       for insn from star to end:
         ...

> +	}
> +}

...

> @@ -3126,8 +3146,9 @@ static int sort_subprogs_topo(struct bpf_verifier_env *env)
>  					bpf_diag_program_structure(
>  						env, idx, "recursive subprogram call",
>  						"Rewrite the recursion as an explicit bounded loop, or split the logic so subprogram calls do not form a cycle.",
> -						"This bpf2bpf call would make the subprogram call graph recursive. "
> -						"The verifier requires a finite, acyclic call graph so it can bound stack depth and analysis.");
> +						"The call from %s() to %s() would make the subprogram call graph recursive. "
> +						"The verifier requires a finite, acyclic call graph so it can bound stack depth and analysis.",
> +						bpf_subprog_name(env, cur), bpf_subprog_name(env, callee));

Nit: I'd drop this hunk, I think that initial suggestion from the bot
     was bogus. What would be really helpful is to draw the whole
     cycle, but we don't have such info here.

>  					ret = -EINVAL;
>  					goto out;
>  				}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.