* [PATCH v2 0/2] ring-buffer: Clean up resize_disabled checks
@ 2026-09-16 15:28 Vincent Donnefort
2026-09-16 15:28 ` [PATCH v2 1/2] " Vincent Donnefort
2026-09-16 15:28 ` [PATCH v2 2/2] ring-buffer: Remove unnecessary cpumask_test_cpu Vincent Donnefort
0 siblings, 2 replies; 3+ messages in thread
From: Vincent Donnefort @ 2026-09-16 15:28 UTC (permalink / raw)
To: rostedt, mhiramat, linux-trace-kernel
Cc: mathieu.desnoyers, kernel-team, linux-kernel, devnexen,
Vincent Donnefort
ring_buffer_subbuf_order_set() checks for resize_disabled twice under
the same buffer->mutex hold. Moreover, this check duplicates the logic
in ring_buffer_resize(). Create a common helper rb_resize_disabled() to
factor out this code and drop redundant checks.
Additionally, remove the unnecessary cpumask_test_cpu() in
ring_buffer_subbuf_order_set() as for_each_buffer_cpu() already
iterates over buffer->cpumask.
v2:
- Split cpumask_test_cpu() cleanup into its own patch (Steven)
- Remove another unnecessary cpumask_test_cpu() (David)
v1: https://lore.kernel.org/all/20260914175907.1027349-1-vdonnefort@google.com/
Vincent Donnefort (2):
ring-buffer: Clean up resize_disabled checks
ring-buffer: Remove unnecessary cpumask_test_cpu
kernel/trace/ring_buffer.c | 70 +++++++++++++++-----------------------
1 file changed, 28 insertions(+), 42 deletions(-)
base-commit: fd73f4a6659897191fa0d40695fe370925dd3780
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/2] ring-buffer: Clean up resize_disabled checks
2026-09-16 15:28 [PATCH v2 0/2] ring-buffer: Clean up resize_disabled checks Vincent Donnefort
@ 2026-09-16 15:28 ` Vincent Donnefort
2026-09-16 15:28 ` [PATCH v2 2/2] ring-buffer: Remove unnecessary cpumask_test_cpu Vincent Donnefort
1 sibling, 0 replies; 3+ messages in thread
From: Vincent Donnefort @ 2026-09-16 15:28 UTC (permalink / raw)
To: rostedt, mhiramat, linux-trace-kernel
Cc: mathieu.desnoyers, kernel-team, linux-kernel, devnexen,
Vincent Donnefort
ring_buffer_subbuf_order_set() checks for resize_disabled twice under
the same buffer->mutex hold. Moreover, this check duplicates the logic
in ring_buffer_resize(). Create a common helper rb_resize_disabled() to
factor out this code.
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
kernel/trace/ring_buffer.c | 63 +++++++++++++++++---------------------
1 file changed, 28 insertions(+), 35 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 04bb94c29f58..73311c4fc556 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3280,6 +3280,21 @@ static void update_pages_handler(struct work_struct *work)
complete(&cpu_buffer->update_done);
}
+static bool rb_resize_disabled(struct trace_buffer *buffer, int cpu)
+{
+ lockdep_assert_held(&buffer->mutex);
+
+ if (cpu != RING_BUFFER_ALL_CPUS)
+ return atomic_read(&buffer->buffers[cpu]->resize_disabled);
+
+ for_each_buffer_cpu(buffer, cpu) {
+ if (atomic_read(&buffer->buffers[cpu]->resize_disabled))
+ return true;
+ }
+
+ return false;
+}
+
/**
* ring_buffer_resize - resize the ring buffer
* @buffer: the buffer to resize.
@@ -3324,20 +3339,17 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
if (nr_pages < 2)
nr_pages = 2;
- if (cpu_id == RING_BUFFER_ALL_CPUS) {
- /*
- * Don't succeed if resizing is disabled, as a reader might be
- * manipulating the ring buffer and is expecting a sane state while
- * this is true.
- */
- for_each_buffer_cpu(buffer, cpu) {
- cpu_buffer = buffer->buffers[cpu];
- if (atomic_read(&cpu_buffer->resize_disabled)) {
- err = -EBUSY;
- goto out_err_unlock;
- }
- }
+ /*
+ * Don't succeed if resizing is disabled, as a reader might be
+ * manipulating the ring buffer and is expecting a sane state while
+ * this is true.
+ */
+ if (rb_resize_disabled(buffer, cpu_id)) {
+ err = -EBUSY;
+ goto out_err_unlock;
+ }
+ if (cpu_id == RING_BUFFER_ALL_CPUS) {
/* calculate the pages to update */
for_each_buffer_cpu(buffer, cpu) {
cpu_buffer = buffer->buffers[cpu];
@@ -3409,16 +3421,6 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
if (nr_pages == cpu_buffer->nr_pages)
goto out;
- /*
- * Don't succeed if resizing is disabled, as a reader might be
- * manipulating the ring buffer and is expecting a sane state while
- * this is true.
- */
- if (atomic_read(&cpu_buffer->resize_disabled)) {
- err = -EBUSY;
- goto out_err_unlock;
- }
-
cpu_buffer->nr_pages_to_update = nr_pages -
cpu_buffer->nr_pages;
@@ -7473,13 +7475,9 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
old_capacity = rb_subbuf_capacity(buffer);
- /* The mmap fast path reads subbuf_order without buffer->mutex. */
- for_each_buffer_cpu(buffer, cpu) {
- if (!cpumask_test_cpu(cpu, buffer->cpumask))
- continue;
- if (atomic_read(&buffer->buffers[cpu]->resize_disabled))
- return -EBUSY;
- }
+ /* Check it is resizable before we touch subbuf_order */
+ if (rb_resize_disabled(buffer, RING_BUFFER_ALL_CPUS))
+ return -EBUSY;
atomic_inc(&buffer->record_disabled);
@@ -7496,11 +7494,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
cpu_buffer = buffer->buffers[cpu];
- if (atomic_read(&cpu_buffer->resize_disabled)) {
- err = -EBUSY;
- goto error;
- }
-
/* Update the number of pages to match the new size */
nr_pages = old_capacity * buffer->buffers[cpu]->nr_pages;
nr_pages = DIV_ROUND_UP(nr_pages, rb_subbuf_capacity(buffer));
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] ring-buffer: Remove unnecessary cpumask_test_cpu
2026-09-16 15:28 [PATCH v2 0/2] ring-buffer: Clean up resize_disabled checks Vincent Donnefort
2026-09-16 15:28 ` [PATCH v2 1/2] " Vincent Donnefort
@ 2026-09-16 15:28 ` Vincent Donnefort
1 sibling, 0 replies; 3+ messages in thread
From: Vincent Donnefort @ 2026-09-16 15:28 UTC (permalink / raw)
To: rostedt, mhiramat, linux-trace-kernel
Cc: mathieu.desnoyers, kernel-team, linux-kernel, devnexen,
Vincent Donnefort
for_each_buffer_cpu() already iterates over buffer->cpumask. Remove the
unnecessary cpumask_test_cpu() found in ring_buffer_subbuf_order_set().
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
---
kernel/trace/ring_buffer.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 73311c4fc556..2087bbfd8f20 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -7488,10 +7488,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
/* Make sure all new buffers are allocated, before deleting the old ones */
for_each_buffer_cpu(buffer, cpu) {
-
- if (!cpumask_test_cpu(cpu, buffer->cpumask))
- continue;
-
cpu_buffer = buffer->buffers[cpu];
/* Update the number of pages to match the new size */
@@ -7522,9 +7518,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
struct list_head old_pages;
unsigned long flags;
- if (!cpumask_test_cpu(cpu, buffer->cpumask))
- continue;
-
cpu_buffer = buffer->buffers[cpu];
raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-16 15:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-16 15:28 [PATCH v2 0/2] ring-buffer: Clean up resize_disabled checks Vincent Donnefort
2026-09-16 15:28 ` [PATCH v2 1/2] " Vincent Donnefort
2026-09-16 15:28 ` [PATCH v2 2/2] ring-buffer: Remove unnecessary cpumask_test_cpu Vincent Donnefort
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).