From: Tejun Heo <tj@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Emil Tsalapatis <emil@etsalapatis.com>,
David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
bpf@vger.kernel.org, sched-ext@lists.linux.dev,
linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCHSET SLOP RFC 0/6] bpf: make arena pointers first-class kfunc and struct_ops arguments
Date: Sun, 12 Jul 2026 16:44:08 -1000 [thread overview]
Message-ID: <20260713024414.3759854-1-tj@kernel.org> (raw)
RFC. I am not familiar with the BPF verifier code base and this series is
heavily AI-assisted. I reviewed and iterated on all of it but leaned on the
AI outright in places.
BPF arena memory is shared between a BPF program and the kernel, but the two
sides address it through different bases, so an arena pointer cannot be
passed across the kfunc or struct_ops boundary as a pointer. It crosses as a
bare scalar, and the receiving side then offsets it to the other address
space and casts it by hand. Every kfunc and struct_ops caller that touches
arena memory open-codes the same translation.
This series adds an __arena argument suffix that makes the translation
automatic. The callee declares the parameter by its real pointer type and
dereferences it directly, and the verifier rebases it at the boundary
(arena to kernel address into a kfunc, kernel address to arena into a
struct_ops callback), with NULL preserved. The pointer arrives ready to use
on both sides, with no scalar laundering and no hand-written offset or cast.
The approach comes out of rough discussions with Alexei and Kumar.
Patches 1-4 are the BPF core support plus selftests, the kfunc direction
then the struct_ops direction. Patches 5-6 convert two sched_ext consumers
to show the result. They are marked NOT_SIGNED_OFF and are not meant to be
applied. sched_ext has moved on since, notably the pending cap work, so once
the core lands the plan is to pull bpf-next into sched_ext and redo the
consumer side there.
Tested: the BPF selftests pass at bpf_jit_harden 0/1/2, the arena,
struct_ops and kfunc regression suites are clean, and scx_qmap schedules
correctly through the converted paths.
Tejun Heo (6):
bpf: Support __arena suffix for kfunc arguments
selftests/bpf: Add kfunc __arena argument tests
bpf: Support __arena suffix on struct_ops stub arguments
selftests/bpf: Add struct_ops __arena argument tests
sched_ext: Pass a kernel arena pointer to ops_cid.set_cmask()
sched_ext: Convert scx_bpf_cid_override() to take an arena pointer
Documentation/bpf/kfuncs.rst | 27 ++++
include/linux/bpf_verifier.h | 2 +
kernel/bpf/bpf_struct_ops.c | 17 ++-
kernel/bpf/btf.c | 10 +-
kernel/bpf/fixups.c | 70 +++++++++
kernel/bpf/verifier.c | 103 +++++++++++--
kernel/sched/ext/cid.c | 24 +++-
kernel/sched/ext/ext.c | 11 +-
kernel/sched/ext/internal.h | 16 +--
tools/sched_ext/include/scx/compat.bpf.h | 8 +-
tools/sched_ext/scx_qmap.bpf.c | 13 +-
tools/sched_ext/scx_qmap.c | 41 ++++--
tools/sched_ext/scx_qmap.h | 3 +
.../selftests/bpf/prog_tests/arena_kfunc.c | 14 ++
.../bpf/prog_tests/test_struct_ops_arena.c | 61 ++++++++
.../testing/selftests/bpf/progs/arena_kfunc.c | 135 ++++++++++++++++++
.../selftests/bpf/progs/struct_ops_arena.c | 67 +++++++++
.../bpf/progs/struct_ops_arena_fail.c | 20 +++
.../selftests/bpf/test_kmods/bpf_testmod.c | 45 ++++++
.../selftests/bpf/test_kmods/bpf_testmod.h | 2 +
.../bpf/test_kmods/bpf_testmod_kfunc.h | 5 +
21 files changed, 622 insertions(+), 72 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_kfunc.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
create mode 100644 tools/testing/selftests/bpf/progs/arena_kfunc.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena.c
create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_fail.c
--
2.55.0
next reply other threads:[~2026-07-13 2:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 2:44 Tejun Heo [this message]
2026-07-13 2:44 ` [PATCHSET SLOP RFC 1/6] bpf: Support __arena suffix for kfunc arguments Tejun Heo
[not found] ` <20260713025819.A302C1F000E9@smtp.kernel.org>
2026-07-13 19:38 ` Tejun Heo
2026-07-13 21:45 ` Kumar Kartikeya Dwivedi
2026-07-13 2:44 ` [PATCHSET SLOP RFC 2/6] selftests/bpf: Add kfunc __arena argument tests Tejun Heo
[not found] ` <20260713031657.7ECAB1F000E9@smtp.kernel.org>
2026-07-13 19:38 ` Tejun Heo
2026-07-13 2:44 ` [PATCHSET SLOP RFC 3/6] bpf: Support __arena suffix on struct_ops stub arguments Tejun Heo
2026-07-13 19:37 ` [PATCH v2 " Tejun Heo
2026-07-13 2:44 ` [PATCHSET SLOP RFC 4/6] selftests/bpf: Add struct_ops __arena argument tests Tejun Heo
[not found] ` <20260713025537.510321F000E9@smtp.kernel.org>
2026-07-13 19:38 ` Tejun Heo
2026-07-13 2:44 ` [PATCHSET SLOP RFC 5/6] sched_ext: Pass a kernel arena pointer to ops_cid.set_cmask() Tejun Heo
2026-07-13 2:44 ` [PATCHSET SLOP RFC 6/6] sched_ext: Convert scx_bpf_cid_override() to take an arena pointer Tejun Heo
[not found] ` <20260713025916.68A941F000E9@smtp.kernel.org>
2026-07-13 19:38 ` Tejun Heo
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=20260713024414.3759854-1-tj@kernel.org \
--to=tj@kernel.org \
--cc=andrii@kernel.org \
--cc=arighi@nvidia.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=changwoo@igalia.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=sched-ext@lists.linux.dev \
--cc=void@manifault.com \
/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