Skip to content

Commit 12c48e8

Browse files
rostedtgregkh
authored andcommitted
tracing: Stop current tracer when resizing buffer
commit d78ab79 upstream. 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/20231205220010.748996423@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Fixes: 3928a8a ("ftrace: make work with new ring buffer") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1741e17 commit 12c48e8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/trace/trace.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6394,9 +6394,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
63946394
if (!tr->array_buffer.buffer)
63956395
return 0;
63966396

6397+
/* Do not allow tracing while resizng ring buffer */
6398+
tracing_stop_tr(tr);
6399+
63976400
ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu);
63986401
if (ret < 0)
6399-
return ret;
6402+
goto out_start;
64006403

64016404
#ifdef CONFIG_TRACER_MAX_TRACE
64026405
if (!tr->current_trace->use_max_tr)
@@ -6424,7 +6427,7 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
64246427
WARN_ON(1);
64256428
tracing_disabled = 1;
64266429
}
6427-
return ret;
6430+
goto out_start;
64286431
}
64296432

64306433
update_buffer_entries(&tr->max_buffer, cpu);
@@ -6433,7 +6436,8 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
64336436
#endif /* CONFIG_TRACER_MAX_TRACE */
64346437

64356438
update_buffer_entries(&tr->array_buffer, cpu);
6436-
6439+
out_start:
6440+
tracing_start_tr(tr);
64376441
return ret;
64386442
}
64396443

0 commit comments

Comments
 (0)