ftrace: Protect ftrace_graph_hash with ftrace_sync
Steven Rostedt
maintainerPATCH 1/1 ftrace: Protect ftrace_graph_hash with ftrace_sync
From: "Steven Rostedt (VMware)" <[email protected]>
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.
--- kernel/trace/ftrace.c | 11 +++++++++-- kernel/trace/trace.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)
kernel/trace/ftrace.c +9 -2
@@ -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); }
kernel/trace/trace.h +2 -0
@@ -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 ());
Signature · 1 line
2.20.1
Quoted 7 lines · Steven Rostedt
From: "Steven Rostedt (VMware)" <[email protected]>
As
function_graphtracer can run when RCU is not "watching", it can not be protected bysynchronize_rcu()it requires running a task on each CPU before it can be freed. Callingschedule_on_each_cpu(ftrace_sync)needs to be used.
Quoted 6 lines
Fixes b9b0c831bed26 ("ftrace: Convert graph filter to use hash tables")Reported-by "Paul E. McKenney" <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>
thanks,
- Joel
Quoted 50 lines
--- kernel/trace/ftrace.c | 11 +++++++++-- kernel/trace/trace.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)kernel/trace/ftrace.c +9
-2@@ -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); }kernel/trace/trace.h +2
-0@@ -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 ());Signature · 1 line
2.20.1
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees