Re: [PATCH] ring-buffer: Handle a reader taking the new head in rb_handle_head_page()
From: Breno Leitao
Date: Thu Nov 05 2026 - 05:38:35 EST
On Thu, Nov 05, 2026 at 09:15:43AM +0000, Vincent Donnefort wrote:
> On Mon, Nov 02, 2026 at 06:30:11AM -0800, Breno Leitao wrote:
> > I am occasionally seeing the following KASAN warning when running
>
> a KASAN warning?
Sorry. It is a regular WARN from RB_WARN_ON(), on a kernel that happened
to have KASAN enabled. I will fix the wording.
> > I've understood that rb_handle_head_page() moves the head page forward
>
> Drop "I've understood".
Ack!
> Besides, I am not sure about returning 1. If the nested writer interrupts
> between rb_head_page_set_head() and rb_head_page_set_normal(), it can also get
> RB_PAGE_MOVED and skipping rb_tail_page_update() means the retry will observe
> the old tail.
>
> All in all, I wonder if it shouldn't simply be:
>
> case RB_PAGE_MOVED:
> break;
>
Good point, that handles both writers. The outer one falls through to
the existing UPDATE clear, and rb_tail_page_update() finds the tail
already moved by the interrupt, as when the cmpxchg returns HEAD. The
nested one moves the tail to next_page, which is right because the outer
writer already did the accounting for that page. And the duplication
goes away.
> Additionally, the comment with "Valid returns" must be amended.
Will do.
My reproducer used a two-page buffer, where this retry is harmless, so
I will re-test v2 with a bigger buffer before sending it.
Thanks for the review,
--breno