Skip to content

Commit a1e2e31

Browse files
Steven Rostedtrostedt
authored andcommitted
ftrace: Return pt_regs to function trace callback
Return as the 4th paramater to the function tracer callback the pt_regs. Later patches that implement regs passing for the architectures will require having the ftrace_ops set the SAVE_REGS flag, which will tell the arch to take the time to pass a full set of pt_regs to the ftrace_ops callback function. If the arch does not support it then it should pass NULL. If an arch can pass full regs, then it should define: ARCH_SUPPORTS_FTRACE_SAVE_REGS to 1 Link: http://lkml.kernel.org/r/20120702201821.019966811@goodmis.org Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent ccf3672 commit a1e2e31

9 files changed

Lines changed: 47 additions & 30 deletions

File tree

include/linux/ftrace.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/kallsyms.h>
1111
#include <linux/linkage.h>
1212
#include <linux/bitops.h>
13+
#include <linux/ptrace.h>
1314
#include <linux/ktime.h>
1415
#include <linux/sched.h>
1516
#include <linux/types.h>
@@ -54,7 +55,7 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
5455
struct ftrace_ops;
5556

5657
typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
57-
struct ftrace_ops *op);
58+
struct ftrace_ops *op, struct pt_regs *regs);
5859

5960
/*
6061
* FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
@@ -188,7 +189,8 @@ static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
188189
return *this_cpu_ptr(ops->disabled);
189190
}
190191

191-
extern void ftrace_stub(unsigned long a0, unsigned long a1, struct ftrace_ops *op);
192+
extern void ftrace_stub(unsigned long a0, unsigned long a1,
193+
struct ftrace_ops *op, struct pt_regs *regs);
192194

193195
#else /* !CONFIG_FUNCTION_TRACER */
194196
/*

kernel/trace/ftrace.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static struct ftrace_ops control_ops;
103103

104104
#if ARCH_SUPPORTS_FTRACE_OPS
105105
static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
106-
struct ftrace_ops *op);
106+
struct ftrace_ops *op, struct pt_regs *regs);
107107
#else
108108
/* See comment below, where ftrace_ops_list_func is defined */
109109
static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip);
@@ -121,27 +121,27 @@ static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip);
121121
*/
122122
static void
123123
ftrace_global_list_func(unsigned long ip, unsigned long parent_ip,
124-
struct ftrace_ops *op)
124+
struct ftrace_ops *op, struct pt_regs *regs)
125125
{
126126
if (unlikely(trace_recursion_test(TRACE_GLOBAL_BIT)))
127127
return;
128128

129129
trace_recursion_set(TRACE_GLOBAL_BIT);
130130
op = rcu_dereference_raw(ftrace_global_list); /*see above*/
131131
while (op != &ftrace_list_end) {
132-
op->func(ip, parent_ip, op);
132+
op->func(ip, parent_ip, op, regs);
133133
op = rcu_dereference_raw(op->next); /*see above*/
134134
};
135135
trace_recursion_clear(TRACE_GLOBAL_BIT);
136136
}
137137

138138
static void ftrace_pid_func(unsigned long ip, unsigned long parent_ip,
139-
struct ftrace_ops *op)
139+
struct ftrace_ops *op, struct pt_regs *regs)
140140
{
141141
if (!test_tsk_trace_trace(current))
142142
return;
143143

144-
ftrace_pid_function(ip, parent_ip, op);
144+
ftrace_pid_function(ip, parent_ip, op, regs);
145145
}
146146

147147
static void set_ftrace_pid_function(ftrace_func_t func)
@@ -763,7 +763,7 @@ ftrace_profile_alloc(struct ftrace_profile_stat *stat, unsigned long ip)
763763

764764
static void
765765
function_profile_call(unsigned long ip, unsigned long parent_ip,
766-
struct ftrace_ops *ops)
766+
struct ftrace_ops *ops, struct pt_regs *regs)
767767
{
768768
struct ftrace_profile_stat *stat;
769769
struct ftrace_profile *rec;
@@ -793,7 +793,7 @@ function_profile_call(unsigned long ip, unsigned long parent_ip,
793793
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
794794
static int profile_graph_entry(struct ftrace_graph_ent *trace)
795795
{
796-
function_profile_call(trace->func, 0, NULL);
796+
function_profile_call(trace->func, 0, NULL, NULL);
797797
return 1;
798798
}
799799

@@ -2771,7 +2771,7 @@ static int __init ftrace_mod_cmd_init(void)
27712771
device_initcall(ftrace_mod_cmd_init);
27722772

27732773
static void function_trace_probe_call(unsigned long ip, unsigned long parent_ip,
2774-
struct ftrace_ops *op)
2774+
struct ftrace_ops *op, struct pt_regs *pt_regs)
27752775
{
27762776
struct ftrace_func_probe *entry;
27772777
struct hlist_head *hhd;
@@ -3923,7 +3923,7 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip)
39233923

39243924
static void
39253925
ftrace_ops_control_func(unsigned long ip, unsigned long parent_ip,
3926-
struct ftrace_ops *op)
3926+
struct ftrace_ops *op, struct pt_regs *regs)
39273927
{
39283928
if (unlikely(trace_recursion_test(TRACE_CONTROL_BIT)))
39293929
return;
@@ -3938,7 +3938,7 @@ ftrace_ops_control_func(unsigned long ip, unsigned long parent_ip,
39383938
while (op != &ftrace_list_end) {
39393939
if (!ftrace_function_local_disabled(op) &&
39403940
ftrace_ops_test(op, ip))
3941-
op->func(ip, parent_ip, op);
3941+
op->func(ip, parent_ip, op, regs);
39423942

39433943
op = rcu_dereference_raw(op->next);
39443944
};
@@ -3952,7 +3952,7 @@ static struct ftrace_ops control_ops = {
39523952

39533953
static inline void
39543954
__ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
3955-
struct ftrace_ops *ignored)
3955+
struct ftrace_ops *ignored, struct pt_regs *regs)
39563956
{
39573957
struct ftrace_ops *op;
39583958

@@ -3971,7 +3971,7 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
39713971
op = rcu_dereference_raw(ftrace_ops_list);
39723972
while (op != &ftrace_list_end) {
39733973
if (ftrace_ops_test(op, ip))
3974-
op->func(ip, parent_ip, op);
3974+
op->func(ip, parent_ip, op, regs);
39753975
op = rcu_dereference_raw(op->next);
39763976
};
39773977
preempt_enable_notrace();
@@ -3983,17 +3983,24 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
39833983
* the list function ignores the op parameter, we do not want any
39843984
* C side effects, where a function is called without the caller
39853985
* sending a third parameter.
3986+
* Archs are to support both the regs and ftrace_ops at the same time.
3987+
* If they support ftrace_ops, it is assumed they support regs.
3988+
* If call backs want to use regs, they must either check for regs
3989+
* being NULL, or ARCH_SUPPORTS_FTRACE_SAVE_REGS.
3990+
* Note, ARCH_SUPPORT_SAVE_REGS expects a full regs to be saved.
3991+
* An architecture can pass partial regs with ftrace_ops and still
3992+
* set the ARCH_SUPPORT_FTARCE_OPS.
39863993
*/
39873994
#if ARCH_SUPPORTS_FTRACE_OPS
39883995
static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
3989-
struct ftrace_ops *op)
3996+
struct ftrace_ops *op, struct pt_regs *regs)
39903997
{
3991-
__ftrace_ops_list_func(ip, parent_ip, NULL);
3998+
__ftrace_ops_list_func(ip, parent_ip, NULL, regs);
39923999
}
39934000
#else
39944001
static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip)
39954002
{
3996-
__ftrace_ops_list_func(ip, parent_ip, NULL);
4003+
__ftrace_ops_list_func(ip, parent_ip, NULL, NULL);
39974004
}
39984005
#endif
39994006

