public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: Fix nr_subbufs initialization in simple_ring_buffer_init_mm()
@ 2026-03-18 17:19 David Carlier
  2026-03-18 19:28 ` Steven Rostedt
  2026-03-19  9:41 ` [PATCH v2] " David Carlier
  0 siblings, 2 replies; 7+ messages in thread
From: David Carlier @ 2026-03-18 17:19 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
  Cc: linux-kernel, David Carlier

In simple_ring_buffer_init_mm(), meta->nr_subbufs is assigned from
cpu_buffer->nr_pages at line 398, but cpu_buffer was just zeroed by
memset() at line 390. The actual page count is only computed later in
the loop (lines 410-429), so nr_subbufs is always set to 0.

This field is part of struct trace_buffer_meta (UAPI), exposed to
consumers who rely on it for buffer geometry calculations (e.g.,
data_len = subbuf_size * nr_subbufs). A value of 0 breaks ring buffer
consumption entirely.

Fix by using desc->nr_page_va directly, which holds the correct total
page count (reader + ring pages) and is available at this point. This
matches the UAPI documentation: "Number of subbufs in the ring-buffer,
including the reader."

Fixes: 34e5b958bdad ("tracing: Introduce simple_ring_buffer")
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 kernel/trace/simple_ring_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/simple_ring_buffer.c b/kernel/trace/simple_ring_buffer.c
index 02af2297ae5a..e991a0d8def2 100644
--- a/kernel/trace/simple_ring_buffer.c
+++ b/kernel/trace/simple_ring_buffer.c
@@ -395,7 +395,7 @@ int simple_ring_buffer_init_mm(struct simple_rb_per_cpu *cpu_buffer,
 
 	memset(cpu_buffer->meta, 0, sizeof(*cpu_buffer->meta));
 	cpu_buffer->meta->meta_page_size = PAGE_SIZE;
-	cpu_buffer->meta->nr_subbufs = cpu_buffer->nr_pages;
+	cpu_buffer->meta->nr_subbufs = desc->nr_page_va;
 
 	/* The reader page is not part of the ring initially */
 	page = load_page(desc->page_va[0]);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-19 21:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 17:19 [PATCH] tracing: Fix nr_subbufs initialization in simple_ring_buffer_init_mm() David Carlier
2026-03-18 19:28 ` Steven Rostedt
2026-03-18 19:34   ` David CARLIER
2026-03-19  9:12     ` Marc Zyngier
2026-03-19  9:26   ` Vincent Donnefort
2026-03-19 21:13     ` Steven Rostedt
2026-03-19  9:41 ` [PATCH v2] " David Carlier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox