From: sashiko-bot@kernel.org
To: "Puranjay Mohan" <puranjay@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 1/4] bpf: Add bpf_call_rcu() kfunc
Date: Tue, 15 Sep 2026 16:04:12 +0000 [thread overview]
Message-ID: <20260915160412.9D7391F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915154248.3612028-2-puranjay@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: deadlock when bpf_call_rcu() is called from NMI context
--
commit af52c52f0edbfb5e1da2aca1dc782426e0ea9091
Author: Puranjay Mohan <puranjay@kernel.org>
bpf: Add bpf_call_rcu() kfunc
This patch adds a new bpf_call_rcu() kfunc that allows BPF programs to
execute a callback after an RCU grace period. This is primarily useful
for programs managing their own objects that need to defer free operations.
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 051b6654e57c6..6debb92fc8740 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
[ ... ]
> +__bpf_kfunc int bpf_call_rcu(struct bpf_rcu_head *rh, void *map__const_map,
> + bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)
> +{
> + struct bpf_rcu_head_kern *rhk = (void *)rh;
> + struct bpf_map *map = map__const_map;
> + struct bpf_prog *prog;
[ ... ]
> + rhk->callback_fn = (bpf_callback_t)(void *)callback;
> + rhk->map = map;
> + rhk->prog = prog;
> + call_rcu(&rhk->rcu, bpf_rcu_run_callback);
[Severity: High]
Could this lead to a deadlock if called from an NMI context?
Tracing BPF programs (like those attached to perf_events or NMI-based
kprobes) can execute in NMI context. If such a program calls this kfunc,
it unconditionally invokes call_rcu().
Since call_rcu() is not NMI-safe and acquires internal raw spinlocks
(like rdp->nocb_lock or rcu_node locks), an NMI interrupting a CPU already
holding one of these locks would try to acquire it again, deadlocking the
CPU.
Is there a way to prevent bpf_call_rcu() from being called in NMI
context, or use an NMI-safe alternative?
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915154248.3612028-1-puranjay@kernel.org?part=1
next prev parent reply other threads:[~2026-09-15 16:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 15:42 [PATCH bpf-next v4 0/4] bpf: Add bpf_call_rcu() and bpf_call_rcu_tasks_trace() Puranjay Mohan
2026-09-15 15:42 ` [PATCH bpf-next v4 1/4] bpf: Add bpf_call_rcu() kfunc Puranjay Mohan
2026-09-15 16:04 ` sashiko-bot [this message]
2026-09-16 18:41 ` Mykyta Yatsenko
2026-09-18 10:58 ` Puranjay Mohan
2026-09-18 16:03 ` Paul E. McKenney
2026-09-19 5:15 ` Alexei Starovoitov
2026-09-21 19:53 ` Puranjay Mohan
2026-09-15 15:42 ` [PATCH bpf-next v4 2/4] selftests/bpf: Add tests for bpf_call_rcu() Puranjay Mohan
2026-09-15 15:52 ` sashiko-bot
2026-09-15 16:51 ` bot+bpf-ci
2026-09-15 16:53 ` Puranjay Mohan
2026-09-15 15:42 ` [PATCH bpf-next v4 3/4] bpf: Add bpf_call_rcu_tasks_trace() kfunc Puranjay Mohan
2026-09-15 16:07 ` sashiko-bot
2026-09-15 15:42 ` [PATCH bpf-next v4 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=20260915160412.9D7391F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=puranjay@kernel.org \
--cc=sashiko-reviews@lists.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