* [PATCH] ftrace: Protect ftrace_graph_hash with ftrace_sync
@ 2020-02-05 14:41 ` Steven Rostedt
0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2020-02-05 14:41 UTC (permalink / raw)
To: LKML
Cc: Paul E. McKenney, Joel Fernandes, Amol Grover, Ingo Molnar,
linux-kernel-mentees, Madhuparna Bhowmik
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
As function_graph tracer can run when RCU is not "watching", it can not be
protected by synchronize_rcu() it requires running a task on each CPU before
it can be freed. Calling schedule_on_each_cpu(ftrace_sync) needs to be used.
Link: https://lore.kernel.org/r/20200205131110.GT2935@paulmck-ThinkPad-P72
Cc: stable@vger.kernel.org
Fixes: b9b0c831bed26 ("ftrace: Convert graph filter to use hash tables")
Reported-by: "Paul E. McKenney" <paulmck@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
kernel/trace/ftrace.c | 11 +++++++++--
kernel/trace/trace.h | 2 ++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 481ede3eac13..3f7ee102868a 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5867,8 +5867,15 @@ ftrace_graph_release(struct inode *inode, struct file *file)
mutex_unlock(&graph_lock);
- /* Wait till all users are no longer using the old hash */
- synchronize_rcu();
+ /*
+ * We need to do a hard force of sched synchronization.
+ * This is because we use preempt_disable() to do RCU, but
+ * the function tracers can be called where RCU is not watching
+ * (like before user_exit()). We can not rely on the RCU
+ * infrastructure to do the synchronization, thus we must do it
+ * ourselves.
+ */
+ schedule_on_each_cpu(ftrace_sync);
free_ftrace_hash(old_hash);
}
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 8c52f5de9384..3c75d29bd861 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -979,6 +979,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
* Have to open code "rcu_dereference_sched()" because the
* function graph tracer can be called when RCU is not
* "watching".
+ * Protected with schedule_on_each_cpu(ftrace_sync)
*/
hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
@@ -1031,6 +1032,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr)
* Have to open code "rcu_dereference_sched()" because the
* function graph tracer can be called when RCU is not
* "watching".
+ * Protected with schedule_on_each_cpu(ftrace_sync)
*/
notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
!preemptible());
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Linux-kernel-mentees] [PATCH] ftrace: Protect ftrace_graph_hash with ftrace_sync
@ 2020-02-05 14:41 ` Steven Rostedt
0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2020-02-05 14:41 UTC (permalink / raw)
To: LKML
Cc: Madhuparna Bhowmik, Ingo Molnar, Joel Fernandes,
Paul E. McKenney, linux-kernel-mentees
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
As function_graph tracer can run when RCU is not "watching", it can not be
protected by synchronize_rcu() it requires running a task on each CPU before
it can be freed. Calling schedule_on_each_cpu(ftrace_sync) needs to be used.
Link: https://lore.kernel.org/r/20200205131110.GT2935@paulmck-ThinkPad-P72
Cc: stable@vger.kernel.org
Fixes: b9b0c831bed26 ("ftrace: Convert graph filter to use hash tables")
Reported-by: "Paul E. McKenney" <paulmck@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
kernel/trace/ftrace.c | 11 +++++++++--
kernel/trace/trace.h | 2 ++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 481ede3eac13..3f7ee102868a 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5867,8 +5867,15 @@ ftrace_graph_release(struct inode *inode, struct file *file)
mutex_unlock(&graph_lock);
- /* Wait till all users are no longer using the old hash */
- synchronize_rcu();
+ /*
+ * We need to do a hard force of sched synchronization.
+ * This is because we use preempt_disable() to do RCU, but
+ * the function tracers can be called where RCU is not watching
+ * (like before user_exit()). We can not rely on the RCU
+ * infrastructure to do the synchronization, thus we must do it
+ * ourselves.
+ */
+ schedule_on_each_cpu(ftrace_sync);
free_ftrace_hash(old_hash);
}
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 8c52f5de9384..3c75d29bd861 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -979,6 +979,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
* Have to open code "rcu_dereference_sched()" because the
* function graph tracer can be called when RCU is not
* "watching".
+ * Protected with schedule_on_each_cpu(ftrace_sync)
*/
hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
@@ -1031,6 +1032,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr)
* Have to open code "rcu_dereference_sched()" because the
* function graph tracer can be called when RCU is not
* "watching".
+ * Protected with schedule_on_each_cpu(ftrace_sync)
*/
notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
!preemptible());
--
2.20.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ftrace: Protect ftrace_graph_hash with ftrace_sync
2020-02-05 14:41 ` [Linux-kernel-mentees] " Steven Rostedt
@ 2020-02-05 21:57 ` Joel Fernandes
-1 siblings, 0 replies; 4+ messages in thread
From: Joel Fernandes @ 2020-02-05 21:57 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Paul E. McKenney, Amol Grover, Ingo Molnar,
linux-kernel-mentees, Madhuparna Bhowmik
On Wed, Feb 05, 2020 at 09:41:56AM -0500, Steven Rostedt wrote:
>
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
>
> As function_graph tracer can run when RCU is not "watching", it can not be
> protected by synchronize_rcu() it requires running a task on each CPU before
> it can be freed. Calling schedule_on_each_cpu(ftrace_sync) needs to be used.
>
> Link: https://lore.kernel.org/r/20200205131110.GT2935@paulmck-ThinkPad-P72
>
> Cc: stable@vger.kernel.org
> Fixes: b9b0c831bed26 ("ftrace: Convert graph filter to use hash tables")
> Reported-by: "Paul E. McKenney" <paulmck@kernel.org>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
thanks,
- Joel
> ---
> kernel/trace/ftrace.c | 11 +++++++++--
> kernel/trace/trace.h | 2 ++
> 2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 481ede3eac13..3f7ee102868a 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -5867,8 +5867,15 @@ ftrace_graph_release(struct inode *inode, struct file *file)
>
> mutex_unlock(&graph_lock);
>
> - /* Wait till all users are no longer using the old hash */
> - synchronize_rcu();
> + /*
> + * We need to do a hard force of sched synchronization.
> + * This is because we use preempt_disable() to do RCU, but
> + * the function tracers can be called where RCU is not watching
> + * (like before user_exit()). We can not rely on the RCU
> + * infrastructure to do the synchronization, thus we must do it
> + * ourselves.
> + */
> + schedule_on_each_cpu(ftrace_sync);
>
> free_ftrace_hash(old_hash);
> }
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index 8c52f5de9384..3c75d29bd861 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -979,6 +979,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
> * Have to open code "rcu_dereference_sched()" because the
> * function graph tracer can be called when RCU is not
> * "watching".
> + * Protected with schedule_on_each_cpu(ftrace_sync)
> */
> hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
>
> @@ -1031,6 +1032,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr)
> * Have to open code "rcu_dereference_sched()" because the
> * function graph tracer can be called when RCU is not
> * "watching".
> + * Protected with schedule_on_each_cpu(ftrace_sync)
> */
> notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
> !preemptible());
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] ftrace: Protect ftrace_graph_hash with ftrace_sync
@ 2020-02-05 21:57 ` Joel Fernandes
0 siblings, 0 replies; 4+ messages in thread
From: Joel Fernandes @ 2020-02-05 21:57 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Madhuparna Bhowmik, Ingo Molnar, Paul E. McKenney,
linux-kernel-mentees
On Wed, Feb 05, 2020 at 09:41:56AM -0500, Steven Rostedt wrote:
>
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
>
> As function_graph tracer can run when RCU is not "watching", it can not be
> protected by synchronize_rcu() it requires running a task on each CPU before
> it can be freed. Calling schedule_on_each_cpu(ftrace_sync) needs to be used.
>
> Link: https://lore.kernel.org/r/20200205131110.GT2935@paulmck-ThinkPad-P72
>
> Cc: stable@vger.kernel.org
> Fixes: b9b0c831bed26 ("ftrace: Convert graph filter to use hash tables")
> Reported-by: "Paul E. McKenney" <paulmck@kernel.org>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
thanks,
- Joel
> ---
> kernel/trace/ftrace.c | 11 +++++++++--
> kernel/trace/trace.h | 2 ++
> 2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 481ede3eac13..3f7ee102868a 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -5867,8 +5867,15 @@ ftrace_graph_release(struct inode *inode, struct file *file)
>
> mutex_unlock(&graph_lock);
>
> - /* Wait till all users are no longer using the old hash */
> - synchronize_rcu();
> + /*
> + * We need to do a hard force of sched synchronization.
> + * This is because we use preempt_disable() to do RCU, but
> + * the function tracers can be called where RCU is not watching
> + * (like before user_exit()). We can not rely on the RCU
> + * infrastructure to do the synchronization, thus we must do it
> + * ourselves.
> + */
> + schedule_on_each_cpu(ftrace_sync);
>
> free_ftrace_hash(old_hash);
> }
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index 8c52f5de9384..3c75d29bd861 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -979,6 +979,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
> * Have to open code "rcu_dereference_sched()" because the
> * function graph tracer can be called when RCU is not
> * "watching".
> + * Protected with schedule_on_each_cpu(ftrace_sync)
> */
> hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
>
> @@ -1031,6 +1032,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr)
> * Have to open code "rcu_dereference_sched()" because the
> * function graph tracer can be called when RCU is not
> * "watching".
> + * Protected with schedule_on_each_cpu(ftrace_sync)
> */
> notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
> !preemptible());
> --
> 2.20.1
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-05 21:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05 14:41 [PATCH] ftrace: Protect ftrace_graph_hash with ftrace_sync Steven Rostedt
2020-02-05 14:41 ` [Linux-kernel-mentees] " Steven Rostedt
2020-02-05 21:57 ` Joel Fernandes
2020-02-05 21:57 ` [Linux-kernel-mentees] " Joel Fernandes
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.