From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] tracing: ring_buffer: Rewind persistent ring buffer when reboot
Date: Tue, 27 May 2025 12:54:44 +0900 [thread overview]
Message-ID: <20250527125444.80e59e659a7f087fed3c6fc9@kernel.org> (raw)
In-Reply-To: <20250527121549.2d40608e9463199d85bf9ba4@kernel.org>
On Tue, 27 May 2025 12:15:49 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> > What about this? It seems if we keep the reader->page->commit, when we
> > catch up the tail page, rb_get_reader_page() returns new reader (== tail)
> > because reader->read(==0) < reader->page->commit. But we should not return
> > new reader.
> >
> >
> > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> > index 5034bae02f08..179142db9586 100644
> > --- a/kernel/trace/ring_buffer.c
> > +++ b/kernel/trace/ring_buffer.c
> > @@ -5522,6 +5522,12 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
> > cpu_buffer->last_overrun = overwrite;
> > }
> >
> > + /* But if we catch up to the tail, do not return reader page. */
> > + if (cpu_buffer->commit_page == cpu_buffer->reader_page) {
>
>
> Hmm, I found this might not work if it is called twice.
> Maybe rb_get_reader_page() can check the reader_page->ts > head_page->ts
> and return NULL (or reader_page if read < commit) at first.
Here is what I meant. As far as I ran my test, it looks good (it prevents
over-read by `cat per_cpu/cpu0/trace_pipe_raw`)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 5034bae02f08..de1831eb3446 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -5405,6 +5405,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
unsigned long flags;
int nr_loops = 0;
bool ret;
+ u64 ts;
local_irq_save(flags);
arch_spin_lock(&cpu_buffer->lock);
@@ -5423,6 +5424,18 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
reader = cpu_buffer->reader_page;
+ /*
+ * Now the page->commit is not cleared when it read.
+ * Check whether timestamp is newer instead. We also don't
+ * care the head_page is overwritten. In that case, timestamp
+ * should be newer than reader timestamp too.
+ */
+ ts = cpu_buffer->head_page->page->time_stamp;
+ if (ts < reader->page->time_stamp) {
+ reader = NULL;
+ goto out;
+ }
+
/* If there's more to read, return this page */
if (cpu_buffer->reader_page->read < rb_page_size(reader))
goto out;
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2025-05-27 3:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 15:54 [PATCH v3 0/2] tracing: Rewind persistent ring buffer Masami Hiramatsu (Google)
2025-05-22 15:54 ` [PATCH v3 1/2] tracing: ring_buffer: Rewind persistent ring buffer when reboot Masami Hiramatsu (Google)
2025-05-23 20:54 ` Steven Rostedt
2025-05-23 21:28 ` Steven Rostedt
2025-05-26 3:03 ` Masami Hiramatsu
2025-05-27 0:17 ` Masami Hiramatsu
2025-05-27 3:15 ` Masami Hiramatsu
2025-05-27 3:54 ` Masami Hiramatsu [this message]
2025-05-27 13:47 ` Steven Rostedt
2025-05-28 0:22 ` Masami Hiramatsu
2025-05-23 23:20 ` Steven Rostedt
2025-05-26 3:44 ` Masami Hiramatsu
2025-05-27 13:48 ` Steven Rostedt
2025-06-03 16:00 ` Steven Rostedt
2025-06-03 21:58 ` Masami Hiramatsu
2025-05-22 15:54 ` [PATCH v3 2/2] tracing: Reset last-boot buffers when reading out all cpu buffers Masami Hiramatsu (Google)
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=20250527125444.80e59e659a7f087fed3c6fc9@kernel.org \
--to=mhiramat@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).