* [PATCH] rcu: Mark rcu_read_unlock_special() notrace
@ 2026-11-24 18:56 Sechang Lim
2026-11-24 18:59 ` Bradley Morgan
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Sechang Lim @ 2026-11-24 18:56 UTC (permalink / raw)
To: Paul E. McKenney, Frederic Weisbecker, Neeraj Upadhyay,
Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki
Cc: Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
bpf
The BPF trampoline calls rcu_read_unlock() on its exit path. If the
task was preempted in the RCU read-side critical section, this ends up
in rcu_read_unlock_special(). When a BPF fentry or fexit program is
attached to rcu_read_unlock_special() itself, the trampoline runs again
before ->rcu_read_unlock_special is cleared, calls rcu_read_unlock()
again, and recurses until the stack overflows:
BUG: TASK stack guard page was hit at ffffc90001657ff8
...
bpf_trampoline_6442575622+0x5e/0xac
rcu_read_unlock_special+0x5/0x490
__rcu_read_unlock+0x9c/0x120
rcu_read_unlock_migrate+0x93/0x220
bpf_trampoline_6442575622+0x5e/0xac
rcu_read_unlock_special+0x5/0x490
...
Mark rcu_read_unlock_special() notrace.
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
kernel/rcu/tree_plugin.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index ae5d21bae7bc..a887ab69f486 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -746,7 +746,7 @@ static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
* notify RCU core processing or task having blocked during the RCU
* read-side critical section.
*/
-static void rcu_read_unlock_special(struct task_struct *t)
+static notrace void rcu_read_unlock_special(struct task_struct *t)
{
unsigned long flags;
bool irqs_were_disabled;
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] rcu: Mark rcu_read_unlock_special() notrace
2026-11-24 18:56 [PATCH] rcu: Mark rcu_read_unlock_special() notrace Sechang Lim
@ 2026-11-24 18:59 ` Bradley Morgan
2026-11-24 19:11 ` sashiko-bot
2026-11-24 21:08 ` Alexei Starovoitov
2 siblings, 0 replies; 5+ messages in thread
From: Bradley Morgan @ 2026-11-24 18:59 UTC (permalink / raw)
To: rhkrqnwk98
Cc: boqun, bpf, frederic, jiangshanlai, joelagnelf, josh,
mathieu.desnoyers, neeraj.upadhyay, paulmck, qiang.zhang, rcu,
rostedt, urezki
On 24 November 2026 18:56:51 GMT, Sechang Lim <rhkrqnwk98@gmail.com> wrote:
>The BPF trampoline calls rcu_read_unlock() on its exit path. If the
>task was preempted in the RCU read-side critical section, this ends up
>in rcu_read_unlock_special(). When a BPF fentry or fexit program is
>attached to rcu_read_unlock_special() itself, the trampoline runs again
>before ->rcu_read_unlock_special is cleared, calls rcu_read_unlock()
>again, and recurses until the stack overflows:
>
> BUG: TASK stack guard page was hit at ffffc90001657ff8
> ...
> bpf_trampoline_6442575622+0x5e/0xac
> rcu_read_unlock_special+0x5/0x490
> __rcu_read_unlock+0x9c/0x120
> rcu_read_unlock_migrate+0x93/0x220
> bpf_trampoline_6442575622+0x5e/0xac
> rcu_read_unlock_special+0x5/0x490
> ...
>
>Mark rcu_read_unlock_special() notrace.
Hmm.. this seems to be edge case, but no big deal.
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>
>Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
>---
> kernel/rcu/tree_plugin.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
>index ae5d21bae7bc..a887ab69f486 100644
>--- a/kernel/rcu/tree_plugin.h
>+++ b/kernel/rcu/tree_plugin.h
>@@ -746,7 +746,7 @@ static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
> * notify RCU core processing or task having blocked during the RCU
> * read-side critical section.
> */
>-static void rcu_read_unlock_special(struct task_struct *t)
>+static notrace void rcu_read_unlock_special(struct task_struct *t)
> {
> unsigned long flags;
> bool irqs_were_disabled;
>
--- Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rcu: Mark rcu_read_unlock_special() notrace
2026-11-24 18:56 [PATCH] rcu: Mark rcu_read_unlock_special() notrace Sechang Lim
2026-11-24 18:59 ` Bradley Morgan
@ 2026-11-24 19:11 ` sashiko-bot
2026-11-24 21:08 ` Alexei Starovoitov
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-24 19:11 UTC (permalink / raw)
To: Sechang Lim; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] rcu: missing notrace on rcu_unlock_needs_exp_handling() allows
recursion
--
commit 0062b967b0900da7cf7c59da2e3a111544dc9aec
Author: Sechang Lim <rhkrqnwk98@gmail.com>
rcu: Mark rcu_read_unlock_special() notrace
This commit marks rcu_read_unlock_special() notrace to prevent infinite
recursion when a BPF trampoline attached to it calls rcu_read_unlock().
> diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> index ae5d21bae7bc0..a887ab69f4860 100644
> --- a/kernel/rcu/tree_plugin.h
> +++ b/kernel/rcu/tree_plugin.h
> @@ -746,7 +746,7 @@ static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
> * notify RCU core processing or task having blocked during the RCU
> * read-side critical section.
> */
> -static void rcu_read_unlock_special(struct task_struct *t)
> +static notrace void rcu_read_unlock_special(struct task_struct *t)
> {
> unsigned long flags;
> bool irqs_were_disabled;
[Severity: High]
Should rcu_unlock_needs_exp_handling() also be marked notrace (or static
inline)?
In the preempt_bh_were_disabled || irqs_were_disabled path,
rcu_read_unlock_special() disables IRQs and calls
rcu_unlock_needs_exp_handling() while t->rcu_read_unlock_special.s is
still non-zero. Because rcu_unlock_needs_exp_handling() is neither
notrace nor inline, marking rcu_read_unlock_special() notrace prevents the
compiler from inlining it when notrace expands to
__no_instrument_function__. Attaching a BPF fentry or fexit program to
rcu_unlock_needs_exp_handling() then triggers the same
rcu_read_unlock() -> rcu_read_unlock_special() recursion and stack
overflow.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124185659.1370644-1-rhkrqnwk98@gmail.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rcu: Mark rcu_read_unlock_special() notrace
2026-11-24 18:56 [PATCH] rcu: Mark rcu_read_unlock_special() notrace Sechang Lim
2026-11-24 18:59 ` Bradley Morgan
2026-11-24 19:11 ` sashiko-bot
@ 2026-11-24 21:08 ` Alexei Starovoitov
2026-11-24 22:11 ` Bradley Morgan
2 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2026-11-24 21:08 UTC (permalink / raw)
To: Sechang Lim, Paul E. McKenney, Frederic Weisbecker,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki
Cc: Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, rcu,
bpf
On Tue, Nov 24, 2026 at 10:56 AM Sechang Lim <rhkrqnwk98@gmail.com> wrote:
> The BPF trampoline calls rcu_read_unlock() on its exit path. If the
> task was preempted in the RCU read-side critical section, this ends up
> in rcu_read_unlock_special(). When a BPF fentry or fexit program is
> attached to rcu_read_unlock_special() itself, the trampoline runs again
Not quite. need_qs and exp_hint set rcu_read_unlock_special.s too,
no preemption needed.
With fexit it recurses on entry, before the prog runs:
__rcu_read_unlock() nesting 1 -> 0, .s != 0
rcu_read_unlock_special()
__bpf_tramp_enter()
percpu_ref_get() nesting 0 -> 1 -> 0, .s != 0
rcu_read_unlock_special()
> -static void rcu_read_unlock_special(struct task_struct *t)
> +static notrace void rcu_read_unlock_special(struct task_struct *t)
It should be fixed on bpf side. Only the bpf trampoline recurses.
ftrace, fprobe and kprobes take ftrace_test_recursion_trylock().
notrace takes the function away from them and from livepatch.
__rcu_read_unlock() is in btf_id_deny for the same reason.
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index e7013ed..0e8afc0 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -24735,6 +24735,7 @@ BTF_ID(func, preempt_count_sub)
#ifdef CONFIG_PREEMPT_RCU
BTF_ID(func, __rcu_read_lock)
BTF_ID(func, __rcu_read_unlock)
+BTF_ID(func, rcu_read_unlock_special)
#endif
BTF_SET_END(btf_id_deny)
Pls target bpf-next.
pw-bot: cr
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] rcu: Mark rcu_read_unlock_special() notrace
2026-11-24 21:08 ` Alexei Starovoitov
@ 2026-11-24 22:11 ` Bradley Morgan
0 siblings, 0 replies; 5+ messages in thread
From: Bradley Morgan @ 2026-11-24 22:11 UTC (permalink / raw)
To: alexei.starovoitov
Cc: boqun, bpf, frederic, jiangshanlai, joelagnelf, josh,
mathieu.desnoyers, neeraj.upadhyay, paulmck, qiang.zhang, rcu,
rhkrqnwk98, rostedt, urezki
On 24 November 2026 21:08:46 GMT, Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>On Tue, Nov 24, 2026 at 10:56 AM Sechang Lim <rhkrqnwk98@gmail.com> wrote:
>> The BPF trampoline calls rcu_read_unlock() on its exit path. If the
>> task was preempted in the RCU read-side critical section, this ends up
>> in rcu_read_unlock_special(). When a BPF fentry or fexit program is
>> attached to rcu_read_unlock_special() itself, the trampoline runs again
>
>Not quite. need_qs and exp_hint set rcu_read_unlock_special.s too,
>no preemption needed.
>With fexit it recurses on entry, before the prog runs:
>
> __rcu_read_unlock() nesting 1 -> 0, .s != 0
> rcu_read_unlock_special()
> __bpf_tramp_enter()
> percpu_ref_get() nesting 0 -> 1 -> 0, .s != 0
> rcu_read_unlock_special()
>
>> -static void rcu_read_unlock_special(struct task_struct *t)
>> +static notrace void rcu_read_unlock_special(struct task_struct *t)
>
>It should be fixed on bpf side. Only the bpf trampoline recurses.
>ftrace, fprobe and kprobes take ftrace_test_recursion_trylock().
>notrace takes the function away from them and from livepatch.
>__rcu_read_unlock() is in btf_id_deny for the same reason.
>
>
>diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>index e7013ed..0e8afc0 100644
>--- a/kernel/bpf/verifier.c
>+++ b/kernel/bpf/verifier.c
>@@ -24735,6 +24735,7 @@ BTF_ID(func, preempt_count_sub)
> #ifdef CONFIG_PREEMPT_RCU
> BTF_ID(func, __rcu_read_lock)
> BTF_ID(func, __rcu_read_unlock)
>+BTF_ID(func, rcu_read_unlock_special)
> #endif
> BTF_SET_END(btf_id_deny)
ahh crap, brain fog, sorry.
yeah, this approach looks good, again, looks correct to me, won't blow
anything up.
If a patch is submitted:
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>
>Pls target bpf-next.
>
>pw-bot: cr
>
>
--- Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-24 22:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 18:56 [PATCH] rcu: Mark rcu_read_unlock_special() notrace Sechang Lim
2026-11-24 18:59 ` Bradley Morgan
2026-11-24 19:11 ` sashiko-bot
2026-11-24 21:08 ` Alexei Starovoitov
2026-11-24 22:11 ` Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox