From: Eduard Zingerman <eddyz87@gmail.com>
To: Paul Chaignon <paul.chaignon@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>,
Srinivas Narayana <srinivas.narayana@rutgers.edu>,
Santosh Nagarakatte <santosh.nagarakatte@rutgers.edu>
Subject: Re: [PATCH v2 bpf 3/4] selftests/bpf: Test refinement of single-value tnum
Date: Thu, 26 Feb 2026 01:27:23 -0800 [thread overview]
Message-ID: <da102d447848a34cf13b2f490eded8d6afa056aa.camel@gmail.com> (raw)
In-Reply-To: <aZ7NOlhsG5RZIhIl@Tunnel>
On Wed, 2026-02-25 at 11:21 +0100, Paul Chaignon wrote:
> On Fri, Feb 20, 2026 at 04:20:55PM -0800, Eduard Zingerman wrote:
> > On Fri, 2026-02-20 at 14:57 +0100, Paul Chaignon wrote:
> > > This patch introduces selftests to cover the new bounds refinement
> > > logic introduced in the previous patch. Without the previous patch,
> > > the first two tests fail because of the invariant violation they
> > > trigger. The last test fails because the R10 access is not detected as
> > > dead code. In addition, all tests fail because of R0 having a
> > > non-constant value in the verifier logs.
> > >
> > > Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
> > > ---
> >
> > Hi Paul,
>
> Hi Eduard,
>
> Sorry for the late answer, I've been travelling.
>
> >
> > I have a few nitpicks, sorry for not commenting about it in v1.
>
> No worries. The AI bot also found a new small thing :')
>
> I noticed you haven't acked the first patch. I think it's a bit thougher
> to follow, so is there anything we could do to ease review?
It made sense on the first pass, comments help.
Let me re-read it tomorrow, but I assume this patch works.
> >
> > > .../selftests/bpf/progs/verifier_bounds.c | 91 +++++++++++++++++++
> > > 1 file changed, 91 insertions(+)
> > >
> > > diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c
> > > b/tools/testing/selftests/bpf/progs/verifier_bounds.c
> > > index 560531404bce..41dd249faadd 100644
> > > --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c
> > > +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c
> > > @@ -1863,4 +1863,95 @@ l1_%=: r0 = 1; \
> > > : __clobber_all);
> > > }
> > >
> > > +/* This test covers the bounds deduction when the u64 range and the tnum
> > > + * overlap only at umax. After instruction 3, the ranges look as follows:
> > > + *
> > > + * 0 umin=0xe01 umax=0xf00 U64_MAX
> > > + * | [xxxxxxxxxxxxxx] |
> > > + * |----------------------------|------------------------------|
> > > + * | x x | tnum values
> > > + *
> > > + * The verifier can therefore deduce that the R0=0xf00=3840.
> > > + */
> > > +SEC("socket")
> > > +__description("bounds refinement with single-value tnum on umax")
> > > +__msg("3: (15) if r0 == 0xe00 {{.*}} R0=3840")
> > > +__success __log_level(2)
> > > +__flag(BPF_F_TEST_REG_INVARIANTS)
> > > +__naked void bounds_refinement_tnum_umax(void *ctx)
> > > +{
> > > + asm volatile(" \
> > > + call %[bpf_get_prandom_u32]; \
> > > + r0 |= 0xe00; \
> > > + r0 &= 0xf00; \
> > > + if r0 == 0xe00 goto +2; \
> > > + if r0 == 0xf00 goto +1; \
> > > + r0 = 0; \
> >
> > Nit: make this `r10 = 0;`, just like in the last test?
> > (and in the next test).
> >
> > Also, the test works the same if I replace 0xe00 -> 0xe, 0xf00 -> 0xf.
> > Maybe pick the smaller constants to ease the readability?
>
> If we switch to 0xe and 0xf, the test won't validate the changes
> anymore: it will pass regardless of the second patch. That's because
> the range would only contain two values. We can however change it to
> 0xe0 and 0xf0.
You mean that min/max logic for 'r0 == 0xe' will adjust the range, right?
Makes sense, no changes necessary then.
>
> [...]
>
> > Also, I think a few more tests are necessary, there are three cases:
> >
> > if (umin_in_tnum && tnum_next > reg->umax_value) { // A
> > ...
> > } else if (!umin_in_tnum && tnum_next == tmax) { // B
> > ...
> > } else if (!umin_in_tnum && tnum_next <= reg->umax_value && // C
> > ...
> > }
> >
> > If I remove 'umin_in_tnum &&' from A no tests fail.
>
> That would be expected. As you pointed out in the v1, this part of the
> condition is not strictly necessary because it should be implied by the
> second part. We ended up adding it just for readability.
Wellp, that's a bit embarrassing, sorry for the noise.
> > If I remove '!umin_in_tnum &&' from B or C test cases
> > 'verifier_bounds/verifier_bounds/bounds check based on reg_off + var_off + insn_off. test{1,2}'
> > fail,
> > but these seem unrelated.
> > Maybe craft a few test cases covering these conditions?
>
> Ack. I'll include the two cases I mentioned when discussing this in the
> v1.
>
> Thanks for the review!
next prev parent reply other threads:[~2026-02-26 9:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 13:55 [PATCH v2 bpf 0/4] Fix invariant violation for single-value tnums Paul Chaignon
2026-02-20 13:56 ` [PATCH v2 bpf 1/4] bpf: Introduce tnum_step to step through tnum's members Paul Chaignon
2026-02-20 13:57 ` [PATCH v2 bpf 2/4] bpf: Improve bounds when tnum has a single possible value Paul Chaignon
2026-02-20 14:29 ` bot+bpf-ci
2026-02-20 23:27 ` Eduard Zingerman
2026-02-20 13:57 ` [PATCH v2 bpf 3/4] selftests/bpf: Test refinement of single-value tnum Paul Chaignon
2026-02-21 0:20 ` Eduard Zingerman
2026-02-25 10:21 ` Paul Chaignon
2026-02-26 9:27 ` Eduard Zingerman [this message]
2026-02-20 13:58 ` [PATCH v2 bpf 4/4] selftests/bpf: Avoid simplification of crafted bounds test Paul Chaignon
2026-02-21 0:34 ` Eduard Zingerman
2026-02-20 19:45 ` [PATCH v2 bpf 0/4] Fix invariant violation for single-value tnums Marco Schirrmeister
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=da102d447848a34cf13b2f490eded8d6afa056aa.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=harishankar.vishwanathan@gmail.com \
--cc=paul.chaignon@gmail.com \
--cc=santosh.nagarakatte@rutgers.edu \
--cc=srinivas.narayana@rutgers.edu \
/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