From: Anton Protopopov <aspsk@isovalent.com>
To: Yonghong Song <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org, Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Quentin Monnet <qmo@kernel.org>,
Alexei Starovoitov <ast@kernel.org>
Subject: Re: [RFC PATCH bpf-next 14/14] selftests/bpf: Add tests for BPF static calls
Date: Tue, 18 Mar 2025 21:00:46 +0000 [thread overview]
Message-ID: <Z9ne/o9lmIwbVN+3@mail.gmail.com> (raw)
In-Reply-To: <543f9e82-b941-4a90-90c8-f559c2e3d908@linux.dev>
On 25/03/18 01:53PM, Yonghong Song wrote:
>
>
> On 3/18/25 7:33 AM, Anton Protopopov wrote:
> > Add self-tests to test new BPF_STATIC_BRANCH_JA jump instructions
> > and the BPF_STATIC_KEY_UPDATE syscall.
> >
> > Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> > ---
> > .../bpf/prog_tests/bpf_static_keys.c | 359 ++++++++++++++++++
> > .../selftests/bpf/progs/bpf_static_keys.c | 131 +++++++
> > 2 files changed, 490 insertions(+)
> > create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_static_keys.c
> > create mode 100644 tools/testing/selftests/bpf/progs/bpf_static_keys.c
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_static_keys.c b/tools/testing/selftests/bpf/prog_tests/bpf_static_keys.c
> > new file mode 100644
> > index 000000000000..3f105d36743b
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_static_keys.c
> > @@ -0,0 +1,359 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include <test_progs.h>
> > +
> > +#include <sys/syscall.h>
> > +#include <bpf/bpf.h>
> > +
> > +#include "bpf_static_keys.skel.h"
> > +
> > +#define VAL_ON 7
> > +#define VAL_OFF 3
> > +
> > +enum {
> > + OFF,
> > + ON
> > +};
> > +
> > +static int _bpf_prog_load(struct bpf_insn *insns, __u32 insn_cnt)
> > +{
> > + return bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL);
> > +}
> > +
> > +static int _bpf_static_key_update(int map_fd, __u32 on)
> > +{
> > + LIBBPF_OPTS(bpf_static_key_update_opts, opts);
> > +
> > + opts.on = on;
> > +
> > + return bpf_static_key_update(map_fd, &opts);
> > +}
> > +
> > +#define BPF_JMP32_OR_NOP(IMM, OFF) \
> > + ((struct bpf_insn) { \
> > + .code = BPF_JMP32 | BPF_JA | BPF_K, \
> > + .dst_reg = 0, \
> > + .src_reg = BPF_STATIC_BRANCH_JA, \
> > + .off = OFF, \
> > + .imm = IMM })
> > +
> > +#define BPF_JMP_OR_NOP(IMM, OFF) \
> > + ((struct bpf_insn) { \
> > + .code = BPF_JMP | BPF_JA | BPF_K, \
> > + .dst_reg = 0, \
> > + .src_reg = BPF_STATIC_BRANCH_JA, \
> > + .off = OFF, \
> > + .imm = IMM })
> > +
> > +#define BPF_NOP_OR_JMP32(IMM, OFF) \
> > + ((struct bpf_insn) { \
> > + .code = BPF_JMP32 | BPF_JA | BPF_K, \
> > + .dst_reg = 0, \
> > + .src_reg = BPF_STATIC_BRANCH_JA | \
> > + BPF_STATIC_BRANCH_NOP, \
> > + .off = OFF, \
> > + .imm = IMM })
> > +
> > +#define BPF_NOP_OR_JMP(IMM, OFF) \
> > + ((struct bpf_insn) { \
> > + .code = BPF_JMP | BPF_JA | BPF_K, \
> > + .dst_reg = 0, \
> > + .src_reg = BPF_STATIC_BRANCH_JA | \
> > + BPF_STATIC_BRANCH_NOP, \
> > + .off = OFF, \
> > + .imm = IMM })
> > +
> > +static const struct bpf_insn insns0[] = {
> > + BPF_JMP_OR_NOP(0, 1),
> > + BPF_NOP_OR_JMP(0, 1),
> > + BPF_JMP32_OR_NOP(1, 0),
> > + BPF_NOP_OR_JMP32(1, 0),
> > +};
> > +
>
> [...]
>
> > +
> > +static void check_bpf_to_bpf_call(struct bpf_static_keys *skel,
> > + struct bpf_map *key1,
> > + struct bpf_map *key2)
> > +{
> > + struct bpf_link *link;
> > +
> > + link = bpf_program__attach(skel->progs.check_bpf_to_bpf_call);
>
> there is no progcheck_bpf_to_bpf_call. Compilation will fail.
Oops, thanks! I haven't cleaned it out (have it in my dev branch)...
(Compilation will fail in the first place in progs/bpf_static_keys.c, as
`asm(gotol_or_nop)` will not compile.
> > + if (!ASSERT_OK_PTR(link, "link"))
> > + return;
> > +
> > + __check_multiple_keys(skel, key1, key2, 0, 303, 3030, 3333);
> > +
> > + bpf_link__destroy(link);
> > +}
> > +
> [...]
next prev parent reply other threads:[~2025-03-18 20:57 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 14:33 [RFC PATCH bpf-next 00/14] instruction sets and static keys Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 01/14] bpf: fix a comment describing bpf_attr Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 02/14] bpf: add new map type: instructions set Anton Protopopov
2025-03-20 7:56 ` Leon Hwang
2025-03-20 9:34 ` Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 03/14] selftests/bpf: add selftests for new insn_set map Anton Protopopov
2025-03-18 20:56 ` Yonghong Song
2025-03-19 17:26 ` Anton Protopopov
2025-03-19 17:30 ` Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 04/14] bpf: add support for an extended JA instruction Anton Protopopov
2025-03-18 19:00 ` David Faust
2025-03-18 19:24 ` Anton Protopopov
2025-03-18 19:30 ` David Faust
2025-03-18 19:47 ` Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 05/14] bpf: Add kernel/bpftool asm support for new instructions Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 06/14] bpf: add BPF_STATIC_KEY_UPDATE syscall Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 07/14] bpf: save the start of functions in bpf_prog_aux Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 08/14] bpf, x86: implement static key support Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 09/14] selftests/bpf: add guard macros around likely/unlikely Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 10/14] libbpf: add likely/unlikely macros Anton Protopopov
2025-03-28 20:57 ` Andrii Nakryiko
2025-03-29 13:38 ` Anton Protopopov
2025-03-31 20:10 ` Andrii Nakryiko
2025-03-18 14:33 ` [RFC PATCH bpf-next 11/14] selftests/bpf: remove likely/unlikely definitions Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 12/14] libbpf: BPF Static Keys support Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 13/14] libbpf: Add bpf_static_key_update() API Anton Protopopov
2025-03-18 14:33 ` [RFC PATCH bpf-next 14/14] selftests/bpf: Add tests for BPF static calls Anton Protopopov
2025-03-18 20:53 ` Yonghong Song
2025-03-18 21:00 ` Anton Protopopov [this message]
2025-03-18 21:00 ` [RFC PATCH bpf-next 00/14] instruction sets and static keys Yonghong Song
2025-03-19 17:45 ` Anton Protopopov
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=Z9ne/o9lmIwbVN+3@mail.gmail.com \
--to=aspsk@isovalent.com \
--cc=andrii@kernel.org \
--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.