From: Karl Mehltretter <kmehltretter@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>, Song Liu <song@kernel.org>,
linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing: Keep preemption disabled until the recursion bit is cleared
Date: Sun, 29 Nov 2026 23:34:57 +0100 [thread overview]
Message-ID: <awymd-hlDBuj_JRD@gmail.com> (raw)
In-Reply-To: <20261124111425.487a2ec8@gandalf.local.home>
On Tue, Nov 24, 2026 at 11:14:25AM +0100, Steven Rostedt wrote:
> > + 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. :-/
>
Good point, better keep this check.
Making the acquire preempt-count update call traced preempt_count_add()
confirms it: the current order catches it on x86 and arm64 (recorded in
recursed_functions), while my patch locks up both with no output and
triple-faults x86 without VMAP_STACK (under TCG, and in 1 of 12 KVM
runs, with gdb attached).
Over 99% of scheduler runs with the bit held on x86 come from
preempt_enable_notrace() in trace_clear_recursion() rescheduling before
trace_recursion_clear(). Moving only the reschedule keeps both count
updates under the bit:
static __always_inline void trace_clear_recursion(int bit)
{
barrier();
__preempt_count_dec();
barrier();
trace_recursion_clear(bit);
if (unlikely(should_resched(0)))
__preempt_schedule_notrace();
}
With traced count updates, this still catches the recursion on x86 and
arm64. Without them, rejected callbacks per boot on x86:
current this change my patch
TCG, function 6-58 0 0
TCG, function_graph 755-1463 0 0
KVM + KASAN, function 160-291 0-12 0
KVM + KASAN, function_graph 104-362 0-14 0
With KASAN, this change hit rejects in 1/10 boots per tracer. On arm64
KVM, all variants had 0 rejects in 23 boots each.
Two short windows remain where an interrupt can preempt with the bit
held (between setting the bit and preempt_disable_notrace(), and between
the decrement and clearing the bit). In the KASAN runs, those were the
only scheduler entries with the bit held.
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).
Thanks,
Karl
prev parent reply other threads:[~2026-11-29 22:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 1:13 Karl Mehltretter
2026-11-24 16:14 ` Steven Rostedt
2026-11-29 22:34 ` Karl Mehltretter [this message]
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=awymd-hlDBuj_JRD@gmail.com \
--to=kmehltretter@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
--cc=tglx@kernel.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
all inboxes | Powered by JetHome®