BPF List
 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 06/17] bpf: Track verifier reference diagnostic events
Date: Wed, 24 Jun 2026 12:49:21 -0700	[thread overview]
Message-ID: <df2bf4c0205f8c8395736c687aa4e293850311e2.camel@gmail.com> (raw)
In-Reply-To: <20260619205934.1312876-7-memxor@gmail.com>

On Fri, 2026-06-19 at 22:59 +0200, Kumar Kartikeya Dwivedi wrote:
> Add reference acquire and release events to diagnostic history so Resource
> Lifetime Safety reports can show the lifetime of a specific reference id along
> the path.
> 
> Record acquisitions after the verifier assigns the reference id. Record
> releases only after release_reference_nomark() succeeds, including the
> kptr_xchg RCU conversion path and owning-to-non-owning conversion path that
> consume an owning reference.
> 
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

[...]

> @@ -1536,6 +1570,20 @@ static void bpf_diag_print_stack_slot(struct bpf_verifier_env *env,
>  			       off, fmt->old_buf, fmt->new_buf);
>  }
>  
> +static void bpf_diag_print_ref_event(struct bpf_verifier_env *env,
> +				     const struct bpf_diag_history_event *event)
> +{
> +	if (event->kind == BPF_DIAG_HISTORY_REF_ACQUIRE) {
> +		bpf_diag_report_source(env, event->insn_idx, "acquired",
> +				       "owned resource (id=%u)",
> +				       event->ref.ref_id);
> +		return;
> +	}
> +
> +	bpf_diag_report_source(env, event->insn_idx, "released",
> +			       "owned resource (id=%u)", event->ref.ref_id);

Nit:

		char *label = event->kind == BPF_DIAG_HISTORY_REF_ACQUIRE ? "acquired" : "released";

		bpf_diag_report_source(env, event->insn_idx, label,
                		       "owned resource (id=%u)", event->ref.ref_id);


[...]

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index fedabb6bb515..93941deb2cd8 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[...]

> @@ -9140,8 +9141,12 @@ static int release_reference(struct bpf_verifier_env *env, int id)
>  	if (err)
>  		return err;
>  
> -	if (find_reference_state(vstate, id))
> -		WARN_ON_ONCE(release_reference_nomark(vstate, id));
> +	if (find_reference_state(vstate, id)) {
> +		err = release_reference_nomark(vstate, id);

I'd say that bpf_diag_record_ref_release() should go inside
release_reference_nomark(), but there is one odd case with
mark_ptr_or_null_regs(). Almost like we want __release_reference_nomark().

> +		WARN_ON_ONCE(err);
> +		if (!err)
> +			bpf_diag_record_ref_release(env, env->insn_idx, id);
> +	}
>  
>  	while ((id = idstack_pop(idstack))) {
>  		/*

[...]

  reply	other threads:[~2026-06-24 19:49 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
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 [this message]
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=df2bf4c0205f8c8395736c687aa4e293850311e2.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox