From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Ian Rogers <irogers@google.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v18 3/8] ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer
Date: Thu, 30 Apr 2026 00:15:59 +0900 [thread overview]
Message-ID: <20260430001559.a2d0489d956c06059e13e58d@kernel.org> (raw)
In-Reply-To: <20260428155508.4f47279e@gandalf.local.home>
On Tue, 28 Apr 2026 15:55:08 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 24 Apr 2026 15:52:27 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > @@ -5648,11 +5668,12 @@ __rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
> > again:
> > /*
> > * This should normally only loop twice. But because the
> > - * start of the reader inserts an empty page, it causes
> > - * a case where we will loop three times. There should be no
> > - * reason to loop four times (that I know of).
> > + * start of the reader inserts an empty page, it causes a
> > + * case where we will loop three times. There should be no
> > + * reason to loop four times unless the ring buffer is a
> > + * recovered persistent ring buffer.
>
> Can you explain more to why this is allowed for persistent ring buffer?
Ah, that was introduced in v15.
Changes in v15:
- Skip reader_page loop check on persistent ring buffer because
there can be contiguous empty(invalidated) pages.
So, finding next reader_page, we need to skip empty pages, which is normally
not contiguous. However, if we see more than 3 invalid pages on recovering
persistent ring buffer, it will be reset and become empty.
>
> Note, I do not like any loops that can go into an infinite loop and lock up
> the machine. If something goes wrong with a persistent ring buffer, then
> this could possibly go into an infinite loop.
Yeah, so I think we should not use goto here. OK, let me update it to
an actual loop.
>
> I want to understand why this is allowed, and possibly add a check that
> prevents this from never ending.
It should not be a never ending loop (there are other exit conditions),
but I agreed. What about limiting with nr_subbufs?
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 5326924615a4..aa89ec96e964 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -5630,7 +5630,8 @@ __rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
* a case where we will loop three times. There should be no
* reason to loop four times (that I know of).
*/
- if (RB_WARN_ON(cpu_buffer, ++nr_loops > 3)) {
+ if (RB_WARN_ON(cpu_buffer,
+ ++nr_loops > (cpu_buffer->ring_meta ? cpu_buffer->nr_subbufs : 3))) {
reader = NULL;
goto out;
}
>
> -- Steve
>
>
> > */
> > - if (RB_WARN_ON(cpu_buffer, ++nr_loops > 3)) {
> > + if (RB_WARN_ON(cpu_buffer, ++nr_loops > 3 && !cpu_buffer->ring_meta)) {
> > reader = NULL;
> > goto out;
> > }
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-04-29 15:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 6:51 [PATCH v18 0/8] ring-buffer: Making persistent ring buffers robust Masami Hiramatsu (Google)
2026-04-24 6:52 ` [PATCH v18 1/8] ring-buffer: Do not double count the reader_page Masami Hiramatsu (Google)
2026-04-24 6:52 ` [PATCH v18 2/8] ring-buffer: Flush and stop persistent ring buffer on panic Masami Hiramatsu (Google)
2026-04-24 6:52 ` [PATCH v18 3/8] ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer Masami Hiramatsu (Google)
2026-04-28 19:55 ` Steven Rostedt
2026-04-29 15:15 ` Masami Hiramatsu [this message]
2026-04-29 16:32 ` Steven Rostedt
2026-04-24 6:52 ` [PATCH v18 4/8] ring-buffer: Skip invalid sub-buffers when rewinding " Masami Hiramatsu (Google)
2026-04-28 20:21 ` Steven Rostedt
2026-04-29 15:20 ` Masami Hiramatsu
2026-04-29 16:39 ` Steven Rostedt
2026-04-24 6:52 ` [PATCH v18 5/8] ring-buffer: Add persistent ring buffer invalid-page inject test Masami Hiramatsu (Google)
2026-04-24 6:52 ` [PATCH v18 6/8] ring-buffer: Show commit numbers in buffer_meta file Masami Hiramatsu (Google)
2026-04-24 6:52 ` [PATCH v18 7/8] ring-buffer: Cleanup persistent ring buffer validation Masami Hiramatsu (Google)
2026-04-28 20:24 ` Steven Rostedt
2026-04-29 15:21 ` Masami Hiramatsu
2026-04-29 15:50 ` Steven Rostedt
2026-04-24 6:53 ` [PATCH v18 8/8] ring-buffer: Cleanup buffer_data_page related code Masami Hiramatsu (Google)
2026-04-24 7:06 ` [PATCH v18 0/8] ring-buffer: Making persistent ring buffers robust Masami Hiramatsu
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=20260430001559.a2d0489d956c06059e13e58d@kernel.org \
--to=mhiramat@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=irogers@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=will@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