diff mbox series

[3/8] ring-buffer: Add ring_buffer_meta_scratch()

Message ID 20250205225103.425325060@goodmis.org (mailing list archive)
State Superseded
Headers show
Series ring-buffer/tracing: Save module information in persistent memory | expand

Commit Message

Steven Rostedt Feb. 5, 2025, 10:50 p.m. UTC
From: Steven Rostedt <rostedt@goodmis.org>

Now that there's one page at the start of the persistent memory used by
the ring buffer, make the part of that page that is not used by the ring
buffer available for the tracer to use. This will allow the tracer to
store its own persistent data.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 include/linux/ring_buffer.h |  1 +
 kernel/trace/ring_buffer.c  | 13 +++++++++++++
 2 files changed, 14 insertions(+)

Comments

Masami Hiramatsu (Google) Feb. 6, 2025, 5:13 a.m. UTC | #1
On Wed, 05 Feb 2025 17:50:34 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> Now that there's one page at the start of the persistent memory used by
> the ring buffer, make the part of that page that is not used by the ring
> buffer available for the tracer to use. This will allow the tracer to
> store its own persistent data.

Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  include/linux/ring_buffer.h |  1 +
>  kernel/trace/ring_buffer.c  | 13 +++++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
> index 8de035f4f0d9..b95f940fd07a 100644
> --- a/include/linux/ring_buffer.h
> +++ b/include/linux/ring_buffer.h
> @@ -95,6 +95,7 @@ struct trace_buffer *__ring_buffer_alloc_range(unsigned long size, unsigned flag
>  					       struct lock_class_key *key);
>  
>  bool ring_buffer_last_boot_delta(struct trace_buffer *buffer, unsigned long *kaslr_addr);
> +void *ring_buffer_meta_scratch(struct trace_buffer *buffer, unsigned int *size);
>  
>  /*
>   * Because the ring buffer is generic, if other users of the ring buffer get
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 0446d053dbd6..5a81ff785665 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -1730,6 +1730,9 @@ static bool rb_meta_init(struct trace_buffer *buffer)
>  	bmeta->total_size = total_size;
>  	bmeta->buffers_offset = (void *)ptr - (void *)bmeta;
>  
> +	/* Zero out the scatch pad */
> +	memset((void *)bmeta + sizeof(*bmeta), 0, PAGE_SIZE - sizeof(*bmeta));
> +
>  	return false;
>  }
>  
> @@ -2532,6 +2535,16 @@ bool ring_buffer_last_boot_delta(struct trace_buffer *buffer, unsigned long *kas
>  	return true;
>  }
>  
> +void *ring_buffer_meta_scratch(struct trace_buffer *buffer, unsigned int *size)
> +{
> +	if (!buffer || !buffer->meta)
> +		return NULL;
> +
> +	*size = PAGE_SIZE - sizeof(*buffer->meta);
> +
> +	return (void *)buffer->meta + sizeof(*buffer->meta);
> +}
> +
>  /**
>   * ring_buffer_free - free a ring buffer.
>   * @buffer: the buffer to free.
> -- 
> 2.45.2
> 
>
diff mbox series

Patch

diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index 8de035f4f0d9..b95f940fd07a 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -95,6 +95,7 @@  struct trace_buffer *__ring_buffer_alloc_range(unsigned long size, unsigned flag
 					       struct lock_class_key *key);
 
 bool ring_buffer_last_boot_delta(struct trace_buffer *buffer, unsigned long *kaslr_addr);
+void *ring_buffer_meta_scratch(struct trace_buffer *buffer, unsigned int *size);
 
 /*
  * Because the ring buffer is generic, if other users of the ring buffer get
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 0446d053dbd6..5a81ff785665 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1730,6 +1730,9 @@  static bool rb_meta_init(struct trace_buffer *buffer)
 	bmeta->total_size = total_size;
 	bmeta->buffers_offset = (void *)ptr - (void *)bmeta;
 
+	/* Zero out the scatch pad */
+	memset((void *)bmeta + sizeof(*bmeta), 0, PAGE_SIZE - sizeof(*bmeta));
+
 	return false;
 }
 
@@ -2532,6 +2535,16 @@  bool ring_buffer_last_boot_delta(struct trace_buffer *buffer, unsigned long *kas
 	return true;
 }
 
+void *ring_buffer_meta_scratch(struct trace_buffer *buffer, unsigned int *size)
+{
+	if (!buffer || !buffer->meta)
+		return NULL;
+
+	*size = PAGE_SIZE - sizeof(*buffer->meta);
+
+	return (void *)buffer->meta + sizeof(*buffer->meta);
+}
+
 /**
  * ring_buffer_free - free a ring buffer.
  * @buffer: the buffer to free.