Re: [PATCH v14 05/19] function_graph: Pass ftrace_regs to retfunc

Will Deacon
2024-09-17T10:08:54Z

On Sun, Sep 15, 2024 at 04:49:20AM -0400, Steven Rostedt wrote:
> On Fri, 13 Sep 2024 00:09:02 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> >
> > Pass ftrace_regs to the fgraph_ops::retfunc(). If ftrace_regs is not
> > available, it passes a NULL instead. User callback function can access
> > some registers (including return address) via this ftrace_regs.
> >
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > ---
> > Changes in v8:
> > - Pass ftrace_regs to retfunc, instead of adding retregfunc.
> > Changes in v6:
> > - update to use ftrace_regs_get_return_value() because of reordering
> > patches.
> > Changes in v3:
> > - Update for new multiple fgraph.
> > - Save the return address to instruction pointer in ftrace_regs.
> > ---
> > include/linux/ftrace.h | 3 ++-
> > kernel/trace/fgraph.c | 16 +++++++++++-----
> > kernel/trace/ftrace.c | 3 ++-
> > kernel/trace/trace.h | 3 ++-
> > kernel/trace/trace_functions_graph.c | 7 ++++---
> > kernel/trace/trace_irqsoff.c | 3 ++-
> > kernel/trace/trace_sched_wakeup.c | 3 ++-
> > kernel/trace/trace_selftest.c | 3 ++-
> > 8 files changed, 27 insertions(+), 14 deletions(-)
> >
> > diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
> > index 13987cd63553..e7c41d9988e1 100644
> > --- a/include/linux/ftrace.h
> > +++ b/include/linux/ftrace.h
> > @@ -1069,7 +1069,8 @@ struct fgraph_ops;
> >
> > /* Type of the callback handlers for tracing function graph*/
> > typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *,
> > - struct fgraph_ops *); /* return */
> > + struct fgraph_ops *,
> > + struct ftrace_regs *); /* return */
> > typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *,
> > struct fgraph_ops *,
> > struct ftrace_regs *); /* entry */
> > diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> > index 30bebe43607d..6a3e2db16aa4 100644
> > --- a/kernel/trace/fgraph.c
> > +++ b/kernel/trace/fgraph.c
> > @@ -297,7 +297,8 @@ static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops,
> > }
> >
> > /* ftrace_graph_return set to this to tell some archs to run function graph */
> > -static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops)
> > +static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops,
> > + struct ftrace_regs *fregs)
> > {
> > }
> >
> > @@ -491,7 +492,8 @@ int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace,
> > }
> >
> > static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace,
> > - struct fgraph_ops *gops)
> > + struct fgraph_ops *gops,
> > + struct ftrace_regs *fregs)
> > {
> > }
> >
> > @@ -787,6 +789,9 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
> > }
> >
> > trace.rettime = trace_clock_local();
> > + if (fregs)
> > + ftrace_regs_set_instruction_pointer(fregs, ret);

Where does the instruction pointer get used after this? The arm64
'return_to_handler' function doesn't look at it when we return.

Will