Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Ian Rogers <irogers@google.com>
Subject: [PATCH v20 07/10] ring-buffer: Skip invalid sub-buffers for iterator
Date: Wed, 20 May 2026 14:49:45 -0400	[thread overview]
Message-ID: <20260520185018.051228084@kernel.org> (raw)
In-Reply-To: 20260520184938.749337513@kernel.org

From: Steven Rostedt <rostedt@goodmis.org>

On bootup if the persistent ring buffer finds an invalid sub-buffer, it
only invalidates the invalid sub-buffer and continues. Several sub-buffers
may be invalid and this can cause the iterator to loop more than 3 times
looking for a new event. If that happens, then it returns NULL. Having a
NULL return early can confuse the iterator looking for the next event, and
may show events out of order.

Have the same logic for the consuming read for the iterator that will
allow the loop to find the next event to happen the number of sub-buffers
and not just 3.

Fixes: **TBD** ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index c6c2f92bfc24..bda53a2d2159 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -6103,12 +6103,14 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
 	struct ring_buffer_per_cpu *cpu_buffer;
 	struct ring_buffer_event *event;
 	int nr_loops = 0;
+	int max_loops;
 
 	if (ts)
 		*ts = 0;
 
 	cpu_buffer = iter->cpu_buffer;
 	buffer = cpu_buffer->buffer;
+	max_loops = cpu_buffer->ring_meta ? cpu_buffer->nr_pages : 3;
 
 	/*
 	 * Check if someone performed a consuming read to the buffer
@@ -6131,7 +6133,7 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
 	 * the ring buffer with an active write as the consumer is.
 	 * Do not warn if the three failures is reached.
 	 */
-	if (++nr_loops > 3)
+	if (++nr_loops > max_loops)
 		return NULL;
 
 	if (rb_per_cpu_empty(cpu_buffer))
-- 
2.53.0



  parent reply	other threads:[~2026-05-20 18:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 18:49 [PATCH v20 00/10] ring-buffer: Making persistent ring buffers robust Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 01/10] ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 02/10] ring-buffer: Skip invalid sub-buffers when rewinding " Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 03/10] ring-buffer: Add persistent ring buffer invalid-page inject test Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 04/10] ring-buffer: Show commit numbers in buffer_meta file Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 05/10] ring-buffer: Cleanup persistent ring buffer validation Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 06/10] ring-buffer: Cleanup buffer_data_page related code Steven Rostedt
2026-05-20 18:49 ` Steven Rostedt [this message]
2026-05-20 18:49 ` [PATCH v20 08/10] ring-buffer: Have dropped subbuffers be persistent across reboots Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 09/10] ring-buffer: Show persistent buffer dropped events in trace file Steven Rostedt
2026-05-20 18:49 ` [PATCH v20 10/10] ring-buffer: Show persistent buffer dropped events in trace_pipe file Steven Rostedt

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=20260520185018.051228084@kernel.org \
    --to=rostedt@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.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