All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Anton Protopopov <aspsk@isovalent.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Quentin Monnet <qmo@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH v3 bpf-next 13/13] selftests/bpf: add selftests for indirect jumps
Date: Thu, 25 Sep 2025 18:14:05 +0000	[thread overview]
Message-ID: <aNWGbdMKci1gu2iU@mail.gmail.com> (raw)
In-Reply-To: <8f529733004eed937b92cc7afab25a6f288b29aa.camel@gmail.com>

On 25/09/20 03:27PM, Eduard Zingerman wrote:
> On Fri, 2025-09-19 at 17:58 -0700, Eduard Zingerman wrote:
> > On Thu, 2025-09-18 at 09:38 +0000, Anton Protopopov wrote:
> > > Add selftests for indirect jumps. All the indirect jumps are
> > > generated from C switch statements, so, if compiled by a compiler
> > > which doesn't support indirect jumps, then should pass as well.
> > >
> > > Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
> > > ---
> >
> > Patch #8 adds a lot of error conditions that are effectively untested
> > at the moment. I think we need to figure out a way to express gotox
> > tests in inline assembly, independent of clang version, and add a
> > bunch of correctness tests.
> >
> > [...]
> 
> Here is an example (I modifier verifier_and.c, the patch should use
> some verifier_gotox.c, of course):
> 
>   #include <linux/bpf.h>
>   #include <bpf/bpf_helpers.h>
>   #include "bpf_misc.h"
>   #include "../../../include/linux/filter.h"
> 
>   SEC("socket")
>   __success
>   __retval(1)
>   __naked void jump_table1(void)
>   {
>   	asm volatile (
>   ".pushsection .jumptables,\"\",@progbits;\n"
>   "jt0_%=:\n"
>   	".quad ret0_%=;\n"
>   	".quad ret1_%=;\n"
>   ".size jt0_%=, 16;\n"
>   ".global jt0_%=;\n"
>   ".popsection;\n"
> 
>   	"r0 = jt0_%= ll;\n"
>   	"r0 += 8;\n"
>   	"r0 = *(u64 *)(r0 + 0);\n"
>   	".8byte %[gotox_r0];\n"
>   "ret0_%=:\n"
>   	"r0 = 0;\n"
>   	"exit;\n"
>   "ret1_%=:\n"
>   	"r0 = 1;\n"
>   	"exit;\n"
>   	:
>   	: __imm_insn(gotox_r0, BPF_RAW_INSN(BPF_JMP | BPF_JA | BPF_X, BPF_REG_0, 0, 0 , 0))
>   	: __clobber_all);
>   }
> 
>   char _license[] SEC("license") = "GPL";
> 
> It verifies and executes (having fix for emit_indirect_jump() applied):
> 
>   VERIFIER LOG:
>   =============
>   func#0 @0
>   Live regs before insn:
>         0: .......... (18) r0 = 0xffff888108c66700
>         2: 0......... (07) r0 += 8
>         3: 0......... (79) r0 = *(u64 *)(r0 +0)
>         4: .......... (0d) gotox r0
>         5: .......... (b7) r0 = 0
>         6: 0......... (95) exit
>         7: .......... (b7) r0 = 1
>         8: 0......... (95) exit
>   Global function jump_table1() doesn't return scalar. Only those are supported.
>   0: R1=ctx() R10=fp0
>   ; asm volatile ( @ verifier_and.c:122
>   0: (18) r0 = 0xffff888108c66700       ; R0_w=map_value(map=jt,ks=4,vs=8)
>   2: (07) r0 += 8                       ; R0_w=map_value(map=jt,ks=4,vs=8,off=8)
>   3: (79) r0 = *(u64 *)(r0 +0)          ; R0_w=insn(off=8)
>   4: (0d) gotox r0
>   7: (b7) r0 = 1                        ; R0_w=1
>   8: (95) exit
>   processed 6 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
>   =============
>   do_prog_test_run:PASS:bpf_prog_test_run 0 nsec
>   #488/1   verifier_and/jump_table1:OK
>   #488     verifier_and:OK
>   Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
> 
> This example can be mutated in various ways to check behaviour and
> error conditions.
> 
> Having such complete set of such tests, I'd only keep a few canary
> C-level tests.

Thanks a lot, I can use it for sure!

As for C-level tests, I want to keep a bunch of them in any
case to test libbpf operations.

(I also remember your request to extend compute_live_registers,
just didn't have time to get to it yet.)

  parent reply	other threads:[~2025-09-25 18:08 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18  9:38 [PATCH v3 bpf-next 00/13] BPF indirect jumps Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 01/13] bpf: fix the return value of push_stack Anton Protopopov
2025-09-19  0:17   ` Eduard Zingerman
2025-09-19  7:18     ` Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 02/13] bpf: save the start of functions in bpf_prog_aux Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 03/13] bpf, x86: add new map type: instructions array Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 04/13] selftests/bpf: add selftests for new insn_array map Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 05/13] bpf: support instructions arrays with constants blinding Anton Protopopov
2025-09-19  6:35   ` Eduard Zingerman
2025-09-19  7:05     ` Anton Protopopov
2025-09-19  7:12       ` Eduard Zingerman
2025-09-19 18:26         ` Alexei Starovoitov
2025-09-19 19:28           ` Daniel Borkmann
2025-09-19 19:44             ` Eduard Zingerman
2025-09-19 20:27               ` Anton Protopopov
2025-09-19 20:47                 ` Eduard Zingerman
2025-09-22  9:28                   ` Anton Protopopov
2025-09-30  9:07                     ` Anton Protopopov
2025-09-19 21:41               ` Daniel Borkmann
2025-09-18  9:38 ` [PATCH v3 bpf-next 06/13] selftests/bpf: test instructions arrays with blinding Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 07/13] bpf, x86: allow indirect jumps to r8...r15 Anton Protopopov
2025-09-19 18:25   ` Eduard Zingerman
2025-09-19 18:38     ` Eduard Zingerman
2025-09-19 19:25       ` Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 08/13] bpf, x86: add support for indirect jumps Anton Protopopov
2025-09-20  0:28   ` Eduard Zingerman
2025-09-21 19:12     ` Eduard Zingerman
2025-09-25 18:07     ` Anton Protopopov
2025-09-29 14:10       ` Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 09/13] bpf: disasm: add support for BPF_JMP|BPF_JA|BPF_X Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 10/13] libbpf: fix formatting of bpf_object__append_subprog_code Anton Protopopov
2025-09-19 23:18   ` Andrii Nakryiko
2025-09-18  9:38 ` [PATCH v3 bpf-next 11/13] libbpf: support llvm-generated indirect jumps Anton Protopopov
2025-09-19 23:18   ` Andrii Nakryiko
2025-09-22 10:13     ` Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 12/13] bpftool: Recognize insn_array map type Anton Protopopov
2025-09-18  9:38 ` [PATCH v3 bpf-next 13/13] selftests/bpf: add selftests for indirect jumps Anton Protopopov
2025-09-20  0:58   ` Eduard Zingerman
2025-09-20 22:27     ` Eduard Zingerman
2025-09-20 22:32       ` Eduard Zingerman
2025-09-25 18:14       ` Anton Protopopov [this message]
2025-09-19  6:46 ` [PATCH v3 bpf-next 00/13] BPF " Eduard Zingerman
2025-09-19 14:57   ` Anton Protopopov
2025-09-19 16:49     ` Eduard Zingerman
2025-09-19 17:27   ` Eduard Zingerman
2025-09-19 18:03     ` 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=aNWGbdMKci1gu2iU@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=aspsk@isovalent.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=qmo@kernel.org \
    --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 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.