Skip to content

Commit

Permalink
tracing: Stop current tracer when resizing buffer
Browse files Browse the repository at this point in the history
When the ring buffer is being resized, it can cause side effects to the
running tracer. For instance, there's a race with irqsoff tracer that
swaps individual per cpu buffers between the main buffer and the snapshot
buffer. The resize operation modifies the main buffer and then the
snapshot buffer. If a swap happens in between those two operations it will
break the tracer.

Simply stop the running tracer before resizing the buffers and enable it
again when finished.

Link: https://lkml.kernel.org/r/[email protected]

Cc: [email protected]
Cc: Masami Hiramatsu <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: Andrew Morton <[email protected]>
Fixes: 3928a8a ("ftrace: make work with new ring buffer")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed Dec 5, 2023
1 parent 7be7646 commit d78ab79
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6387,9 +6387,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
if (!tr->array_buffer.buffer)
return 0;

/* Do not allow tracing while resizng ring buffer */
tracing_stop_tr(tr);

ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu);
if (ret < 0)
return ret;
goto out_start;

#ifdef CONFIG_TRACER_MAX_TRACE
if (!tr->current_trace->use_max_tr)
Expand Down Expand Up @@ -6417,7 +6420,7 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
WARN_ON(1);
tracing_disabled = 1;
}
return ret;
goto out_start;
}

update_buffer_entries(&tr->max_buffer, cpu);
Expand All @@ -6426,7 +6429,8 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
#endif /* CONFIG_TRACER_MAX_TRACE */

update_buffer_entries(&tr->array_buffer, cpu);

out_start:
tracing_start_tr(tr);
return ret;
}

Expand Down

0 comments on commit d78ab79

Please sign in to comment.