All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracepoint: add lockdep rcu_is_watching() check to trace_call__##name()
@ 2026-04-30  5:35 David Carlier
  2026-04-30 13:35 ` Steven Rostedt
  2026-04-30 14:41 ` [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled() David Carlier
  0 siblings, 2 replies; 5+ messages in thread
From: David Carlier @ 2026-04-30  5:35 UTC (permalink / raw)
  To: linux-trace-kernel
  Cc: linux-kernel, David Carlier, Vineeth Pillai (Google),
	Mathieu Desnoyers, Masami Hiramatsu, Peter Zijlstra,
	Steven Rostedt

trace_call__##name() was added by commit 677a3d82b640 ("tracepoint: Add
trace_call__##name() API") to let callers that already gate on
trace_##name##_enabled() skip the redundant static_branch_unlikely()
re-evaluation. The changelog states that the new helper retains the
LOCKDEP RCU-watching assertion carried by trace_##name(), but the
WARN_ONCE() was omitted from both definitions.

Without it, sites converted from trace_foo(args) to trace_call__foo(args)
lose the WARN_ONCE(!rcu_is_watching()) coverage under CONFIG_LOCKDEP when
the tracepoint is enabled - the case that commit c2679254b9c9 ("tracing:
Make tracepoint lockdep check actually test something") added the warning
for.

Mirror the same block in both trace_call__##name() bodies, gated by
(cond) in __DECLARE_TRACE to match its trace_##name() and ungated in
__DECLARE_TRACE_SYSCALL.

Fixes: 677a3d82b640 ("tracepoint: Add trace_call__##name() API")
Cc: Vineeth Pillai (Google) <vineeth@bitbyteword.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 include/linux/tracepoint.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index 578e520b6ee6..048e0035d4fa 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -318,6 +318,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 	static inline void trace_call__##name(proto)			\
 	{								\
 		__do_trace_##name(args);				\
+		if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) {		\
+			WARN_ONCE(!rcu_is_watching(),			\
+				  "RCU not watching for tracepoint");	\
+		}							\
 	}
 
 #define __DECLARE_TRACE_SYSCALL(name, proto, args, data_proto)		\
@@ -342,6 +346,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 	{								\
 		might_fault();						\
 		__do_trace_##name(args);				\
+		if (IS_ENABLED(CONFIG_LOCKDEP)) {			\
+			WARN_ONCE(!rcu_is_watching(),			\
+				  "RCU not watching for tracepoint");	\
+		}							\
 	}
 
 /*
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tracepoint: add lockdep rcu_is_watching() check to trace_call__##name()
  2026-04-30  5:35 [PATCH] tracepoint: add lockdep rcu_is_watching() check to trace_call__##name() David Carlier
@ 2026-04-30 13:35 ` Steven Rostedt
  2026-04-30 14:41 ` [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled() David Carlier
  1 sibling, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2026-04-30 13:35 UTC (permalink / raw)
  To: David Carlier
  Cc: linux-trace-kernel, linux-kernel, Vineeth Pillai (Google),
	Mathieu Desnoyers, Masami Hiramatsu, Peter Zijlstra

On Thu, 30 Apr 2026 06:35:10 +0100
David Carlier <devnexen@gmail.com> wrote:

> Without it, sites converted from trace_foo(args) to trace_call__foo(args)
> lose the WARN_ONCE(!rcu_is_watching()) coverage under CONFIG_LOCKDEP when
> the tracepoint is enabled - the case that commit c2679254b9c9 ("tracing:
> Make tracepoint lockdep check actually test something") added the warning
> for.
> 
> Mirror the same block in both trace_call__##name() bodies, gated by
> (cond) in __DECLARE_TRACE to match its trace_##name() and ungated in
> __DECLARE_TRACE_SYSCALL.

If it gets called without rcu watching, the rcu dereference in
__DO_TRACE_CALL() will trigger.

No need to add the warning here. The reason the trace_foo() had it, was to
trigger when the tracepoint WASN'T enabled.

Now, perhaps where the warning should go, is in the trace_foo_enabled()
code.

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled()
  2026-04-30  5:35 [PATCH] tracepoint: add lockdep rcu_is_watching() check to trace_call__##name() David Carlier
  2026-04-30 13:35 ` Steven Rostedt
@ 2026-04-30 14:41 ` David Carlier
  2026-04-30 20:01   ` Steven Rostedt
  2026-05-20 19:55   ` Steven Rostedt
  1 sibling, 2 replies; 5+ messages in thread
From: David Carlier @ 2026-04-30 14:41 UTC (permalink / raw)
  To: linux-trace-kernel
  Cc: linux-kernel, rostedt, mhiramat, mathieu.desnoyers, peterz,
	vineeth, David Carlier

trace_call__##name() was added by commit 677a3d82b640 ("tracepoint: Add
trace_call__##name() API") for callers that already gate on
trace_##name##_enabled(), letting them skip the redundant
static_branch_unlikely() re-evaluation. The LOCKDEP rcu_is_watching()
WARN_ONCE() that trace_##name() carries on the disabled path was not
mirrored, so the cold-path coverage added by commit c2679254b9c9
("tracing: Make tracepoint lockdep check actually test something") is
lost for trace_call__##name() callers when the tracepoint is disabled.

When the tracepoint is enabled, the rcu_dereference inside
__DO_TRACE_CALL() already trips under PROVE_RCU, so the warning is
only needed on the !enabled path. The natural place is the gate that
trace_call__##name() callers consult: trace_##name##_enabled().

Fixes: 677a3d82b640 ("tracepoint: Add trace_call__##name() API")
Cc: Vineeth Pillai (Google) <vineeth@bitbyteword.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 include/linux/tracepoint.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index 578e520b6ee6..3b3ab19c2627 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -293,6 +293,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 	static inline bool						\
 	trace_##name##_enabled(void)					\
 	{								\
+		if (IS_ENABLED(CONFIG_LOCKDEP)) {			\
+			WARN_ONCE(!rcu_is_watching(),			\
+				  "RCU not watching for tracepoint");	\
+		}							\
 		return static_branch_unlikely(&__tracepoint_##name.key);\
 	}
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled()
  2026-04-30 14:41 ` [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled() David Carlier
@ 2026-04-30 20:01   ` Steven Rostedt
  2026-05-20 19:55   ` Steven Rostedt
  1 sibling, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2026-04-30 20:01 UTC (permalink / raw)
  To: David Carlier
  Cc: linux-trace-kernel, linux-kernel, mhiramat, mathieu.desnoyers,
	peterz, vineeth

On Thu, 30 Apr 2026 15:41:59 +0100
David Carlier <devnexen@gmail.com> wrote:

> trace_call__##name() was added by commit 677a3d82b640 ("tracepoint: Add
> trace_call__##name() API") for callers that already gate on
> trace_##name##_enabled(), letting them skip the redundant
> static_branch_unlikely() re-evaluation. The LOCKDEP rcu_is_watching()
> WARN_ONCE() that trace_##name() carries on the disabled path was not
> mirrored, so the cold-path coverage added by commit c2679254b9c9
> ("tracing: Make tracepoint lockdep check actually test something") is
> lost for trace_call__##name() callers when the tracepoint is disabled.
> 
> When the tracepoint is enabled, the rcu_dereference inside
> __DO_TRACE_CALL() already trips under PROVE_RCU, so the warning is
> only needed on the !enabled path. The natural place is the gate that
> trace_call__##name() callers consult: trace_##name##_enabled().
> 
> Fixes: 677a3d82b640 ("tracepoint: Add trace_call__##name() API")

Thanks, but I'm 86'ing the Fixes tag. The above commit has absolutely
nothing to do with this patch. This issue was there from the beginning of
having the trace_*_enabled() macro. This isn't a fix.

I'll modify the change log to be more accurate as well.

-- Steve


> Cc: Vineeth Pillai (Google) <vineeth@bitbyteword.org>
> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---
>  include/linux/tracepoint.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
> index 578e520b6ee6..3b3ab19c2627 100644
> --- a/include/linux/tracepoint.h
> +++ b/include/linux/tracepoint.h
> @@ -293,6 +293,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
>  	static inline bool						\
>  	trace_##name##_enabled(void)					\
>  	{								\
> +		if (IS_ENABLED(CONFIG_LOCKDEP)) {			\
> +			WARN_ONCE(!rcu_is_watching(),			\
> +				  "RCU not watching for tracepoint");	\
> +		}							\
>  		return static_branch_unlikely(&__tracepoint_##name.key);\
>  	}
>  


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled()
  2026-04-30 14:41 ` [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled() David Carlier
  2026-04-30 20:01   ` Steven Rostedt
@ 2026-05-20 19:55   ` Steven Rostedt
  1 sibling, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2026-05-20 19:55 UTC (permalink / raw)
  To: David Carlier
  Cc: linux-trace-kernel, linux-kernel, mhiramat, mathieu.desnoyers,
	peterz, vineeth, sashiko-bot, sashiko-reviews


[ Replying to Sashiko ]

> commit 7596bdcd9abf9a26b3964f10b5d5de3249e731e9
> Author: David Carlier <devnexen@gmail.com>
> tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled()
> This commit attempts to restore RCU lockdep coverage for trace_call__##name()
> callers by adding a warning directly to the trace_##name##_enabled() static
> branch check.
> > When the tracepoint is enabled, the rcu_dereference inside
> > __DO_TRACE_CALL() already trips under PROVE_RCU, so the warning is
> > only needed on the !enabled path.
> Is this description accurate regarding __DO_TRACE_CALL()?
> Looking at the implementation, it uses rcu_dereference_raw() which
> intentionally bypasses lockdep checking. This means trace_call__##name()
> lacks lockdep coverage on both the enabled and disabled paths.
> > diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
> > --- a/include/linux/tracepoint.h
> > +++ b/include/linux/tracepoint.h
> > @@ -293,6 +293,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
> >  	static inline bool						\
> >  	trace_##name##_enabled(void)					\
> >  	{								\
> > +		if (IS_ENABLED(CONFIG_LOCKDEP)) {			\
> > +			WARN_ONCE(!rcu_is_watching(),			\
> > +				  "RCU not watching for tracepoint");	\
> > +		}							\
> >  		return static_branch_unlikely(&__tracepoint_##name.key);\
> >  	}

> Does this unconditional check cause spurious lockdep splats?
> Unlike the original trace_##name() macro, trace_##name##_enabled() takes no
> arguments and cannot evaluate the tracepoint's condition, such as
> cpu_online(raw_smp_processor_id()). If a subsystem queries
> trace_##name##_enabled() on an offline CPU where RCU is not watching, won't
> this trigger a false positive warning, even if the tracepoint itself would
> have been safely skipped by its condition?

If the CPU is offline, you shouldn't be using trace_##name##_enabled() to
begin with.


> Furthermore, is it already safe to query a static branch outside of an RCU
> watch window? Subsystems sometimes use this boolean query in RCU-idle
> contexts simply to skip data gathering without ever intending to execute
> the tracepoint.

The entire point of this patch is to make sure lockdep *always* checks that
"RCU is watching" at every trace_##name##_enabled() location regardless if
the tracepoint is active or not. It's not about the static branch, but the
tracepoint that is hidden behind it.


> Would it be more reliable to add the WARN_ONCE check, guarded by its cond
> parameter, directly to trace_call__##name() to appropriately mirror how
> trace_##name() behaves?

Hmm, if this does become an issue, that may be worth doing. But currently,
I do not believe the enabled() code is used by anything with conditional
tracepoints.

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-20 19:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30  5:35 [PATCH] tracepoint: add lockdep rcu_is_watching() check to trace_call__##name() David Carlier
2026-04-30 13:35 ` Steven Rostedt
2026-04-30 14:41 ` [PATCH v2] tracepoint: add lockdep rcu_is_watching() check to trace_##name##_enabled() David Carlier
2026-04-30 20:01   ` Steven Rostedt
2026-05-20 19:55   ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.