Skip to content

Commit 2348cad

Browse files
rostedtgregkh
authored andcommitted
ring-buffer: Protect ring_buffer_reset() from reentrancy
commit 51d1579 upstream. The resetting of the entire ring buffer use to simply go through and reset each individual CPU buffer that had its own protection and synchronization. But this was very slow, due to performing a synchronization for each CPU. The code was reshuffled to do one disabling of all CPU buffers, followed by a single RCU synchronization, and then the resetting of each of the CPU buffers. But unfortunately, the mutex that prevented multiple occurrences of resetting the buffer was not moved to the upper function, and there is nothing to protect from it. Take the ring buffer mutex around the global reset. Cc: stable@vger.kernel.org Fixes: b23d7a5 ("ring-buffer: speed up buffer resets by avoiding synchronize_rcu for each CPU") Reported-by: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6f67cf0 commit 2348cad

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5233,6 +5233,9 @@ void ring_buffer_reset(struct trace_buffer *buffer)
52335233
struct ring_buffer_per_cpu *cpu_buffer;
52345234
int cpu;
52355235

5236+
/* prevent another thread from changing buffer sizes */
5237+
mutex_lock(&buffer->mutex);
5238+
52365239
for_each_buffer_cpu(buffer, cpu) {
52375240
cpu_buffer = buffer->buffers[cpu];
52385241

@@ -5251,6 +5254,8 @@ void ring_buffer_reset(struct trace_buffer *buffer)
52515254
atomic_dec(&cpu_buffer->record_disabled);
52525255
atomic_dec(&cpu_buffer->resize_disabled);
52535256
}
5257+
5258+
mutex_unlock(&buffer->mutex);
52545259
}
52555260
EXPORT_SYMBOL_GPL(ring_buffer_reset);
52565261

0 commit comments

Comments
 (0)