Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Steven Rostedt" <rostedt@goodmis.org>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] ring-buffer: Fixes for subbuf resizing
Date: Fri, 14 Aug 2026 02:09:26 +0000	[thread overview]
Message-ID: <20260814020926.E571B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260813215230.7aa47950@gandalf.local.home>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Calculating the total ring buffer size in `ring_buffer_subbuf_order_set` truncates large sizes because `nr_pages` is declared as a 32-bit `int`, causing large ring buffers (>4GB) to silently shrink.
--

--- Patch [1]: [PATCH] ring-buffer: Fixes for subbuf resizing ---
commit 2e24224b70e061b34a4388f3a630382a4b8c1c44
Author: Vincent Donnefort <vdonnefort@google.com>

ring-buffer: Fixes for subbuf resizing

This series addresses multiple issues discovered with the dynamic ring
buffer resizing.

Link: https://lore.kernel.org/all/20260813131152.3589632-1-vdonnefort@google.com/

> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -7320,7 +7376,8 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
>  {
>  	struct ring_buffer_per_cpu *cpu_buffer;
>  	struct buffer_page *bpage, *tmp;
> -	int old_order, old_size;
> +	unsigned int old_capacity;
> +	int old_order;
>  	int nr_pages;
>  	int psize;
>  	int err;

[ ... ]

> @@ -7367,8 +7424,8 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
>  		}
>  
>  		/* Update the number of pages to match the new size */
> -		nr_pages = old_size * buffer->buffers[cpu]->nr_pages;
> -		nr_pages = DIV_ROUND_UP(nr_pages, buffer->subbuf_size);
> +		nr_pages = old_capacity * buffer->buffers[cpu]->nr_pages;
> +		nr_pages = DIV_ROUND_UP(nr_pages, rb_subbuf_capacity(buffer));

[Severity: High]
This is a pre-existing issue, but does this size calculation truncate when
the ring buffer is larger than 4GB?

Because nr_pages is declared as a 32-bit int at the top of the function,
assigning the total byte size (old_capacity * buffer->buffers[cpu]->nr_pages)
to it truncates the upper bits of the 64-bit result before calculating the
new number of pages.

For example, a 5GB buffer would get its byte size silently truncated to
around 705MB before DIV_ROUND_UP computes the new number of pages, leading
to an unexpectedly shrunken ring buffer. Should nr_pages or a temporary
variable be declared as unsigned long to hold the intermediate byte size?

>  
>  		/* we need a minimum of two pages */
>  		if (nr_pages < 2)
>  			nr_pages = 2;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260813215230.7aa47950@gandalf.local.home?part=1

  reply	other threads:[~2026-08-14  2:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14  1:52 [PATCH] ring-buffer: Fixes for subbuf resizing Steven Rostedt
2026-08-14  2:09 ` sashiko-bot [this message]
2026-08-14  8:25 ` Vincent Donnefort

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260814020926.E571B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox