Re: [PATCH] tracing: Keep preemption disabled until the recursion bit is cleared

From: Steven Rostedt

Date: Mon Nov 30 2026 - 11:31:24 EST


On Sun, 29 Nov 2026 23:34:57 +0100
Karl Mehltretter <kmehltretter@xxxxxxxxx> wrote:

> Would you rather drop the patch, or go with one of these?
>
> 1. Send the partial fix above as v2 (keeps your check, fixes >99%,
> leaves the two short interrupt windows).
> 2. Reorder as in my patch using small noinstr helpers for the count
> updates (closes both windows, objtool checks noinstr on x86, loses
> the runtime check, adds a helper call).

Why are disabling preemption before the checks anyway. It's not the checks
that are causing the issue, it's the setting of the bits themselves.

Why not this patch which disables preemption *before* setting the bits,
which should give you the same results?

-- Steve

diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h
index e6ca052b2a85..95c3a066dab7 100644
--- a/include/linux/trace_recursion.h
+++ b/include/linux/trace_recursion.h
@@ -149,12 +149,12 @@ static __always_inline int trace_test_and_set_recursion(unsigned long ip, unsign
}
}

+ preempt_disable_notrace();
+
val |= 1 << bit;
current->trace_recursion = val;
barrier();

- preempt_disable_notrace();
-
return bit;
}

@@ -163,9 +163,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();
}

/**