From: Puranjay Mohan <puranjay@kernel.org>
To: bpf@vger.kernel.org, rcu@vger.kernel.org
Cc: Puranjay Mohan <puranjay@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Harry Yoo (Oracle)" <harry@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>
Subject: [PATCH bpf-next 0/4] bpf: Add bpf_call_rcu() and bpf_call_rcu_tasks_trace()
Date: Mon, 7 Sep 2026 06:45:47 -0700 [thread overview]
Message-ID: <20260907134552.1772405-1-puranjay@kernel.org> (raw)
BPF programs that manage their own objects have no way to run their own
logic once an RCU grace period has elapsed. bpf_obj_drop() defers a
free, but returning an index to an allocator or unpinning a resource
once readers are done has no equivalent. sched_ext's BPF library works
around this today by pushing freed nodes onto a list and having a
userspace thread call membarrier(MEMBARRIER_CMD_GLOBAL) and then run a
BPF program to reclaim them; it is the first intended user.
Add:
int bpf_call_rcu(struct bpf_rcu_head *rh, void *map,
int (*callback)(struct bpf_map *map, void *key,
void *value));
and bpf_call_rcu_tasks_trace(), same signature, which also waits for
sleepable programs.
@rh is a struct bpf_rcu_head embedded in a value of @map, so the
callback runs as callback(map, key, value) for the element it lives in
and needs no cookie. The field is only accepted in BPF_MAP_TYPE_ARRAY,
and arming holds a reference on the calling program until the callback
has run. Patch 1 covers the lifetime rules.
This needs
https://lore.kernel.org/all/20260810122758.183765-1-puranjay@kernel.org/
for call_rcu() and call_srcu() to be safe from the contexts a BPF
program can be called in.
Puranjay Mohan (4):
bpf: Add bpf_call_rcu() kfunc
selftests/bpf: Add tests for bpf_call_rcu()
bpf: Add bpf_call_rcu_tasks_trace() kfunc
selftests/bpf: Add a test for bpf_call_rcu_tasks_trace()
include/linux/bpf.h | 9 +
include/uapi/linux/bpf.h | 4 +
kernel/bpf/btf.c | 7 +
kernel/bpf/helpers.c | 104 ++++++++++
kernel/bpf/map_in_map.c | 4 +
kernel/bpf/map_iter.c | 6 +
kernel/bpf/syscall.c | 11 +-
kernel/bpf/verifier.c | 86 +++++++-
tools/include/uapi/linux/bpf.h | 4 +
.../selftests/bpf/prog_tests/call_rcu.c | 191 ++++++++++++++++++
tools/testing/selftests/bpf/progs/call_rcu.c | 89 ++++++++
.../selftests/bpf/progs/call_rcu_fail.c | 114 +++++++++++
12 files changed, 626 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/call_rcu.c
create mode 100644 tools/testing/selftests/bpf/progs/call_rcu.c
create mode 100644 tools/testing/selftests/bpf/progs/call_rcu_fail.c
base-commit: 1b7415bf70be95b9a1e7e87d544867881065613f
--
2.53.0-Meta
next reply other threads:[~2026-09-07 13:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 13:45 Puranjay Mohan [this message]
2026-09-07 13:45 ` [PATCH bpf-next 1/4] bpf: Add bpf_call_rcu() kfunc Puranjay Mohan
2026-09-07 14:06 ` sashiko-bot
2026-09-07 14:29 ` Puranjay Mohan
2026-09-08 0:19 ` Alexei Starovoitov
2026-09-08 12:22 ` Puranjay Mohan
2026-09-07 13:45 ` [PATCH bpf-next 2/4] selftests/bpf: Add tests for bpf_call_rcu() Puranjay Mohan
2026-09-07 13:58 ` sashiko-bot
2026-09-07 13:45 ` [PATCH bpf-next 3/4] bpf: Add bpf_call_rcu_tasks_trace() kfunc Puranjay Mohan
2026-09-07 13:45 ` [PATCH bpf-next 4/4] selftests/bpf: Add a test for bpf_call_rcu_tasks_trace() Puranjay Mohan
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=20260907134552.1772405-1-puranjay@kernel.org \
--to=puranjay@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=harry@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=song@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox