From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yonghong.song@linux.dev, sunhao.th@gmail.com
Subject: Re: [PATCH bpf-next v2 1/3] bpf: track find_equal_scalars history on per-instruction level
Date: Tue, 09 Jul 2024 23:36:00 -0700 [thread overview]
Message-ID: <61b1630295c8df2f78ffabfc1768c521b69a705f.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzbnduEs50kcFbN=jR1otTBtbqxrQrtRHo8iF4b=j_onUw@mail.gmail.com>
On Tue, 2024-07-09 at 22:28 -0700, Andrii Nakryiko wrote:
[...]
> > > > r2 = r10 |
> > > > r2 += r0 v mark_chain_precision(r0)
> > > >
> > > > while doing mark_chain_precision(r0)
> > > > r1 = r0 ^
> > > > if r1 < 8 goto ... | mark r0,r1 as precise
> > > > if r0 > 16 goto ... | mark r0,r1 as precise
> > > > r2 = r10 |
> > > > r2 += r0 | mark r0 precise
> > >
> > > let's reverse the order here so it's linear in how the algorithm
> > > actually works (backwards)?
> >
> > I thought the arrow would be enough. Ok, can reverse.
>
> it's the reverse order compared to what you'd see in the verifier log.
> I did see the arrow (though it wasn't all that clear on the first
> reading), but still feels like it would be better to have consistent
> order with verifier log
Ok, no problem
>
> [...]
>
> > > > @@ -3844,6 +3974,7 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,
> > > > */
> > > > bt_set_reg(bt, dreg);
> > > > bt_set_reg(bt, sreg);
> > > > + } else if (BPF_SRC(insn->code) == BPF_K) {
> > > > /* else dreg <cond> K
> > >
> > > drop "else" from the comment then? I like this change.
> >
> > This is actually a leftover from v1. I can drop "else" from the
> > comment or drop this hunk as it is not necessary for the series.
>
> I'd keep explicit `else if`
Ok, will do
[...]
> > > > @@ -15312,6 +15500,21 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
> > > > return 0;
> > > > }
> > > >
> > > > + /* Push scalar registers sharing same ID to jump history,
> > > > + * do this before creating 'other_branch', so that both
> > > > + * 'this_branch' and 'other_branch' share this history
> > > > + * if parent state is created.
> > > > + */
> > > > + if (BPF_SRC(insn->code) == BPF_X && src_reg->type == SCALAR_VALUE && src_reg->id)
> > > > + find_equal_scalars(this_branch, src_reg->id, &linked_regs);
> > > > + if (dst_reg->type == SCALAR_VALUE && dst_reg->id)
> > > > + find_equal_scalars(this_branch, dst_reg->id, &linked_regs);
> > > > + if (linked_regs.cnt > 1) {
> > >
> > > if we have just one, should it be even marked as linked?
> >
> > Sorry, I don't understand. Do you suggest to add an additional check
> > in find_equal_scalars/collect_linked_regs and reset it if 'cnt' equals 1?
>
> I find `if (linked_regs.cnt > 1)` check a bit weird and it feels like
> it should be unnecessary. As soon as we are left with just one
> "linked" register (linked with what? with itself?) it shouldn't be
> linked anymore. Is there a point where we break the link between
> registers where we can/should drop ID from the singularly linked
> register? Why keep that scalar register ID set?
I can push this check inside find_equal_scalars/collect_linked_regs, e.g.:
collect_linked_regs(... linked_regs ...)
{
...
if (linked_regs.cnt == 1)
linked_regs.cnt = 0;
...
}
But then this particular place would have to be modified as follows:
if (linked_regs.cnt > 0) {
err = push_jmp_history(env, this_branch, 0, linked_regs_pack(&linked_regs));
if (err)
return err;
}
Or something similar has to be done inside push_jmp_history().
[...]
next prev parent reply other threads:[~2024-07-10 6:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 20:58 [PATCH bpf-next v2 0/3] bpf: track find_equal_scalars history on per-instruction level Eduard Zingerman
2024-07-05 20:58 ` [PATCH bpf-next v2 1/3] " Eduard Zingerman
2024-07-10 0:34 ` Andrii Nakryiko
2024-07-10 1:21 ` Eduard Zingerman
2024-07-10 5:28 ` Andrii Nakryiko
2024-07-10 6:36 ` Eduard Zingerman [this message]
2024-07-10 15:21 ` Andrii Nakryiko
2024-07-05 20:58 ` [PATCH bpf-next v2 2/3] bpf: remove mark_precise_scalar_ids() Eduard Zingerman
2024-07-05 20:58 ` [PATCH bpf-next v2 3/3] selftests/bpf: tests for per-insn find_equal_scalars() precision tracking 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=61b1630295c8df2f78ffabfc1768c521b69a705f.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=sunhao.th@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox