All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 00/15] bpf: Support programs compiled by rust-bpf
@ 2026-10-02 12:46 Alexei Starovoitov
  2026-10-02 12:47 ` [PATCH bpf-next v2 01/15] bpf: Allow bitwise ops, shifts and mul/div on pointers with CAP_PERFMON Alexei Starovoitov
                   ` (15 more replies)
  0 siblings, 16 replies; 23+ messages in thread
From: Alexei Starovoitov @ 2026-10-02 12:46 UTC (permalink / raw)
  To: bpf; +Cc: daniel, andrii, eddyz87, memxor

From: Alexei Starovoitov <ast@kernel.org>

Rust programs compiled by rust-bpf keep all memory in arena and access
it through plain numbers, since there are no address spaces in Rust.
core tags pointers in the low bit. BTF of such program has names like
'Option<alloc::collections::btree::map::BTreeMap<u32, u32>>'.

Patches 1-2   Allow ALU on pointers with CAP_PERFMON. The result is
              a number.
Patches 3-4   Treat load and store through a number as arena access
              in programs loaded with BPF_F_ARENA_SCALAR.
Patches 5-11  Accept BTF of Rust programs in the kernel: names of types
              and functions that are not C identifiers, arguments of
              static functions without names, a variable in DATASEC
              that is smaller than its type. bpftool doesn't read
              past such variable.
Patches 12-14 libbpf: Keep .data, .bss and .rodata in arena when
              the object has .arena.data section and load its programs
              with BPF_F_ARENA_SCALAR. Format strings of bpf_printk() go
              to .rodata.str, which stays a map.
Patch 15      A program in Rust, built by upstream rustc, that shows why
              the data has to be in arena.

No changes for unprivileged programs. Without the flag a number is not
an address, whether the program has an arena or not.

Arena access through a number is for x86 and arm64: other JITs have to
say that they take BPF_REG_AX as the address, the flag is rejected with
-EOPNOTSUPP there. arm64 is compile tested only.

With the series the kernel loads BTF of scx_simple and scx_cosmos
schedulers written in Rust, of the unwind and of the immediate-abort
builds. The objects call bpf_alloc(), bpf_free(), bpf_arena_memcpy() and
bpf_arena_memcmp(), which are not in the series, so they don't load yet.

v1 -> v2:
- Rebased. Added Acked-by from Alan.
- Patch 6: the test is serial, since other tests set bpf_jit_harden and
  programs are not in kallsyms then. Use kallsyms_find().
- Patch 8: add comments and a test for vararg of a global function (Alan).
- Patch 10: new. bpftool map dump and bpftool prog show read past
  a variable in DATASEC that is smaller than its type.
- Patch 11: check bpftool map dump.
- Patch 12:
  . fix overflow in the check of r_offset of a pointer in data.
  . __arena variables in an object without .maps section were placed
    over .data in the arena that libbpf creates. Fail the open.
  . pin_path and bpf_map__reuse_fd() of the arena were ignored when
    there are pointers in data. Fail the load.
  . don't create the arena when its autocreate is off.
- Patch 14: tests for the above.
- Patch 15:
  . skip the test when rustc is older than 1.87 and when clang is older
    than LLVM of rustc, instead of breaking the build.
  . the exit status of rustc was lost in the pipe and clang made
    an empty object. Go through a file. Follow BPF_STRICT_BUILD=0.

v1: https://lore.kernel.org/bpf/20260930193127.2181684-1-alexei.starovoitov@gmail.com/

Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Alexei Starovoitov (15):
  bpf: Allow bitwise ops, shifts and mul/div on pointers with
    CAP_PERFMON
  selftests/bpf: Add tests for ALU on pointers with CAP_PERFMON
  bpf: Treat load and store through a number as arena access
  selftests/bpf: Add tests for arena access through numbers
  bpf: Allow names of Rust types and functions in BTF
  selftests/bpf: Add tests for names of Rust types and functions in BTF
  bpf: Allow arguments without names in static functions in BTF
  selftests/bpf: Add test for arguments without names in static
    functions
  bpf: Allow a variable in DATASEC that is smaller than its type
  bpftool: Skip pieces of variables in DATASEC
  selftests/bpf: Add tests for a variable that is smaller than its type
  libbpf: Keep global data in arena when the object has .arena.data
  libbpf: Keep format strings of bpf_printk() in .rodata.str
  selftests/bpf: Add test for global data in arena
  selftests/bpf: Add test for global data of a program in Rust

 arch/arm64/net/bpf_jit_comp.c                 |   5 +
 arch/x86/net/bpf_jit_comp.c                   |   6 +
 include/linux/bpf_verifier.h                  |   2 +
 include/linux/filter.h                        |   1 +
 include/uapi/linux/bpf.h                      |   6 +
 kernel/bpf/btf.c                              |  50 +-
 kernel/bpf/core.c                             |  11 +
 kernel/bpf/fixups.c                           |  39 +
 kernel/bpf/syscall.c                          |   4 +
 kernel/bpf/verifier.c                         |  74 +-
 tools/bpf/bpftool/btf_dumper.c                |  11 +
 tools/bpf/bpftool/main.h                      |   2 +
 tools/bpf/bpftool/prog.c                      |   4 +-
 tools/include/uapi/linux/bpf.h                |   6 +
 tools/lib/bpf/bpf_helpers.h                   |  18 +-
 tools/lib/bpf/libbpf.c                        | 433 ++++++++-
 tools/testing/selftests/bpf/Makefile          |  12 +-
 .../testing/selftests/bpf/Makefile.buildvars  |  25 +
 tools/testing/selftests/bpf/Makefile.skel     |  18 +-
 .../bpf/prog_tests/arena_scalar_blinded.c     |  21 +
 tools/testing/selftests/bpf/prog_tests/btf.c  | 132 ++-
 .../selftests/bpf/prog_tests/btf_rust.c       | 142 +++
 .../selftests/bpf/prog_tests/data_in_arena.c  | 216 +++++
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/data_in_arena.c       | 107 ++
 .../selftests/bpf/progs/data_in_arena_decl.c  |  37 +
 .../bpf/progs/data_in_arena_extern.c          |  20 +
 .../selftests/bpf/progs/data_in_arena_fail.c  |  20 +
 .../selftests/bpf/progs/data_in_arena_nomap.c |  20 +
 .../selftests/bpf/progs/data_in_arena_rust.rs |  70 ++
 .../bpf/progs/verifier_arena_scalar.c         | 912 ++++++++++++++++++
 .../bpf/progs/verifier_value_illegal_alu.c    | 173 +++-
 tools/testing/selftests/bpf/test_loader.c     |   2 +
 33 files changed, 2500 insertions(+), 101 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_scalar_blinded.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/btf_rust.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/data_in_arena.c
 create mode 100644 tools/testing/selftests/bpf/progs/data_in_arena.c
 create mode 100644 tools/testing/selftests/bpf/progs/data_in_arena_decl.c
 create mode 100644 tools/testing/selftests/bpf/progs/data_in_arena_extern.c
 create mode 100644 tools/testing/selftests/bpf/progs/data_in_arena_fail.c
 create mode 100644 tools/testing/selftests/bpf/progs/data_in_arena_nomap.c
 create mode 100644 tools/testing/selftests/bpf/progs/data_in_arena_rust.rs
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena_scalar.c


base-commit: b5a4aa31abd6fe90009b63e35dc18c67d041ec0c
-- 
2.55.0


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2026-10-03 14:20 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-02 12:46 [PATCH bpf-next v2 00/15] bpf: Support programs compiled by rust-bpf Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 01/15] bpf: Allow bitwise ops, shifts and mul/div on pointers with CAP_PERFMON Alexei Starovoitov
2026-10-02 13:49   ` bot+bpf-ci
2026-10-02 12:47 ` [PATCH bpf-next v2 02/15] selftests/bpf: Add tests for ALU " Alexei Starovoitov
2026-10-02 13:08   ` sashiko-bot
2026-10-03 11:48     ` Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 03/15] bpf: Treat load and store through a number as arena access Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 04/15] selftests/bpf: Add tests for arena access through numbers Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 05/15] bpf: Allow names of Rust types and functions in BTF Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 06/15] selftests/bpf: Add tests for " Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 07/15] bpf: Allow arguments without names in static " Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 08/15] selftests/bpf: Add test for arguments without names in static functions Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 09/15] bpf: Allow a variable in DATASEC that is smaller than its type Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 10/15] bpftool: Skip pieces of variables in DATASEC Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 11/15] selftests/bpf: Add tests for a variable that is smaller than its type Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 12/15] libbpf: Keep global data in arena when the object has .arena.data Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 13/15] libbpf: Keep format strings of bpf_printk() in .rodata.str Alexei Starovoitov
2026-10-02 12:47 ` [PATCH bpf-next v2 14/15] selftests/bpf: Add test for global data in arena Alexei Starovoitov
2026-10-02 13:49   ` bot+bpf-ci
2026-10-02 12:47 ` [PATCH bpf-next v2 15/15] selftests/bpf: Add test for global data of a program in Rust Alexei Starovoitov
2026-10-03  1:33   ` sashiko-bot
2026-10-03 11:47     ` Alexei Starovoitov
2026-10-03 14:20 ` [PATCH bpf-next v2 00/15] bpf: Support programs compiled by rust-bpf patchwork-bot+netdevbpf

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.