From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>, bpf <bpf@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Anton Protopopov <aspsk@isovalent.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Quentin Monnet <qmo@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH v5 bpf-next 09/15] bpf: make bpf_insn_successors to return a pointer
Date: Thu, 2 Oct 2025 08:19:01 +0000 [thread overview]
Message-ID: <aN41dbxNPIUrKzNz@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQ+K9hYhwxLO3+2xAcm04=SeyCQuYZtHmKMkmkKTUDQG4Q@mail.gmail.com>
On 25/10/01 04:49PM, Alexei Starovoitov wrote:
> On Wed, Oct 1, 2025 at 3:39 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > On Tue, 2025-09-30 at 12:51 +0000, Anton Protopopov wrote:
> > > The bpf_insn_successors() function is used to return successors
> > > to a BPF instruction. So far, an instruction could have 0, 1 or 2
> > > successors. Prepare the verifier code to introduction of instructions
> > > with more than 2 successors (namely, indirect jumps).
> > >
> > > To do this, introduce a new struct, struct bpf_iarray, containing
> > > an array of bpf instruction indexes and make bpf_insn_successors
> > > to return a pointer of that type. The storage for all instructions
> > > is allocated in the env->succ, which holds an array of size 2,
> > > to be used for all instructions.
> > >
> > > Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
> > > ---
> >
> > Acked-by: Eduard Zingerman <eddyz87@gmail.com>
> >
> > (but please fix the IS_ERR things, see below).
> >
> > [...]
> >
> > > --- a/include/linux/bpf_verifier.h
> > > +++ b/include/linux/bpf_verifier.h
> > > @@ -509,6 +509,15 @@ struct bpf_map_ptr_state {
> > > #define BPF_ALU_SANITIZE (BPF_ALU_SANITIZE_SRC | \
> > > BPF_ALU_SANITIZE_DST)
> > >
> > > +/*
> > > + * An array of BPF instructions.
> > > + * Primary usage: return value of bpf_insn_successors.
> > > + */
> > > +struct bpf_iarray {
> > > + int off_cnt;
> > > + u32 off[];
> > > +};
> > > +
> >
> > Tbh, the names `off` and `off_cnt` are a bit strange in context of
> > instruction successors.
> >
> > [...]
> >
> > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > > index 705535711d10..6c742d2f4c04 100644
> > > --- a/kernel/bpf/verifier.c
> > > +++ b/kernel/bpf/verifier.c
> > > @@ -17770,6 +17770,22 @@ static int mark_fastcall_patterns(struct bpf_verifier_env *env)
> > > return 0;
> > > }
> > >
> > > +static struct bpf_iarray *iarray_realloc(struct bpf_iarray *old, size_t n_elem)
> > > +{
> > > + size_t new_size = sizeof(struct bpf_iarray) + n_elem * 4;
> >
> > Nit: n_elem * 4 -> n_elem * sizeof(*old->off) ?
> >
> > > + struct bpf_iarray *new;
> > > +
> > > + new = kvrealloc(old, new_size, GFP_KERNEL_ACCOUNT);
> > > + if (!new) {
> > > + /* this is what callers always want, so simplify the call site */
> > > + kvfree(old);
> > > + return NULL;
> > > + }
> > > +
> > > + new->off_cnt = n_elem;
> > > + return new;
> > > +}
> >
> > [...]
> >
> > > @@ -24325,14 +24342,18 @@ static int compute_live_registers(struct bpf_verifier_env *env)
> > > for (i = 0; i < env->cfg.cur_postorder; ++i) {
> > > int insn_idx = env->cfg.insn_postorder[i];
> > > struct insn_live_regs *live = &state[insn_idx];
> > > - int succ_num;
> > > - u32 succ[2];
> > > + struct bpf_iarray *succ;
> > > u16 new_out = 0;
> > > u16 new_in = 0;
> > >
> > > - succ_num = bpf_insn_successors(env->prog, insn_idx, succ);
> > > - for (int s = 0; s < succ_num; ++s)
> > > - new_out |= state[succ[s]].in;
> > > + succ = bpf_insn_successors(env, insn_idx);
> > > + if (IS_ERR(succ)) {
> >
> > This error check is no longer necessary.
>
> Speaking of IS_ERR checks...
> https://github.com/kernel-patches/bpf/pull/9895#issuecomment-3352016682
>
> AI for-the-win!
Nice! Won't be surprised if it was trained just based on Eduard's reviews :)
(Actually, are there any details anywhere about this AI?)
next prev parent reply other threads:[~2025-10-02 8:12 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 12:50 [PATCH v5 bpf-next 00/15] BPF indirect jumps Anton Protopopov
2025-09-30 12:50 ` [PATCH v5 bpf-next 01/15] bpf: fix the return value of push_stack Anton Protopopov
2025-09-30 12:50 ` [PATCH v5 bpf-next 02/15] bpf: save the start of functions in bpf_prog_aux Anton Protopopov
2025-10-01 21:53 ` Eduard Zingerman
2025-09-30 12:50 ` [PATCH v5 bpf-next 03/15] bpf: generalize and export map_get_next_key for arrays Anton Protopopov
2025-10-01 21:56 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 04/15] bpf, x86: add new map type: instructions array Anton Protopopov
2025-10-03 0:50 ` Eduard Zingerman
2025-10-03 7:39 ` Anton Protopopov
2025-10-03 8:48 ` Eduard Zingerman
2025-10-03 9:13 ` Anton Protopopov
2025-10-03 17:22 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 05/15] selftests/bpf: add selftests for new insn_array map Anton Protopopov
2025-10-03 1:16 ` Eduard Zingerman
2025-10-03 7:46 ` Anton Protopopov
2025-10-03 8:15 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 06/15] bpf: support instructions arrays with constants blinding Anton Protopopov
2025-10-03 17:38 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 07/15] selftests/bpf: test instructions arrays with blinding Anton Protopopov
2025-10-03 9:00 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 08/15] bpf, x86: allow indirect jumps to r8...r15 Anton Protopopov
2025-10-01 22:03 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 09/15] bpf: make bpf_insn_successors to return a pointer Anton Protopopov
2025-10-01 22:39 ` Eduard Zingerman
2025-10-01 23:49 ` Alexei Starovoitov
2025-10-02 8:19 ` Anton Protopopov [this message]
2025-10-02 16:07 ` Alexei Starovoitov
2025-10-02 8:16 ` Anton Protopopov
2025-10-02 19:35 ` Eduard Zingerman
2025-09-30 12:51 ` [PATCH v5 bpf-next 10/15] bpf, x86: add support for indirect jumps Anton Protopopov
2025-10-02 0:15 ` Eduard Zingerman
2025-10-02 9:27 ` Anton Protopopov
2025-10-02 19:52 ` Eduard Zingerman
2025-10-03 7:04 ` Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 11/15] bpf: disasm: add support for BPF_JMP|BPF_JA|BPF_X Anton Protopopov
2025-10-02 0:18 ` Eduard Zingerman
2025-10-02 7:49 ` Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 12/15] libbpf: fix formatting of bpf_object__append_subprog_code Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 13/15] libbpf: support llvm-generated indirect jumps Anton Protopopov
2025-10-02 21:01 ` Eduard Zingerman
2025-10-03 7:19 ` Anton Protopopov
2025-10-15 15:32 ` Yonghong Song
2025-10-15 17:35 ` Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 14/15] bpftool: Recognize insn_array map type Anton Protopopov
2025-09-30 12:51 ` [PATCH v5 bpf-next 15/15] selftests/bpf: add selftests for indirect jumps Anton Protopopov
2025-10-02 21:07 ` Eduard Zingerman
2025-10-03 7:22 ` Anton Protopopov
2025-10-03 7:29 ` Eduard Zingerman
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=aN41dbxNPIUrKzNz@mail.gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=aspsk@isovalent.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=qmo@kernel.org \
--cc=yonghong.song@linux.dev \
/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.