Skip to content

Commit

Permalink
tracing: Disable buffer switching when starting or stopping trace
Browse files Browse the repository at this point in the history
When the trace iterator is read, tracing_start() and tracing_stop()
is called to stop tracing while the iterator is processing the trace
output.

These functions disable both the standard buffer and the max latency
buffer. But if the wakeup tracer is running, it can switch these
buffers between the two disables:

  buffer = global_trace.buffer;
  if (buffer)
      ring_buffer_record_disable(buffer);

      <<<--------- swap happens here

  buffer = max_tr.buffer;
  if (buffer)
      ring_buffer_record_disable(buffer);

What happens is that we disabled the same buffer twice. On tracing_start()
we can enable the same buffer twice. All ring_buffer_record_disable()
must be matched with a ring_buffer_record_enable() or the buffer
can be disable permanently, or enable prematurely, and cause a bug
where a reset happens while a trace is commiting.

This patch protects these two by taking the ftrace_max_lock to prevent
a switch from occurring.

Found with Li Zefan's ftrace_stress_test.

Cc: stable@kernel.org
Reported-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt authored and Steven Rostedt committed Mar 13, 2010
1 parent 283740c commit a2f8071
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,8 @@ void tracing_start(void)
goto out;
}

/* Prevent the buffers from switching */
arch_spin_lock(&ftrace_max_lock);

buffer = global_trace.buffer;
if (buffer)
Expand All @@ -959,6 +961,8 @@ void tracing_start(void)
if (buffer)
ring_buffer_record_enable(buffer);

arch_spin_unlock(&ftrace_max_lock);

ftrace_start();
out:
spin_unlock_irqrestore(&tracing_start_lock, flags);
Expand All @@ -980,6 +984,9 @@ void tracing_stop(void)
if (trace_stop_count++)
goto out;

/* Prevent the buffers from switching */
arch_spin_lock(&ftrace_max_lock);

buffer = global_trace.buffer;
if (buffer)
ring_buffer_record_disable(buffer);
Expand All @@ -988,6 +995,8 @@ void tracing_stop(void)
if (buffer)
ring_buffer_record_disable(buffer);

arch_spin_unlock(&ftrace_max_lock);

out:
spin_unlock_irqrestore(&tracing_start_lock, flags);
}
Expand Down

0 comments on commit a2f8071

Please sign in to comment.