Linux Trace Kernel
 help / color / mirror / Atom feed
From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>, linux-trace-kernel@vger.kernel.org
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Tom Zanussi <zanussi@kernel.org>,
	"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>,
	Donggeun Yoo <donggeunyoo.kernel@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/3] tracing: Clear RECORDED_CMD and RECORDED_TGID flags on register failure
Date: Sun, 06 Dec 2026 23:31:39 +0900	[thread overview]
Message-ID: <20261206142805.70891-2-mhiramat@kernel.org> (raw)
In-Reply-To: <20261206142805.70891-1-mhiramat@kernel.org>

In __ftrace_event_enable_disable(), when RECORD_CMD or RECORD_TGID is
enabled, tracing_start_cmdline_record() / tracing_start_tgid_record() is
called and EVENT_FILE_FL_RECORDED_CMD_BIT / EVENT_FILE_FL_RECORDED_TGID_BIT
is set before calling call->class->reg(call, TRACE_REG_REGISTER, file).
If reg() fails, tracing_stop_cmdline_record() and
tracing_stop_tgid_record() are called, but the corresponding flag bits
remain set on file->flags.

If record-cmd or record-tgid is later turned off and the event is
subsequently enabled and disabled, the stale flag bit triggers an extra
stop call and underflows the global cmdline/tgid recording refcount
(sched_cmdline_ref / sched_tgid_ref drops from 0 to -1), preventing
tracing_sched_register() from running on the next enable.

Reproducer (using trace-events-sample module to fail register_fprobe()):

  cd /sys/kernel/tracing
  echo 0 > options/record-cmd
  echo 0 > options/record-tgid
  modprobe trace-events-sample
  echo 'f:fprobes/testfp sample_timer_cb' >> dynamic_events
  rmmod trace-events-sample
  echo 1 > options/record-tgid
  echo 1 > events/fprobes/testfp/enable   # fails with -ENOENT
  echo 0 > options/record-tgid
  modprobe trace-events-sample
  echo 1 > events/fprobes/testfp/enable
  echo 0 > events/fprobes/testfp/enable   # underflows sched_tgid_ref
  echo 1 > options/record-tgid
  echo 1 > events/fprobes/testfp/enable
  sleep 1
  cat saved_tgids

Before:
  `cat saved_tgids` prints nothing (empty), because sched_tgid_ref only
  increments from -1 to 0 and tracing_sched_register() is never called.

Expected:
  `cat saved_tgids` prints recorded "<pid> <tgid>" entries (non-empty).

Clear EVENT_FILE_FL_RECORDED_CMD_BIT and EVENT_FILE_FL_RECORDED_TGID_BIT
in the registration error path alongside the stop calls.

Fixes: e870e9a1240b ("tracing: Allow to disable cmdline recording")
Fixes: d914ba37d714 ("tracing: Add support for recording tgid of tasks")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_events.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 60720d9236a1..f33fd00d2604 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -912,10 +912,16 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
 
 			ret = call->class->reg(call, TRACE_REG_REGISTER, file);
 			if (ret) {
-				if (cmd)
+				if (cmd) {
+					clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT,
+						  &file->flags);
 					tracing_stop_cmdline_record();
-				if (tgid)
+				}
+				if (tgid) {
+					clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT,
+						  &file->flags);
 					tracing_stop_tgid_record();
+				}
 				pr_info("event trace: Could not enable event "
 					"%s\n", trace_event_name(call));
 				break;
-- 
2.43.0


  reply	other threads:[~2026-12-06 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 14:31 [PATCH v2 0/3] tracing: Roll back event flags and soft/trigger-mode refs on register failure Masami Hiramatsu (Google)
2026-12-06 14:31 ` Masami Hiramatsu (Google) [this message]
2026-12-06 14:31 ` [PATCH v2 2/3] tracing/eprobe: Handle trace_event_trigger_enable_disable() failure in enable_eprobe() Masami Hiramatsu (Google)
2026-12-06 14:31 ` [PATCH v2 3/3] tracing: Roll back soft-mode and trigger-mode refs on register failure Masami Hiramatsu (Google)
2026-12-06 14:51   ` sashiko-bot

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=20261206142805.70891-2-mhiramat@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=donggeunyoo.kernel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.org \
    --cc=tz.stoyanov@gmail.com \
    --cc=zanussi@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