public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Chaignon <paul.chaignon@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>,
	bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Srinivas Narayana <srinivas.narayana@rutgers.edu>,
	Santosh Nagarakatte <santosh.nagarakatte@rutgers.edu>
Subject: Re: [PATCH bpf 2/4] bpf: Improve bounds when tnum has a single possible value
Date: Thu, 19 Feb 2026 19:55:29 +0100	[thread overview]
Message-ID: <aZdcoaH9ERUNpln1@mail.gmail.com> (raw)
In-Reply-To: <5044b1d83c3c916c0754eb5556008316c36c15ae.camel@gmail.com>

On Thu, Feb 19, 2026 at 10:32:19AM -0800, Eduard Zingerman wrote:
> On Wed, 2026-02-18 at 01:06 -0500, Harishankar Vishwanathan wrote:
> > On Tue, Feb 17, 2026 at 5:58 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > [...]
> > > > 1. The u64 range and the tnum only overlap in umin.
> > > >    u64:  ---[xxxxxx]-----
> > > >    tnum: --xx----------x-
> > > I think this hunk should be rewritten as follows:
> > > 
> > >         tnum_next = tnum_step(reg->var_off, reg->umin_value);
> > >         tnum_max = reg->var_off.value | reg->var_off.mask;
> > >         tnum_min = reg->var_off.value;
> > >         if (tnum_next > reg->umax_value) {
> > >                 /* The only overlap is umin */
> > >                 ___mark_reg_known(reg, tnum_min);
> > >         } else if (tnum_min < reg->umin_value && tnum_next == tnum_max) {
> > >                 /* The only overlap is tmax */
> > >                 ___mark_reg_known(reg, tnum_next);
> > >         } else if (tnum_next <= reg->umax_value &&
> > >                    tnum_step(reg->var_off, tnum_next) > reg->umax_value) {
> > >                 ___mark_reg_known(reg, tnum_next);
> > >         }
> > > 
> > > - At-least to me, it easier to understand this way.

Agree. That looks easier to parse to me too. Thanks!

> > 
> > We can also use tmin and tmax, like tnum_step from the previous commit does,
> > to keep things consistent.
> > 
> > > - There is no need to gate the condition `tnum_next > reg->umax_value`,
> > >   if next tnum overshoots the reg->umax_value then only tnum_min is left.
> > 
> 
> Hi Harishankar,
> 
> Sorry for delayed response.
> 
> > The guard helps avoid the case where u64 and tnum have no intersection:
> > u64:  ---[xxxxxx]-----
> > tnum: x------------x-
> > 
> > The entire condition for "only overlap of tnum is with umin" needs to check both
> > (1) if umin is a member of var_off
> > (2) if the next member of var_off after umin > umax.
> 
> Right before the hunk there is:
> 
>   reg->umin_value = max(reg->umin_value, reg->var_off.value);
> 
> Which implies that:
> 
>   tnum_min <= reg->umin_value
> 
> My mental model for register sync functions is that all ranges are
> considered valid, hence I suggested dropping the check.

I think I agree with that, especially considering the reg->umin_value
computation above. If we think we need extra checks to be on the safe
side, they should probably live in reg_bounds_sanity_check.

> If you think the check should be preserved, maybe still rewrite it like:
> 
>   tnum_min == reg->umin_value && tnum_next > reg->umax_value
> 
> That's a bit easier to parse compared to
> '(reg->umin_value & ~reg->var_off.mask) == reg->var_off.value'.
> Wdyt?
> 
> > 
> > > - Accidentally, it fixes the scx_cosmos regression
> > >   (probably, because first condition is relaxed).
> 
> I double-checked scx_cosmos with current master, patch as posted and
> patch with my changes, in all three cases I see:
> 
> File              Program             Verdict  Insns
> ----------------  ------------------  -------  -----
> scx_cosmos.bpf.o  cosmos_select_cpu   success    475
> 
> So, I'm not sure why CI flagged this as +500%.

Ok, that's reassuring. I was going crazy trying to understand how your
changes could have fixed this given the semantics should be unchanged.

I'm re-testing the patchset on Cilium just to be sure, and I'll send a
v2 afterward. Thanks for the review!

  reply	other threads:[~2026-02-19 18:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-17  8:53 [PATCH bpf 0/4] Fix invariant violation for single-value tnums Paul Chaignon
2026-02-17  8:59 ` [PATCH bpf 1/4] bpf: Introduce tnum_step to step through tnum's members Paul Chaignon
2026-02-17  9:44   ` bot+bpf-ci
2026-02-18  2:36     ` Harishankar Vishwanathan
2026-02-18  2:51       ` Alexei Starovoitov
2026-02-18  6:17         ` Harishankar Vishwanathan
2026-02-17  9:01 ` [PATCH bpf 2/4] bpf: Improve bounds when tnum has a single possible value Paul Chaignon
2026-02-17 18:58   ` Alexei Starovoitov
2026-02-17 22:57   ` Eduard Zingerman
2026-02-18  6:06     ` Harishankar Vishwanathan
2026-02-19 18:32       ` Eduard Zingerman
2026-02-19 18:55         ` Paul Chaignon [this message]
2026-02-20  0:13           ` Paul Chaignon
2026-02-20  1:29             ` Eduard Zingerman
2026-02-20  6:34               ` Harishankar Vishwanathan
2026-02-20 14:02                 ` Paul Chaignon
2026-02-17  9:04 ` [PATCH bpf 3/4] selftests/bpf: Test refinement of single-value tnum Paul Chaignon
2026-02-17  9:06 ` [PATCH bpf 4/4] selftests/bpf: Avoid simplification of crafted bounds test Paul Chaignon

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=aZdcoaH9ERUNpln1@mail.gmail.com \
    --to=paul.chaignon@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=harishankar.vishwanathan@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