ring-buffer: Protect ring_buffer_reset() from reentrancy
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 8 Nov 2021 15:58:10 +0000 (10:58 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 13:03:49 +0000 (14:03 +0100)
commitc1e6e42740cb3904d80abd2e0c623c7736ed57d9
treeee3eefc3a79c5498b40e7b804636f30db8438bdc
parent93fccb1f8939ef5328a674a2301286a0d0a77bfa
ring-buffer: Protect ring_buffer_reset() from reentrancy

commit 51d157946666382e779f94c39891e8e9a020da78 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: b23d7a5f4a07a ("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>
kernel/trace/ring_buffer.c