Skip to content

Commit d78ab79

Browse files
committed
tracing: Stop current tracer when resizing buffer
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]>
1 parent 7be7646 commit d78ab79

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/trace/trace.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -6387,9 +6387,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
63876387
if (!tr->array_buffer.buffer)
63886388
return 0;
63896389

6390+
/* Do not allow tracing while resizng ring buffer */
6391+
tracing_stop_tr(tr);
6392+
63906393
ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu);
63916394
if (ret < 0)
6392-
return ret;
6395+
goto out_start;
63936396

63946397
#ifdef CONFIG_TRACER_MAX_TRACE
63956398
if (!tr->current_trace->use_max_tr)
@@ -6417,7 +6420,7 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
64176420
WARN_ON(1);
64186421
tracing_disabled = 1;
64196422
}
6420-
return ret;
6423+
goto out_start;
64216424
}
64226425

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

64286431
update_buffer_entries(&tr->array_buffer, cpu);
6429-
6432+
out_start:
6433+
tracing_start_tr(tr);
64306434
return ret;
64316435
}
64326436

0 commit comments

Comments
 (0)