Skip to content

Commit

Permalink
tracing: Use same local variable when resetting the ring buffer
Browse files Browse the repository at this point in the history
In the ftrace code that resets the ring buffer it references the
buffer with a local variable, but then uses the tr->buffer as the
parameter to reset. If the wakeup tracer is running, which can
switch the tr->buffer with the max saved buffer, this can break
the requirement of disabling the buffer before the reset.

   buffer = tr->buffer;
   ring_buffer_record_disable(buffer);
   synchronize_sched();
   __tracing_reset(tr->buffer, cpu);

If the tr->buffer is swapped, then the reset is not happening to the
buffer that was disabled. This will cause the ring buffer to fail.

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 ea14eb7 commit 283740c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ void unregister_tracer(struct tracer *type)
mutex_unlock(&trace_types_lock);
}

static void __tracing_reset(struct trace_array *tr, int cpu)
static void __tracing_reset(struct ring_buffer *buffer, int cpu)
{
ftrace_disable_cpu();
ring_buffer_reset_cpu(tr->buffer, cpu);
ring_buffer_reset_cpu(buffer, cpu);
ftrace_enable_cpu();
}

Expand All @@ -855,7 +855,7 @@ void tracing_reset(struct trace_array *tr, int cpu)

/* Make sure all commits have finished */
synchronize_sched();
__tracing_reset(tr, cpu);
__tracing_reset(buffer, cpu);

ring_buffer_record_enable(buffer);
}
Expand All @@ -873,7 +873,7 @@ void tracing_reset_online_cpus(struct trace_array *tr)
tr->time_start = ftrace_now(tr->cpu);

for_each_online_cpu(cpu)
__tracing_reset(tr, cpu);
__tracing_reset(buffer, cpu);

ring_buffer_record_enable(buffer);
}
Expand Down

0 comments on commit 283740c

Please sign in to comment.