tracing: Stop the tracing while changing the ring buffer subbuf size
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 19 Dec 2023 18:54:24 +0000 (13:54 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 21 Dec 2023 16:00:56 +0000 (11:00 -0500)
Because the main buffer and the snapshot buffer need to be the same for
some tracers, otherwise it will fail and disable all tracing, the tracers
need to be stopped while updating the sub buffer sizes so that the tracers
see the main and snapshot buffers with the same sub buffer size.

Link: https://lore.kernel.org/linux-trace-kernel/20231219185630.353222794@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>
Fixes: 2808e31ec12e ("ring-buffer: Add interface for configuring trace sub buffer size")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace.c

index 2439e00aa4ce90a455abd14bfe61425d54ae74e0..82303bd2bba1372c267a6f2199f3a72d12988d17 100644 (file)
@@ -9412,13 +9412,16 @@ buffer_order_write(struct file *filp, const char __user *ubuf,
        if (val < 0 || val > 7)
                return -EINVAL;
 
+       /* Do not allow tracing while changing the order of the ring buffer */
+       tracing_stop_tr(tr);
+
        old_order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer);
        if (old_order == val)
-               return 0;
+               goto out;
 
        ret = ring_buffer_subbuf_order_set(tr->array_buffer.buffer, val);
        if (ret)
-               return 0;
+               goto out;
 
 #ifdef CONFIG_TRACER_MAX_TRACE
 
@@ -9445,11 +9448,15 @@ buffer_order_write(struct file *filp, const char __user *ubuf,
                         */
                        tracing_disabled = 1;
                }
-               return ret;
+               goto out;
        }
  out_max:
 #endif
        (*ppos)++;
+ out:
+       if (ret)
+               cnt = ret;
+       tracing_start_tr(tr);
        return cnt;
 }