Skip to content

Commit

Permalink
tracing: WARN on rcuidle
Browse files Browse the repository at this point in the history
ARCH_WANTS_NO_INSTR (a superset of CONFIG_GENERIC_ENTRY) disallows any
and all tracing when RCU isn't enabled.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Tested-by: Tony Lindgren <[email protected]>
Tested-by: Ulf Hansson <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Acked-by: Frederic Weisbecker <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Jan 13, 2023
1 parent dc73056 commit 408b961
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions include/linux/tracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
#define __DO_TRACE_CALL(name, args) __traceiter_##name(NULL, args)
#endif /* CONFIG_HAVE_STATIC_CALL */

/*
* ARCH_WANTS_NO_INSTR archs are expected to have sanitized entry and idle
* code that disallow any/all tracing/instrumentation when RCU isn't watching.
*/
#ifdef CONFIG_ARCH_WANTS_NO_INSTR
#define RCUIDLE_COND(rcuidle) (rcuidle)
#else
/* srcu can't be used from NMI */
#define RCUIDLE_COND(rcuidle) (rcuidle && in_nmi())
#endif

/*
* it_func[0] is never NULL because there is at least one element in the array
* when the array itself is non NULL.
Expand All @@ -188,8 +199,8 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
if (!(cond)) \
return; \
\
/* srcu can't be used from NMI */ \
WARN_ON_ONCE(rcuidle && in_nmi()); \
if (WARN_ON_ONCE(RCUIDLE_COND(rcuidle))) \
return; \
\
/* keep srcu and sched-rcu usage consistent */ \
preempt_disable_notrace(); \
Expand Down
3 changes: 3 additions & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,9 @@ void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,
return;
}

if (WARN_ON_ONCE(IS_ENABLED(CONFIG_GENERIC_ENTRY)))
return;

/*
* When an NMI triggers, RCU is enabled via ct_nmi_enter(),
* but if the above rcu_is_watching() failed, then the NMI
Expand Down

0 comments on commit 408b961

Please sign in to comment.