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 v4 1/3] ring-buffer: Flush and stop persistent ring buffer on panic
Date: Thu, 26 Feb 2026 21:56:56 +0900 [thread overview]
Message-ID: <20260226215656.7f4d5368393c417fd8da5a2f@kernel.org> (raw)
In-Reply-To: <177191596224.435720.8250761603256925623.stgit@mhiramat.tok.corp.google.com>
On Tue, 24 Feb 2026 15:52:42 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> On real hardware, panic and machine reboot may not flush hardware cache
> to memory. This means the persistent ring buffer, which relies on a
> coherent state of memory, may not have its events written to the buffer
> and they may be lost. Moreover, there may be inconsistency with the
> counters which are used for validation of the integrity of the
> persistent ring buffer which may cause all data to be discarded.
>
> To avoid this issue, stop recording of the ring buffer on panic and
> flush the cache of the ring buffer's memory.
>
> Fixes: e645535a954a ("tracing: Add option to use memmapped memory for trace boot instance")
> Cc: stable@vger.kernel.org
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
> Changes in v3:
> - update patch description.
> ---
> kernel/trace/ring_buffer.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index f16f053ef77d..3eb124c93d72 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -6,6 +6,7 @@
> */
> #include <linux/sched/isolation.h>
> #include <linux/trace_recursion.h>
> +#include <linux/panic_notifier.h>
> #include <linux/trace_events.h>
> #include <linux/ring_buffer.h>
> #include <linux/trace_clock.h>
> @@ -589,6 +590,7 @@ struct trace_buffer {
>
> unsigned long range_addr_start;
> unsigned long range_addr_end;
> + struct notifier_block flush_nb;
>
> struct ring_buffer_meta *meta;
>
> @@ -2471,6 +2473,16 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
> kfree(cpu_buffer);
> }
>
> +static int rb_flush_buffer_cb(struct notifier_block *nb, unsigned long event, void *data)
> +{
> + struct trace_buffer *buffer = container_of(nb, struct trace_buffer, flush_nb);
> +
> + ring_buffer_record_disable(buffer);
I found this was a wrong API. I have to use ring_buffer_record_off().
> + flush_kernel_vmap_range((void *)buffer->range_addr_start,
> + buffer->range_addr_end - buffer->range_addr_start);
This does nothing on arm64.
Thanks,
> + return NOTIFY_DONE;
> +}
> +
> static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
> int order, unsigned long start,
> unsigned long end,
> @@ -2590,6 +2602,12 @@ static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
>
> mutex_init(&buffer->mutex);
>
> + /* Persistent ring buffer needs to flush cache before reboot. */
> + if (start & end) {
> + buffer->flush_nb.notifier_call = rb_flush_buffer_cb;
> + atomic_notifier_chain_register(&panic_notifier_list, &buffer->flush_nb);
> + }
> +
> return_ptr(buffer);
>
> fail_free_buffers:
> @@ -2677,6 +2695,9 @@ ring_buffer_free(struct trace_buffer *buffer)
> {
> int cpu;
>
> + if (buffer->range_addr_start && buffer->range_addr_end)
> + atomic_notifier_chain_unregister(&panic_notifier_list, &buffer->flush_nb);
> +
> cpuhp_state_remove_instance(CPUHP_TRACE_RB_PREPARE, &buffer->node);
>
> irq_work_sync(&buffer->irq_work.work);
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-02-26 12:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 6:52 [PATCH v4 0/3] ring-buffer: Making persistent ring buffers robust Masami Hiramatsu (Google)
2026-02-24 6:52 ` [PATCH v4 1/3] ring-buffer: Flush and stop persistent ring buffer on panic Masami Hiramatsu (Google)
2026-02-26 12:56 ` Masami Hiramatsu [this message]
2026-02-24 6:52 ` [PATCH v4 2/3] ring-buffer: Handle RB_MISSED_* flags on commit field correctly Masami Hiramatsu (Google)
2026-02-24 6:52 ` [PATCH v4 3/3] ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer Masami Hiramatsu (Google)
2026-02-26 12:58 ` Masami Hiramatsu
2026-02-26 17:36 ` Steven Rostedt
2026-02-26 23:29 ` 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=20260226215656.7f4d5368393c417fd8da5a2f@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