From: Steven Rostedt <rostedt@kernel.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>,
stable@vger.kernel.org
Subject: [for-linus][PATCH 8/8] tracing: Reject backup instance opens only after autoremove is queued
Date: Thu, 03 Dec 2026 09:17:33 -0500 [thread overview]
Message-ID: <20261203141757.594416625@kernel.org> (raw)
In-Reply-To: 20261203141725.845506016@kernel.org
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Commit eca33fdab47b ("tracing: Remove the backup instance automatically
after read") sets tr->free_on_close in update_last_data() once all
previous-boot data has been read out or cleared, and queues
autoremove_work in __trace_array_put() when the last user reference is
dropped (tr->ref == 1). However, __trace_array_get() rejects new
references with -ENODEV as soon as tr->free_on_close is set, even while
existing file descriptors still hold tr->ref > 1 and autoremove has not
yet been queued.
This breaks userspace consumers that keep multiple file descriptors open
on the backup instance while finishing a dump. For example, a reader
that keeps per_cpu/cpu*/trace_pipe_raw open across CPUs and drains them
via read() triggers update_last_data_if_empty() on the final empty read,
setting tr->free_on_close while those pipe file descriptors are still
open. Any subsequent open of another file in the same instance before
closing the pipes -- such as reading per_cpu/cpu*/stats or opening trace
with O_WRONLY | O_TRUNC to clear the buffer -- then fails with -ENODEV.
Introduce a tr->autoremove_queued flag set when autoremove_work is
queued, and check it in __trace_array_get() instead of tr->free_on_close.
This allows opening files while existing references remain, while still
blocking new opens once autoremove is queued.
Cc: stable@vger.kernel.org
Fixes: eca33fdab47b ("tracing: Remove the backup instance automatically after read")
Link: https://patch.msgid.link/179622393332.9100.10906884385392450114.stgit@mhiramat.c.googlers.com
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace.c | 12 +++++++++---
kernel/trace/trace.h | 4 ++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index fa65ef8d7fbe..f153ffedb9d2 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -585,8 +585,12 @@ static struct workqueue_struct *autoremove_wq;
static void trace_array_kick_autoremove(struct trace_array *tr)
{
- if (autoremove_wq)
+ lockdep_assert_held(&trace_types_lock);
+
+ if (autoremove_wq && !tr->autoremove_queued) {
+ tr->autoremove_queued = true;
queue_work(autoremove_wq, &tr->autoremove_work);
+ }
}
static void trace_array_cancel_autoremove(struct trace_array *tr)
@@ -619,8 +623,10 @@ LIST_HEAD(ftrace_trace_arrays);
static int __trace_array_get(struct trace_array *this_tr)
{
- /* When free_on_close is set, this is not available anymore. */
- if (autoremove_wq && this_tr->free_on_close)
+ lockdep_assert_held(&trace_types_lock);
+
+ /* Once autoremove is queued, this is not available anymore. */
+ if (this_tr->autoremove_queued)
return -ENODEV;
this_tr->ref++;
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 45971e4be77e..0211db62d6a1 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -462,8 +462,12 @@ struct trace_array {
/*
* If the ring buffer is a read only backup instance, it will be
* removed after dumping all data via pipe, because no readable data.
+ * @free_on_close is set once the buffer is drained or cleared, and
+ * @autoremove_queued is set when the last reference is released and
+ * @autoremove_work is queued.
*/
bool free_on_close;
+ bool autoremove_queued;
struct work_struct autoremove_work;
};
--
2.53.0
prev parent reply other threads:[~2026-12-03 14:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:17 [for-linus][PATCH 0/8] tracing: Fixes for v7.4 Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 1/8] tracing: Fix crash on lseek of recursed_functions file in WRONLY mode Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 2/8] tracing/filters: Fix glob matching on zero size string fields Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 3/8] ring-buffer: Use irqsave for the reader lock in ring_buffer_poll_remote Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 4/8] ring-buffer: Avoid reader_lock deadlock during panic Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 5/8] tracing/histograms: Reject non-string fields for synthetic string fields Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 6/8] tracing: Free all event filters after RCU synchronization Steven Rostedt
2026-12-03 14:17 ` [for-linus][PATCH 7/8] tracing: Fix trace_event_file leak on read-only instances Steven Rostedt
2026-12-03 14:17 ` Steven Rostedt [this message]
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=20261203141757.594416625@kernel.org \
--to=rostedt@kernel.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=stable@vger.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 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.