Skip to contentSkip to conversation

rcu: Mark rcu_read_unlock_special() notrace

PATCH In review Sechang Lim 5 participants 5 messages Nov 28 – Nov 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 rcu: Mark rcu_read_unlock_special() notrace

The BPF trampoline takes and drops the RCU read lock itself. When the outermost rcu_read_unlock() finds ->rcu_read_unlock_special.s set, it calls rcu_read_unlock_special(). If an fentry program is attached to rcu_read_unlock_special(), the unlock on the trampoline exit path still sees .s set and calls rcu_read_unlock_special() again, which 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
   ...

With fexit it recurses even earlier, from percpu_ref_get() in __bpf_tramp_enter(), which takes and drops the RCU read lock before the program runs.

Mark rcu_read_unlock_special() notrace. rcu_unlock_needs_exp_handling() also runs with .s set, so mark it notrace too.

---
v4:
- Go back to notrace as in v1
- Also mark rcu_unlock_needs_exp_handling() notrace (Alexei)

v3: https://lore.kernel.org/bpf/[email protected]/
v2: https://lore.kernel.org/bpf/[email protected]/
v1: https://lore.kernel.org/rcu/[email protected]/

 kernel/rcu/tree_plugin.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/rcu/tree_plugin.h +5 -5
index 3500e4874833..9c1b227f5fa0 100644
@@ -689,10 +689,10 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
  *
  * Returns true if expedited processing of the rcu_read_unlock() is needed.
  */
-static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
-				      struct rcu_data *rdp,
-				      struct rcu_node *rnp,
-				      bool irqs_were_disabled)
+static notrace bool rcu_unlock_needs_exp_handling(struct task_struct *t,
+						  struct rcu_data *rdp,
+						  struct rcu_node *rnp,
+						  bool irqs_were_disabled)
 {
 	/*
 	 * Check if this task is blocking an expedited grace period. If the
@@ -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;

base-commit: 2348d158c7fcc2c9557b2fb550ee841c62942fbd

Signature · 1 line
2.56.1
Reviewed-by on v4 1/1
#1 lore raw
Quoted 17 lines · Sechang Lim

The BPF trampoline takes and drops the RCU read lock itself. When the outermost rcu_read_unlock() finds ->rcu_read_unlock_special.s set, it calls rcu_read_unlock_special(). If an fentry program is attached to rcu_read_unlock_special(), the unlock on the trampoline exit path still sees .s set and calls rcu_read_unlock_special() again, which 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
  ...
Quoted 6 lines

With fexit it recurses even earlier, from percpu_ref_get() in __bpf_tramp_enter(), which takes and drops the RCU read lock before the program runs.

Mark rcu_read_unlock_special() notrace. rcu_unlock_needs_exp_handling() also runs with .s set, so mark it notrace too.

I took a double look, like loads of looks, this seriously LGTM, like, I like this, thanks for the patch,

Quoted 43 lines

---
v4:
- Go back to notrace as in v1
- Also mark rcu_unlock_needs_exp_handling() notrace (Alexei)

v3: https://lore.kernel.org/bpf/[email protected]/
v2: https://lore.kernel.org/bpf/[email protected]/
v1: https://lore.kernel.org/rcu/[email protected]/

kernel/rcu/tree_plugin.h | 10 +++++-----

1 file changed, 5 insertions(+), 5 deletions(-)
kernel/rcu/tree_plugin.h +5 -5
index 3500e4874833..9c1b227f5fa0 100644
@@ -689,10 +689,10 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
 *
 * Returns true if expedited processing of the rcu_read_unlock() is needed.
 */
-static bool rcu_unlock_needs_exp_handling(struct task_struct *t,
-				      struct rcu_data *rdp,
-				      struct rcu_node *rnp,
-				      bool irqs_were_disabled)
+static notrace bool rcu_unlock_needs_exp_handling(struct task_struct *t,
+						  struct rcu_data *rdp,
+						  struct rcu_node *rnp,
+						  bool irqs_were_disabled)
 {
 	/*
 	 * Check if this task is blocking an expedited grace period. If the
@@ -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;
Quoted 2 lines

base-commit: 2348d158c7fcc2c9557b2fb550ee841c62942fbd

--- Thanks!

maintainer Reviewed-by
#3 lore raw
Quoted 8 lines · Alexei Starovoitov
Quoted 2 lines · Sechang Lim

Mark rcu_read_unlock_special() notrace. rcu_unlock_needs_exp_handling() also runs with .s set, so mark it notrace too.

Paul, Joel,
pls take it via rcu tree.

I am getting a bit worried about the increasing fraction of RCU functions that cannot be traced, but:

Joel, are you comfortable taking this one, or would you prefer deferring it to the following merge window?

Thanx, Paul

maintainer
#4 lore raw
Quoted 10 lines · Paul E. McKenney
Quoted 8 lines · Alexei Starovoitov
Quoted 2 lines · Sechang Lim

Mark rcu_read_unlock_special() notrace. rcu_unlock_needs_exp_handling() also runs with .s set, so mark it notrace too.

Paul, Joel,
pls take it via rcu tree.

Quoted 7 lines

I am getting a bit worried about the increasing fraction of RCU functions that cannot be traced, but:

Joel, are you comfortable taking this one, or would you prefer deferring it to the following merge window?

With the above tags, I am comfortable with it for 7.5 so I'll apply it, thanks!

I am planning to push (other recent patches, not this one) to rcu/dev branch in RCU tree, but this one can go in my almost frozen 7.5 tree :)

thanks,

Joel Fernandes