提交 9a469f6a 编写于 作者: S Steven Rostedt (VMware) 提交者: Yang Yingliang

ftrace: Move RCU is watching check after recursion check

stable inclusion
from linux-4.19.150
commit 2fd5a462eb7b39694ae013450dc47d84cdf7204a

--------------------------------

commit b40341fa upstream.

The first thing that the ftrace function callback helper functions should do
is to check for recursion. Peter Zijlstra found that when
"rcu_is_watching()" had its notrace removed, it caused perf function tracing
to crash. This is because the call of rcu_is_watching() is tested before
function recursion is checked and and if it is traced, it will cause an
infinite recursion loop.

rcu_is_watching() should still stay notrace, but to prevent this should
never had crashed in the first place. The recursion prevention must be the
first thing done in callback functions.

Link: https://lore.kernel.org/r/20200929112541.GM2628@hirez.programming.kicks-ass.net

Cc: stable@vger.kernel.org
Cc: Paul McKenney <paulmck@kernel.org>
Fixes: c68c0fa2 ("ftrace: Have ftrace_ops_get_func() handle RCU and PER_CPU flags too")
Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Reported-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 52fdd36b
...@@ -6363,16 +6363,14 @@ static void ftrace_ops_assist_func(unsigned long ip, unsigned long parent_ip, ...@@ -6363,16 +6363,14 @@ static void ftrace_ops_assist_func(unsigned long ip, unsigned long parent_ip,
{ {
int bit; int bit;
if ((op->flags & FTRACE_OPS_FL_RCU) && !rcu_is_watching())
return;
bit = trace_test_and_set_recursion(TRACE_LIST_START, TRACE_LIST_MAX); bit = trace_test_and_set_recursion(TRACE_LIST_START, TRACE_LIST_MAX);
if (bit < 0) if (bit < 0)
return; return;
preempt_disable_notrace(); preempt_disable_notrace();
op->func(ip, parent_ip, op, regs); if (!(op->flags & FTRACE_OPS_FL_RCU) || rcu_is_watching())
op->func(ip, parent_ip, op, regs);
preempt_enable_notrace(); preempt_enable_notrace();
trace_clear_recursion(bit); trace_clear_recursion(bit);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册