From b5aa3a472b6d13d57a7521a663290dea2fb483a7 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (Red Hat)" Date: Mon, 4 Nov 2013 18:34:44 -0500 Subject: [PATCH] ftrace: Have control op function callback only trace when RCU is watching Dave Jones reported that trinity would be able to trigger the following back trace: =============================== [ INFO: suspicious RCU usage. ] 3.10.0-rc2+ #38 Not tainted ------------------------------- include/linux/rcupdate.h:771 rcu_read_lock() used illegally while idle! other info that might help us debug this: RCU used illegally from idle CPU! rcu_scheduler_active = 1, debug_locks = 0 RCU used illegally from extended quiescent state! 1 lock held by trinity-child1/18786: #0: (rcu_read_lock){.+.+..}, at: [] __perf_event_overflow+0x108/0x310 stack backtrace: CPU: 3 PID: 18786 Comm: trinity-child1 Not tainted 3.10.0-rc2+ #38 0000000000000000 ffff88020767bac8 ffffffff816e2f6b ffff88020767baf8 ffffffff810b5897 ffff88021de92520 0000000000000000 ffff88020767bbf8 0000000000000000 ffff88020767bb78 ffffffff8113ded4 ffffffff8113dd48 Call Trace: [] dump_stack+0x19/0x1b [] lockdep_rcu_suspicious+0xe7/0x120 [] __perf_event_overflow+0x294/0x310 [] ? __perf_event_overflow+0x108/0x310 [] ? __const_udelay+0x29/0x30 [] ? __rcu_read_unlock+0x54/0xa0 [] ? ftrace_call+0x5/0x2f [] perf_swevent_overflow+0x51/0xe0 [] perf_swevent_event+0x5f/0x90 [] perf_tp_event+0x109/0x4f0 [] ? perf_tp_event+0x2af/0x4f0 [] ? __rcu_read_lock+0x20/0x20 [] perf_ftrace_function_call+0xbf/0xd0 [] ? ftrace_ops_control_func+0x181/0x210 [] ? __rcu_read_lock+0x20/0x20 [] ? rcu_eqs_enter_common+0x5e/0x470 [] ftrace_ops_control_func+0x181/0x210 [] ftrace_call+0x5/0x2f [] ? ftrace_ops_control_func+0x1c9/0x210 [] ? ftrace_call+0x5/0x2f [] ? debug_lockdep_rcu_enabled+0x5/0x40 [] ? debug_lockdep_rcu_enabled+0x5/0x40 [] ? rcu_eqs_enter_common+0x5e/0x470 [] rcu_eqs_enter+0x6a/0xb0 [] rcu_user_enter+0x13/0x20 [] user_enter+0x6a/0xd0 [] syscall_trace_leave+0x78/0x140 [] int_check_syscall_exit_work+0x34/0x3d ------------[ cut here ]------------ Perf uses rcu_read_lock() but as the function tracer can trace functions even when RCU is not currently active, this makes the rcu_read_lock() used by perf ineffective. As perf is currently the only user of the ftrace_ops_control_func() and perf is also the only function callback that actively uses rcu_read_lock(), the quick fix is to prevent the ftrace_ops_control_func() from calling its callbacks if RCU is not active. With Paul's new "rcu_is_watching()" we can tell if RCU is active or not. Reported-by: Dave Jones Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Jiri Olsa Signed-off-by: Steven Rostedt --- kernel/trace/ftrace.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 44e826a79665..080b7d41e17f 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4388,12 +4388,21 @@ ftrace_ops_control_func(unsigned long ip, unsigned long parent_ip, */ preempt_disable_notrace(); trace_recursion_set(TRACE_CONTROL_BIT); + + /* + * Control funcs (perf) uses RCU. Only trace if + * RCU is currently active. + */ + if (!rcu_is_watching()) + goto out; + do_for_each_ftrace_op(op, ftrace_control_list) { if (!(op->flags & FTRACE_OPS_FL_STUB) && !ftrace_function_local_disabled(op) && ftrace_ops_test(op, ip, regs)) op->func(ip, parent_ip, op, regs); } while_for_each_ftrace_op(op); + out: trace_recursion_clear(TRACE_CONTROL_BIT); preempt_enable_notrace(); }