mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] tracing: Make the backup instance readonly
Date: Wed, 7 Jan 2026 11:41:33 -0500	[thread overview]
Message-ID: <20260107114133.7f14dac2@gandalf.local.home> (raw)
In-Reply-To: <176779715937.4193242.8486149802702305279.stgit@mhiramat.tok.corp.google.com>

On Wed,  7 Jan 2026 23:45:59 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Since there is no reason to reuse the backup instance, make it
> readonly. Note that only backup instances are readonly, because
> other trace instances will be empty unless it is writable.
> Only backup instances have copy entries from the original.
> 
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  kernel/trace/trace.c        |   91 ++++++++++++++++++++++++++++++++-----------
>  kernel/trace/trace.h        |    6 +++
>  kernel/trace/trace_events.c |   14 +++++--
>  3 files changed, 84 insertions(+), 27 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 38f7a7a55c23..725930f5980e 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -4888,6 +4888,9 @@ static int tracing_open(struct inode *inode, struct file *file)
>  		int cpu = tracing_get_cpu(inode);
>  		struct array_buffer *trace_buf = &tr->array_buffer;
>  
> +		if (trace_array_is_readonly(tr))
> +			return -EPERM;

So this fails if someone opens a file in RDONLY mode?

Why?


> +
>  #ifdef CONFIG_TRACER_MAX_TRACE
>  		if (tr->current_trace->print_max)
>  			trace_buf = &tr->max_buffer;
> @@ -6077,6 +6080,9 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr,
>  ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
>  				  unsigned long size, int cpu_id)
>  {
> +	if (trace_array_is_readonly(tr))
> +		return -EPERM;

In fact, I don't think we need any of these.

> +
>  	guard(mutex)(&trace_types_lock);
>  
>  	if (cpu_id != RING_BUFFER_ALL_CPUS) {



> @@ -9353,12 +9381,16 @@ static void
>  tracing_init_tracefs_percpu(struct trace_array *tr, long cpu)
>  {
>  	struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu);
> +	umode_t writable_mode = TRACE_MODE_WRITE;
>  	struct dentry *d_cpu;
>  	char cpu_dir[30]; /* 30 characters should be more than enough */
>  
>  	if (!d_percpu)
>  		return;
>  
> +	if (trace_array_is_readonly(tr))
> +		writable_mode = TRACE_MODE_READ;

This is more like what we should do with all the files in a read-only
instance. Just make all files not allow writes.

We may need to make sure they can't be changed to write as well. But that
will require a change to tracefs (and eventfs).

-- Steve


> +
>  	snprintf(cpu_dir, 30, "cpu%ld", cpu);
>  	d_cpu = tracefs_create_dir(cpu_dir, d_percpu);
>  	if (!d_cpu) {
> @@ -9371,7 +9403,7 @@ tracing_init_tracefs_percpu(struct trace_array *tr, long cpu)
>  				tr, cpu, &tracing_pipe_fops);
>  
>  	/* per cpu trace */
> -	trace_create_cpu_file("trace", TRACE_MODE_WRITE, d_cpu,
> +	trace_create_cpu_file("trace", writable_mode, d_cpu,
>  				tr, cpu, &tracing_fops);
>  
>  	trace_create_cpu_file("trace_pipe_raw", TRACE_MODE_READ, d_cpu,


  reply	other threads:[~2026-01-07 16:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 14:45 [PATCH 0/2] tracing: Remove backup instance after read all Masami Hiramatsu (Google)
2026-01-07 14:45 ` [PATCH 1/2] tracing: Make the backup instance readonly Masami Hiramatsu (Google)
2026-01-07 16:41   ` Steven Rostedt [this message]
2026-01-08  2:51     ` Masami Hiramatsu
2026-01-08  3:05       ` Steven Rostedt
2026-01-08  5:30         ` Masami Hiramatsu
2026-01-08  3:07     ` Masami Hiramatsu
2026-01-07 14:46 ` [PATCH 2/2] tracing: Add autoremove feature to the backup instance 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=20260107114133.7f14dac2@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.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

all inboxes | Powered by JetHome®