Re: [PATCH] tracing: Keep preemption disabled until the recursion bit is cleared
From: Steven Rostedt
Date: Tue Nov 24 2026 - 11:14:38 EST
On Fri, 13 Nov 2026 02:13:33 +0100
Karl Mehltretter <kmehltretter@xxxxxxxxx> wrote:
> diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h
> index e6ca052b2a85a..a7c66313bf360 100644
> --- a/include/linux/trace_recursion.h
> +++ b/include/linux/trace_recursion.h
> @@ -132,6 +132,8 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
> if (trace_warn_on_no_rcu(ip))
> return -1;
>
> + preempt_disable_notrace();
> +
> bit = trace_get_context_bit() + start;
> if (unlikely(val & (1 << bit))) {
> /*
> @@ -145,6 +147,7 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
> bit = TRACE_CTX_TRANSITION + start;
> if (val & (1 << bit)) {
> do_ftrace_record_recursion(ip, pip);
> + preempt_enable_notrace();
> return -1;
Honestly, the reason I did it this way was because if for some reason
something in preempt_disable_notrace() was traced, this would catch it.
I guess we could change it to do it this way, but if something were to be
traced in preempt_disable_notrace() it would triple fault and reboot the
machine with no warning. :-/
-- Steve
> }
> }
> @@ -153,8 +156,6 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
> current->trace_recursion = val;
> barrier();
>
> - preempt_disable_notrace();
> -
> return bit;
> }
>
> @@ -163,9 +164,9 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
> */
> static __always_inline void trace_clear_recursion(int bit)
> {
> - preempt_enable_notrace();
> barrier();
> trace_recursion_clear(bit);
> + preempt_enable_notrace();
> }
>
> /**
> base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb