* [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints
@ 2026-12-04 15:34 Andrea Parri
2026-12-04 15:34 ` [PATCH 1/2] tracepoint: Always use the iterator for faultable tracepoints Andrea Parri
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andrea Parri @ 2026-12-04 15:34 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel, bpf
System call tracepoints protect their probes with RCU Tasks Trace
only, but switching a static call to a single probe waits only for RCU
and tracepoint_srcu readers. A preempted reader can then call the new
probe with the old probe's data, and crash in ftrace_syscall_enter() or
bpf_trace_run2().
Patch 1 fixes this by keeping the static call of faultable tracepoints
on __traceiter_*(), which loads each probe together with its data.
Patch 2 drops what faultable tracepoints no longer need: the static
call update and the grace period snapshots and waits. Patch 1 alone
fixes the bug, so patch 2 can wait for the next merge window, or be
squashed into patch 1 if that is preferred.
Tested on v7.4-rc5 in x86-64 KVM guests, with the test-only hook below
the --- of patch 1, which also has the reproducer for 2 -> 1. Both
race sequences oops in 3 of 3 runs without the series, and in none
with patch 1 alone or with both patches. ftracetest: 164 passed,
0 failed in all three cases.
With perf_syscall_enter() as the only sys_enter probe, getppid() takes
153.6 ns with the series and 153.2 ns without it. With patch 1 alone,
whose reader path is the same, another pair of builds measured 155.9
and 153.7 ns: a difference of 2.2 ns, against 0.4 ns for the series.
The bug was found with the help of an LLM, which was also used to write
both patches, their changelogs and the tests.
Andrea Parri (2):
tracepoint: Always use the iterator for faultable tracepoints
tracepoint: Drop static call switching for faultable tracepoints
kernel/tracepoint.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] tracepoint: Always use the iterator for faultable tracepoints
2026-12-04 15:34 [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Andrea Parri
@ 2026-12-04 15:34 ` Andrea Parri
2026-12-04 15:34 ` [PATCH 2/2] tracepoint: Drop static call switching " Andrea Parri
2026-12-04 15:41 ` [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Mathieu Desnoyers
2 siblings, 0 replies; 5+ messages in thread
From: Andrea Parri @ 2026-12-04 15:34 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel, bpf
Closing a perf event on a system call tracepoint can crash a task that
is entering a system call at the same time. With perf and ftrace both
tracing system call entry, the task calls ftrace_syscall_enter() with
the perf probe's NULL data instead of its trace_array:
BUG: kernel NULL pointer dereference, address: 0000000000000188
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
Oops: Oops: 0000 [#1] SMP NOPTI
CPU: 1 UID: 0 PID: 106 Comm: tpvictim Not tainted 7.4.0-rc5-dirty #4 PREEMPT(full)
RIP: 0010:ftrace_syscall_enter+0x88/0x310
Call Trace:
<TASK>
? vprintk_emit+0x20c/0x2f0
trace_syscall_enter+0x73/0xc0
do_syscall_64+0x446/0x4f0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
When a tracepoint ends up with a single probe (2 -> 1, or 1 -> 0 -> 1),
its static call is switched from __traceiter_*() to that probe. Readers
load tp->funcs[0].data before the static call, so tp_rcu_cond_sync()
first makes sure that an RCU and a tracepoint_srcu grace period have
elapsed since the old data was replaced.
Since commit a363d27cdbc2 ("tracing: Allow system call tracepoints to
handle page faults"), system call tracepoints protect their probes with
RCU Tasks Trace only, and neither grace period waits for those readers.
A task preempted between the data load and the static call then resumes
into the new probe with the old data:
CPU 0 CPU 1
__do_trace_sys_enter()
guard(rcu_tasks_trace)();
__data = funcs[0].data; // NULL
<preempted>
perf_trace_event_unreg()
tracepoint_remove_func()
tp_rcu_cond_sync();
tracepoint_update_call();
static_call(tp_func_sys_enter)(__data, ...);
ftrace_syscall_enter(NULL, ...);
Commit 2e8a12b82c40 ("tracing: Fix syscall tracepoint use-after-free")
made release_probes() defer freeing old probe arrays until after an RCU
Tasks Trace grace period, but left the waits before a static call switch
unchanged.
Keep the static call of faultable tracepoints on __traceiter_*(), which
ignores the data it is passed and loads each probe together with its
data from the same tp->funcs entry.
Waiting for an RCU Tasks Trace grace period in tp_rcu_cond_sync() would
also close the race, but under tracepoints_mutex. System call probes
can sleep in their read-side sections while faulting in user memory,
and every tracepoint registration would then wait for the fault.
The cost is an indirect call per system call while the tracepoint has
a single probe, as on kernels without CONFIG_HAVE_STATIC_CALL, which
always use __traceiter_*().
The splat above is from x86-64 with CONFIG_PREEMPT=y and a test-only
mdelay(), with preemption enabled, between the data load and the static
call. A 1 -> 0 -> 1 sequence (perf, then a BPF raw tracepoint) crashes
the same way in bpf_trace_run2(). With this patch, neither crashes.
The bug was found with the help of an LLM, which was also used to write
the fix, the changelog and the tests.
Fixes: a363d27cdbc2 ("tracing: Allow system call tracepoints to handle page faults")
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
---
Reproduced on v7.4-rc5 in x86-64 KVM guests (CONFIG_PREEMPT=y) with
the test-only hook below, which busy-waits once for 2 s, with
preemption enabled, between the data load and the static call of one
task. Without such a delay the window is a few instructions, and I did
not try to hit it by stress alone.
Each sequence oopsed in 3 of 3 runs without this patch and in 0 of 3
runs with it. With this patch, the BPF attach in the 1 -> 0 -> 1 case
returns while the delayed task still holds the old data, and that task
resumes without crashing.
An earlier version of this patch waited for an RCU Tasks Trace grace
period in tp_rcu_cond_sync() instead. With a sys_enter_write probe
parked in a userfaultfd fault, attaching a BPF raw tracepoint to
sched_switch then blocked in tracepoint_add_func() until the fault was
resolved (tested on v7.4-rc4). With this patch the attach returns
after 54 ms, and after 59 ms without it.
Calling __traceiter_*() directly from __DECLARE_TRACE_SYSCALL() would
also fix the bug. I kept the static call, now always targeting the
iterator, so that tracepoint_update_call() remains the one place that
picks the target and the fix stays in kernel/tracepoint.c. I can
switch to the direct call if that is preferred.
With perf_syscall_enter() as the only sys_enter probe, returning early,
getppid() takes 155.9 ns with this patch and 153.7 ns without it
(median of 5 runs, each the best of 5 batches of 2M calls, in a nested
KVM guest). With no probe attached, it takes 124.9 and 124.4 ns.
ftracetest, with tools/testing/selftests/ftrace/config plus
CONFIG_PREEMPT=y: 164 passed, 1 unresolved (checkbashisms is not
installed), 12 unsupported and 2 xfailed, with and without this patch.
Test-only hook, applying to v7.4-rc5 with or without this patch:
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index e0d838c9ce938..863231ad0cfe0 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -227,8 +227,23 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
static_call(tp_func_##name)(__data, args); \
} \
} while (0)
+/* TEST ONLY: widen the window between loading __data and the static call. */
+extern void tp_syscall_race_delay(void);
+#define __DO_TRACE_CALL_SYSCALL(name, args) \
+ do { \
+ struct tracepoint_func *it_func_ptr; \
+ void *__data; \
+ it_func_ptr = \
+ rcu_dereference_raw((&__tracepoint_##name)->funcs); \
+ if (it_func_ptr) { \
+ __data = (it_func_ptr)->data; \
+ tp_syscall_race_delay(); \
+ static_call(tp_func_##name)(__data, args); \
+ } \
+ } while (0)
#else
#define __DO_TRACE_CALL(name, args) __traceiter_##name(NULL, args)
+#define __DO_TRACE_CALL_SYSCALL(name, args) __DO_TRACE_CALL(name, args)
#endif /* CONFIG_HAVE_STATIC_CALL */
/*
@@ -336,7 +351,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
{ \
TRACEPOINT_CHECK(name) \
guard(rcu_tasks_trace)(); \
- __DO_TRACE_CALL(name, TP_ARGS(args)); \
+ __DO_TRACE_CALL_SYSCALL(name, TP_ARGS(args)); \
} \
static inline void trace_##name(proto) \
{ \
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index dffef52a807bc..87d4356078017 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -3,6 +3,8 @@
* Copyright (C) 2008-2014 Mathieu Desnoyers
*/
#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/moduleparam.h>
#include <linux/mutex.h>
#include <linux/types.h>
#include <linux/jhash.h>
@@ -66,6 +68,45 @@ static void tp_rcu_cond_sync(enum tp_transition_sync sync)
snapshot->ongoing = false;
}
+/*
+ * TEST ONLY: one-shot busy-wait inside faultable syscall tracepoints, after
+ * __data has been loaded and before the static call, for the task whose comm
+ * matches race_comm. Busy-wait with preemption enabled, so that regular RCU
+ * (and tracepoint_srcu) grace periods can complete meanwhile, exactly as they
+ * would if the task were preempted at that point.
+ *
+ * /sys/module/tracepoint/parameters/race_comm (write with echo -n)
+ * /sys/module/tracepoint/parameters/race_delay_ms (cleared once consumed)
+ * /sys/module/tracepoint/parameters/race_state (0 idle, 1 spinning, 2 done)
+ */
+static char race_comm[TASK_COMM_LEN];
+module_param_string(race_comm, race_comm, sizeof(race_comm), 0644);
+static unsigned int race_delay_ms;
+module_param(race_delay_ms, uint, 0644);
+static int race_state;
+module_param(race_state, int, 0444);
+
+notrace void tp_syscall_race_delay(void)
+{
+ unsigned int ms;
+
+ if (likely(!READ_ONCE(race_delay_ms)))
+ return;
+ if (strncmp(current->comm, race_comm, TASK_COMM_LEN))
+ return;
+ ms = xchg(&race_delay_ms, 0);
+ if (!ms)
+ return;
+ pr_info("tp-race: %s/%d loaded __data, spinning %u ms (preemptible=%d)\n",
+ current->comm, current->pid, ms, preemptible());
+ WRITE_ONCE(race_state, 1);
+ mdelay(ms);
+ WRITE_ONCE(race_state, 2);
+ pr_info("tp-race: %s/%d resuming into static call\n",
+ current->comm, current->pid);
+}
+EXPORT_SYMBOL_GPL(tp_syscall_race_delay);
+
/* Set to 1 to enable tracepoint debug output */
static const int tracepoint_debug;
With the hook, as root, the following crashes v7.4-rc5 in 3 of 3 runs,
and does not crash it with this patch. This was run under virtme-ng,
with "vng --kconfig" plus CONFIG_PREEMPT=y, CONFIG_FTRACE_SYSCALLS=y,
CONFIG_PERF_EVENTS=y and CONFIG_KALLSYMS_ALL=y, booted with
preempt=full:
P=/sys/module/tracepoint/parameters
E=/sys/kernel/tracing/events/syscalls/sys_enter_openat
echo -n dd > $P/race_comm
# sys_enter probe 1: perf_syscall_enter(), data NULL
perf stat -a -e syscalls:sys_enter_openat &
PERF=$!; sleep 1
echo 1 > $E/enable # probe 2: ftrace_syscall_enter(), data tr
echo 2000 > $P/race_delay_ms
dd if=/dev/zero of=/dev/null count=1 & # loads NULL, spins 2 s
sleep 0.5; kill -INT $PERF # perf exits: 2 -> 1
sleep 3; dmesg | grep -A12 'BUG:'
The trigger script used for the counts above, including the
1 -> 0 -> 1 variant, the userfaultfd test and the benchmark are
available on request.
kernel/tracepoint.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index dffef52a807bc..11401df67e7b2 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -275,7 +275,14 @@ static void tracepoint_update_call(struct tracepoint *tp, struct tracepoint_func
/* Synthetic events do not have static call sites */
if (!tp->static_call_key)
return;
- if (nr_func_state(tp_funcs) == TP_FUNC_1)
+ /*
+ * Faultable tracepoint readers can be preempted between loading
+ * funcs[0].data and the static call, and tp_rcu_cond_sync() does not
+ * wait for them. Keep the iterator, which loads each probe together
+ * with its data.
+ */
+ if (nr_func_state(tp_funcs) == TP_FUNC_1 &&
+ !tracepoint_is_faultable(tp))
func = tp_funcs[0].func;
__static_call_update(tp->static_call_key, tp->static_call_tramp, func);
}
@@ -319,7 +326,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
* 1->0->1 transition sequence.
*/
tp_rcu_cond_sync(TP_TRANSITION_SYNC_1_0_1);
- /* Set static call to first function */
+ /* Set static call to first function, unless faultable */
tracepoint_update_call(tp, tp_funcs);
/* Both iterator and static call handle NULL tp->funcs */
rcu_assign_pointer(tp->funcs, tp_funcs);
@@ -401,7 +408,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
if (tp_funcs[0].data != old[0].data)
tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
tp_rcu_cond_sync(TP_TRANSITION_SYNC_N_2_1);
- /* Set static call to first function */
+ /* Set static call to first function, unless faultable */
tracepoint_update_call(tp, tp_funcs);
break;
case TP_FUNC_2: /* N->N-1 (N>2) */
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] tracepoint: Drop static call switching for faultable tracepoints
2026-12-04 15:34 [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Andrea Parri
2026-12-04 15:34 ` [PATCH 1/2] tracepoint: Always use the iterator for faultable tracepoints Andrea Parri
@ 2026-12-04 15:34 ` Andrea Parri
2026-12-04 15:41 ` [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Mathieu Desnoyers
2 siblings, 0 replies; 5+ messages in thread
From: Andrea Parri @ 2026-12-04 15:34 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel, bpf
The static call of a faultable tracepoint now always targets
__traceiter_*(). When its number of probes changes between zero, one
and two, tracepoint_update_call() still sets it to the iterator again,
which rewrites the trampoline on architectures with out-of-line static
calls, such as arm64 with CONFIG_CFI.
Before switching a static call to a single probe, tp_rcu_cond_sync()
waits for the RCU and tracepoint_srcu grace periods snapshotted by
tp_rcu_get_state(), under tracepoints_mutex. Faultable tracepoints no
longer make that switch, so they need neither the snapshots nor the
waits.
Return early from tracepoint_update_call(), tp_rcu_get_state() and
tp_rcu_cond_sync() for faultable tracepoints. The snapshots are
shared by all tracepoints, but each tracepoint that switches its static
call waits for them itself, so the other tracepoints are still
covered. They also no longer wait for snapshots taken for sys_enter
or sys_exit.
Readers are unaffected: faultable tracepoints keep calling
__traceiter_*(), and the other tracepoints keep their static call
updates and grace periods.
The patch and the changelog were written with the help of an LLM.
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
---
kernel/tracepoint.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 11401df67e7b2..ce2d0403b92cf 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -44,20 +44,26 @@ EXPORT_SYMBOL_GPL(tracepoint_srcu);
/* Protected by tracepoints_mutex */
static struct tp_transition_snapshot tp_transition_snapshot[_NR_TP_TRANSITION_SYNC];
-static void tp_rcu_get_state(enum tp_transition_sync sync)
+static void tp_rcu_get_state(struct tracepoint *tp, enum tp_transition_sync sync)
{
struct tp_transition_snapshot *snapshot = &tp_transition_snapshot[sync];
+ /* Faultable tracepoints never switch their static call. */
+ if (tracepoint_is_faultable(tp))
+ return;
/* Keep the latest get_state snapshot. */
snapshot->rcu = get_state_synchronize_rcu();
snapshot->srcu_gp = start_poll_synchronize_srcu(&tracepoint_srcu);
snapshot->ongoing = true;
}
-static void tp_rcu_cond_sync(enum tp_transition_sync sync)
+static void tp_rcu_cond_sync(struct tracepoint *tp, enum tp_transition_sync sync)
{
struct tp_transition_snapshot *snapshot = &tp_transition_snapshot[sync];
+ /* Faultable tracepoints never switch their static call. */
+ if (tracepoint_is_faultable(tp))
+ return;
if (!snapshot->ongoing)
return;
cond_synchronize_rcu(snapshot->rcu);
@@ -277,12 +283,13 @@ static void tracepoint_update_call(struct tracepoint *tp, struct tracepoint_func
return;
/*
* Faultable tracepoint readers can be preempted between loading
- * funcs[0].data and the static call, and tp_rcu_cond_sync() does not
- * wait for them. Keep the iterator, which loads each probe together
- * with its data.
+ * funcs[0].data and the static call, and the grace periods waited for
+ * by tp_rcu_cond_sync() do not cover them. Their static call stays on
+ * the iterator, which loads each probe together with its data.
*/
- if (nr_func_state(tp_funcs) == TP_FUNC_1 &&
- !tracepoint_is_faultable(tp))
+ if (tracepoint_is_faultable(tp))
+ return;
+ if (nr_func_state(tp_funcs) == TP_FUNC_1)
func = tp_funcs[0].func;
__static_call_update(tp->static_call_key, tp->static_call_tramp, func);
}
@@ -325,7 +332,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
* Make sure new static func never uses old data after a
* 1->0->1 transition sequence.
*/
- tp_rcu_cond_sync(TP_TRANSITION_SYNC_1_0_1);
+ tp_rcu_cond_sync(tp, TP_TRANSITION_SYNC_1_0_1);
/* Set static call to first function, unless faultable */
tracepoint_update_call(tp, tp_funcs);
/* Both iterator and static call handle NULL tp->funcs */
@@ -348,7 +355,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
* N->...->2->1 (N>1) transition sequence.
*/
if (tp_funcs[0].data != old[0].data)
- tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
+ tp_rcu_get_state(tp, TP_TRANSITION_SYNC_N_2_1);
break;
default:
WARN_ON_ONCE(1);
@@ -394,7 +401,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
* Make sure new static func never uses old data after a
* 1->0->1 transition sequence.
*/
- tp_rcu_get_state(TP_TRANSITION_SYNC_1_0_1);
+ tp_rcu_get_state(tp, TP_TRANSITION_SYNC_1_0_1);
break;
case TP_FUNC_1: /* 2->1 */
rcu_assign_pointer(tp->funcs, tp_funcs);
@@ -406,8 +413,8 @@ static int tracepoint_remove_func(struct tracepoint *tp,
* from calling the new function.
*/
if (tp_funcs[0].data != old[0].data)
- tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
- tp_rcu_cond_sync(TP_TRANSITION_SYNC_N_2_1);
+ tp_rcu_get_state(tp, TP_TRANSITION_SYNC_N_2_1);
+ tp_rcu_cond_sync(tp, TP_TRANSITION_SYNC_N_2_1);
/* Set static call to first function, unless faultable */
tracepoint_update_call(tp, tp_funcs);
break;
@@ -420,7 +427,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
* N->...->2->1 (N>2) transition sequence.
*/
if (tp_funcs[0].data != old[0].data)
- tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
+ tp_rcu_get_state(tp, TP_TRANSITION_SYNC_N_2_1);
break;
default:
WARN_ON_ONCE(1);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints
2026-12-04 15:34 [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Andrea Parri
2026-12-04 15:34 ` [PATCH 1/2] tracepoint: Always use the iterator for faultable tracepoints Andrea Parri
2026-12-04 15:34 ` [PATCH 2/2] tracepoint: Drop static call switching " Andrea Parri
@ 2026-12-04 15:41 ` Mathieu Desnoyers
2026-12-04 15:51 ` Andrea Parri
2 siblings, 1 reply; 5+ messages in thread
From: Mathieu Desnoyers @ 2026-12-04 15:41 UTC (permalink / raw)
To: Andrea Parri, Steven Rostedt, Masami Hiramatsu
Cc: linux-kernel, linux-trace-kernel, bpf
On 2026-12-04 10:34, Andrea Parri wrote:
> System call tracepoints protect their probes with RCU Tasks Trace
> only, but switching a static call to a single probe waits only for RCU
> and tracepoint_srcu readers. A preempted reader can then call the new
> probe with the old probe's data, and crash in ftrace_syscall_enter() or
> bpf_trace_run2().
>
> Patch 1 fixes this by keeping the static call of faultable tracepoints
> on __traceiter_*(), which loads each probe together with its data.
>
> Patch 2 drops what faultable tracepoints no longer need: the static
> call update and the grace period snapshots and waits. Patch 1 alone
> fixes the bug, so patch 2 can wait for the next merge window, or be
> squashed into patch 1 if that is preferred.
>
> Tested on v7.4-rc5 in x86-64 KVM guests, with the test-only hook below
> the --- of patch 1, which also has the reproducer for 2 -> 1. Both
> race sequences oops in 3 of 3 runs without the series, and in none
> with patch 1 alone or with both patches. ftracetest: 164 passed,
> 0 failed in all three cases.
>
> With perf_syscall_enter() as the only sys_enter probe, getppid() takes
> 153.6 ns with the series and 153.2 ns without it. With patch 1 alone,
> whose reader path is the same, another pair of builds measured 155.9
> and 153.7 ns: a difference of 2.2 ns, against 0.4 ns for the series.
>
> The bug was found with the help of an LLM, which was also used to write
> both patches, their changelogs and the tests.
Why not just fix tp_rcu_cond_sync() to handle the rcu tasks trace
sychronization which seems to be missing ?
Thanks,
Mathieu
>
> Andrea Parri (2):
> tracepoint: Always use the iterator for faultable tracepoints
> tracepoint: Drop static call switching for faultable tracepoints
>
> kernel/tracepoint.c | 34 ++++++++++++++++++++++++----------
> 1 file changed, 24 insertions(+), 10 deletions(-)
>
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints
2026-12-04 15:41 ` [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Mathieu Desnoyers
@ 2026-12-04 15:51 ` Andrea Parri
0 siblings, 0 replies; 5+ messages in thread
From: Andrea Parri @ 2026-12-04 15:51 UTC (permalink / raw)
To: Mathieu Desnoyers
Cc: Steven Rostedt, Masami Hiramatsu, linux-kernel,
linux-trace-kernel, bpf
On Fri, Dec 04, 2026 at 10:41:13AM -0500, Mathieu Desnoyers wrote:
> Why not just fix tp_rcu_cond_sync() to handle the rcu tasks trace
> sychronization which seems to be missing ?
That was my first version: tp_rcu_get_state() also took a polled
snapshot of rcu_tasks_trace_srcu_struct for faultable tracepoints, and
tp_rcu_cond_sync() waited for it if it had not elapsed yet. It closes
the race, but the wait runs under tracepoints_mutex, and the read-side
sections of the system call tracepoints are not bounded: their probes
can fault in user memory, and sleepable BPF programs can attach there
too. How long a fault takes is up to whoever backs the memory, a
userfaultfd handler for example.
With a sys_enter_write probe parked in a userfaultfd fault, I disabled
that event and then attached a BPF raw tracepoint to sched_switch. The
attach blocked until the fault was resolved (it was still blocked after
3 s, on v7.4-rc4):
__synchronize_srcu+0x92/0xd0
tracepoint_add_func+0x2b5/0x480
tracepoint_probe_register_prio_may_exist+0x6d/0xa0
bpf_raw_tp_link_attach+0x1c2/0x2a0
The snapshots are shared by all tracepoints, so the wait also hits
registrations on unrelated tracepoints such as sched_switch. Keeping
the Tasks Trace snapshot per tracepoint would avoid that, but a
sys_enter or sys_exit registration could still sleep on the fault with
tracepoints_mutex held, and every other probe registration and
unregistration would queue behind it.
Keeping the iterator for faultable tracepoints removes the need for
that wait, at the cost of an indirect call while the tracepoint has a
single probe.
Thanks,
Andrea
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 15:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 15:34 [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Andrea Parri
2026-12-04 15:34 ` [PATCH 1/2] tracepoint: Always use the iterator for faultable tracepoints Andrea Parri
2026-12-04 15:34 ` [PATCH 2/2] tracepoint: Drop static call switching " Andrea Parri
2026-12-04 15:41 ` [PATCH 0/2] tracepoint: Fix stale probe data in system call tracepoints Mathieu Desnoyers
2026-12-04 15:51 ` Andrea Parri
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox