From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Tejun Heo <tj@kernel.org>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v2 00/13] Fix some arena paper cuts
Date: Tue, 13 Oct 2026 10:19:55 +0200 [thread overview]
Message-ID: <20261013082012.1107446-1-memxor@gmail.com> (raw)
Kernel code that shares arena memory with BPF programs runs into two
paper cuts, both visible in sched_ext's cid-form schedulers today.
A kernel struct cannot publish an arena pointer: a pointer member reaches
the program typed as a kernel pointer, so sched_ext hands out a plain u64
holding a pre-translated arena address and every program casts it before
use. __arena and __nullable become BTF type tags like __user and __rcu.
A load through an __arena member of a kernel struct yields PTR_TO_ARENA:
the member holds the kernel address and the fixup pass appends the
conversion to the arena pointer form that the struct_ops trampoline
applies to __arena arguments, with a NULL test for __nullable members.
A __nullable member on its own keeps PTR_MAYBE_NULL on trusted and RCU
pointers, where NULL would otherwise be assumed away. libbpf renders the
arena tag with its address space, so the member arrives in a program
built against vmlinux.h ready to use, without a cast.
A program only has an arena when one of its insns refers to the arena
map, yet the kernel hands programs arena pointers through struct_ops
arguments, tagged members and kfunc return values, and a struct_ops
callback that touches nothing but its arguments fails verification until
it refers to the arena artificially. libbpf binds the arena of an object
to every program loaded from it, through a continuous fd_array. So that
programs which never touch the arena pay nothing for it, the verifier
records which functions have insns that work with the arena base and the
JITs set it up only for those.
Tested with sched_ext for-next as well: a typed cmask member next to the
existing cmask_arena_addr in struct scx_enable_args passes the
enable_cmask selftest read straight from the member, without a cast and
without the asm volatile arena reference.
The series opens with a fix the review of v1 led to: bpf_program__clone()
passed the fd_array fill index of the object as fd_array_cnt, which made
every clone from an object with module kfuncs fail.
See commit logs for details.
Changelog:
----------
v1 -> v2
v1: https://lore.kernel.org/bpf/20261012133711.4030594-1-memxor@gmail.com
* Leave the flags of members walked from a map pointer alone: the
review found that an __rcu member comes out of that path as MEM_RCU,
neither nullable nor probed, which is an older problem of the path
and of the bare PTR_TO_BTF_ID results it accepts, left to a separate
series after a wider audit. (Sashiko)
* Record the non-arena side of a shared load insn for every load, not
only for loads through a kernel struct pointer, since a load insn may
also serve a memory pointer on another path; test that case. (Sashiko)
* Return early in assert_prog_map() when the program lists no map, so a
failing check does not read uninitialized memory. (Sashiko)
* Mark the __arena argument of a kfunc call where the call is verified,
the kfunc pre-pass marked subprogram 0 whatever subprogram held the
call, and test a subprogram whose only arena use is such a call.
(BPF CI)
* Bind the arena only when libbpf creates it, so a program whose arena
has autocreate off still loads; leave out an arena exclusive to
another program and offloaded programs; reset fd_array_cnt after the
load; bind it from bpf_program__clone() as well, so veristat loads
what bpf_object__load() loads. (BPF CI)
* Stop bpf_program__clone() from passing the fd_array fill index of the
object as fd_array_cnt, and rename the index so that it no longer
reads like the uapi field, as a fix patch with a selftest: slot 0
holds no fd, so every clone from an object with module kfuncs failed.
* Skip the __arena and __nullable member tests when the module BTF
carries no type tags, as with a GCC build. (BPF CI)
* Initialize map_ids in the autobind test for GCC's
-Wmaybe-uninitialized. (BPF CI)
* Note in the libbpf commit log that every program of an object with an
arena now needs the JIT and CAP_PERFMON.
* Fix the description of the store failure test. (BPF CI)
Kumar Kartikeya Dwivedi (13):
libbpf: Keep the fd_array fill index out of bpf_program__clone()
selftests/bpf: Clone a program that calls a module kfunc
compiler_types: Add __arena and __nullable BTF type tag qualifiers
bpf: Recognize __nullable on pointer members of kernel structs
bpf: Turn loads of __arena pointer members into arena pointers
selftests/bpf: Test __nullable pointer members
selftests/bpf: Test __arena pointer members
libbpf: Bind the arena of an object to every program in it
selftests/bpf: Test arena binding by libbpf
bpf: Set up the arena base only in functions that use it
libbpf: Render the arena type tag with its address space
selftests/bpf: Test the address space rendering of the arena type tag
selftests/bpf: Test an arena kfunc argument passed from a subprogram
arch/arm64/net/bpf_jit_comp.c | 6 +-
arch/loongarch/net/bpf_jit.c | 6 +-
arch/powerpc/net/bpf_jit_comp.c | 6 +-
arch/riscv/net/bpf_jit_core.c | 6 +-
arch/s390/net/bpf_jit_comp.c | 7 +-
arch/x86/net/bpf_jit_comp.c | 14 +-
include/linux/bpf.h | 2 +
include/linux/bpf_verifier.h | 10 ++
include/linux/compiler_types.h | 10 ++
include/linux/filter.h | 11 ++
kernel/bpf/btf.c | 48 +++++-
kernel/bpf/fixups.c | 51 ++++++-
kernel/bpf/verifier.c | 75 ++++++++++
tools/lib/bpf/btf_dump.c | 3 +
tools/lib/bpf/features.c | 40 +++++
tools/lib/bpf/libbpf.c | 76 ++++++++--
tools/lib/bpf/libbpf_internal.h | 2 +
.../selftests/bpf/prog_tests/btf_dump.c | 16 +-
.../bpf/prog_tests/clone_module_kfunc.c | 30 ++++
.../bpf/prog_tests/test_struct_ops_arena.c | 139 ++++++++++++++++++
.../bpf/prog_tests/test_struct_ops_nullable.c | 68 +++++++++
.../selftests/bpf/prog_tests/verifier.c | 2 +
.../testing/selftests/bpf/progs/arena_kfunc.c | 33 ++++-
.../selftests/bpf/progs/arena_noarena.c | 39 +++++
.../bpf/progs/struct_ops_arena_autobind.c | 64 ++++++++
.../bpf/progs/struct_ops_arena_member.c | 92 ++++++++++++
.../struct_ops_arena_member_fail__load_acq.c | 38 +++++
.../struct_ops_arena_member_fail__mismatch.c | 45 ++++++
...ruct_ops_arena_member_fail__mismatch_mem.c | 54 +++++++
.../struct_ops_arena_member_fail__no_arena.c | 23 +++
.../struct_ops_arena_member_fail__union.c | 34 +++++
.../struct_ops_arena_member_fail__write.c | 32 ++++
.../progs/struct_ops_arena_member_render.c | 82 +++++++++++
.../selftests/bpf/progs/struct_ops_nullable.c | 45 ++++++
.../bpf/progs/struct_ops_nullable_fail.c | 28 ++++
.../bpf/progs/verifier_arena_scalar.c | 13 --
.../selftests/bpf/test_kmods/bpf_testmod.c | 53 +++++++
.../selftests/bpf/test_kmods/bpf_testmod.h | 46 ++++++
.../bpf/test_kmods/bpf_testmod_kfunc.h | 2 +
39 files changed, 1300 insertions(+), 51 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/clone_module_kfunc.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/test_struct_ops_nullable.c
create mode 100644 tools/testing/selftests/bpf/progs/arena_noarena.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_autobind.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__load_acq.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__mismatch.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__mismatch_mem.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__no_arena.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__union.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_fail__write.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_nullable.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_nullable_fail.c
base-commit: 0d5e3fc78a6f2522e6339743b8e5ecc02351a9dd
--
2.53.0-Meta
next reply other threads:[~2026-10-13 8:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 8:19 Kumar Kartikeya Dwivedi [this message]
2026-10-13 8:19 ` [PATCH bpf-next v2 01/13] libbpf: Keep the fd_array fill index out of bpf_program__clone() Kumar Kartikeya Dwivedi
2026-10-13 13:00 ` Mykyta Yatsenko
2026-10-13 8:19 ` [PATCH bpf-next v2 02/13] selftests/bpf: Clone a program that calls a module kfunc Kumar Kartikeya Dwivedi
2026-10-13 8:19 ` [PATCH bpf-next v2 03/13] compiler_types: Add __arena and __nullable BTF type tag qualifiers Kumar Kartikeya Dwivedi
2026-10-13 8:19 ` [PATCH bpf-next v2 04/13] bpf: Recognize __nullable on pointer members of kernel structs Kumar Kartikeya Dwivedi
2026-10-13 8:52 ` sashiko-bot
2026-10-13 9:19 ` Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 05/13] bpf: Turn loads of __arena pointer members into arena pointers Kumar Kartikeya Dwivedi
2026-10-13 8:40 ` sashiko-bot
2026-10-13 9:04 ` Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 06/13] selftests/bpf: Test __nullable pointer members Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 07/13] selftests/bpf: Test __arena " Kumar Kartikeya Dwivedi
2026-10-13 9:14 ` bot+bpf-ci
2026-10-13 9:19 ` Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 08/13] libbpf: Bind the arena of an object to every program in it Kumar Kartikeya Dwivedi
2026-10-13 9:14 ` bot+bpf-ci
2026-10-13 8:20 ` [PATCH bpf-next v2 09/13] selftests/bpf: Test arena binding by libbpf Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 10/13] bpf: Set up the arena base only in functions that use it Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 11/13] libbpf: Render the arena type tag with its address space Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 12/13] selftests/bpf: Test the address space rendering of the arena type tag Kumar Kartikeya Dwivedi
2026-10-13 8:20 ` [PATCH bpf-next v2 13/13] selftests/bpf: Test an arena kfunc argument passed from a subprogram Kumar Kartikeya Dwivedi
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=20261013082012.1107446-1-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=tj@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 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.