From: Jaewon Jung <jaewon8868@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCH] tracing: Make event_enable_count_probe() count atomic
Date: Thu, 3 Dec 2026 13:58:44 +0900 [thread overview]
Message-ID: <20261203045851.2243395-1-jaewon8868@gmail.com> (raw)
In-Reply-To: <20261203025249.2117813-1-jaewon8868@gmail.com>
Concurrent callbacks race on the plain count read and decrement. This can
lose updates or turn 0 into -1 (unlimited). Use atomic_long_t and cmpxchg
for the decrement.
Fixes: 3cd715de2611 ("tracing: Add function probe triggers to enable/disable events")
Signed-off-by: Jaewon Jung <jaewon8868@gmail.com>
---
kernel/trace/trace_events.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 4722d9a8b222..1cc40213e2a9 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -4399,7 +4399,7 @@ EXPORT_SYMBOL_GPL(trace_put_event_file);
#ifdef CONFIG_DYNAMIC_FTRACE
struct event_probe_data {
struct trace_event_file *file;
- unsigned long count;
+ atomic_long_t count;
int ref;
bool enable;
};
@@ -4444,18 +4444,27 @@ event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
edata = *pdata;
- if (!edata->count)
+ long count = atomic_long_read(&edata->count);
+
+ if (!count)
return;
+ /* Make sure we see count before checking event state */
+ smp_rmb();
+
/* Skip if the event is in a state we want to switch to */
if (edata->enable == !test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
&edata->file->flags))
return;
- if (edata->count != -1)
- (edata->count)--;
-
update_event_probe(edata);
+
+ if (count != -1) {
+ /* Make sure event state is visible before updating count */
+ smp_wmb();
+
+ atomic_long_cmpxchg(&edata->count, count, count - 1);
+ }
}
static int
@@ -4480,10 +4489,12 @@ event_enable_print(struct seq_file *m, unsigned long ip,
edata->file->event_call->class->system,
trace_event_name(edata->file->event_call));
- if (edata->count == -1)
+ long count = atomic_long_read(&edata->count);
+
+ if (count == -1)
seq_puts(m, ":unlimited\n");
else
- seq_printf(m, ":count=%ld\n", edata->count);
+ seq_printf(m, ":count=%ld\n", count);
return 0;
}
@@ -4652,7 +4663,7 @@ event_enable_func(struct trace_array *tr, struct ftrace_hash *hash,
goto out_put;
data->enable = enable;
- data->count = count;
+ atomic_long_set(&data->count, count);
data->file = file;
ret = register_ftrace_function_probe(glob, tr, ops, data);
--
2.43.0
next prev parent reply other threads:[~2026-12-03 4:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 2:51 [PATCH] tracing: Make event_enable_count_probe() count atomic Jaewon Jung
2026-12-03 3:02 ` sashiko-bot
2026-12-03 4:58 ` Jaewon Jung [this message]
2026-12-03 5:16 ` 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=20261203045851.2243395-1-jaewon8868@gmail.com \
--to=jaewon8868@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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