From: Andrea Parri <parri.andrea@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
bpf@vger.kernel.org
Subject: [PATCH 2/2] tracepoint: Drop static call switching for faultable tracepoints
Date: Fri, 4 Dec 2026 16:34:51 +0100 [thread overview]
Message-ID: <20261204153452.17096-3-parri.andrea@gmail.com> (raw)
In-Reply-To: <20261204153452.17096-1-parri.andrea@gmail.com>
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
next prev parent reply other threads:[~2026-12-04 15:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20261204153452.17096-3-parri.andrea@gmail.com \
--to=parri.andrea@gmail.com \
--cc=bpf@vger.kernel.org \
--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