Re: [PATCH] tracing: fgraph: Protect return handler from recursion loop
From: Google
Date: Wed Sep 24 2025 - 18:58:52 EST
On Sun, 21 Sep 2025 18:52:03 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Sun, 21 Sep 2025 13:05:19 +0900
> Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> wrote:
>
> >
> > > The reason I would say not to have the warn on, is because we don't have a
> > > warn on for recursion happening at the entry handler. Because this now is
> > > exposed by fprobe allowing different routines to be called at exit than
> > > what is used in entry, it can easily be triggered.
> >
> > At the entry, if it detect recursion, it exits soon. But here we have to
> > process stack unwind to get the return address. This recursion_trylock()
> > is to mark this is in the critical section, not detect it.
>
> Ah, because the first instance of the exit callback sets the recursion
> bit. This will cause recursed entry calls to detect the recursion bit
> and return without setting the exit handler to be called.
>
> That is, by setting the recursion bit in the exit handler, it will cause
> a recursion in entry to fail before the exit is called again.
>
> I'd like to update the comment:
>
> + bit = ftrace_test_recursion_trylock(trace.func, ret);
> + /*
> + * This must be succeeded because the entry handler returns before
> + * modifying the return address if it is nested. Anyway, we need to
> + * avoid calling user callbacks if it is nested.
> + */
> + if (WARN_ON_ONCE(bit < 0))
> + goto out;
> +
>
> to:
>
> /*
> * Setting the recursion bit here will cause the graph entry to
> * detect recursion before the exit handle will. If the ext
> * handler detects recursion, something went wrong.
> */
> if (WARN_ON_ONCE(bit < 0))
OK, let me update it.
Thank you,
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>