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 v9 2/3] tracing: Remove the backup instance automatically after read
Date: Tue, 31 Mar 2026 17:19:36 -0400 [thread overview]
Message-ID: <20260331171936.6f84e357@gandalf.local.home> (raw)
In-Reply-To: <177497475349.569199.11513916633426967730.stgit@mhiramat.tok.corp.google.com>
On Wed, 1 Apr 2026 01:32:33 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 8cec7bd70438..1d73400a01c7 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -539,8 +539,65 @@ void trace_set_ring_buffer_expanded(struct trace_array *tr)
> tr->ring_buffer_expanded = true;
> }
>
> +static int __remove_instance(struct trace_array *tr);
> +
> +static void trace_array_autoremove(struct work_struct *work)
> +{
> + struct trace_array *tr = container_of(work, struct trace_array, autoremove_work);
> +
> + guard(mutex)(&event_mutex);
> + guard(mutex)(&trace_types_lock);
Hmm, should we do a check if the tr still exists? Couldn't the user delete
this via a rmdir after the last file closed and this was kicked?
CPU 0 CPU 1
----- -----
open(trace_pipe);
read(..);
close(trace_pipe);
kick the work queue to delete it....
rmdir();
[instance deleted]
__remove_instance();
[ now the tr is freed, and the remove will crash!]
What would prevent this is this is to use trace_array_destroy() that checks
this and also adds the proper locking:
static void trace_array_autoremove(struct work_struct *work)
{
struct trace_array *tr = container_of(work, struct trace_array, autoremove_work);
trace_array_destroy(tr);
}
> +
> + /*
> + * This can be fail if someone gets @tr before starting this
> + * function, but in that case, this will be kicked again when
> + * putting it. So we don't care about the result.
> + */
> + __remove_instance(tr);
> +}
> +
> +static struct workqueue_struct *autoremove_wq;
> +
> +static void trace_array_kick_autoremove(struct trace_array *tr)
> +{
> + if (autoremove_wq && !work_pending(&tr->autoremove_work))
> + queue_work(autoremove_wq, &tr->autoremove_work);
Doesn't queue_work() check if it's pending? Do we really need to check it
twice?
> +}
> +
> +static void trace_array_cancel_autoremove(struct trace_array *tr)
> +{
> + if (autoremove_wq && work_pending(&tr->autoremove_work))
> + cancel_work(&tr->autoremove_work);
Same here, as can't this be racy?
> +}
> +
> +static void trace_array_init_autoremove(struct trace_array *tr)
> +{
> + INIT_WORK(&tr->autoremove_work, trace_array_autoremove);
> +}
> +
> +static void trace_array_start_autoremove(void)
> +{
> + if (autoremove_wq)
> + return;
> +
> + autoremove_wq = alloc_workqueue("tr_autoremove_wq",
> + WQ_UNBOUND | WQ_HIGHPRI, 0);
> + if (!autoremove_wq)
> + pr_warn("Unable to allocate tr_autoremove_wq. autoremove
> disabled.\n"); +}
> +
> LIST_HEAD(ftrace_trace_arrays);
-- Steve
next prev parent reply other threads:[~2026-03-31 21:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 16:32 [PATCH v9 0/3] tracing: Remove backup instance after read all Masami Hiramatsu (Google)
2026-03-31 16:32 ` [PATCH v9 1/3] tracing: Make the backup instance non-reusable Masami Hiramatsu (Google)
2026-03-31 16:32 ` [PATCH v9 2/3] tracing: Remove the backup instance automatically after read Masami Hiramatsu (Google)
2026-03-31 21:19 ` Steven Rostedt [this message]
2026-04-01 3:19 ` Masami Hiramatsu
2026-04-01 14:40 ` Steven Rostedt
2026-04-02 13:19 ` Masami Hiramatsu
2026-04-02 14:52 ` Steven Rostedt
2026-03-31 16:32 ` [PATCH v9 3/3] tracing/Documentation: Add a section about backup instance Masami Hiramatsu (Google)
2026-03-31 21:21 ` Steven Rostedt
2026-04-01 3:15 ` Masami Hiramatsu
2026-04-01 14:41 ` 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=20260331171936.6f84e357@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