Skip to content

Commit 02e7769

Browse files
committed
tracing: Fix enabling of tracing on file release
The trace file will pause tracing if the tracing instance has the "pause-on-trace" option is set. This happens when the file is opened, and it is unpaused when the file is closed. When this was first added, there was only one user that paused tracing. On open, the check to pause was: if (!iter->snapshot && (tr->trace_flags & TRACE_ITER(PAUSE_ON_TRACE))) Where if it is not the snapshot tracer and the "pause-on-trace" option is set, then it increments a "stop_count" of the trace instance. On close, the check is: if (!iter->snapshot && tr->stop_count) That is, if it is not the snapshot buffer and it was stopped, it will re-enable tracing. Now there's more places that stop tracing. This means, if something else stops tracing the tr->stop_count will be non-zero, and that means if the trace file is closed, it will decrement the stop_count even though it never incremented it. This causes a warning because when the user that stopped tracing enables it again, the stop_count goes below zero. Instead of relying on the stop_count being set to know if the close of the trace file should enable tracing again, add a new flag to the trace iterator. The trace iterator is unique per open of the trace file, and if the open stops tracing set the trace iterator PAUSE flag. On close, if the PAUSE flag is set, then re-enable it again. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://patch.msgid.link/20251202161751.24abaaf1@gandalf.local.home Fixes: 06e0a54 ("tracing: Do not disable tracing when reading the trace file") Reported-by: syzbot+ccdec3bfe0beec58a38d@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/692f44a5.a70a0220.2ea503.00c8.GAE@google.com/ Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 2ba5904 commit 02e7769

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

include/linux/trace_events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ enum trace_iter_flags {
138138
TRACE_FILE_LAT_FMT = 1,
139139
TRACE_FILE_ANNOTATE = 2,
140140
TRACE_FILE_TIME_IN_NS = 4,
141+
TRACE_FILE_PAUSE = 8,
141142
};
142143

143144

kernel/trace/trace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4709,8 +4709,10 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
47094709
* If pause-on-trace is enabled, then stop the trace while
47104710
* dumping, unless this is the "snapshot" file
47114711
*/
4712-
if (!iter->snapshot && (tr->trace_flags & TRACE_ITER(PAUSE_ON_TRACE)))
4712+
if (!iter->snapshot && (tr->trace_flags & TRACE_ITER(PAUSE_ON_TRACE))) {
4713+
iter->iter_flags |= TRACE_FILE_PAUSE;
47134714
tracing_stop_tr(tr);
4715+
}
47144716

47154717
if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
47164718
for_each_tracing_cpu(cpu) {
@@ -4842,7 +4844,7 @@ static int tracing_release(struct inode *inode, struct file *file)
48424844
if (iter->trace && iter->trace->close)
48434845
iter->trace->close(iter);
48444846

4845-
if (!iter->snapshot && tr->stop_count)
4847+
if (iter->iter_flags & TRACE_FILE_PAUSE)
48464848
/* reenable tracing if it was previously enabled */
48474849
tracing_start_tr(tr);
48484850

0 commit comments

Comments
 (0)