From nobody Fri Dec 19 14:44:43 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3CD018FDBE for ; Sat, 6 Dec 2025 01:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764983152; cv=none; b=KroAb8wtawrL4OTLKjpFamuSm48//gVKVGhWgD7Xf7zklCYFIWFrjFXoozD/dKAwgYiins2TvpwOXr5sDChO1K5LfmiYZdh7Kl7dCxnsOddUisvtQ9st48BsA2GUo0rGSUye0SPHeZGazZ5YSgJ8aGmJozfIoqio0tAB9IV+8iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764983152; c=relaxed/simple; bh=hLA2PPwdpEgbg0eFYnwPSBX+N9CvQjgH48MhHsRznzU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ssbbElABE9dAmxv2v0wNzPpVUkYIA21/AJ6trzE78lAwZTrHE9Fqz96ME4BykYHERh7l3GhXF9xOxfazcAIWQt4q0yGhXXpTHOqUiBFTL0ivu6J3xbQ3QdtmJTnU4vFguDk4znCWDh+vhkks3ghsdNTXSJyWQ464mkPIyVXz8HY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GORnL+V9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GORnL+V9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5383CC116C6; Sat, 6 Dec 2025 01:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764983152; bh=hLA2PPwdpEgbg0eFYnwPSBX+N9CvQjgH48MhHsRznzU=; h=Date:From:To:Cc:Subject:References:From; b=GORnL+V9frt0Lqq9x8OX6fUZL39nlg795p78yR2IG/LlT+0wcJgNIOVJobgcrcrwH 2Tq8IhWvmOgkNeQJn+VA2J5cTSXHxq6WPNzOuo0MFMviiXcvYba840iRj+cbisU0EW 7cmTq/bLKio/2/Y1qGQNO0KOu4wP0VvYlTDl8JwsLD67TbOc/OpnxiYoW/1zfyyeAV Dhg/hd0vlAzX808HXTn+UthnIcrFM6/Xq960z4rNJd+OWfP8z/kEUq4tyH1eZMRX7q a8zkHRMK2ZyvkoWLGHRvwz0YHppEJNj6tfzKoEMRjdkOcoLDFSjxmVQjuv2GkzQRAe 67Fai/hjCIH2g== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1vRglI-00000009VlS-41dI; Fri, 05 Dec 2025 20:07:00 -0500 Message-ID: <20251206010700.815241948@kernel.org> User-Agent: quilt/0.68 Date: Fri, 05 Dec 2025 20:06:34 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , syzbot+ccdec3bfe0beec58a38d@syzkaller.appspotmail.com Subject: [for-linus][PATCH 01/15] tracing: Fix enabling of tracing on file release References: <20251206010633.884804695@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt 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 Cc: Mathieu Desnoyers Link: https://patch.msgid.link/20251202161751.24abaaf1@gandalf.local.home Fixes: 06e0a548bad0f ("tracing: Do not disable tracing when reading the tra= ce file") Reported-by: syzbot+ccdec3bfe0beec58a38d@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/692f44a5.a70a0220.2ea503.00c8.GAE@googl= e.com/ Signed-off-by: Steven Rostedt (Google) --- include/linux/trace_events.h | 1 + kernel/trace/trace.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 04307a19cde3..3690221ba3d8 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -138,6 +138,7 @@ enum trace_iter_flags { TRACE_FILE_LAT_FMT =3D 1, TRACE_FILE_ANNOTATE =3D 2, TRACE_FILE_TIME_IN_NS =3D 4, + TRACE_FILE_PAUSE =3D 8, }; =20 =20 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index c9fbb316dcbd..cf725a33d99c 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4709,8 +4709,10 @@ __tracing_open(struct inode *inode, struct file *fil= e, bool snapshot) * If pause-on-trace is enabled, then stop the trace while * dumping, unless this is the "snapshot" file */ - if (!iter->snapshot && (tr->trace_flags & TRACE_ITER(PAUSE_ON_TRACE))) + if (!iter->snapshot && (tr->trace_flags & TRACE_ITER(PAUSE_ON_TRACE))) { + iter->iter_flags |=3D TRACE_FILE_PAUSE; tracing_stop_tr(tr); + } =20 if (iter->cpu_file =3D=3D RING_BUFFER_ALL_CPUS) { for_each_tracing_cpu(cpu) { @@ -4842,7 +4844,7 @@ static int tracing_release(struct inode *inode, struc= t file *file) if (iter->trace && iter->trace->close) iter->trace->close(iter); =20 - if (!iter->snapshot && tr->stop_count) + if (iter->iter_flags & TRACE_FILE_PAUSE) /* reenable tracing if it was previously enabled */ tracing_start_tr(tr); =20 --=20 2.51.0