Skip to content

Commit 3fdc8ff

Browse files
rostedtgregkh
authored andcommitted
ftrace: Protect ftrace_graph_hash with ftrace_sync
[ Upstream commit 54a16ff ] 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: b9b0c83 ("ftrace: Convert graph filter to use hash tables") Reported-by: "Paul E. McKenney" <paulmck@kernel.org> Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1cd057a commit 3fdc8ff

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎kernel/trace/ftrace.c‎

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

58735873
mutex_unlock(&graph_lock);
58745874

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

58785885
free_ftrace_hash(old_hash);
58795886
}

‎kernel/trace/trace.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ static inline int ftrace_graph_addr(struct ftrace_graph_ent *trace)
965965
* Have to open code "rcu_dereference_sched()" because the
966966
* function graph tracer can be called when RCU is not
967967
* "watching".
968+
* Protected with schedule_on_each_cpu(ftrace_sync)
968969
*/
969970
hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
970971

@@ -1017,6 +1018,7 @@ static inline int ftrace_graph_notrace_addr(unsigned long addr)
10171018
* Have to open code "rcu_dereference_sched()" because the
10181019
* function graph tracer can be called when RCU is not
10191020
* "watching".
1021+
* Protected with schedule_on_each_cpu(ftrace_sync)
10201022
*/
10211023
notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
10221024
!preemptible());

0 commit comments

Comments
 (0)