Commit 6224beb1 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt

tracing: Have branch tracer use recursive field of task struct

Fengguang Wu's tests triggered a bug in the branch tracer's start up
test when CONFIG_DEBUG_PREEMPT set. This was because that config
adds some debug logic in the per cpu field, which calls back into
the branch tracer.

The branch tracer has its own recursive checks, but uses a per cpu
variable to implement it. If retrieving the per cpu variable calls
back into the branch tracer, you can see how things will break.

Instead of using a per cpu variable, use the trace_recursion field
of the current task struct. Simply set a bit when entering the
branch tracing and clear it when leaving. If the bit is set on
entry, just don't do the tracing.

There's also the case with lockdep, as the local_irq_save() called
before the recursion can also trigger code that can call back into
the function. Changing that to a raw_local_irq_save() will protect
that as well.

This prevents the recursion and the inevitable crash that follows.

Link: http://lkml.kernel.org/r/20150630141803.GA28071@wfg-t540p.sh.intel.com

Cc: stable@vger.kernel.org # 3.10+
Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Tested-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent d770e558
...@@ -444,6 +444,7 @@ enum { ...@@ -444,6 +444,7 @@ enum {
TRACE_CONTROL_BIT, TRACE_CONTROL_BIT,
TRACE_BRANCH_BIT,
/* /*
* Abuse of the trace_recursion. * Abuse of the trace_recursion.
* As we need a way to maintain state if we are tracing the function * As we need a way to maintain state if we are tracing the function
......
...@@ -36,9 +36,12 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect) ...@@ -36,9 +36,12 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect)
struct trace_branch *entry; struct trace_branch *entry;
struct ring_buffer *buffer; struct ring_buffer *buffer;
unsigned long flags; unsigned long flags;
int cpu, pc; int pc;
const char *p; const char *p;
if (current->trace_recursion & TRACE_BRANCH_BIT)
return;
/* /*
* I would love to save just the ftrace_likely_data pointer, but * I would love to save just the ftrace_likely_data pointer, but
* this code can also be used by modules. Ugly things can happen * this code can also be used by modules. Ugly things can happen
...@@ -49,10 +52,10 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect) ...@@ -49,10 +52,10 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect)
if (unlikely(!tr)) if (unlikely(!tr))
return; return;
local_irq_save(flags); raw_local_irq_save(flags);
cpu = raw_smp_processor_id(); current->trace_recursion |= TRACE_BRANCH_BIT;
data = per_cpu_ptr(tr->trace_buffer.data, cpu); data = this_cpu_ptr(tr->trace_buffer.data);
if (atomic_inc_return(&data->disabled) != 1) if (atomic_read(&data->disabled))
goto out; goto out;
pc = preempt_count(); pc = preempt_count();
...@@ -81,8 +84,8 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect) ...@@ -81,8 +84,8 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect)
__buffer_unlock_commit(buffer, event); __buffer_unlock_commit(buffer, event);
out: out:
atomic_dec(&data->disabled); current->trace_recursion &= ~TRACE_BRANCH_BIT;
local_irq_restore(flags); raw_local_irq_restore(flags);
} }
static inline static inline
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment