BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Puranjay Mohan <puranjay@kernel.org>, bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay12@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau	 <martin.lau@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	kernel-team@meta.com
Subject: Re: [PATCH bpf-next 2/3] selftests/bpf: Add tests for linked register tracking with negative offsets
Date: Wed, 07 Jan 2026 22:55:17 -0800	[thread overview]
Message-ID: <c58877171779ba86762ff413007a61227e7a928c.camel@gmail.com> (raw)
In-Reply-To: <20260107203941.1063754-3-puranjay@kernel.org>

On Wed, 2026-01-07 at 12:39 -0800, Puranjay Mohan wrote:

[...]

> +/*
> + * Test that sync_linked_regs() correctly handles large offset differences.
> + * r1.off = S32_MIN, r2.off = 1, delta = S32_MIN - 1 requires 64-bit math.
> + */
> +SEC("socket")
> +__description("scalars: linked regs sync with large delta (S32_MIN offset)")
> +__success
> +__naked void scalars_sync_delta_overflow(void)
> +{
> +	asm volatile ("					\
> +	call %[bpf_get_prandom_u32];			\
> +	r0 &= 0xff;					\
> +	r1 = r0;					\
> +	r2 = r0;					\
> +	r1 += %[s32_min];				\
> +	r2 += 1;					\
> +	if r2 s< 100 goto l2_overflow;			\

If I remove the above check the test case still passes.
What is the purpose of the test?
If the purpose is to check that S32_MIN can be used as delta for
BPF_ADD operations, then constants in the second comparison should be
picked in a way for comparison to be unpredictable w/o first comparison.

> +	if r1 s< 0 goto l2_overflow;			\

> +	r0 /= 0;					\
> +l2_overflow:						\
> +	r0 = 0;						\
> +	exit;						\
> +"	:
> +	: __imm(bpf_get_prandom_u32),
> +	  [s32_min]"i"((int)(-2147483647 - 1))
> +	: __clobber_all);
> +}
> +
> +/*
> + * Another large delta case: r1.off = S32_MAX, r2.off = -1.
> + * delta = S32_MAX - (-1) = S32_MAX + 1 requires 64-bit math.
> + */
> +SEC("socket")
> +__description("scalars: linked regs sync with large delta (S32_MAX offset)")
> +__success
> +__naked void scalars_sync_delta_overflow_large_range(void)
> +{
> +	asm volatile ("					\
> +	call %[bpf_get_prandom_u32];			\
> +	r0 &= 0xff;					\
> +	r1 = r0;					\
> +	r2 = r0;					\
> +	r1 += %[s32_max];				\
> +	r2 += -1;					\
> +	if r2 s< 0 goto l2_large;			\

Same issue here.

> +	if r1 s>= 0 goto l2_large;			\
> +	r0 /= 0;					\
> +l2_large:						\
> +	r0 = 0;						\
> +	exit;						\
> +"	:
> +	: __imm(bpf_get_prandom_u32),
> +	  [s32_max]"i"((int)2147483647)
                       ^^^^^^^^^^^^^^^
Out of curiosity, did you write this by hand or was it generated?

> +	: __clobber_all);
> +}
> +
>  char _license[] SEC("license") = "GPL";

  parent reply	other threads:[~2026-01-08  6:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 20:39 [PATCH bpf-next 0/3] bpf: Improve linked register tracking Puranjay Mohan
2026-01-07 20:39 ` [PATCH bpf-next 1/3] bpf: Support negative offsets and BPF_SUB for " Puranjay Mohan
2026-01-08  1:40   ` Eduard Zingerman
2026-01-08  1:47     ` Eduard Zingerman
2026-01-08  2:53       ` Alexei Starovoitov
2026-01-07 20:39 ` [PATCH bpf-next 2/3] selftests/bpf: Add tests for linked register tracking with negative offsets Puranjay Mohan
2026-01-08  2:11   ` Eduard Zingerman
2026-01-21  0:46     ` __description(). Was: " Alexei Starovoitov
2026-01-08  6:55   ` Eduard Zingerman [this message]
2026-01-08 11:33     ` Puranjay Mohan
2026-01-07 20:39 ` [PATCH bpf-next 3/3] selftests/bpf: Update expected output for sub64_partial_overflow test Puranjay Mohan
2026-01-08  6:59   ` Eduard Zingerman
2026-01-08 10:39     ` Puranjay Mohan

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=c58877171779ba86762ff413007a61227e7a928c.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=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=puranjay12@gmail.com \
    --cc=puranjay@kernel.org \
    /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