]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/x86/kernel/ftrace.c
ftrace/x86: Have arch x86_64 use breakpoints instead of stop machine
[karo-tx-linux.git] / arch / x86 / kernel / ftrace.c
1 /*
2  * Code for replacing ftrace calls with jumps.
3  *
4  * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5  *
6  * Thanks goes to Ingo Molnar, for suggesting the idea.
7  * Mathieu Desnoyers, for suggesting postponing the modifications.
8  * Arjan van de Ven, for keeping me straight, and explaining to me
9  * the dangers of modifying code on the run.
10  */
11
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14 #include <linux/spinlock.h>
15 #include <linux/hardirq.h>
16 #include <linux/uaccess.h>
17 #include <linux/ftrace.h>
18 #include <linux/percpu.h>
19 #include <linux/sched.h>
20 #include <linux/init.h>
21 #include <linux/list.h>
22 #include <linux/module.h>
23 #include <linux/kprobes.h>
24
25 #include <trace/syscall.h>
26
27 #include <asm/cacheflush.h>
28 #include <asm/ftrace.h>
29 #include <asm/nops.h>
30 #include <asm/nmi.h>
31
32
33 #ifdef CONFIG_DYNAMIC_FTRACE
34
35 /*
36  * modifying_code is set to notify NMIs that they need to use
37  * memory barriers when entering or exiting. But we don't want
38  * to burden NMIs with unnecessary memory barriers when code
39  * modification is not being done (which is most of the time).
40  *
41  * A mutex is already held when ftrace_arch_code_modify_prepare
42  * and post_process are called. No locks need to be taken here.
43  *
44  * Stop machine will make sure currently running NMIs are done
45  * and new NMIs will see the updated variable before we need
46  * to worry about NMIs doing memory barriers.
47  */
48 static int modifying_code __read_mostly;
49 static DEFINE_PER_CPU(int, save_modifying_code);
50
51 int ftrace_arch_code_modify_prepare(void)
52 {
53         set_kernel_text_rw();
54         set_all_modules_text_rw();
55         modifying_code = 1;
56         return 0;
57 }
58
59 int ftrace_arch_code_modify_post_process(void)
60 {
61         modifying_code = 0;
62         set_all_modules_text_ro();
63         set_kernel_text_ro();
64         return 0;
65 }
66
67 union ftrace_code_union {
68         char code[MCOUNT_INSN_SIZE];
69         struct {
70                 char e8;
71                 int offset;
72         } __attribute__((packed));
73 };
74
75 static int ftrace_calc_offset(long ip, long addr)
76 {
77         return (int)(addr - ip);
78 }
79
80 static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
81 {
82         static union ftrace_code_union calc;
83
84         calc.e8         = 0xe8;
85         calc.offset     = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
86
87         /*
88          * No locking needed, this must be called via kstop_machine
89          * which in essence is like running on a uniprocessor machine.
90          */
91         return calc.code;
92 }
93
94 /*
95  * Modifying code must take extra care. On an SMP machine, if
96  * the code being modified is also being executed on another CPU
97  * that CPU will have undefined results and possibly take a GPF.
98  * We use kstop_machine to stop other CPUS from exectuing code.
99  * But this does not stop NMIs from happening. We still need
100  * to protect against that. We separate out the modification of
101  * the code to take care of this.
102  *
103  * Two buffers are added: An IP buffer and a "code" buffer.
104  *
105  * 1) Put the instruction pointer into the IP buffer
106  *    and the new code into the "code" buffer.
107  * 2) Wait for any running NMIs to finish and set a flag that says
108  *    we are modifying code, it is done in an atomic operation.
109  * 3) Write the code
110  * 4) clear the flag.
111  * 5) Wait for any running NMIs to finish.
112  *
113  * If an NMI is executed, the first thing it does is to call
114  * "ftrace_nmi_enter". This will check if the flag is set to write
115  * and if it is, it will write what is in the IP and "code" buffers.
116  *
117  * The trick is, it does not matter if everyone is writing the same
118  * content to the code location. Also, if a CPU is executing code
119  * it is OK to write to that code location if the contents being written
120  * are the same as what exists.
121  */
122
123 #define MOD_CODE_WRITE_FLAG (1 << 31)   /* set when NMI should do the write */
124 static atomic_t nmi_running = ATOMIC_INIT(0);
125 static int mod_code_status;             /* holds return value of text write */
126 static void *mod_code_ip;               /* holds the IP to write to */
127 static const void *mod_code_newcode;    /* holds the text to write to the IP */
128
129 static unsigned nmi_wait_count;
130 static atomic_t nmi_update_count = ATOMIC_INIT(0);
131
132 int ftrace_arch_read_dyn_info(char *buf, int size)
133 {
134         int r;
135
136         r = snprintf(buf, size, "%u %u",
137                      nmi_wait_count,
138                      atomic_read(&nmi_update_count));
139         return r;
140 }
141
142 static void clear_mod_flag(void)
143 {
144         int old = atomic_read(&nmi_running);
145
146         for (;;) {
147                 int new = old & ~MOD_CODE_WRITE_FLAG;
148
149                 if (old == new)
150                         break;
151
152                 old = atomic_cmpxchg(&nmi_running, old, new);
153         }
154 }
155
156 static void ftrace_mod_code(void)
157 {
158         /*
159          * Yes, more than one CPU process can be writing to mod_code_status.
160          *    (and the code itself)
161          * But if one were to fail, then they all should, and if one were
162          * to succeed, then they all should.
163          */
164         mod_code_status = probe_kernel_write(mod_code_ip, mod_code_newcode,
165                                              MCOUNT_INSN_SIZE);
166
167         /* if we fail, then kill any new writers */
168         if (mod_code_status)
169                 clear_mod_flag();
170 }
171
172 void ftrace_nmi_enter(void)
173 {
174         __this_cpu_write(save_modifying_code, modifying_code);
175
176         if (!__this_cpu_read(save_modifying_code))
177                 return;
178
179         if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
180                 smp_rmb();
181                 ftrace_mod_code();
182                 atomic_inc(&nmi_update_count);
183         }
184         /* Must have previous changes seen before executions */
185         smp_mb();
186 }
187
188 void ftrace_nmi_exit(void)
189 {
190         if (!__this_cpu_read(save_modifying_code))
191                 return;
192
193         /* Finish all executions before clearing nmi_running */
194         smp_mb();
195         atomic_dec(&nmi_running);
196 }
197
198 static void wait_for_nmi_and_set_mod_flag(void)
199 {
200         if (!atomic_cmpxchg(&nmi_running, 0, MOD_CODE_WRITE_FLAG))
201                 return;
202
203         do {
204                 cpu_relax();
205         } while (atomic_cmpxchg(&nmi_running, 0, MOD_CODE_WRITE_FLAG));
206
207         nmi_wait_count++;
208 }
209
210 static void wait_for_nmi(void)
211 {
212         if (!atomic_read(&nmi_running))
213                 return;
214
215         do {
216                 cpu_relax();
217         } while (atomic_read(&nmi_running));
218
219         nmi_wait_count++;
220 }
221
222 static inline int
223 within(unsigned long addr, unsigned long start, unsigned long end)
224 {
225         return addr >= start && addr < end;
226 }
227
228 static int
229 do_ftrace_mod_code(unsigned long ip, const void *new_code)
230 {
231         /*
232          * On x86_64, kernel text mappings are mapped read-only with
233          * CONFIG_DEBUG_RODATA. So we use the kernel identity mapping instead
234          * of the kernel text mapping to modify the kernel text.
235          *
236          * For 32bit kernels, these mappings are same and we can use
237          * kernel identity mapping to modify code.
238          */
239         if (within(ip, (unsigned long)_text, (unsigned long)_etext))
240                 ip = (unsigned long)__va(__pa(ip));
241
242         mod_code_ip = (void *)ip;
243         mod_code_newcode = new_code;
244
245         /* The buffers need to be visible before we let NMIs write them */
246         smp_mb();
247
248         wait_for_nmi_and_set_mod_flag();
249
250         /* Make sure all running NMIs have finished before we write the code */
251         smp_mb();
252
253         ftrace_mod_code();
254
255         /* Make sure the write happens before clearing the bit */
256         smp_mb();
257
258         clear_mod_flag();
259         wait_for_nmi();
260
261         return mod_code_status;
262 }
263
264 static const unsigned char *ftrace_nop_replace(void)
265 {
266         return ideal_nops[NOP_ATOMIC5];
267 }
268
269 static int
270 ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
271                    unsigned const char *new_code)
272 {
273         unsigned char replaced[MCOUNT_INSN_SIZE];
274
275         /*
276          * Note: Due to modules and __init, code can
277          *  disappear and change, we need to protect against faulting
278          *  as well as code changing. We do this by using the
279          *  probe_kernel_* functions.
280          *
281          * No real locking needed, this code is run through
282          * kstop_machine, or before SMP starts.
283          */
284
285         /* read the text we want to modify */
286         if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
287                 return -EFAULT;
288
289         /* Make sure it is what we expect it to be */
290         if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
291                 return -EINVAL;
292
293         /* replace the text with the new text */
294         if (do_ftrace_mod_code(ip, new_code))
295                 return -EPERM;
296
297         sync_core();
298
299         return 0;
300 }
301
302 int ftrace_make_nop(struct module *mod,
303                     struct dyn_ftrace *rec, unsigned long addr)
304 {
305         unsigned const char *new, *old;
306         unsigned long ip = rec->ip;
307
308         old = ftrace_call_replace(ip, addr);
309         new = ftrace_nop_replace();
310
311         return ftrace_modify_code(rec->ip, old, new);
312 }
313
314 int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
315 {
316         unsigned const char *new, *old;
317         unsigned long ip = rec->ip;
318
319         old = ftrace_nop_replace();
320         new = ftrace_call_replace(ip, addr);
321
322         return ftrace_modify_code(rec->ip, old, new);
323 }
324
325 int ftrace_update_ftrace_func(ftrace_func_t func)
326 {
327         unsigned long ip = (unsigned long)(&ftrace_call);
328         unsigned char old[MCOUNT_INSN_SIZE], *new;
329         int ret;
330
331         memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
332         new = ftrace_call_replace(ip, (unsigned long)func);
333         ret = ftrace_modify_code(ip, old, new);
334
335         return ret;
336 }
337
338 int modifying_ftrace_code __read_mostly;
339
340 /*
341  * A breakpoint was added to the code address we are about to
342  * modify, and this is the handle that will just skip over it.
343  * We are either changing a nop into a trace call, or a trace
344  * call to a nop. While the change is taking place, we treat
345  * it just like it was a nop.
346  */
347 int ftrace_int3_handler(struct pt_regs *regs)
348 {
349         if (WARN_ON_ONCE(!regs))
350                 return 0;
351
352         if (!ftrace_location(regs->ip - 1))
353                 return 0;
354
355         regs->ip += MCOUNT_INSN_SIZE - 1;
356
357         return 1;
358 }
359
360 static int ftrace_write(unsigned long ip, const char *val, int size)
361 {
362         /*
363          * On x86_64, kernel text mappings are mapped read-only with
364          * CONFIG_DEBUG_RODATA. So we use the kernel identity mapping instead
365          * of the kernel text mapping to modify the kernel text.
366          *
367          * For 32bit kernels, these mappings are same and we can use
368          * kernel identity mapping to modify code.
369          */
370         if (within(ip, (unsigned long)_text, (unsigned long)_etext))
371                 ip = (unsigned long)__va(__pa(ip));
372
373         return probe_kernel_write((void *)ip, val, size);
374 }
375
376 static int add_break(unsigned long ip, const char *old)
377 {
378         unsigned char replaced[MCOUNT_INSN_SIZE];
379         unsigned char brk = BREAKPOINT_INSTRUCTION;
380
381         if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
382                 return -EFAULT;
383
384         /* Make sure it is what we expect it to be */
385         if (memcmp(replaced, old, MCOUNT_INSN_SIZE) != 0)
386                 return -EINVAL;
387
388         if (ftrace_write(ip, &brk, 1))
389                 return -EPERM;
390
391         return 0;
392 }
393
394 static int add_brk_on_call(struct dyn_ftrace *rec, unsigned long addr)
395 {
396         unsigned const char *old;
397         unsigned long ip = rec->ip;
398
399         old = ftrace_call_replace(ip, addr);
400
401         return add_break(rec->ip, old);
402 }
403
404
405 static int add_brk_on_nop(struct dyn_ftrace *rec)
406 {
407         unsigned const char *old;
408
409         old = ftrace_nop_replace();
410
411         return add_break(rec->ip, old);
412 }
413
414 static int add_breakpoints(struct dyn_ftrace *rec, int enable)
415 {
416         unsigned long ftrace_addr;
417         int ret;
418
419         ret = ftrace_test_record(rec, enable);
420
421         ftrace_addr = (unsigned long)FTRACE_ADDR;
422
423         switch (ret) {
424         case FTRACE_UPDATE_IGNORE:
425                 return 0;
426
427         case FTRACE_UPDATE_MAKE_CALL:
428                 /* converting nop to call */
429                 return add_brk_on_nop(rec);
430
431         case FTRACE_UPDATE_MAKE_NOP:
432                 /* converting a call to a nop */
433                 return add_brk_on_call(rec, ftrace_addr);
434         }
435         return 0;
436 }
437
438 /*
439  * On error, we need to remove breakpoints. This needs to
440  * be done caefully. If the address does not currently have a
441  * breakpoint, we know we are done. Otherwise, we look at the
442  * remaining 4 bytes of the instruction. If it matches a nop
443  * we replace the breakpoint with the nop. Otherwise we replace
444  * it with the call instruction.
445  */
446 static int remove_breakpoint(struct dyn_ftrace *rec)
447 {
448         unsigned char ins[MCOUNT_INSN_SIZE];
449         unsigned char brk = BREAKPOINT_INSTRUCTION;
450         const unsigned char *nop;
451         unsigned long ftrace_addr;
452         unsigned long ip = rec->ip;
453
454         /* If we fail the read, just give up */
455         if (probe_kernel_read(ins, (void *)ip, MCOUNT_INSN_SIZE))
456                 return -EFAULT;
457
458         /* If this does not have a breakpoint, we are done */
459         if (ins[0] != brk)
460                 return -1;
461
462         nop = ftrace_nop_replace();
463
464         /*
465          * If the last 4 bytes of the instruction do not match
466          * a nop, then we assume that this is a call to ftrace_addr.
467          */
468         if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) != 0) {
469                 /*
470                  * For extra paranoidism, we check if the breakpoint is on
471                  * a call that would actually jump to the ftrace_addr.
472                  * If not, don't touch the breakpoint, we make just create
473                  * a disaster.
474                  */
475                 ftrace_addr = (unsigned long)FTRACE_ADDR;
476                 nop = ftrace_call_replace(ip, ftrace_addr);
477
478                 if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) != 0)
479                         return -EINVAL;
480         }
481
482         return probe_kernel_write((void *)ip, &nop[0], 1);
483 }
484
485 static int add_update_code(unsigned long ip, unsigned const char *new)
486 {
487         /* skip breakpoint */
488         ip++;
489         new++;
490         if (ftrace_write(ip, new, MCOUNT_INSN_SIZE - 1))
491                 return -EPERM;
492         return 0;
493 }
494
495 static int add_update_call(struct dyn_ftrace *rec, unsigned long addr)
496 {
497         unsigned long ip = rec->ip;
498         unsigned const char *new;
499
500         new = ftrace_call_replace(ip, addr);
501         return add_update_code(ip, new);
502 }
503
504 static int add_update_nop(struct dyn_ftrace *rec)
505 {
506         unsigned long ip = rec->ip;
507         unsigned const char *new;
508
509         new = ftrace_nop_replace();
510         return add_update_code(ip, new);
511 }
512
513 static int add_update(struct dyn_ftrace *rec, int enable)
514 {
515         unsigned long ftrace_addr;
516         int ret;
517
518         ret = ftrace_test_record(rec, enable);
519
520         ftrace_addr = (unsigned long)FTRACE_ADDR;
521
522         switch (ret) {
523         case FTRACE_UPDATE_IGNORE:
524                 return 0;
525
526         case FTRACE_UPDATE_MAKE_CALL:
527                 /* converting nop to call */
528                 return add_update_call(rec, ftrace_addr);
529
530         case FTRACE_UPDATE_MAKE_NOP:
531                 /* converting a call to a nop */
532                 return add_update_nop(rec);
533         }
534
535         return 0;
536 }
537
538 static int finish_update_call(struct dyn_ftrace *rec, unsigned long addr)
539 {
540         unsigned long ip = rec->ip;
541         unsigned const char *new;
542
543         new = ftrace_call_replace(ip, addr);
544
545         if (ftrace_write(ip, new, 1))
546                 return -EPERM;
547
548         return 0;
549 }
550
551 static int finish_update_nop(struct dyn_ftrace *rec)
552 {
553         unsigned long ip = rec->ip;
554         unsigned const char *new;
555
556         new = ftrace_nop_replace();
557
558         if (ftrace_write(ip, new, 1))
559                 return -EPERM;
560         return 0;
561 }
562
563 static int finish_update(struct dyn_ftrace *rec, int enable)
564 {
565         unsigned long ftrace_addr;
566         int ret;
567
568         ret = ftrace_update_record(rec, enable);
569
570         ftrace_addr = (unsigned long)FTRACE_ADDR;
571
572         switch (ret) {
573         case FTRACE_UPDATE_IGNORE:
574                 return 0;
575
576         case FTRACE_UPDATE_MAKE_CALL:
577                 /* converting nop to call */
578                 return finish_update_call(rec, ftrace_addr);
579
580         case FTRACE_UPDATE_MAKE_NOP:
581                 /* converting a call to a nop */
582                 return finish_update_nop(rec);
583         }
584
585         return 0;
586 }
587
588 static void do_sync_core(void *data)
589 {
590         sync_core();
591 }
592
593 static void run_sync(void)
594 {
595         int enable_irqs = irqs_disabled();
596
597         /* We may be called with interrupts disbled (on bootup). */
598         if (enable_irqs)
599                 local_irq_enable();
600         on_each_cpu(do_sync_core, NULL, 1);
601         if (enable_irqs)
602                 local_irq_disable();
603 }
604
605 static void ftrace_replace_code(int enable)
606 {
607         struct ftrace_rec_iter *iter;
608         struct dyn_ftrace *rec;
609         const char *report = "adding breakpoints";
610         int count = 0;
611         int ret;
612
613         for_ftrace_rec_iter(iter) {
614                 rec = ftrace_rec_iter_record(iter);
615
616                 ret = add_breakpoints(rec, enable);
617                 if (ret)
618                         goto remove_breakpoints;
619                 count++;
620         }
621
622         run_sync();
623
624         report = "updating code";
625
626         for_ftrace_rec_iter(iter) {
627                 rec = ftrace_rec_iter_record(iter);
628
629                 ret = add_update(rec, enable);
630                 if (ret)
631                         goto remove_breakpoints;
632         }
633
634         run_sync();
635
636         report = "removing breakpoints";
637
638         for_ftrace_rec_iter(iter) {
639                 rec = ftrace_rec_iter_record(iter);
640
641                 ret = finish_update(rec, enable);
642                 if (ret)
643                         goto remove_breakpoints;
644         }
645
646         run_sync();
647
648         return;
649
650  remove_breakpoints:
651         ftrace_bug(ret, rec ? rec->ip : 0);
652         printk(KERN_WARNING "Failed on %s (%d):\n", report, count);
653         for_ftrace_rec_iter(iter) {
654                 rec = ftrace_rec_iter_record(iter);
655                 remove_breakpoint(rec);
656         }
657 }
658
659 void arch_ftrace_update_code(int command)
660 {
661         modifying_ftrace_code++;
662
663         if (command & FTRACE_UPDATE_CALLS)
664                 ftrace_replace_code(1);
665         else if (command & FTRACE_DISABLE_CALLS)
666                 ftrace_replace_code(0);
667
668         if (command & FTRACE_UPDATE_TRACE_FUNC)
669                 ftrace_update_ftrace_func(ftrace_trace_function);
670
671         if (command & FTRACE_START_FUNC_RET)
672                 ftrace_enable_ftrace_graph_caller();
673         else if (command & FTRACE_STOP_FUNC_RET)
674                 ftrace_disable_ftrace_graph_caller();
675
676         modifying_ftrace_code--;
677 }
678
679 int __init ftrace_dyn_arch_init(void *data)
680 {
681         /* The return code is retured via data */
682         *(unsigned long *)data = 0;
683
684         return 0;
685 }
686 #endif
687
688 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
689
690 #ifdef CONFIG_DYNAMIC_FTRACE
691 extern void ftrace_graph_call(void);
692
693 static int ftrace_mod_jmp(unsigned long ip,
694                           int old_offset, int new_offset)
695 {
696         unsigned char code[MCOUNT_INSN_SIZE];
697
698         if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
699                 return -EFAULT;
700
701         if (code[0] != 0xe9 || old_offset != *(int *)(&code[1]))
702                 return -EINVAL;
703
704         *(int *)(&code[1]) = new_offset;
705
706         if (do_ftrace_mod_code(ip, &code))
707                 return -EPERM;
708
709         return 0;
710 }
711
712 int ftrace_enable_ftrace_graph_caller(void)
713 {
714         unsigned long ip = (unsigned long)(&ftrace_graph_call);
715         int old_offset, new_offset;
716
717         old_offset = (unsigned long)(&ftrace_stub) - (ip + MCOUNT_INSN_SIZE);
718         new_offset = (unsigned long)(&ftrace_graph_caller) - (ip + MCOUNT_INSN_SIZE);
719
720         return ftrace_mod_jmp(ip, old_offset, new_offset);
721 }
722
723 int ftrace_disable_ftrace_graph_caller(void)
724 {
725         unsigned long ip = (unsigned long)(&ftrace_graph_call);
726         int old_offset, new_offset;
727
728         old_offset = (unsigned long)(&ftrace_graph_caller) - (ip + MCOUNT_INSN_SIZE);
729         new_offset = (unsigned long)(&ftrace_stub) - (ip + MCOUNT_INSN_SIZE);
730
731         return ftrace_mod_jmp(ip, old_offset, new_offset);
732 }
733
734 #endif /* !CONFIG_DYNAMIC_FTRACE */
735
736 /*
737  * Hook the return address and push it in the stack of return addrs
738  * in current thread info.
739  */
740 void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
741                            unsigned long frame_pointer)
742 {
743         unsigned long old;
744         int faulted;
745         struct ftrace_graph_ent trace;
746         unsigned long return_hooker = (unsigned long)
747                                 &return_to_handler;
748
749         if (unlikely(atomic_read(&current->tracing_graph_pause)))
750                 return;
751
752         /*
753          * Protect against fault, even if it shouldn't
754          * happen. This tool is too much intrusive to
755          * ignore such a protection.
756          */
757         asm volatile(
758                 "1: " _ASM_MOV " (%[parent]), %[old]\n"
759                 "2: " _ASM_MOV " %[return_hooker], (%[parent])\n"
760                 "   movl $0, %[faulted]\n"
761                 "3:\n"
762
763                 ".section .fixup, \"ax\"\n"
764                 "4: movl $1, %[faulted]\n"
765                 "   jmp 3b\n"
766                 ".previous\n"
767
768                 _ASM_EXTABLE(1b, 4b)
769                 _ASM_EXTABLE(2b, 4b)
770
771                 : [old] "=&r" (old), [faulted] "=r" (faulted)
772                 : [parent] "r" (parent), [return_hooker] "r" (return_hooker)
773                 : "memory"
774         );
775
776         if (unlikely(faulted)) {
777                 ftrace_graph_stop();
778                 WARN_ON(1);
779                 return;
780         }
781
782         trace.func = self_addr;
783         trace.depth = current->curr_ret_stack + 1;
784
785         /* Only trace if the calling function expects to */
786         if (!ftrace_graph_entry(&trace)) {
787                 *parent = old;
788                 return;
789         }
790
791         if (ftrace_push_return_trace(old, self_addr, &trace.depth,
792                     frame_pointer) == -EBUSY) {
793                 *parent = old;
794                 return;
795         }
796 }
797 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */