From: Eduard Zingerman <eddyz87@gmail.com>
To: Paul Chaignon <paul.chaignon@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Shung-Hsi Yu <shung-hsi.yu@suse.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: Use tnums for JEQ/JNE is_branch_taken logic
Date: Wed, 13 Aug 2025 11:08:05 -0700 [thread overview]
Message-ID: <814ea1fd4f2186b62a03d5ce195a97ee1446771d.camel@gmail.com> (raw)
In-Reply-To: <ba9baf9f73d51d9bce9ef13778bd39408d67db79.1755098817.git.paul.chaignon@gmail.com>
On Wed, 2025-08-13 at 17:34 +0200, Paul Chaignon wrote:
> In the following toy program (reg states minimized for readability), R0
> and R1 always have different values at instruction 6. This is obvious
> when reading the program but cannot be guessed from ranges alone as
> they overlap (R0 in [0; 0xc0000000], R1 in [1024; 0xc0000400]).
>
> 0: call bpf_get_prandom_u32#7 ; R0_w=scalar()
> 1: w0 = w0 ; R0_w=scalar(var_off=(0x0; 0xffffffff))
> 2: r0 >>= 30 ; R0_w=scalar(var_off=(0x0; 0x3))
> 3: r0 <<= 30 ; R0_w=scalar(var_off=(0x0; 0xc0000000))
> 4: r1 = r0 ; R1_w=scalar(var_off=(0x0; 0xc0000000))
> 5: r1 += 1024 ; R1_w=scalar(var_off=(0x400; 0xc0000000))
> 6: if r1 != r0 goto pc+1
>
> Looking at tnums however, we can deduce that R1 is always different from
> R0 because their tnums don't agree on known bits. This patch uses this
> logic to improve is_scalar_branch_taken in case of BPF_JEQ and BPF_JNE.
>
> This change has a tiny impact on complexity, which was measured with
> the Cilium complexity CI test. That test covers 72 programs with
> various build and load time configurations for a total of 970 test
> cases. For 80% of test cases, the patch has no impact. On the other
> test cases, the patch decreases complexity by only 0.08% on average. In
> the best case, the verifier needs to walk 3% less instructions and, in
> the worst case, 1.5% more. Overall, the patch has a small positive
> impact, especially for our largest programs.
>
> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
> ---
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Note: CI reports verifier performance differences for Meta internal programs:
https://github.com/kernel-patches/bpf/actions/runs/16942287206
But I can't confirm the difference after running veristat for these programs,
looks like a CI glitch.
[...]
next prev parent reply other threads:[~2025-08-13 18:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 15:34 [PATCH bpf-next 1/2] bpf: Use tnums for JEQ/JNE is_branch_taken logic Paul Chaignon
2025-08-13 15:35 ` [PATCH bpf-next 2/2] selftests/bpf: Tests for is_scalar_branch_taken tnum logic Paul Chaignon
2025-08-13 18:34 ` Eduard Zingerman
2025-08-13 18:08 ` Eduard Zingerman [this message]
2025-08-14 12:55 ` [PATCH bpf-next 1/2] bpf: Use tnums for JEQ/JNE is_branch_taken logic Shung-Hsi Yu
2025-08-18 17:44 ` Paul Chaignon
2025-08-20 5:09 ` Shung-Hsi Yu
2025-08-21 9:40 ` Paul Chaignon
2025-08-15 8:24 ` [syzbot ci] " syzbot ci
2025-08-20 11:34 ` Paul Chaignon
2025-08-20 19:37 ` Eduard Zingerman
2025-08-21 10:04 ` 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=814ea1fd4f2186b62a03d5ce195a97ee1446771d.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=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;
as well as URLs for NNTP newsgroup(s).