77 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
88 *
99 * future possible enhancements:
10- * - add CONFIG_DYNAMIC_FTRACE
1110 * - add CONFIG_STACK_TRACER
1211 */
1312
1413#include <linux/init.h>
1514#include <linux/ftrace.h>
15+ #include <linux/uaccess.h>
1616
1717#include <asm/assembly.h>
1818#include <asm/sections.h>
1919#include <asm/ftrace.h>
20-
20+ #include <asm/patch.h>
2121
2222#define __hot __attribute__ ((__section__ (".text.hot")))
2323
@@ -50,13 +50,11 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
5050 unsigned long self_addr ,
5151 unsigned long org_sp_gr3 )
5252{
53- extern ftrace_func_t ftrace_trace_function ; /* depends on CONFIG_DYNAMIC_FTRACE */
54-
55- if (ftrace_trace_function != ftrace_stub ) {
56- /* struct ftrace_ops *op, struct pt_regs *regs); */
57- ftrace_trace_function (parent , self_addr , NULL , NULL );
58- return ;
59- }
53+ #ifndef CONFIG_DYNAMIC_FTRACE
54+ extern ftrace_func_t ftrace_trace_function ;
55+ #endif
56+ if (ftrace_trace_function != ftrace_stub )
57+ ftrace_trace_function (self_addr , parent , NULL , NULL );
6058
6159#ifdef CONFIG_FUNCTION_GRAPH_TRACER
6260 if (ftrace_graph_return != (trace_func_graph_ret_t ) ftrace_stub ||
@@ -75,3 +73,116 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
7573#endif
7674}
7775
76+ #ifdef CONFIG_FUNCTION_GRAPH_TRACER
77+ int ftrace_enable_ftrace_graph_caller (void )
78+ {
79+ return 0 ;
80+ }
81+
82+ int ftrace_disable_ftrace_graph_caller (void )
83+ {
84+ return 0 ;
85+ }
86+ #endif
87+
88+ #ifdef CONFIG_DYNAMIC_FTRACE
89+
90+ int __init ftrace_dyn_arch_init (void )
91+ {
92+ return 0 ;
93+ }
94+ int ftrace_update_ftrace_func (ftrace_func_t func )
95+ {
96+ return 0 ;
97+ }
98+
99+ unsigned long ftrace_call_adjust (unsigned long addr )
100+ {
101+ return addr + (FTRACE_PATCHABLE_FUNCTION_SIZE - 1 )* 4 ;
102+ }
103+
104+ int ftrace_make_call (struct dyn_ftrace * rec , unsigned long addr )
105+ {
106+ u32 insn [FTRACE_PATCHABLE_FUNCTION_SIZE ];
107+ u32 * tramp ;
108+ int size , ret , i ;
109+ void * ip ;
110+
111+ #ifdef CONFIG_64BIT
112+ unsigned long addr2 =
113+ (unsigned long )dereference_function_descriptor ((void * )addr );
114+
115+ u32 ftrace_trampoline [] = {
116+ 0x73c10208 , /* std,ma r1,100(sp) */
117+ 0x0c2110c1 , /* ldd -10(r1),r1 */
118+ 0xe820d002 , /* bve,n (r1) */
119+ addr2 >> 32 ,
120+ addr2 & 0xffffffff ,
121+ 0xe83f1fd7 , /* b,l,n .-14,r1 */
122+ };
123+
124+ u32 ftrace_trampoline_unaligned [] = {
125+ addr2 >> 32 ,
126+ addr2 & 0xffffffff ,
127+ 0x37de0200 , /* ldo 100(sp),sp */
128+ 0x73c13e01 , /* std r1,-100(sp) */
129+ 0x34213ff9 , /* ldo -4(r1),r1 */
130+ 0x50213fc1 , /* ldd -20(r1),r1 */
131+ 0xe820d002 , /* bve,n (r1) */
132+ 0xe83f1fcf , /* b,l,n .-20,r1 */
133+ };
134+
135+ BUILD_BUG_ON (ARRAY_SIZE (ftrace_trampoline_unaligned ) >
136+ FTRACE_PATCHABLE_FUNCTION_SIZE );
137+ #else
138+ u32 ftrace_trampoline [] = {
139+ (u32 )addr ,
140+ 0x6fc10080 , /* stw,ma r1,40(sp) */
141+ 0x48213fd1 , /* ldw -18(r1),r1 */
142+ 0xe820c002 , /* bv,n r0(r1) */
143+ 0xe83f1fdf , /* b,l,n .-c,r1 */
144+ };
145+ #endif
146+
147+ BUILD_BUG_ON (ARRAY_SIZE (ftrace_trampoline ) >
148+ FTRACE_PATCHABLE_FUNCTION_SIZE );
149+
150+ size = sizeof (ftrace_trampoline );
151+ tramp = ftrace_trampoline ;
152+
153+ #ifdef CONFIG_64BIT
154+ if (rec -> ip & 0x4 ) {
155+ size = sizeof (ftrace_trampoline_unaligned );
156+ tramp = ftrace_trampoline_unaligned ;
157+ }
158+ #endif
159+
160+ ip = (void * )(rec -> ip + 4 - size );
161+
162+ ret = probe_kernel_read (insn , ip , size );
163+ if (ret )
164+ return ret ;
165+
166+ for (i = 0 ; i < size / 4 ; i ++ ) {
167+ if (insn [i ] != INSN_NOP )
168+ return - EINVAL ;
169+ }
170+
171+ __patch_text_multiple (ip , tramp , size );
172+ return 0 ;
173+ }
174+
175+ int ftrace_make_nop (struct module * mod , struct dyn_ftrace * rec ,
176+ unsigned long addr )
177+ {
178+ u32 insn [FTRACE_PATCHABLE_FUNCTION_SIZE ];
179+ int i ;
180+
181+ for (i = 0 ; i < ARRAY_SIZE (insn ); i ++ )
182+ insn [i ] = INSN_NOP ;
183+
184+ __patch_text_multiple ((void * )rec -> ip + 4 - sizeof (insn ),
185+ insn , sizeof (insn ));
186+ return 0 ;
187+ }
188+ #endif
0 commit comments