From: Eduard Zingerman <eddyz87@gmail.com>
To: Tianci Cao <ziye@zju.edu.cn>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me,
haoluo@google.com, jolsa@kernel.org, tangyazhou518@outlook.com,
shenghaoyuan0928@163.com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add tests for BPF_END bitwise tracking
Date: Mon, 02 Feb 2026 12:23:27 -0800 [thread overview]
Message-ID: <b68a122d7a0b046a9ca5527bcf9f50dfea183ce9.camel@gmail.com> (raw)
In-Reply-To: <20260202133536.66207-3-ziye@zju.edu.cn>
On Mon, 2026-02-02 at 21:35 +0800, Tianci Cao wrote:
> Now BPF_END has bitwise tracking support. This patch adds selftests to
> cover various cases of BPF_END (`bswap(16|32|64)`, `be(16|32|64)`,
> `le(16|32|64)`) with bitwise propagation.
>
> This patch is based on existing `verifier_bswap.c`, and add several
> types of new tests:
>
> 1. Unconditional byte swap operations:
> - bswap16: port number routing (network byte order conversion)
> - bswap32: IPv4 subnet routing (network byte order conversion)
> - bswap64: IPv6 subnet routing (network byte order conversion)
>
> 2. Endian conversion operations (architecture-aware):
> - be16/be32/be64: convert to big-endian
> * on little-endian: do swap
> * on big-endian: truncation (16/32-bit) or no-op (64-bit)
> - le16/le32/le64: convert to little-endian
> * on big-endian: do swap
> * on little-endian: truncation (16/32-bit) or no-op (64-bit)
>
> Each test simulates realistic networking scenarios where a value is
> masked to a specific range (e.g., 0x3f00), then byte-swapped, and the
> verifier must prove the result stays within expected bounds.
>
> Specifically, these selftests are based on dead code elimination:
> If the BPF verifier can precisely track bitwise through byte swap
> operations, it can prune the trap path (invalid memory access) that
> should be unreachable, allowing the program to pass verification.
> If bitwise tracking is incorrect, the verifier cannot prove the trap
> is unreachable, causing verification failure.
>
> The tests use preprocessor conditionals (#ifdef __BYTE_ORDER__) to
> verify correct behavior on both little-endian and big-endian
> architectures, and require Clang 18+ for bswap instruction support.
>
> Co-developed-by: Shenghao Yuan <shenghaoyuan0928@163.com>
> Signed-off-by: Shenghao Yuan <shenghaoyuan0928@163.com>
> Co-developed-by: Yazhou Tang <tangyazhou518@outlook.com>
> Signed-off-by: Yazhou Tang <tangyazhou518@outlook.com>
> Signed-off-by: Tianci Cao <ziye@zju.edu.cn>
> ---
Test cases themselves lgtm.
Essentially you have two groups of tests that follow same template:
- bswap16_port_routing, bswap32_ipv4_subnet_routing, bswap64_ipv6_subnet_routing
(why not just bswap16/32/64 as names, by the way?);
- be16_network, be32_network, be64_network, le16_network, le32_network, le64_network.
Maybe define two macros using bswap64_ipv6_subnet_routing and
le64_network as templates to avoid the copy-paste?
E.g. like DEFINE_BAD_OFFSET_TEST in verifier_value_illegal_alu.c.
Also, could you please cut the amount of comments,
test cases are quite self explaining.
[...]
next prev parent reply other threads:[~2026-02-02 20:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 13:35 [PATCH bpf-next 0/2] bpf: Add bitwise tracking for BPF_END Tianci Cao
2026-02-02 13:35 ` [PATCH bpf-next 1/2] " Tianci Cao
2026-02-02 20:03 ` Eduard Zingerman
2026-02-03 10:17 ` Tianci Cao
2026-02-03 22:36 ` Eduard Zingerman
2026-02-02 13:35 ` [PATCH bpf-next 2/2] selftests/bpf: Add tests for BPF_END bitwise tracking Tianci Cao
2026-02-02 20:23 ` Eduard Zingerman [this message]
2026-02-03 10:20 ` Tianci Cao
2026-02-03 23:16 ` Eduard Zingerman
2026-02-04 6:08 ` Tianci Cao
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=b68a122d7a0b046a9ca5527bcf9f50dfea183ce9.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=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=shenghaoyuan0928@163.com \
--cc=song@kernel.org \
--cc=tangyazhou518@outlook.com \
--cc=yonghong.song@linux.dev \
--cc=ziye@zju.edu.cn \
/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