ring-buffer: Do no swap cpu buffers if order is different
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 19 Dec 2023 18:54:21 +0000 (13:54 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 21 Dec 2023 15:54:50 +0000 (10:54 -0500)
As all the subbuffer order (subbuffer sizes) must be the same throughout
the ring buffer, check the order of the buffers that are doing a CPU
buffer swap in ring_buffer_swap_cpu() to make sure they are the same.

If the are not the same, then fail to do the swap, otherwise the ring
buffer will think the CPU buffer has a specific subbuffer size when it
does not.

Link: https://lore.kernel.org/linux-trace-kernel/20231219185629.467894710@goodmis.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>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Cc: Vincent Donnefort <vdonnefort@google.com>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ring_buffer.c

index 3c11e8e811edd56379f15f25dae94b8582000fb6..fdcd171b09b5d91de39861929bed90b93e60879b 100644 (file)
@@ -5417,6 +5417,9 @@ int ring_buffer_swap_cpu(struct trace_buffer *buffer_a,
        if (cpu_buffer_a->nr_pages != cpu_buffer_b->nr_pages)
                goto out;
 
+       if (buffer_a->subbuf_order != buffer_b->subbuf_order)
+               goto out;
+
        ret = -EAGAIN;
 
        if (atomic_read(&buffer_a->record_disabled))