kernel/trace/trace_event_perf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(perf_trace_buf_prepare);
259259
#ifdef CONFIG_FUNCTION_TRACER
260260
static void
261261
perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
262-
struct ftrace_ops *ops)
262+
struct ftrace_ops *ops, struct pt_regs *pt_regs)
263263
{
264264
struct ftrace_entry *entry;
265265
struct hlist_head *head;

kernel/trace/trace_events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
16821682

16831683
static void
16841684
function_test_events_call(unsigned long ip, unsigned long parent_ip,
1685-
struct ftrace_ops *op)
1685+
struct ftrace_ops *op, struct pt_regs *pt_regs)
16861686
{
16871687
struct ring_buffer_event *event;
16881688
struct ring_buffer *buffer;

kernel/trace/trace_functions.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void function_trace_start(struct trace_array *tr)
4949

5050
static void
5151
function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip,
52-
struct ftrace_ops *op)
52+
struct ftrace_ops *op, struct pt_regs *pt_regs)
5353
{
5454
struct trace_array *tr = func_trace;
5555
struct trace_array_cpu *data;
@@ -77,7 +77,8 @@ function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip,
7777

7878
static void
7979
function_trace_call(unsigned long ip, unsigned long parent_ip,
80-
struct ftrace_ops *op)
80+
struct ftrace_ops *op, struct pt_regs *pt_regs)
81+
8182
{
8283
struct trace_array *tr = func_trace;
8384
struct trace_array_cpu *data;
@@ -109,7 +110,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
109110

110111
static void
111112
function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
112-
struct ftrace_ops *op)
113+
struct ftrace_ops *op, struct pt_regs *pt_regs)
113114
{
114115
struct trace_array *tr = func_trace;
115116
struct trace_array_cpu *data;

kernel/trace/trace_irqsoff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int func_prolog_dec(struct trace_array *tr,
137137
*/
138138
static void
139139
irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
140-
struct ftrace_ops *op)
140+
struct ftrace_ops *op, struct pt_regs *pt_regs)
141141
{
142142
struct trace_array *tr = irqsoff_trace;
143143
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
@@ -108,7 +108,8 @@ func_prolog_preempt_disable(struct trace_array *tr,
108108
* wakeup uses its own tracer function to keep the overhead down:
109109
*/
110110
static void
111-
wakeup_tracer_call(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op)
111+
wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,
112+
struct ftrace_ops *op, struct pt_regs *pt_regs)
112113
{
113114
struct trace_array *tr = wakeup_trace;
114115
struct trace_array_cpu *data;

kernel/trace/trace_selftest.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,44 @@ static inline void warn_failed_init_tracer(struct tracer *trace, int init_ret)
104104
static int trace_selftest_test_probe1_cnt;
105105
static void trace_selftest_test_probe1_func(unsigned long ip,
106106
unsigned long pip,
107-
struct ftrace_ops *op)
107+
struct ftrace_ops *op,
108+
struct pt_regs *pt_regs)
108109
{
109110
trace_selftest_test_probe1_cnt++;
110111
}
111112

112113
static int trace_selftest_test_probe2_cnt;
113114
static void trace_selftest_test_probe2_func(unsigned long ip,
114115
unsigned long pip,
115-
struct ftrace_ops *op)
116+
struct ftrace_ops *op,
117+
struct pt_regs *pt_regs)
116118
{
117119
trace_selftest_test_probe2_cnt++;
118120
}
119121

120122
static int trace_selftest_test_probe3_cnt;
121123
static void trace_selftest_test_probe3_func(unsigned long ip,
122124
unsigned long pip,
123-
struct ftrace_ops *op)
125+
struct ftrace_ops *op,
126+
struct pt_regs *pt_regs)
124127
{
125128
trace_selftest_test_probe3_cnt++;
126129
}
127130

128131
static int trace_selftest_test_global_cnt;
129132
static void trace_selftest_test_global_func(unsigned long ip,
130133
unsigned long pip,
131-
struct ftrace_ops *op)
134+
struct ftrace_ops *op,
135+
struct pt_regs *pt_regs)
132136
{
133137
trace_selftest_test_global_cnt++;
134138
}
135139

136140
static int trace_selftest_test_dyn_cnt;
137141
static void trace_selftest_test_dyn_func(unsigned long ip,
138142
unsigned long pip,
139-
struct ftrace_ops *op)
143+
struct ftrace_ops *op,
144+
struct pt_regs *pt_regs)
140145
{
141146
trace_selftest_test_dyn_cnt++;
142147
}

kernel/trace/trace_stack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ static inline void check_stack(void)
111111
}
112112

113113
static void
114-
stack_trace_call(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op)
114+
stack_trace_call(unsigned long ip, unsigned long parent_ip,
115+
struct ftrace_ops *op, struct pt_regs *pt_regs)
115116
{
116117
int cpu;
117118

0 commit comments

Comments
 (0)