public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Anton Protopopov <aspsk@isovalent.com>,
	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 00/14] instruction sets and static keys
Date: Tue, 18 Mar 2025 14:00:37 -0700	[thread overview]
Message-ID: <4a128a09-0b8b-488a-986b-7882f96bc5bb@linux.dev> (raw)
In-Reply-To: <20250318143318.656785-1-aspsk@isovalent.com>



On 3/18/25 7:33 AM, Anton Protopopov wrote:
> This patchset implements new type of map, instruction set, and uses
> it to build support for BPF static keys. The same map will be later
> used to provide support for indirect jumps and indirect calls. See
> [1], [2] for more context.
>
> Short table of contents:
>
>    * patches 1, 9, 10, 11 are simple fixes (which can be sent
>      independently, if acked)
>
>    * patches 2, 3 add a new map type, BPF_MAP_TYPE_INSN_SET, and
>      corresponding selftests. This map is used to track how original
>      instructions were relocated into 'xlated' during the verification
>
>    * patches 4, 5, 6, 7, 8 add support for static keys (kernel only)
>      using (an extension) to that new map type. Only x86 support is
>      added in this RFC
>
>    * patches 12, 13, 14 add libbpf-side support for static keys and
>      selftests
>
> It is RFC for a few reasons:
>
> 1) The kernel side of the static keys looks clear, however, the
> libbpf side is not _that_ clear. I thought that this is better to
> commit to a particular userspace design, as any particular design
> requires a lot of changes on the libbpf side. See patch 12 for
> the details
>
> 2) The libbpf part of the series requires a patched LLVM (see [3]),
> which adds support for gotol_or_nop/nop_or_gotol instructions, so
> selftests would not compile in CI.
>
> 3) Patch 4 adds support for a new BPF instruction. It looks
> reasonable to use an extended BPF_JMP|BPF_JA instruction, and not
> may_goto. Reasons: a follow up will add support for
> BPF_JMP|BPF_JA|BPF_X (indirect jumps), which also utilizes INSN_SET maps (see [2]).
> Then another follow up will add support CALL|BPF_X, for which there's
> no corresponding magic instruction (to be discussed at the following
> LSF/MM/BPF).
>
> Besides these reasons, there are some questions / known bugs,
> which will be fixed once the general plan is confirmed:
>
>    * bpf_jit_blind_constants will patch code, which is ignored in this
>      RFC series. The solution would be either moving tracking
>      instruction sets to bpf_prog from the verifier environment,
>      or moving bpf_jit_blind_constants upper the stack (right now,
>      this is the first thing which every jit does, so maybe it can
>      be actually executed from the verifier, and provide env context)
>
>    * gen-loader not supported, fd_array usage in libbpf should be
>      re-designed (see patch 12 for more details)
>
>    * insn_off -> insn_set map mapping should be optimized (now it is
>      brute force)
>
> Links:
>    1. http://oldvger.kernel.org/bpfconf2024_material/bpf_static_keys.pdf
>    2. https://lpc.events/event/18/contributions/1941/
>    3. https://github.com/aspsk/llvm-project/tree/static-keys

For llvm patch in [3], please remove changes in function isValidIdInMiddle()
as gotol_or_nop or nop_or_gotol will not appear in the *middle* of any
instruction. "gotol" should not be there either, I may remove it sometime
later.

>
> Anton Protopopov (14):
>    bpf: fix a comment describing bpf_attr
>    bpf: add new map type: instructions set
>    selftests/bpf: add selftests for new insn_set map
>    bpf: add support for an extended JA instruction
>    bpf: Add kernel/bpftool asm support for new instructions
>    bpf: add BPF_STATIC_KEY_UPDATE syscall
>    bpf: save the start of functions in bpf_prog_aux
>    bpf, x86: implement static key support
>    selftests/bpf: add guard macros around likely/unlikely
>    libbpf: add likely/unlikely macros
>    selftests/bpf: remove likely/unlikely definitions
>    libbpf: BPF Static Keys support
>    libbpf: Add bpf_static_key_update() API
>    selftests/bpf: Add tests for BPF static calls
>
>   arch/x86/net/bpf_jit_comp.c                   |  65 +-
>   include/linux/bpf.h                           |  28 +
>   include/linux/bpf_types.h                     |   1 +
>   include/linux/bpf_verifier.h                  |   2 +
>   include/uapi/linux/bpf.h                      |  40 +-
>   kernel/bpf/Makefile                           |   2 +-
>   kernel/bpf/bpf_insn_set.c                     | 400 +++++++++++
>   kernel/bpf/core.c                             |   5 +
>   kernel/bpf/disasm.c                           |  33 +-
>   kernel/bpf/syscall.c                          |  28 +
>   kernel/bpf/verifier.c                         |  94 ++-
>   tools/include/uapi/linux/bpf.h                |  40 +-
>   tools/lib/bpf/bpf.c                           |  17 +
>   tools/lib/bpf/bpf.h                           |  19 +
>   tools/lib/bpf/bpf_helpers.h                   |  63 ++
>   tools/lib/bpf/libbpf.c                        | 362 +++++++++-
>   tools/lib/bpf/libbpf.map                      |   1 +
>   tools/lib/bpf/libbpf_internal.h               |   3 +
>   tools/lib/bpf/linker.c                        |   6 +-
>   .../selftests/bpf/bpf_arena_spin_lock.h       |   3 -
>   .../selftests/bpf/prog_tests/bpf_insn_set.c   | 639 ++++++++++++++++++
>   .../bpf/prog_tests/bpf_static_keys.c          | 359 ++++++++++
>   .../selftests/bpf/progs/bpf_static_keys.c     | 131 ++++
>   tools/testing/selftests/bpf/progs/iters.c     |   2 -
>   24 files changed, 2315 insertions(+), 28 deletions(-)
>   create mode 100644 kernel/bpf/bpf_insn_set.c
>   create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_insn_set.c
>   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
>


  parent reply	other threads:[~2025-03-18 21:00 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
2025-03-18 21:00 ` Yonghong Song [this message]
2025-03-19 17:45   ` [RFC PATCH bpf-next 00/14] instruction sets and static keys 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=4a128a09-0b8b-488a-986b-7882f96bc5bb@linux.dev \
    --to=yonghong.song@linux.dev \
    --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 \
    /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