Skip to content

Commit 54a16ff

Browse files
committed
ftrace: Protect ftrace_graph_hash with ftrace_sync
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: [email protected] Fixes: b9b0c83 ("ftrace: Convert graph filter to use hash tables") Reported-by: "Paul E. McKenney" <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 16052dd commit 54a16ff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

kernel/trace/ftrace.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,8 +5867,15 @@ ftrace_graph_release(struct inode *inode, struct file *file)
58675867

58685868
mutex_unlock(&graph_lock);
58695869

5870-
/* Wait till all users are no longer using the old hash */
5871-
synchronize_rcu();
5870+
/*
5871+
* We need to do a hard force of sched synchronization.
5872+
* This is because we use preempt_disable() to do RCU, but
5873+
* the function tracers can be called where RCU is not watching
5874+
* (like before user_exit()). We can not rely on the RCU
5875+
* infrastructure to do the synchronization, thus we must do it
5876+
* ourselves.
5877+
*/
5878+
schedule_on_each_cpu(ftrace_sync);
58725879

58735880
free_ftrace_hash(old_hash);
58745881
}

kernel/trace/trace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
979979
* Have to open code "rcu_dereference_sched()" because the
980980
* function graph tracer can be called when RCU is not
981981
* "watching".
982+
* Protected with schedule_on_each_cpu(ftrace_sync)
982983
*/
983984
hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
984985

@@ -1031,6 +1032,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr)
10311032
* Have to open code "rcu_dereference_sched()" because the
10321033
* function graph tracer can be called when RCU is not
10331034
* "watching".
1035+
* Protected with schedule_on_each_cpu(ftrace_sync)
10341036
*/
10351037
notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
10361038
!preemptible());

0 commit comments

Comments
 (0)