[PATCH] tracing/probes: Guard probe dispatchers with tracepoint_srcu

From: Masami Hiramatsu (Google)

Date: Thu Dec 03 2026 - 22:29:55 EST


Since commit a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of
__DO_TRACE_CALL() with SRCU-fast"), tracepoint_synchronize_unregister()
waits only on rcu_tasks_trace and tracepoint_srcu, and no longer waits
for a standard RCU grace period.

However, kprobe, fprobe, and uprobe event dispatchers still execute only
under standard RCU protection. Once trace_probe_remove_file() defers
releasing event_file_link and trace_event_file via call_rcu() without
an inline synchronize_rcu(), teardown paths that synchronize via
tracepoint_synchronize_unregister() -- such as event_trace_del_tracer(),
__ftrace_clear_event_pids(), trigger_data_free(), and
perf_trace_event_unreg() -- can free trace_array (file->tr), ring
buffers, PID filter lists, trigger data, or perf state while a probe
handler is still running.

Guard the kprobe, kretprobe, fentry, fexit, uprobe, and uretprobe
dispatchers with guard(srcu_fast_notrace)(&tracepoint_srcu) so that
probe execution is synchronized with tracepoint_synchronize_unregister()
while keeping standard RCU protection for call_rcu()-freed objects and
avoiding inline synchronize_rcu() in trace_probe_remove_file().

Also update the stale synchronization comments in disable_trace_kprobe(),
disable_trace_fprobe(), and disable_trace_eprobe().

Fixes: a46023d5616e ("tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
kernel/trace/trace_eprobe.c | 5 ++++-
kernel/trace/trace_fprobe.c | 16 ++++++++++------
kernel/trace/trace_kprobe.c | 13 ++++++++-----
kernel/trace/trace_uprobe.c | 2 ++
4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
index f65393fb1c10..9e9b2e53b42d 100644
--- a/kernel/trace/trace_eprobe.c
+++ b/kernel/trace/trace_eprobe.c
@@ -711,7 +711,10 @@ static int disable_trace_eprobe(struct trace_event_call *call,
for_each_trace_eprobe_tp(ep, tp)
disable_eprobe(ep, file->tr);

- /* Synchronization is done in below function. */
+ /*
+ * disable_eprobe() synchronizes via tracepoint_synchronize_unregister(),
+ * and trace_probe_remove_file() defers freeing link and file via call_rcu().
+ */
trace_probe_remove_file(tp, file);

return 0;
diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c
index 9ab0871a6461..1152ec6f1f02 100644
--- a/kernel/trace/trace_fprobe.c
+++ b/kernel/trace/trace_fprobe.c
@@ -519,9 +519,11 @@ static int fentry_dispatcher(struct fprobe *fp, unsigned long entry_ip,
void *entry_data)
{
struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp);
- unsigned int flags = trace_probe_load_flag(&tf->tp);
+ unsigned int flags;
int ret = 0;

+ guard(srcu_fast_notrace)(&tracepoint_srcu);
+ flags = trace_probe_load_flag(&tf->tp);
if (flags & TP_FLAG_TRACE)
fentry_trace_func(tf, entry_ip, fregs);

@@ -538,8 +540,10 @@ static void fexit_dispatcher(struct fprobe *fp, unsigned long entry_ip,
void *entry_data)
{
struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp);
- unsigned int flags = trace_probe_load_flag(&tf->tp);
+ unsigned int flags;

+ guard(srcu_fast_notrace)(&tracepoint_srcu);
+ flags = trace_probe_load_flag(&tf->tp);
if (flags & TP_FLAG_TRACE)
fexit_trace_func(tf, entry_ip, ret_ip, fregs, entry_data);
#ifdef CONFIG_PERF_EVENTS
@@ -1530,10 +1534,10 @@ static int disable_trace_fprobe(struct trace_event_call *call,
out:
if (file)
/*
- * Synchronization is done in below function. For perf event,
- * file == NULL and perf_trace_event_unreg() calls
- * tracepoint_synchronize_unregister() to ensure synchronize
- * event. We don't need to care about it.
+ * trace_probe_remove_file() defers releasing link and file
+ * via call_rcu(). Teardown paths (e.g. event_trace_del_tracer(),
+ * perf_trace_event_unreg()) synchronize with in-flight
+ * dispatchers via tracepoint_synchronize_unregister().
*/
trace_probe_remove_file(tp, file);

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 1dd6a6942eb7..474c7fd8da61 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -437,10 +437,10 @@ static int disable_trace_kprobe(struct trace_event_call *call,
out:
if (file)
/*
- * Synchronization is done in below function. For perf event,
- * file == NULL and perf_trace_event_unreg() calls
- * tracepoint_synchronize_unregister() to ensure synchronize
- * event. We don't need to care about it.
+ * trace_probe_remove_file() defers releasing link and file
+ * via call_rcu(). Teardown paths (e.g. event_trace_del_tracer(),
+ * perf_trace_event_unreg()) synchronize with in-flight
+ * dispatchers via tracepoint_synchronize_unregister().
*/
trace_probe_remove_file(tp, file);

@@ -1834,11 +1834,13 @@ static int kprobe_register(struct trace_event_call *event,
static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
{
struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp);
- unsigned int flags = trace_probe_load_flag(&tk->tp);
+ unsigned int flags;
int ret = 0;

raw_cpu_inc(*tk->nhit);

+ guard(srcu_fast_notrace)(&tracepoint_srcu);
+ flags = trace_probe_load_flag(&tk->tp);
if (flags & TP_FLAG_TRACE)
kprobe_trace_func(tk, regs);
#ifdef CONFIG_PERF_EVENTS
@@ -1867,6 +1869,7 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
tk = container_of(rp, struct trace_kprobe, rp);
raw_cpu_inc(*tk->nhit);

+ guard(srcu_fast_notrace)(&tracepoint_srcu);
flags = trace_probe_load_flag(&tk->tp);
if (flags & TP_FLAG_TRACE)
kretprobe_trace_func(tk, ri, regs);
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index fb7991543db7..a53ffd8b2790 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -1569,6 +1569,7 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs,
if (WARN_ON_ONCE(!uprobe_cpu_buffer))
return 0;

+ guard(srcu_fast_notrace)(&tracepoint_srcu);
flags = trace_probe_load_flag(&tu->tp);
if (flags & TP_FLAG_TRACE)
ret |= uprobe_trace_func(tu, regs, &ucb);
@@ -1600,6 +1601,7 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con,
if (WARN_ON_ONCE(!uprobe_cpu_buffer))
return 0;

+ guard(srcu_fast_notrace)(&tracepoint_srcu);
flags = trace_probe_load_flag(&tu->tp);
if (flags & TP_FLAG_TRACE)
uretprobe_trace_func(tu, func, regs, &ucb);
--
2.43.0