Skip to contentSkip to conversation

rcu,ftrace: Fix ftrace recursion

PATCH In review Peter Zijlstra 4 participants 11 messages Sep 29, 2020 – Oct 5, 2020 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcu,ftrace: Fix ftrace recursion

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Reinstate the notrace and add a comment to avoid loosing it again.

Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")
---
 kernel/rcu/tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +4 -1
index ee5e595501e8..33020d84ec6b 100644
@@ -1098,8 +1098,11 @@ noinstr bool __rcu_is_watching(void)
  * CPU can safely enter RCU read-side critical sections.  In other words,
  * if the current CPU is not in its idle loop or is in an interrupt or
  * NMI handler, return true.
+ *
+ * Must be notrace because __ftrace_ops_list_func() / ftrace_ops_assist_func()
+ * will call this (for every function) outside of recursion protection.
  */
-bool rcu_is_watching(void)
+notrace bool rcu_is_watching(void)
 {
 	bool ret;
 
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Peter Zijlstra

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Reinstate the notrace and add a comment to avoid loosing it again.

s/loosing/losing/, but otherwise:

But please let me know if you would prefer that I take it via -rcu.

Thanx, Paul

Quoted 24 lines
Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")
---
 kernel/rcu/tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +4 -1
index ee5e595501e8..33020d84ec6b 100644
@@ -1098,8 +1098,11 @@ noinstr bool __rcu_is_watching(void)
  * CPU can safely enter RCU read-side critical sections.  In other words,
  * if the current CPU is not in its idle loop or is in an interrupt or
  * NMI handler, return true.
+ *
+ * Must be notrace because __ftrace_ops_list_func() / ftrace_ops_assist_func()
+ * will call this (for every function) outside of recursion protection.
  */
-bool rcu_is_watching(void)
+notrace bool rcu_is_watching(void)
 {
 	bool ret;
 
#2 lore raw
In reply to Peter Zijlstra
Quoted 24 lines · On Tue, 29 Sep 2020 13:33:40 +0200 Peter Zijlstra <[email protected]> wrote:

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Reinstate the notrace and add a comment to avoid loosing it again.

Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")
---
 kernel/rcu/tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +0 -0
index ee5e595501e8..33020d84ec6b 100644
@@ -1098,8 +1098,11 @@ noinstr bool __rcu_is_watching(void)
  * CPU can safely enter RCU read-side critical sections.  In other words,
  * if the current CPU is not in its idle loop or is in an interrupt or

kernel/rcu/tree.c noinstr bool __rcu_is_watching(void) · line 1108

Quoted 10 lines
kernel/rcu/tree.c +4 -1
  * NMI handler, return true.
+ *
+ * Must be notrace because __ftrace_ops_list_func() / ftrace_ops_assist_func()
+ * will call this (for every function) outside of recursion protection.
  */
-bool rcu_is_watching(void)
+notrace bool rcu_is_watching(void)
 {
 	bool ret;
 

I think the patch I suggested is more suitable.

-- Steve

maintainer
#3 lore raw
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Tue, 29 Sep 2020 13:33:40 +0200 Peter Zijlstra <[email protected]> wrote:

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Reinstate the notrace and add a comment to avoid loosing it again.

Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")
---
 kernel/rcu/tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +3 -0
index ee5e595501e8..33020d84ec6b 100644
@@ -1098,8 +1098,11 @@ noinstr bool __rcu_is_watching(void)
  * CPU can safely enter RCU read-side critical sections.  In other words,
  * if the current CPU is not in its idle loop or is in an interrupt or
  * NMI handler, return true.
+ *
+ * Must be notrace because __ftrace_ops_list_func() / ftrace_ops_assist_func()
+ * will call this (for every function) outside of recursion protection.
Quoted 8 lines

kernel/rcu/tree.c noinstr bool __rcu_is_watching(void) · line 1108

Quoted 6 lines
kernel/rcu/tree.c +1 -1
  */
-bool rcu_is_watching(void)
+notrace bool rcu_is_watching(void)
 {
 	bool ret;
 

I think the patch I suggested is more suitable.

OK, I will let you guys fight it out. ;-)

Thanx, Paul

#4 lore raw
Quoted 41 lines · On Tue, 29 Sep 2020 07:41:06 -0700 "Paul E. McKenney" <[email protected]>…
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Tue, 29 Sep 2020 13:33:40 +0200 Peter Zijlstra <[email protected]> wrote:

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Reinstate the notrace and add a comment to avoid loosing it again.

Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")
---
 kernel/rcu/tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +3 -0
index ee5e595501e8..33020d84ec6b 100644
@@ -1098,8 +1098,11 @@ noinstr bool __rcu_is_watching(void)
  * CPU can safely enter RCU read-side critical sections.  In other words,
  * if the current CPU is not in its idle loop or is in an interrupt or
  * NMI handler, return true.
+ *
+ * Must be notrace because __ftrace_ops_list_func() / ftrace_ops_assist_func()
+ * will call this (for every function) outside of recursion protection.
Quoted 8 lines

kernel/rcu/tree.c noinstr bool __rcu_is_watching(void) · line 1108

Quoted 6 lines
kernel/rcu/tree.c +1 -1
  */
-bool rcu_is_watching(void)
+notrace bool rcu_is_watching(void)
 {
 	bool ret;
 

I think the patch I suggested is more suitable.

Quoted 2 lines

OK, I will let you guys fight it out. ;-)

Well, I think we should actually apply both, but the comment needs to be updated, as it will no longer be outside recursion. And the comment is wrong now as well, as its only outside recursion protection for the assist_func().

But it does prevent it from being always called for perf.

* Make notrace because it can be called by the internal functions of
* ftrace, and making this notrace removes unnecessary recursion calls.

-- Steve

maintainer
#5 lore raw
Quoted 52 lines · Steven Rostedt
Quoted 41 lines · On Tue, 29 Sep 2020 07:41:06 -0700 "Paul E. McKenney" <[email protected]>…
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Tue, 29 Sep 2020 13:33:40 +0200 Peter Zijlstra <[email protected]> wrote:

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Reinstate the notrace and add a comment to avoid loosing it again.

Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")
---
 kernel/rcu/tree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +3 -0
index ee5e595501e8..33020d84ec6b 100644
@@ -1098,8 +1098,11 @@ noinstr bool __rcu_is_watching(void)
  * CPU can safely enter RCU read-side critical sections.  In other words,
  * if the current CPU is not in its idle loop or is in an interrupt or
  * NMI handler, return true.
+ *
+ * Must be notrace because __ftrace_ops_list_func() / ftrace_ops_assist_func()
+ * will call this (for every function) outside of recursion protection.
Quoted 8 lines

kernel/rcu/tree.c noinstr bool __rcu_is_watching(void) · line 1108

Quoted 6 lines
kernel/rcu/tree.c +1 -1
  */
-bool rcu_is_watching(void)
+notrace bool rcu_is_watching(void)
 {
 	bool ret;
 

I think the patch I suggested is more suitable.

Quoted 2 lines

OK, I will let you guys fight it out. ;-)

Well, I think we should actually apply both, but the comment needs to be updated, as it will no longer be outside recursion. And the comment is wrong now as well, as its only outside recursion protection for the assist_func().

Quoted 4 lines

But it does prevent it from being always called for perf.

* Make notrace because it can be called by the internal functions of
* ftrace, and making this notrace removes unnecessary recursion calls.

Fair enough. ;-)

If I don't hear otherwise by late today (Tuesday), Pacific Time, I will update the comment and pull it into -rcu. If you guys have some other route to mainline in mind, you have my Reviewed-by. Either way, just let me know.

Thanx, Paul

#6 lore raw
Quoted 10 lines · On Tue, 29 Sep 2020 09:56:40 -0700 "Paul E. McKenney" <[email protected]>…
Quoted 9 lines

Well, I think we should actually apply both, but the comment needs to be updated, as it will no longer be outside recursion. And the comment is wrong now as well, as its only outside recursion protection for the assist_func().

But it does prevent it from being always called for perf.

* Make notrace because it can be called by the internal functions of
* ftrace, and making this notrace removes unnecessary recursion calls.

Quoted 6 lines

Fair enough. ;-)

If I don't hear otherwise by late today (Tuesday), Pacific Time, I will update the comment and pull it into -rcu. If you guys have some other route to mainline in mind, you have my Reviewed-by. Either way, just let me know.

I'm currently testing the recursion fix and will push that to Linus when done. But you can take the comment update through your tree.

Peter, are you OK if Paul changes your comment to what I suggested?

-- Steve

maintainer
#7 lore raw
Quoted 20 lines · Steven Rostedt
Quoted 10 lines · On Tue, 29 Sep 2020 09:56:40 -0700 "Paul E. McKenney" <[email protected]>…
Quoted 9 lines

Well, I think we should actually apply both, but the comment needs to be updated, as it will no longer be outside recursion. And the comment is wrong now as well, as its only outside recursion protection for the assist_func().

But it does prevent it from being always called for perf.

* Make notrace because it can be called by the internal functions of
* ftrace, and making this notrace removes unnecessary recursion calls.

Quoted 6 lines

Fair enough. ;-)

If I don't hear otherwise by late today (Tuesday), Pacific Time, I will update the comment and pull it into -rcu. If you guys have some other route to mainline in mind, you have my Reviewed-by. Either way, just let me know.

Quoted 4 lines

I'm currently testing the recursion fix and will push that to Linus when done. But you can take the comment update through your tree.

Peter, are you OK if Paul changes your comment to what I suggested?

Hearing no objections, I have queued the patch with the comment updated as suggested by Steven. Thank you all!

Thanx, Paul

#8 lore raw
In reply to Steven Rostedt
Quoted 6 lines · Steven Rostedt

kernel/rcu/tree.c noinstr bool __rcu_is_watching(void) · line 1107

Quoted 4 lines
kernel/rcu/tree.c +1 -0
+notrace bool rcu_is_watching(void)
 {
 	bool ret;

I think the patch I suggested is more suitable.

Both, with only your patch we'd still take the pointless mcount call, which is then pure overhead.

#9 lore raw
Quoted 11 lines · On Tue, 29 Sep 2020 16:49:53 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 6 lines · Steven Rostedt

kernel/rcu/tree.c noinstr bool __rcu_is_watching(void) · line 1107

Quoted 4 lines
kernel/rcu/tree.c +1 -0
+notrace bool rcu_is_watching(void)
 {
 	bool ret;

I think the patch I suggested is more suitable.

Both, with only your patch we'd still take the pointless mcount call, which is then pure overhead.

Yep, and I stated the same thing to Paul ;-)

-- Steve

Tested-by on v1 1/1
#10 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra

Kim reported that perf-ftrace made his box unhappy. It turns out that commit:

ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

removed one too many notrace. Probably due to there not being a helpful comment.

Quoted 6 lines

Reinstate the notrace and add a comment to avoid loosing it again.

Fixes ff5c4f5cad33 ("rcu/tree: Mark the idle relevant functions noinstr")

---

Thanks,

Kim