From: Vincent Donnefort <vdonnefort@google.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org,
mathieu.desnoyers@efficios.com, kernel-team@android.com,
linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH 4/6] ring-buffer: Fix subbuf resize concurrency
Date: Mon, 10 Aug 2026 14:38:41 +0100 [thread overview]
Message-ID: <annUYSQxg3Yo1nar@google.com> (raw)
In-Reply-To: <20260810092606.1742d25a@gandalf.local.home>
On Mon, Aug 10, 2026 at 09:26:06AM -0400, Steven Rostedt wrote:
> On Mon, 10 Aug 2026 08:54:22 +0100
> Vincent Donnefort <vdonnefort@google.com> wrote:
>
> > This is probably the issue.
> >
> > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> > index c2cbdb3ef727..a64cdc925078 100644
> > --- a/kernel/trace/ring_buffer.c
> > +++ b/kernel/trace/ring_buffer.c
> > @@ -3534,7 +3534,7 @@ rb_event_index(struct ring_buffer_per_cpu *cpu_buffer, struct ring_buffer_event
> > {
> > unsigned long addr = (unsigned long)event;
> >
> > - addr &= rb_subbuf_size(cpu_buffer->buffer) - 1;
> > + addr &= (unsigned long)rb_subbuf_size(cpu_buffer->buffer) - 1;
> >
> > return addr - BUF_PAGE_HDR_SIZE;
> > }
> > @@ -4123,7 +4123,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
> > new_index = rb_event_index(cpu_buffer, event);
> > old_index = new_index + rb_event_ts_length(event);
> > addr = (unsigned long)event;
> > - addr &= ~(rb_subbuf_size(cpu_buffer->buffer) - 1);
> > + addr &= ~((unsigned long)rb_subbuf_size(cpu_buffer->buffer) - 1);
> >
> > bpage = READ_ONCE(cpu_buffer->tail_page);
> >
> > @@ -5033,7 +5033,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
> > struct buffer_page *bpage = cpu_buffer->commit_page;
> > struct buffer_page *start;
> >
> > - addr &= ~(rb_subbuf_size(cpu_buffer->buffer) - 1);
> > + addr &= ~((unsigned long)rb_subbuf_size(cpu_buffer->buffer) - 1);
>
> What about just making those functions return unsigned long instead of
> having to add typecasts all over. It shouldn't hurt the places it's made an
> int? Although I'm not sure if bots will complain. :-/
I thought about that, but it is used to assign to 32-bits variables, such as
ring_buffer_cpu_meta::subbuf_size or in ring_buffer_subbuf_size_get().
so it felt the (unsigned long) cast wasn't that bad in the end.
Alternatively, I could make all the "size" (_size, _capacity _max_data_size)
related accessors "unsigned long" and do the same for the buffer_data_page and
buffer_page accessors?
And just WARN() if we set one of the meta data fields with more than U32_MAX?
>
> >
> > /* Do the likely case first */
> > if (likely(bpage->page == (void *)addr)) {
> >
> >
> > I will resend a V3 dropping the 3 first patches you have applied already.
>
> Yeah, they are already in Linus's tree.
>
> -- Steve
I have sent the v3:
https://lore.kernel.org/all/20260810125633.3344684-1-vdonnefort@google.com/
--
Vincent
next prev parent reply other threads:[~2026-08-10 13:38 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 21:13 [PATCH 0/6] ring-buffer: Fixes for subbuf resizing and persistent buffers Vincent Donnefort
2026-08-06 21:13 ` [PATCH 1/6] ring-buffer: Prevent resizing of persistent ring buffer Vincent Donnefort
2026-08-07 2:18 ` Masami Hiramatsu
2026-08-07 8:14 ` Vincent Donnefort
2026-08-07 9:43 ` Vincent Donnefort
2026-08-07 10:25 ` Vincent Donnefort
2026-08-07 14:45 ` Steven Rostedt
2026-08-07 15:25 ` Vincent Donnefort
2026-08-07 15:45 ` Vincent Donnefort
2026-08-07 19:26 ` Steven Rostedt
2026-08-10 8:31 ` Masami Hiramatsu
2026-08-10 8:56 ` Vincent Donnefort
2026-08-10 14:13 ` Steven Rostedt
2026-08-06 21:13 ` [PATCH 2/6] ring-buffer: Prevent subbuf order change when resizing is disabled Vincent Donnefort
2026-08-06 21:13 ` [PATCH 3/6] ring-buffer: Initialise reader page order in rb_allocate_cpu_buffer() Vincent Donnefort
2026-08-06 21:13 ` [PATCH 4/6] ring-buffer: Fix subbuf resize concurrency Vincent Donnefort
2026-08-08 18:58 ` Steven Rostedt
2026-08-10 7:54 ` Vincent Donnefort
2026-08-10 13:26 ` Steven Rostedt
2026-08-10 13:38 ` Vincent Donnefort [this message]
2026-08-06 21:13 ` [PATCH 5/6] ring-buffer: Dynamically calculate max_data_size Vincent Donnefort
2026-08-06 21:13 ` [PATCH 6/6] ring-buffer: Remove ring_buffer_per_cpu::mapped 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=annUYSQxg3Yo1nar@google.com \
--to=vdonnefort@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sashiko-bot@kernel.org \
/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