The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: [PATCH v2] tracing: Fix nr_subbufs initialization in simple_ring_buffer_init_mm()
       [not found] ` <20260319094126.109691-1-devnexen@gmail.com>
@ 2026-05-12 13:26   ` Vincent Donnefort
  0 siblings, 0 replies; only message in thread
From: Vincent Donnefort @ 2026-05-12 13:26 UTC (permalink / raw)
  To: David Carlier
  Cc: Steven Rostedt, Mathieu Desnoyers, Masami Hiramatsu,
	Catalin Marinas, Ryan Roberts, linux-kernel

On Thu, Mar 19, 2026 at 09:41:26AM +0000, David Carlier wrote:
> nr_subbufs in the ring buffer metadata is always initialized to zero
> because it is assigned from cpu_buffer->nr_pages before the page
> initialization loop has run. While nr_subbufs is not currently read
> by the kernel, it should reflect the actual buffer geometry in the
> meta page for correctness.
> 
> Move the assignment after the page loop so that cpu_buffer->nr_pages
> holds the final count. Bug discover by Opus AI agent.

nit: I believe we can put that new Assisted-by: tag now.

> 
> 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..f731f14d0ff7 100644
> --- a/kernel/trace/simple_ring_buffer.c
> +++ b/kernel/trace/simple_ring_buffer.c
> @@ -395,7 +395,6 @@ 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;
>  
>  	/* The reader page is not part of the ring initially */
>  	page = load_page(desc->page_va[0]);
> @@ -437,6 +436,7 @@ int simple_ring_buffer_init_mm(struct simple_rb_per_cpu *cpu_buffer,
>  		return ret;
>  	}
>  
> +	cpu_buffer->meta->nr_subbufs = cpu_buffer->nr_pages;
>  	/* Close the ring */
>  	bpage->link.next = &cpu_buffer->tail_page->link;
>  	cpu_buffer->tail_page->link.prev = &bpage->link;
> -- 
> 2.53.0
> 

Reviewed-by: Vincent Donnefort <vdonnefort@google.com>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-12 13:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260318171907.19640-1-devnexen@gmail.com>
     [not found] ` <20260319094126.109691-1-devnexen@gmail.com>
2026-05-12 13:26   ` [PATCH v2] tracing: Fix nr_subbufs initialization in simple_ring_buffer_init_mm() Vincent Donnefort

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