From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Vincent Donnefort <vdonnefort@google.com>
Subject: [for-next][PATCH 2/8] ring-buffer: Add magic and struct size to boot up meta data
Date: Tue, 27 Aug 2024 05:27:18 -0400 [thread overview]
Message-ID: <20240827092746.359657809@goodmis.org> (raw)
In-Reply-To: 20240827092716.515115830@goodmis.org
From: Steven Rostedt <rostedt@goodmis.org>
Add a magic number as well as save the struct size of the ring_buffer_meta
structure in the meta data to also use as validation. Updating the magic
number could be used to force a invalidation between kernel versions, and
saving the structure size is also a good method to make sure the content
is what is expected.
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Vincent Donnefort <vdonnefort@google.com>
Link: https://lore.kernel.org/20240815115032.0c197b32@rorschach.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/ring_buffer.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index b16f301b8a93..c3a5e6cbb940 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -44,7 +44,11 @@
static void update_pages_handler(struct work_struct *work);
+#define RING_BUFFER_META_MAGIC 0xBADFEED
+
struct ring_buffer_meta {
+ int magic;
+ int struct_size;
unsigned long text_addr;
unsigned long data_addr;
unsigned long first_buffer;
@@ -1627,6 +1631,13 @@ static bool rb_meta_valid(struct ring_buffer_meta *meta, int cpu,
unsigned long buffers_end;
int i;
+ /* Check the meta magic and meta struct size */
+ if (meta->magic != RING_BUFFER_META_MAGIC ||
+ meta->struct_size != sizeof(*meta)) {
+ pr_info("Ring buffer boot meta[%d] mismatch of magic or struct size\n", cpu);
+ return false;
+ }
+
/* The subbuffer's size and number of subbuffers must match */
if (meta->subbuf_size != subbuf_size ||
meta->nr_subbufs != nr_pages + 1) {
@@ -1858,6 +1869,9 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)
memset(meta, 0, next_meta - (void *)meta);
+ meta->magic = RING_BUFFER_META_MAGIC;
+ meta->struct_size = sizeof(*meta);
+
meta->nr_subbufs = nr_pages + 1;
meta->subbuf_size = PAGE_SIZE;
--
2.43.0
next prev parent reply other threads:[~2024-08-27 9:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 9:27 [for-next][PATCH 0/8] ring-buffer: Updates for 6.12 Steven Rostedt
2024-08-27 9:27 ` [for-next][PATCH 1/8] ring-buffer: Dont reset persistent ring-buffer meta saved addresses Steven Rostedt
2024-08-27 9:27 ` Steven Rostedt [this message]
2024-08-27 9:27 ` [for-next][PATCH 3/8] ring-buffer: Align meta-page to sub-buffers for improved TLB usage Steven Rostedt
2024-08-27 9:27 ` [for-next][PATCH 4/8] tracing: Add "traceoff" flag to boot time tracing instances Steven Rostedt
2024-08-27 9:27 ` [for-next][PATCH 5/8] tracing: Allow trace_printk() to go to other instance buffers Steven Rostedt
2024-08-27 9:27 ` [for-next][PATCH 6/8] tracing: Have trace_printk not use binary prints if boot buffer Steven Rostedt
2024-08-27 9:27 ` [for-next][PATCH 7/8] tracing: Add option to set an instance to be the trace_printk destination Steven Rostedt
2024-08-27 9:27 ` [for-next][PATCH 8/8] tracing/Documentation: Start a document on how to debug with tracing 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=20240827092746.359657809@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=vdonnefort@google.com \
/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