All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	kkd@meta.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v2 04/17] bpf: Prune verifier diagnostics on backtracking
Date: Tue, 23 Jun 2026 14:57:05 -0700	[thread overview]
Message-ID: <2e01e2580cee612d458f99253b3e9c91d4a75e98.camel@gmail.com> (raw)
In-Reply-To: <20260619205934.1312876-5-memxor@gmail.com>

On Fri, 2026-06-19 at 22:59 +0200, Kumar Kartikeya Dwivedi wrote:
> Save the diagnostic event-log position with each verifier stack entry and
> reset the environment-owned stream together with the normal verifier log
> when a queued state is popped. Also reset the diagnostic stream after
> successful subprogram verification even when level-2 logging preserves the
> normal verifier log.
> 
> Record branch outcomes as true or false. Later reports use those
> events to show the path that reached a verifier error. For queued branches,
> append the queued outcome before push_stack() so the saved diagnostic
> position includes it, then reset back to the active path before continuing.
> 
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---

Nit: Let's not use the word "backtracking" as a subject for this
     patch, as in verifier it is easy to confuse with precision
     tracking backtracking.

>  kernel/bpf/verifier.c | 44 +++++++++++++++++++++++++++++++++++++------
>  1 file changed, 38 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index e81fdb0e22ae..ca4bba163418 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -192,6 +192,9 @@ struct bpf_verifier_stack_elem {
>  	struct bpf_verifier_stack_elem *next;
>  	/* length of verifier log at the time this state was pushed on stack */
>  	u32 log_pos;
> +	u64 diag_log_pos;

log_pos is u32, can we use u32 for diag_log_pos as well?

> +	bool diag_branch_valid;
> +	bool diag_branch_cond_true;

There is a 1 byte hole after 'st' and before 'insn_idx',
these two flags can fit there as bitfields.

Together this will remove the 6-byte padding and a 4-bytes hole from
this structure.

[...]

> @@ -1786,6 +1794,21 @@ static struct bpf_verifier_state *push_stack(struct bpf_verifier_env *env,
>  	return &elem->st;
>  }
>  
> +static struct bpf_verifier_state *
> +push_stack_with_branch_diag(struct bpf_verifier_env *env, int insn_idx,
> +			    int prev_insn_idx, bool speculative,
> +			    bool cond_true)
> +{
> +	struct bpf_verifier_state *st;
> +
> +	st = push_stack(env, insn_idx, prev_insn_idx, speculative);
> +	if (!IS_ERR(st)) {
> +		env->head->diag_branch_valid = true;
> +		env->head->diag_branch_cond_true = cond_true;

Tbh, I'd infer these flags instead of storing them.
If the state's prev_insn_idx is a conditional jump one can check if
this state's insn_idx is a target or a falltrhough. Would break for
'if ... goto +0' but I'd argue that it does not matter.
This would allow to move the

  bpf_diag_record_branch(env, head->prev_insn_idx, head->diag_branch_cond_true);

call from pop_stack to do_check(), near the:

  if (env->log.level & BPF_LOG_LEVEL2 && do_print_state) {
     verbose(env, "\nfrom %d to %d%s:", ...);
     ...
  }

and to make do with the activate_diag_branch flag in the pop_stack().

> +	}
> +	return st;
> +}
> +
>  static const char *reg_arg_name(struct bpf_verifier_env *env, argno_t argno)
>  {
>  	char *buf = env->tmp_arg_name;

[...]

  parent reply	other threads:[~2026-06-23 21:57 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19 20:59 [PATCH bpf-next v2 00/17] Redesign Verification Errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 01/17] bpf: Add verifier diagnostics report helpers Kumar Kartikeya Dwivedi
2026-06-19 21:09   ` sashiko-bot
2026-06-22 23:47   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 02/17] bpf: Add source and instruction diagnostic context Kumar Kartikeya Dwivedi
2026-06-19 21:46   ` bot+bpf-ci
2026-06-23 20:34   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 03/17] bpf: Add verifier diagnostic event log Kumar Kartikeya Dwivedi
2026-06-19 21:46   ` bot+bpf-ci
2026-06-23 21:20   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 04/17] bpf: Prune verifier diagnostics on backtracking Kumar Kartikeya Dwivedi
2026-06-19 21:46   ` bot+bpf-ci
2026-06-23 21:57   ` Eduard Zingerman [this message]
2026-06-19 20:59 ` [PATCH bpf-next v2 05/17] bpf: Track verifier register diagnostic events Kumar Kartikeya Dwivedi
2026-06-19 21:18   ` sashiko-bot
2026-06-19 23:35   ` Alexei Starovoitov
2026-06-24 19:17   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 06/17] bpf: Track verifier reference " Kumar Kartikeya Dwivedi
2026-06-24 19:49   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 07/17] bpf: Track verifier context " Kumar Kartikeya Dwivedi
2026-06-19 21:13   ` sashiko-bot
2026-06-19 21:19     ` Kumar Kartikeya Dwivedi
2026-06-19 21:46   ` bot+bpf-ci
2026-06-24 21:21   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 08/17] bpf: Report Register Type Safety errors Kumar Kartikeya Dwivedi
2026-06-24 23:55   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 09/17] bpf: Report Memory Safety bounds errors Kumar Kartikeya Dwivedi
2026-06-19 21:46   ` bot+bpf-ci
2026-06-19 23:40   ` Alexei Starovoitov
2026-06-25  1:30   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 10/17] bpf: Report Resource Lifetime reference leaks Kumar Kartikeya Dwivedi
2026-06-19 21:12   ` sashiko-bot
2026-06-19 23:42   ` Alexei Starovoitov
2026-06-25  1:58   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 11/17] bpf: Report Call Type Safety argument errors Kumar Kartikeya Dwivedi
2026-06-19 21:47   ` bot+bpf-ci
2026-06-25  6:05   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 12/17] bpf: Report Execution Context Safety errors Kumar Kartikeya Dwivedi
2026-06-19 21:19   ` sashiko-bot
2026-06-19 23:44   ` Alexei Starovoitov
2026-06-19 20:59 ` [PATCH bpf-next v2 13/17] bpf: Report Program Structure CFG errors Kumar Kartikeya Dwivedi
2026-06-25  0:47   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 14/17] bpf: Report Policy helper and kfunc errors Kumar Kartikeya Dwivedi
2026-06-25  0:36   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 15/17] bpf: Report Verifier Limit errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 16/17] bpf: Report Verifier Internal errors Kumar Kartikeya Dwivedi
2026-06-25  0:26   ` Eduard Zingerman
2026-06-19 20:59 ` [PATCH bpf-next v2 17/17] bpf: Gate verifier diagnostics on log level Kumar Kartikeya Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e01e2580cee612d458f99253b3e9c91d4a75e98.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=emil@etsalapatis.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=memxor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.