@@ -72,15 +72,6 @@ static inline void ftrace_generate_orig_insn(struct ftrace_insn *insn)
7272#endif
7373}
7474
75- static inline int is_kprobe_on_ftrace (struct ftrace_insn * insn )
76- {
77- #ifdef CONFIG_KPROBES
78- if (insn -> opc == BREAKPOINT_INSTRUCTION )
79- return 1 ;
80- #endif
81- return 0 ;
82- }
83-
8475static inline void ftrace_generate_kprobe_nop_insn (struct ftrace_insn * insn )
8576{
8677#ifdef CONFIG_KPROBES
@@ -114,16 +105,6 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
114105 /* Initial code replacement */
115106 ftrace_generate_orig_insn (& orig );
116107 ftrace_generate_nop_insn (& new );
117- } else if (is_kprobe_on_ftrace (& old )) {
118- /*
119- * If we find a breakpoint instruction, a kprobe has been
120- * placed at the beginning of the function. We write the
121- * constant KPROBE_ON_FTRACE_NOP into the remaining four
122- * bytes of the original instruction so that the kprobes
123- * handler can execute a nop, if it reaches this breakpoint.
124- */
125- ftrace_generate_kprobe_call_insn (& orig );
126- ftrace_generate_kprobe_nop_insn (& new );
127108 } else {
128109 /* Replace ftrace call with a nop. */
129110 ftrace_generate_call_insn (& orig , rec -> ip );
@@ -142,21 +123,10 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
142123
143124 if (probe_kernel_read (& old , (void * ) rec -> ip , sizeof (old )))
144125 return - EFAULT ;
145- if (is_kprobe_on_ftrace (& old )) {
146- /*
147- * If we find a breakpoint instruction, a kprobe has been
148- * placed at the beginning of the function. We write the
149- * constant KPROBE_ON_FTRACE_CALL into the remaining four
150- * bytes of the original instruction so that the kprobes
151- * handler can execute a brasl if it reaches this breakpoint.
152- */
153- ftrace_generate_kprobe_nop_insn (& orig );
154- ftrace_generate_kprobe_call_insn (& new );
155- } else {
156- /* Replace nop with an ftrace call. */
157- ftrace_generate_nop_insn (& orig );
158- ftrace_generate_call_insn (& new , rec -> ip );
159- }
126+ /* Replace nop with an ftrace call. */
127+ ftrace_generate_nop_insn (& orig );
128+ ftrace_generate_call_insn (& new , rec -> ip );
129+
160130 /* Verify that the to be replaced code matches what we expect. */
161131 if (memcmp (& orig , & old , sizeof (old )))
162132 return - EINVAL ;
@@ -241,3 +211,45 @@ int ftrace_disable_ftrace_graph_caller(void)
241211}
242212
243213#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
214+
215+ #ifdef CONFIG_KPROBES_ON_FTRACE
216+ void kprobe_ftrace_handler (unsigned long ip , unsigned long parent_ip ,
217+ struct ftrace_ops * ops , struct pt_regs * regs )
218+ {
219+ struct kprobe_ctlblk * kcb ;
220+ struct kprobe * p = get_kprobe ((kprobe_opcode_t * )ip );
221+
222+ if (unlikely (!p ) || kprobe_disabled (p ))
223+ return ;
224+
225+ if (kprobe_running ()) {
226+ kprobes_inc_nmissed_count (p );
227+ return ;
228+ }
229+
230+ __this_cpu_write (current_kprobe , p );
231+
232+ kcb = get_kprobe_ctlblk ();
233+ kcb -> kprobe_status = KPROBE_HIT_ACTIVE ;
234+
235+ instruction_pointer_set (regs , ip );
236+
237+ if (!p -> pre_handler || !p -> pre_handler (p , regs )) {
238+
239+ instruction_pointer_set (regs , ip + MCOUNT_INSN_SIZE );
240+
241+ if (unlikely (p -> post_handler )) {
242+ kcb -> kprobe_status = KPROBE_HIT_SSDONE ;
243+ p -> post_handler (p , regs , 0 );
244+ }
245+ }
246+ __this_cpu_write (current_kprobe , NULL );
247+ }
248+ NOKPROBE_SYMBOL (kprobe_ftrace_handler );
249+
250+ int arch_prepare_kprobe_ftrace (struct kprobe * p )
251+ {
252+ p -> ainsn .insn = NULL ;
253+ return 0 ;
254+ }
255+ #endif
0 commit comments