From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org
Cc: daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yonghong.song@linux.dev, shung-hsi.yu@suse.com,
paul.chaignon@gmail.com, harishankar.vishwanathan@gmail.com
Subject: Re: [PATCH RFC bpf-next 3/4] bpf: replace min/max fields with struct cnum{32,64}
Date: Tue, 21 Apr 2026 10:20:37 -0700 [thread overview]
Message-ID: <b74aadc5d26466a4558bed01e0e1e8a1d9b96ae1.camel@gmail.com> (raw)
In-Reply-To: <DHZ04PGE9D6Y.356RPW2LMPPIT@gmail.com>
On Tue, 2026-04-21 at 10:16 -0700, Alexei Starovoitov wrote:
> On Tue Apr 21, 2026 at 9:48 AM PDT, Eduard Zingerman wrote:
> > On Tue, 2026-04-21 at 09:23 -0700, Alexei Starovoitov wrote:
> > > On Tue Apr 21, 2026 at 3:28 AM PDT, Eduard Zingerman wrote:
> > > >
> > > > static void scalar32_min_max_udiv(struct bpf_reg_state *dst_reg,
> > > > @@ -14119,7 +13548,6 @@ static void scalar32_min_max_udiv(struct bpf_reg_state *dst_reg,
> > > > reg_u32_max(dst_reg) / src_val);
> > > >
> > > > /* Reset other ranges/tnum to unbounded/unknown. */
> > > > - reg_set_srange32(dst_reg, S32_MIN, S32_MAX);
> > > > reset_reg64_and_tnum(dst_reg);
> > > > }
> > >
> > > div/mod don't need special cnum_div ?
> >
> > There is an algorithm for that in the paper, but it turned out to be
> > unnecessary for our verification purposes. At-least for the corpora of
> > programs I used for testing. I didn't try the "dumb" multiplication
> > version, expect it to fail for cross sign-domains cases.
> >
> > >
> > > > @@ -15861,38 +15209,54 @@ static void regs_refine_cond_op(struct bpf_reg_state *reg1, struct bpf_reg_state
> > > > break;
> > > > case BPF_JLE:
> > > > if (is_jmp32) {
> > > > - reg_set_urange32(reg1, reg_u32_min(reg1), min(reg_u32_max(reg1), reg_u32_max(reg2)));
> > > > - reg_set_urange32(reg2, max(reg_u32_min(reg1), reg_u32_min(reg2)), reg_u32_max(reg2));
> > > > + lo32 = cnum32_from_urange(0, reg_u32_max(reg2));
> > > > + hi32 = cnum32_from_urange(reg_u32_min(reg1), U32_MAX);
> > > > + reg1->r32 = cnum32_intersect(reg1->r32, lo32);
> > > > + reg2->r32 = cnum32_intersect(reg2->r32, hi32);
> > > > } else {
> > > > - reg_set_urange64(reg1, reg_umin(reg1), min(reg_umax(reg1), reg_umax(reg2)));
> > > > - reg_set_urange64(reg2, max(reg_umin(reg1), reg_umin(reg2)), reg_umax(reg2));
> > > > + lo = cnum64_from_urange(0, reg_umax(reg2));
> > > > + hi = cnum64_from_urange(reg_umin(reg1), U64_MAX);
> > > > + reg1->r64 = cnum64_intersect(reg1->r64, lo);
> > > > + reg2->r64 = cnum64_intersect(reg2->r64, hi);
> > >
> > > Maybe a helper like:
> > > cnum64_intersect_with_range(®1->r64, 0, reg_umax(reg2));
> > > ?
> > >
> > > Also I found only one case:
> > > dst_reg->r64 = cnum64_intersect(u, s);
> > >
> > > all others dst and src are the same.
> > > So maybe:
> > > cnum64_intersect(&dst_reg->r64, ..);
> > > as a main helper and __cnum64_intersect(r->r64, ...) as a subhelper that returns cnum?
> >
> > Are you concerned about machine code inefficiencies from struct cnum
> > being passed around as a temporary/parameter/return value? Since cnum
> > functions are in a separate compilation unit, I'd guess there won't be
> > much optimization outside LTO builds.
> > Or do you just like the &r->r64 notation more?
>
> The latter. Just less verbose and less error prone.
> While looking at the diff I kept comparing both sides of '='.
> Just unnecessary mental overhead.
Funny thing is, I find the explicit '=' style easier to read :)
Anyway, can change to &r->r64 if people like it more.
next prev parent reply other threads:[~2026-04-21 17:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 10:28 [PATCH RFC bpf-next 0/4] bpf: replace min/max fields with struct cnum{32,64} Eduard Zingerman
2026-04-21 10:28 ` [PATCH RFC bpf-next 1/4] bpf: representation and basic operations on circular numbers Eduard Zingerman
2026-04-21 11:16 ` bot+bpf-ci
2026-04-21 17:18 ` sashiko-bot
2026-04-21 17:45 ` Eduard Zingerman
2026-04-21 10:28 ` [PATCH RFC bpf-next 2/4] bpf: use accessor functions for bpf_reg_state min/max fields Eduard Zingerman
2026-04-21 10:28 ` [PATCH RFC bpf-next 3/4] bpf: replace min/max fields with struct cnum{32,64} Eduard Zingerman
2026-04-21 11:16 ` bot+bpf-ci
2026-04-21 16:23 ` Alexei Starovoitov
2026-04-21 16:48 ` Eduard Zingerman
2026-04-21 17:16 ` Alexei Starovoitov
2026-04-21 17:20 ` Eduard Zingerman [this message]
2026-04-21 18:06 ` sashiko-bot
2026-04-21 18:31 ` Eduard Zingerman
2026-04-21 10:28 ` [PATCH RFC bpf-next 4/4] selftests/bpf: new cases handled by 32->64 range refinements Eduard Zingerman
2026-04-21 16:10 ` [PATCH RFC bpf-next 0/4] bpf: replace min/max fields with struct cnum{32,64} Alexei Starovoitov
2026-04-21 16:33 ` Eduard Zingerman
2026-04-21 17:14 ` Alexei Starovoitov
2026-04-21 23:45 ` Eduard Zingerman
2026-04-22 14:50 ` Yazhou Tang
2026-04-22 15:03 ` Alexei Starovoitov
2026-04-22 15:32 ` Yazhou Tang
2026-04-22 16:13 ` Alexei Starovoitov
2026-04-22 19:05 ` 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=b74aadc5d26466a4558bed01e0e1e8a1d9b96ae1.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@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=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=paul.chaignon@gmail.com \
--cc=shung-hsi.yu@suse.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