Skip to content

Commit 2ca8c11

Browse files
mhiramatrostedt
authored andcommitted
fgraph: Pass ftrace_regs to retfunc
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. Cc: Alexei Starovoitov <[email protected]> Cc: Florent Revest <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: bpf <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Alan Maguire <[email protected]> Cc: Mark Rutland <[email protected]> Link: https://lore.kernel.org/173518992972.391279.14055405490327765506.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent a3ed415 commit 2ca8c11

File tree

8 files changed

+27
-14
lines changed

8 files changed

+27
-14
lines changed

include/linux/ftrace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,8 @@ struct fgraph_ops;
10751075

10761076
/* Type of the callback handlers for tracing function graph*/
10771077
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *,
1078-
struct fgraph_ops *); /* return */
1078+
struct fgraph_ops *,
1079+
struct ftrace_regs *); /* return */
10791080
typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *,
10801081
struct fgraph_ops *,
10811082
struct ftrace_regs *); /* entry */

kernel/trace/fgraph.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops,
299299
}
300300

301301
/* ftrace_graph_return set to this to tell some archs to run function graph */
302-
static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops)
302+
static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops,
303+
struct ftrace_regs *fregs)
303304
{
304305
}
305306

@@ -528,7 +529,8 @@ int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace,
528529
}
529530

530531
static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace,
531-
struct fgraph_ops *gops)
532+
struct fgraph_ops *gops,
533+
struct ftrace_regs *fregs)
532534
{
533535
}
534536

@@ -825,6 +827,9 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
825827
}
826828

827829
trace.rettime = trace_clock_local();
830+
if (fregs)
831+
ftrace_regs_set_instruction_pointer(fregs, ret);
832+
828833
#ifdef CONFIG_FUNCTION_GRAPH_RETVAL
829834
trace.retval = ftrace_regs_get_return_value(fregs);
830835
#endif
@@ -834,7 +839,7 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
834839
#ifdef CONFIG_HAVE_STATIC_CALL
835840
if (static_branch_likely(&fgraph_do_direct)) {
836841
if (test_bit(fgraph_direct_gops->idx, &bitmap))
837-
static_call(fgraph_retfunc)(&trace, fgraph_direct_gops);
842+
static_call(fgraph_retfunc)(&trace, fgraph_direct_gops, fregs);
838843
} else
839844
#endif
840845
{
@@ -844,7 +849,7 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
844849
if (gops == &fgraph_stub)
845850
continue;
846851

847-
gops->retfunc(&trace, gops);
852+
gops->retfunc(&trace, gops, fregs);
848853
}
849854
}
850855

@@ -1016,7 +1021,8 @@ void ftrace_graph_sleep_time_control(bool enable)
10161021
* Simply points to ftrace_stub, but with the proper protocol.
10171022
* Defined by the linker script in linux/vmlinux.lds.h
10181023
*/
1019-
void ftrace_stub_graph(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
1024+
void ftrace_stub_graph(struct ftrace_graph_ret *trace, struct fgraph_ops *gops,
1025+
struct ftrace_regs *fregs);
10201026

10211027
/* The callbacks that hook a function */
10221028
trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph;

kernel/trace/ftrace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ static int profile_graph_entry(struct ftrace_graph_ent *trace,
842842
}
843843

844844
static void profile_graph_return(struct ftrace_graph_ret *trace,
845-
struct fgraph_ops *gops)
845+
struct fgraph_ops *gops,
846+
struct ftrace_regs *fregs)
846847
{
847848
struct profile_fgraph_data *profile_data;
848849
struct ftrace_profile_stat *stat;

kernel/trace/trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ void trace_latency_header(struct seq_file *m);
693693
void trace_default_header(struct seq_file *m);
694694
void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
695695

696-
void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
696+
void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops,
697+
struct ftrace_regs *fregs);
697698
int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
698699
struct ftrace_regs *fregs);
699700

kernel/trace/trace_functions_graph.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void handle_nosleeptime(struct ftrace_graph_ret *trace,
310310
}
311311

312312
void trace_graph_return(struct ftrace_graph_ret *trace,
313-
struct fgraph_ops *gops)
313+
struct fgraph_ops *gops, struct ftrace_regs *fregs)
314314
{
315315
unsigned long *task_var = fgraph_get_task_var(gops);
316316
struct trace_array *tr = gops->private;
@@ -348,7 +348,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace,
348348
}
349349

350350
static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
351-
struct fgraph_ops *gops)
351+
struct fgraph_ops *gops,
352+
struct ftrace_regs *fregs)
352353
{
353354
struct fgraph_times *ftimes;
354355
int size;
@@ -372,7 +373,7 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
372373
(trace->rettime - ftimes->calltime < tracing_thresh))
373374
return;
374375
else
375-
trace_graph_return(trace, gops);
376+
trace_graph_return(trace, gops, fregs);
376377
}
377378

378379
static struct fgraph_ops funcgraph_ops = {

kernel/trace/trace_irqsoff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent *trace,
208208
}
209209

210210
static void irqsoff_graph_return(struct ftrace_graph_ret *trace,
211-
struct fgraph_ops *gops)
211+
struct fgraph_ops *gops,
212+
struct ftrace_regs *fregs)
212213
{
213214
struct trace_array *tr = irqsoff_trace;
214215
struct trace_array_cpu *data;

kernel/trace/trace_sched_wakeup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *trace,
144144
}
145145

146146
static void wakeup_graph_return(struct ftrace_graph_ret *trace,
147-
struct fgraph_ops *gops)
147+
struct fgraph_ops *gops,
148+
struct ftrace_regs *fregs)
148149
{
149150
struct trace_array *tr = wakeup_trace;
150151
struct trace_array_cpu *data;

kernel/trace/trace_selftest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ static __init int store_entry(struct ftrace_graph_ent *trace,
808808
}
809809

810810
static __init void store_return(struct ftrace_graph_ret *trace,
811-
struct fgraph_ops *gops)
811+
struct fgraph_ops *gops,
812+
struct ftrace_regs *fregs)
812813
{
813814
struct fgraph_fixture *fixture = container_of(gops, struct fgraph_fixture, gops);
814815
const char *type = fixture->store_type_name;

0 commit comments

Comments
 (0)