All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Jiyong Yang <ksur673@gmail.com>
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add more tests for loading insn arrays with offsets
Date: Thu, 2 Apr 2026 08:28:52 +0000	[thread overview]
Message-ID: <ac4oxGJVRYN/K2co@mail.gmail.com> (raw)
In-Reply-To: <680e35d1-04bd-403c-9aca-f2b8a0af9af3@gmail.com>

On 26/04/01 11:38PM, Mykyta Yatsenko wrote:
> 
> 
> On 4/1/26 5:15 PM, Anton Protopopov wrote:
> > A typical series of load instructions for a gotox looks like
> > 
> >     r1 = &map + offset1
> >     r1 += offset2
> >     r1 = *(r1 + offset3)
> >     gotox r1
> > 
> > Here offset3 is, normally, equal to zero; but this is not guaranteed.
> > Extend selftests with tests for non-zero offset3 and, while here, also
> > add tests for negative offsets (the offset1 and the sum of three offsets
> > still have to be non-negative).
> > 
> > Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
> > ---
> >   .../selftests/bpf/prog_tests/bpf_gotox.c      | 114 +++++++++++-------
> >   1 file changed, 73 insertions(+), 41 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c b/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
> > index 75b0cf2467ab..594adf698fdb 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
> > @@ -317,7 +317,7 @@ static void check_ldimm64_off_load(struct bpf_gotox *skel __always_unused)
> >   static int __check_ldimm64_gotox_prog_load(struct bpf_insn *insns,
> >   					   __u32 insn_cnt,
> > -					   __u32 off1, __u32 off2)
> > +					   int off1, int off2, int off3)
> >   {
> >   	const __u32 values[] = {5, 7, 9, 11, 13, 15};
> >   	const __u32 max_entries = ARRAY_SIZE(values);
> > @@ -349,16 +349,46 @@ static int __check_ldimm64_gotox_prog_load(struct bpf_insn *insns,
> >   	/* r1 += off2 */
> >   	insns[2].imm = off2;
> > +	/* r1 = *(r1 + off3) */
> > +	insns[3].off = off3;
> > +
> >   	ret = prog_load(insns, insn_cnt);
> >   	close(map_fd);
> >   	return ret;
> >   }
> > -static void reject_offsets(struct bpf_insn *insns, __u32 insn_cnt, __u32 off1, __u32 off2)
> > +static void
> > +allow_offsets(struct bpf_insn *insns, __u32 insn_cnt, int off1, int off2, int off3)
> > +{
> > +	LIBBPF_OPTS(bpf_test_run_opts, topts);
> > +	int prog_fd, err;
> > +	char s[128] = "";
> > +
> > +	prog_fd = __check_ldimm64_gotox_prog_load(insns, insn_cnt, off1, off2, off3);
> > +	snprintf(s, sizeof(s), "__check_ldimm64_gotox_prog_load(%u,%u,%u)", off1, off2, off3);
> 
> here offsets are int, but printed with %u.

Yes, thanks, fixed.

> > +	if (!ASSERT_GE(prog_fd, 0, s))
> > +		return;
> > +
> > +	err = bpf_prog_test_run_opts(prog_fd, &topts);
> > +	if (!ASSERT_OK(err, "test_run_opts err")) {
> > +		close(prog_fd);
> > +		return;
> > +	}
> > +
> > +	if (!ASSERT_EQ(topts.retval, (off1 + off2 + off3) / 8, "test_run_opts retval")) {
> > +		close(prog_fd);
> > +		return;
> > +	}
> > +
> > +	close(prog_fd);
> > +}
> > +
> > +static void
> > +reject_offsets(struct bpf_insn *insns, __u32 insn_cnt, __u32 off1, __u32 off2, __u32 off3)
> 
> If offsets can be negative, should these arguments be int rather than __u32,
> also matching reject_offsets?

Fixed.

> [...]

      reply	other threads:[~2026-04-02  8:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01 16:15 [PATCH bpf-next 0/2] Properly load values from insn_arays with non-zero offsets Anton Protopopov
2026-04-01 16:15 ` [PATCH bpf-next 1/2] bpf: Do not ignore offsets for loads from insn_arrays Anton Protopopov
2026-04-01 22:47   ` Mykyta Yatsenko
     [not found]     ` <CAGzPb2Ed+Z513yWDUE91H_OP2eF_fHucy_xV3-cpYOkmw73xmg@mail.gmail.com>
2026-04-02  0:27       ` Alexei Starovoitov
2026-04-02  2:37     ` sun jian
2026-04-02  8:37       ` Anton Protopopov
2026-04-02  8:36     ` Anton Protopopov
2026-04-01 16:15 ` [PATCH bpf-next 2/2] selftests/bpf: Add more tests for loading insn arrays with offsets Anton Protopopov
2026-04-01 22:38   ` Mykyta Yatsenko
2026-04-02  8:28     ` Anton Protopopov [this message]

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=ac4oxGJVRYN/K2co@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ksur673@gmail.com \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.