6464
6565#define FL_GLOBAL_CONTROL_MASK (FTRACE_OPS_FL_GLOBAL | FTRACE_OPS_FL_CONTROL)
6666
67+ static struct ftrace_ops ftrace_list_end __read_mostly = {
68+ .func = ftrace_stub ,
69+ };
70+
6771/* ftrace_enabled is a method to turn ftrace on or off */
6872int ftrace_enabled __read_mostly ;
6973static int last_ftrace_enabled ;
7074
7175/* Quick disabling of function tracer. */
72- int function_trace_stop ;
76+ int function_trace_stop __read_mostly ;
77+
78+ /* Current function tracing op */
79+ struct ftrace_ops * function_trace_op __read_mostly = & ftrace_list_end ;
7380
7481/* List for set_ftrace_pid's pids. */
7582LIST_HEAD (ftrace_pids );
@@ -86,10 +93,6 @@ static int ftrace_disabled __read_mostly;
8693
8794static DEFINE_MUTEX (ftrace_lock );
8895
89- static struct ftrace_ops ftrace_list_end __read_mostly = {
90- .func = ftrace_stub ,
91- };
92-
9396static struct ftrace_ops * ftrace_global_list __read_mostly = & ftrace_list_end ;
9497static struct ftrace_ops * ftrace_control_list __read_mostly = & ftrace_list_end ;
9598static struct ftrace_ops * ftrace_ops_list __read_mostly = & ftrace_list_end ;
@@ -100,8 +103,14 @@ ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub;
100103static struct ftrace_ops global_ops ;
101104static struct ftrace_ops control_ops ;
102105
103- static void
104- ftrace_ops_list_func (unsigned long ip , unsigned long parent_ip );
106+ #if ARCH_SUPPORTS_FTRACE_OPS
107+ static void ftrace_ops_list_func (unsigned long ip , unsigned long parent_ip ,
108+ struct ftrace_ops * op );
109+ #else
110+ /* See comment below, where ftrace_ops_list_func is defined */
111+ static void ftrace_ops_no_ops (unsigned long ip , unsigned long parent_ip );
112+ #define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
113+ #endif
105114
106115/*
107116 * Traverse the ftrace_global_list, invoking all entries. The reason that we
@@ -112,29 +121,29 @@ ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip);
112121 *
113122 * Silly Alpha and silly pointer-speculation compiler optimizations!
114123 */
115- static void ftrace_global_list_func (unsigned long ip ,
116- unsigned long parent_ip )
124+ static void
125+ ftrace_global_list_func (unsigned long ip , unsigned long parent_ip ,
126+ struct ftrace_ops * op )
117127{
118- struct ftrace_ops * op ;
119-
120128 if (unlikely (trace_recursion_test (TRACE_GLOBAL_BIT )))
121129 return ;
122130
123131 trace_recursion_set (TRACE_GLOBAL_BIT );
124132 op = rcu_dereference_raw (ftrace_global_list ); /*see above*/
125133 while (op != & ftrace_list_end ) {
126- op -> func (ip , parent_ip );
134+ op -> func (ip , parent_ip , op );
127135 op = rcu_dereference_raw (op -> next ); /*see above*/
128136 };
129137 trace_recursion_clear (TRACE_GLOBAL_BIT );
130138}
131139
132- static void ftrace_pid_func (unsigned long ip , unsigned long parent_ip )
140+ static void ftrace_pid_func (unsigned long ip , unsigned long parent_ip ,
141+ struct ftrace_ops * op )
133142{
134143 if (!test_tsk_trace_trace (current ))
135144 return ;
136145
137- ftrace_pid_function (ip , parent_ip );
146+ ftrace_pid_function (ip , parent_ip , op );
138147}
139148
140149static void set_ftrace_pid_function (ftrace_func_t func )
@@ -163,12 +172,13 @@ void clear_ftrace_function(void)
163172 * For those archs that do not test ftrace_trace_stop in their
164173 * mcount call site, we need to do it from C.
165174 */
166- static void ftrace_test_stop_func (unsigned long ip , unsigned long parent_ip )
175+ static void ftrace_test_stop_func (unsigned long ip , unsigned long parent_ip ,
176+ struct ftrace_ops * op )
167177{
168178 if (function_trace_stop )
169179 return ;
170180
171- __ftrace_trace_function (ip , parent_ip );
181+ __ftrace_trace_function (ip , parent_ip , op );
172182}
173183#endif
174184
@@ -230,15 +240,24 @@ static void update_ftrace_function(void)
230240
231241 /*
232242 * If we are at the end of the list and this ops is
233- * not dynamic, then have the mcount trampoline call
234- * the function directly
243+ * not dynamic and the arch supports passing ops , then have the
244+ * mcount trampoline call the function directly.
235245 */
236246 if (ftrace_ops_list == & ftrace_list_end ||
237247 (ftrace_ops_list -> next == & ftrace_list_end &&
238- !(ftrace_ops_list -> flags & FTRACE_OPS_FL_DYNAMIC )))
248+ !(ftrace_ops_list -> flags & FTRACE_OPS_FL_DYNAMIC ) &&
249+ ARCH_SUPPORTS_FTRACE_OPS )) {
250+ /* Set the ftrace_ops that the arch callback uses */
251+ if (ftrace_ops_list == & global_ops )
252+ function_trace_op = ftrace_global_list ;
253+ else
254+ function_trace_op = ftrace_ops_list ;
239255 func = ftrace_ops_list -> func ;
240- else
256+ } else {
257+ /* Just use the default ftrace_ops */
258+ function_trace_op = & ftrace_list_end ;
241259 func = ftrace_ops_list_func ;
260+ }
242261
243262#ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
244263 ftrace_trace_function = func ;
@@ -773,7 +792,8 @@ ftrace_profile_alloc(struct ftrace_profile_stat *stat, unsigned long ip)
773792}
774793
775794static void
776- function_profile_call (unsigned long ip , unsigned long parent_ip )
795+ function_profile_call (unsigned long ip , unsigned long parent_ip ,
796+ struct ftrace_ops * ops )
777797{
778798 struct ftrace_profile_stat * stat ;
779799 struct ftrace_profile * rec ;
@@ -803,7 +823,7 @@ function_profile_call(unsigned long ip, unsigned long parent_ip)
803823#ifdef CONFIG_FUNCTION_GRAPH_TRACER
804824static int profile_graph_entry (struct ftrace_graph_ent * trace )
805825{
806- function_profile_call (trace -> func , 0 );
826+ function_profile_call (trace -> func , 0 , NULL );
807827 return 1 ;
808828}
809829
@@ -2790,8 +2810,8 @@ static int __init ftrace_mod_cmd_init(void)
27902810}
27912811device_initcall (ftrace_mod_cmd_init );
27922812
2793- static void
2794- function_trace_probe_call ( unsigned long ip , unsigned long parent_ip )
2813+ static void function_trace_probe_call ( unsigned long ip , unsigned long parent_ip ,
2814+ struct ftrace_ops * op )
27952815{
27962816 struct ftrace_func_probe * entry ;
27972817 struct hlist_head * hhd ;
@@ -3942,10 +3962,9 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip)
39423962#endif /* CONFIG_DYNAMIC_FTRACE */
39433963
39443964static void
3945- ftrace_ops_control_func (unsigned long ip , unsigned long parent_ip )
3965+ ftrace_ops_control_func (unsigned long ip , unsigned long parent_ip ,
3966+ struct ftrace_ops * op )
39463967{
3947- struct ftrace_ops * op ;
3948-
39493968 if (unlikely (trace_recursion_test (TRACE_CONTROL_BIT )))
39503969 return ;
39513970
@@ -3959,7 +3978,7 @@ ftrace_ops_control_func(unsigned long ip, unsigned long parent_ip)
39593978 while (op != & ftrace_list_end ) {
39603979 if (!ftrace_function_local_disabled (op ) &&
39613980 ftrace_ops_test (op , ip ))
3962- op -> func (ip , parent_ip );
3981+ op -> func (ip , parent_ip , op );
39633982
39643983 op = rcu_dereference_raw (op -> next );
39653984 };
@@ -3971,8 +3990,9 @@ static struct ftrace_ops control_ops = {
39713990 .func = ftrace_ops_control_func ,
39723991};
39733992
3974- static void
3975- ftrace_ops_list_func (unsigned long ip , unsigned long parent_ip )
3993+ static inline void
3994+ __ftrace_ops_list_func (unsigned long ip , unsigned long parent_ip ,
3995+ struct ftrace_ops * ignored )
39763996{
39773997 struct ftrace_ops * op ;
39783998
@@ -3988,13 +4008,32 @@ ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip)
39884008 op = rcu_dereference_raw (ftrace_ops_list );
39894009 while (op != & ftrace_list_end ) {
39904010 if (ftrace_ops_test (op , ip ))
3991- op -> func (ip , parent_ip );
4011+ op -> func (ip , parent_ip , op );
39924012 op = rcu_dereference_raw (op -> next );
39934013 };
39944014 preempt_enable_notrace ();
39954015 trace_recursion_clear (TRACE_INTERNAL_BIT );
39964016}
39974017
4018+ /*
4019+ * Some archs only support passing ip and parent_ip. Even though
4020+ * the list function ignores the op parameter, we do not want any
4021+ * C side effects, where a function is called without the caller
4022+ * sending a third parameter.
4023+ */
4024+ #if ARCH_SUPPORTS_FTRACE_OPS
4025+ static void ftrace_ops_list_func (unsigned long ip , unsigned long parent_ip ,
4026+ struct ftrace_ops * op )
4027+ {
4028+ __ftrace_ops_list_func (ip , parent_ip , NULL );
4029+ }
4030+ #else
4031+ static void ftrace_ops_no_ops (unsigned long ip , unsigned long parent_ip )
4032+ {
4033+ __ftrace_ops_list_func (ip , parent_ip , NULL );
4034+ }
4035+ #endif
4036+
39984037static void clear_ftrace_swapper (void )
39994038{
40004039 struct task_struct * p ;
0 commit comments