All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Joel Fernandes <joel@joelfernandes.org>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	suleiman@google.com, Thomas Gleixner <tglx@linutronix.de>,
	Vineeth Pillai <vineeth@bitbyteword.org>,
	Youssef Esmat <youssefesmat@google.com>,
	Beau Belgrave <beaub@linux.microsoft.com>,
	Alexander Graf <graf@amazon.com>, Baoquan He <bhe@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	David Howells <dhowells@redhat.com>
Subject: Re: [PATCH v2 01/11] ring-buffer: Allow mapped field to be set without mapping
Date: Fri, 12 Apr 2024 15:47:15 +0100	[thread overview]
Message-ID: <ZhlJc6gni3rcOWW7@google.com> (raw)
In-Reply-To: <20240411012904.237435058@goodmis.org>

On Wed, Apr 10, 2024 at 09:25:42PM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> In preparation for having the ring buffer mapped to a dedicated location,
> which will have the same restrictions as user space memory mapped buffers,
> allow it to use the "mapped" field of the ring_buffer_per_cpu structure
> without having the user space meta page mapping.
> 
> When this starts using the mapped field, it will need to handle adding a
> user space mapping (and removing it) from a ring buffer that is using a
> dedicated memory range.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/ring_buffer.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 793ecc454039..44b1d5f1a99a 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -5223,6 +5223,9 @@ static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
>  {
>  	struct trace_buffer_meta *meta = cpu_buffer->meta_page;
>  
> +	if (!meta)
> +		return;
> +
>  	meta->reader.read = cpu_buffer->reader_page->read;
>  	meta->reader.id = cpu_buffer->reader_page->id;
>  	meta->reader.lost_events = cpu_buffer->lost_events;
> @@ -6167,7 +6170,7 @@ rb_get_mapped_buffer(struct trace_buffer *buffer, int cpu)
>  
>  	mutex_lock(&cpu_buffer->mapping_lock);
>  
> -	if (!cpu_buffer->mapped) {
> +	if (!cpu_buffer->mapped || !cpu_buffer->meta_page) {
>  		mutex_unlock(&cpu_buffer->mapping_lock);
>  		return ERR_PTR(-ENODEV);
>  	}
> @@ -6345,12 +6348,13 @@ int ring_buffer_map(struct trace_buffer *buffer, int cpu,

IIUC, we still allow to map from user-space this buffer. So we now can have
mapped && !meta_page.

Then the "if (cpu_buffer->mapped) {" that skips the meta_page creation in
ring_buffer_map() should be replaced by if (cpu_buffer->meta_page).

>  	 */
>  	raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
>  	rb_setup_ids_meta_page(cpu_buffer, subbuf_ids);
> +
>  	raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
>  
>  	err = __rb_map_vma(cpu_buffer, vma);
>  	if (!err) {
>  		raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> -		cpu_buffer->mapped = 1;
> +		cpu_buffer->mapped++;
>  		raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
>  	} else {
>  		kfree(cpu_buffer->subbuf_ids);
> @@ -6388,7 +6392,7 @@ int ring_buffer_unmap(struct trace_buffer *buffer, int cpu)
>  	mutex_lock(&buffer->mutex);
>  	raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);

In this function, there's also a check for cpu_buffer->mapped > 1. This avoids
killing the meta-page while someone is still in use.

It seems like a dedicated meta_page counter will be necessary. Otherwise, in the
event of a ring-buffer mapped at boot we, would setup the meta-page on the first
mmap() and never tear it down.

>  
> -	cpu_buffer->mapped = 0;
> +	cpu_buffer->mapped--;
>  
>  	raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
>  
> -- 
> 2.43.0
> 
> 

  reply	other threads:[~2024-04-12 14:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  1:25 [PATCH v2 00/11] tracing: Persistent traces across a reboot or crash Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 01/11] ring-buffer: Allow mapped field to be set without mapping Steven Rostedt
2024-04-12 14:47   ` Vincent Donnefort [this message]
2024-04-11  1:25 ` [PATCH v2 02/11] ring-buffer: Add ring_buffer_alloc_range() Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 03/11] ring-buffer: Add ring_buffer_meta data Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 04/11] tracing: Implement creating an instance based on a given memory region Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 05/11] ring-buffer: Add output of ring buffer meta page Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 06/11] ring-buffer: Add test if range of boot buffer is valid Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 07/11] ring-buffer: Validate boot range memory events Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 08/11] ring-buffer: Save text and data locations in mapped meta data Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 09/11] tracing/ring-buffer: Add last_boot_info file to boot instance Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 10/11] tracing: Handle old buffer mappings for event strings and functions Steven Rostedt
2024-04-11  1:25 ` [PATCH v2 11/11] tracing: Update function tracing output for previous boot buffer 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=ZhlJc6gni3rcOWW7@google.com \
    --to=vdonnefort@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=beaub@linux.microsoft.com \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=bristot@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=graf@amazon.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=suleiman@google.com \
    --cc=tglx@linutronix.de \
    --cc=vineeth@bitbyteword.org \
    --cc=youssefesmat@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.