1 // SPDX-License-Identifier: GPL-2.0
3 * Code for replacing ftrace calls with jumps.
5 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
7 * Thanks goes out to P.A. Semi, Inc for supplying me with a PPC64 box.
9 * Added function graph tracer code, taken from x86 that was written
10 * by Frederic Weisbecker, and ported to PPC by Steven Rostedt.
14 #define pr_fmt(fmt) "ftrace-powerpc: " fmt
16 #include <linux/spinlock.h>
17 #include <linux/hardirq.h>
18 #include <linux/uaccess.h>
19 #include <linux/module.h>
20 #include <linux/ftrace.h>
21 #include <linux/percpu.h>
22 #include <linux/init.h>
23 #include <linux/list.h>
25 #include <asm/asm-prototypes.h>
26 #include <asm/cacheflush.h>
27 #include <asm/code-patching.h>
28 #include <asm/ftrace.h>
29 #include <asm/syscall.h>
33 #ifdef CONFIG_DYNAMIC_FTRACE
36 * We generally only have a single long_branch tramp and at most 2 or 3 plt
37 * tramps generated. But, we don't use the plt tramps currently. We also allot
38 * 2 tramps after .text and .init.text. So, we only end up with around 3 usable
39 * tramps in total. Set aside 8 just to be sure.
41 #define NUM_FTRACE_TRAMPS 8
42 static unsigned long ftrace_tramps[NUM_FTRACE_TRAMPS];
44 static struct ppc_inst
45 ftrace_call_replace(unsigned long ip, unsigned long addr, int link)
49 addr = ppc_function_entry((void *)addr);
51 /* if (link) set op to 'bl' else 'b' */
52 create_branch(&op, (u32 *)ip, addr, link ? 1 : 0);
58 ftrace_modify_code(unsigned long ip, struct ppc_inst old, struct ppc_inst new)
60 struct ppc_inst replaced;
64 * We are paranoid about modifying text, as if a bug was to happen, it
65 * could cause us to read or write to someplace that could cause harm.
66 * Carefully read and modify the code with probe_kernel_*(), and make
67 * sure what we read is what we expected it to be before modifying it.
70 /* read the text we want to modify */
71 if (copy_inst_from_kernel_nofault(&replaced, (void *)ip))
74 /* Make sure it is what we expect it to be */
75 if (!ppc_inst_equal(replaced, old)) {
76 pr_err("%p: replaced (%s) != old (%s)",
77 (void *)ip, ppc_inst_as_str(replaced), ppc_inst_as_str(old));
81 /* replace the text with the new text */
82 if (patch_instruction((u32 *)ip, new))
89 * Helper functions that are the same for both PPC64 and PPC32.
91 static int test_24bit_addr(unsigned long ip, unsigned long addr)
94 addr = ppc_function_entry((void *)addr);
96 /* use the create_branch to verify that this offset can be branched */
97 return create_branch(&op, (u32 *)ip, addr, 0) == 0;
100 static int is_bl_op(struct ppc_inst op)
102 return (ppc_inst_val(op) & 0xfc000003) == 0x48000001;
105 static int is_b_op(struct ppc_inst op)
107 return (ppc_inst_val(op) & 0xfc000003) == 0x48000000;
110 static unsigned long find_bl_target(unsigned long ip, struct ppc_inst op)
114 offset = (ppc_inst_val(op) & 0x03fffffc);
116 if (offset & 0x02000000)
117 offset |= 0xfe000000;
119 return ip + (long)offset;
122 #ifdef CONFIG_MODULES
125 __ftrace_make_nop(struct module *mod,
126 struct dyn_ftrace *rec, unsigned long addr)
128 unsigned long entry, ptr, tramp;
129 unsigned long ip = rec->ip;
130 struct ppc_inst op, pop;
132 /* read where this goes */
133 if (copy_inst_from_kernel_nofault(&op, (void *)ip)) {
134 pr_err("Fetching opcode failed.\n");
138 /* Make sure that that this is still a 24bit jump */
140 pr_err("Not expected bl: opcode is %s\n", ppc_inst_as_str(op));
144 /* lets find where the pointer goes */
145 tramp = find_bl_target(ip, op);
147 pr_devel("ip:%lx jumps to %lx", ip, tramp);
149 if (module_trampoline_target(mod, tramp, &ptr)) {
150 pr_err("Failed to get trampoline target\n");
154 pr_devel("trampoline target %lx", ptr);
156 entry = ppc_global_function_entry((void *)addr);
157 /* This should match what was called */
159 pr_err("addr %lx does not match expected %lx\n", ptr, entry);
163 #ifdef CONFIG_MPROFILE_KERNEL
164 /* When using -mkernel_profile there is no load to jump over */
165 pop = ppc_inst(PPC_RAW_NOP());
167 if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) {
168 pr_err("Fetching instruction at %lx failed.\n", ip - 4);
172 /* We expect either a mflr r0, or a std r0, LRSAVE(r1) */
173 if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_MFLR(_R0))) &&
174 !ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) {
175 pr_err("Unexpected instruction %s around bl _mcount\n",
176 ppc_inst_as_str(op));
181 * Our original call site looks like:
186 * Milton Miller pointed out that we can not simply nop the branch.
187 * If a task was preempted when calling a trace function, the nops
188 * will remove the way to restore the TOC in r2 and the r2 TOC will
191 * Use a b +8 to jump over the load.
194 pop = ppc_inst(PPC_INST_BRANCH | 8); /* b +8 */
197 * Check what is in the next instruction. We can see ld r2,40(r1), but
198 * on first pass after boot we will see mflr r0.
200 if (copy_inst_from_kernel_nofault(&op, (void *)(ip + 4))) {
201 pr_err("Fetching op failed.\n");
205 if (!ppc_inst_equal(op, ppc_inst(PPC_INST_LD_TOC))) {
206 pr_err("Expected %08lx found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op));
209 #endif /* CONFIG_MPROFILE_KERNEL */
211 if (patch_instruction((u32 *)ip, pop)) {
212 pr_err("Patching NOP failed.\n");
221 __ftrace_make_nop(struct module *mod,
222 struct dyn_ftrace *rec, unsigned long addr)
226 unsigned long ip = rec->ip;
229 if (copy_from_kernel_nofault(&op, (void *)ip, MCOUNT_INSN_SIZE))
232 /* Make sure that that this is still a 24bit jump */
234 pr_err("Not expected bl: opcode is %s\n", ppc_inst_as_str(op));
238 /* lets find where the pointer goes */
239 tramp = find_bl_target(ip, op);
242 * On PPC32 the trampoline looks like:
243 * 0x3d, 0x80, 0x00, 0x00 lis r12,sym@ha
244 * 0x39, 0x8c, 0x00, 0x00 addi r12,r12,sym@l
245 * 0x7d, 0x89, 0x03, 0xa6 mtctr r12
246 * 0x4e, 0x80, 0x04, 0x20 bctr
249 pr_devel("ip:%lx jumps to %lx", ip, tramp);
251 /* Find where the trampoline jumps to */
252 if (copy_from_kernel_nofault(jmp, (void *)tramp, sizeof(jmp))) {
253 pr_err("Failed to read %lx\n", tramp);
257 pr_devel(" %08x %08x ", jmp[0], jmp[1]);
259 /* verify that this is what we expect it to be */
260 if (((jmp[0] & 0xffff0000) != 0x3d800000) ||
261 ((jmp[1] & 0xffff0000) != 0x398c0000) ||
262 (jmp[2] != 0x7d8903a6) ||
263 (jmp[3] != 0x4e800420)) {
264 pr_err("Not a trampoline\n");
268 tramp = (jmp[1] & 0xffff) |
269 ((jmp[0] & 0xffff) << 16);
273 pr_devel(" %lx ", tramp);
276 pr_err("Trampoline location %08lx does not match addr\n",
281 op = ppc_inst(PPC_RAW_NOP());
283 if (patch_instruction((u32 *)ip, op))
289 #endif /* CONFIG_MODULES */
291 static unsigned long find_ftrace_tramp(unsigned long ip)
294 struct ppc_inst instr;
297 * We have the compiler generated long_branch tramps at the end
298 * and we prefer those
300 for (i = NUM_FTRACE_TRAMPS - 1; i >= 0; i--)
301 if (!ftrace_tramps[i])
303 else if (create_branch(&instr, (void *)ip,
304 ftrace_tramps[i], 0) == 0)
305 return ftrace_tramps[i];
310 static int add_ftrace_tramp(unsigned long tramp)
314 for (i = 0; i < NUM_FTRACE_TRAMPS; i++)
315 if (!ftrace_tramps[i]) {
316 ftrace_tramps[i] = tramp;
324 * If this is a compiler generated long_branch trampoline (essentially, a
325 * trampoline that has a branch to _mcount()), we re-write the branch to
326 * instead go to ftrace_[regs_]caller() and note down the location of this
329 static int setup_mcount_compiler_tramp(unsigned long tramp)
334 struct ppc_inst instr;
335 static unsigned long ftrace_plt_tramps[NUM_FTRACE_TRAMPS];
337 /* Is this a known long jump tramp? */
338 for (i = 0; i < NUM_FTRACE_TRAMPS; i++)
339 if (ftrace_tramps[i] == tramp)
342 /* Is this a known plt tramp? */
343 for (i = 0; i < NUM_FTRACE_TRAMPS; i++)
344 if (!ftrace_plt_tramps[i])
346 else if (ftrace_plt_tramps[i] == tramp)
349 /* New trampoline -- read where this goes */
350 if (copy_inst_from_kernel_nofault(&op, (void *)tramp)) {
351 pr_debug("Fetching opcode failed.\n");
355 /* Is this a 24 bit branch? */
357 pr_debug("Trampoline is not a long branch tramp.\n");
361 /* lets find where the pointer goes */
362 ptr = find_bl_target(tramp, op);
364 if (ptr != ppc_global_function_entry((void *)_mcount)) {
365 pr_debug("Trampoline target %p is not _mcount\n", (void *)ptr);
369 /* Let's re-write the tramp to go to ftrace_[regs_]caller */
370 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
371 ptr = ppc_global_function_entry((void *)ftrace_regs_caller);
373 ptr = ppc_global_function_entry((void *)ftrace_caller);
375 if (create_branch(&instr, (void *)tramp, ptr, 0)) {
376 pr_debug("%ps is not reachable from existing mcount tramp\n",
381 if (patch_branch((u32 *)tramp, ptr, 0)) {
382 pr_debug("REL24 out of range!\n");
386 if (add_ftrace_tramp(tramp)) {
387 pr_debug("No tramp locations left\n");
394 static int __ftrace_make_nop_kernel(struct dyn_ftrace *rec, unsigned long addr)
396 unsigned long tramp, ip = rec->ip;
399 /* Read where this goes */
400 if (copy_inst_from_kernel_nofault(&op, (void *)ip)) {
401 pr_err("Fetching opcode failed.\n");
405 /* Make sure that that this is still a 24bit jump */
407 pr_err("Not expected bl: opcode is %s\n", ppc_inst_as_str(op));
411 /* Let's find where the pointer goes */
412 tramp = find_bl_target(ip, op);
414 pr_devel("ip:%lx jumps to %lx", ip, tramp);
416 if (setup_mcount_compiler_tramp(tramp)) {
417 /* Are other trampolines reachable? */
418 if (!find_ftrace_tramp(ip)) {
419 pr_err("No ftrace trampolines reachable from %ps\n",
425 if (patch_instruction((u32 *)ip, ppc_inst(PPC_RAW_NOP()))) {
426 pr_err("Patching NOP failed.\n");
433 int ftrace_make_nop(struct module *mod,
434 struct dyn_ftrace *rec, unsigned long addr)
436 unsigned long ip = rec->ip;
437 struct ppc_inst old, new;
440 * If the calling address is more that 24 bits away,
441 * then we had to use a trampoline to make the call.
442 * Otherwise just update the call site.
444 if (test_24bit_addr(ip, addr)) {
446 old = ftrace_call_replace(ip, addr, 1);
447 new = ppc_inst(PPC_RAW_NOP());
448 return ftrace_modify_code(ip, old, new);
449 } else if (core_kernel_text(ip))
450 return __ftrace_make_nop_kernel(rec, addr);
452 #ifdef CONFIG_MODULES
454 * Out of range jumps are called from modules.
455 * We should either already have a pointer to the module
456 * or it has been passed in.
458 if (!rec->arch.mod) {
460 pr_err("No module loaded addr=%lx\n", addr);
465 if (mod != rec->arch.mod) {
466 pr_err("Record mod %p not equal to passed in mod %p\n",
470 /* nothing to do if mod == rec->arch.mod */
474 return __ftrace_make_nop(mod, rec, addr);
476 /* We should not get here without modules */
478 #endif /* CONFIG_MODULES */
481 #ifdef CONFIG_MODULES
484 * Examine the existing instructions for __ftrace_make_call.
485 * They should effectively be a NOP, and follow formal constraints,
486 * depending on the ABI. Return false if they don't.
488 #ifndef CONFIG_MPROFILE_KERNEL
490 expected_nop_sequence(void *ip, struct ppc_inst op0, struct ppc_inst op1)
498 * The load offset is different depending on the ABI. For simplicity
499 * just mask it out when doing the compare.
501 if (!ppc_inst_equal(op0, ppc_inst(0x48000008)) ||
502 (ppc_inst_val(op1) & 0xffff0000) != 0xe8410000)
508 expected_nop_sequence(void *ip, struct ppc_inst op0, struct ppc_inst op1)
510 /* look for patched "NOP" on ppc64 with -mprofile-kernel */
511 if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_NOP())))
518 __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
520 struct ppc_inst op[2];
521 struct ppc_inst instr;
522 void *ip = (void *)rec->ip;
523 unsigned long entry, ptr, tramp;
524 struct module *mod = rec->arch.mod;
526 /* read where this goes */
527 if (copy_inst_from_kernel_nofault(op, ip))
530 if (copy_inst_from_kernel_nofault(op + 1, ip + 4))
533 if (!expected_nop_sequence(ip, op[0], op[1])) {
534 pr_err("Unexpected call sequence at %p: %s %s\n",
535 ip, ppc_inst_as_str(op[0]), ppc_inst_as_str(op[1]));
539 /* If we never set up ftrace trampoline(s), then bail */
540 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
541 if (!mod->arch.tramp || !mod->arch.tramp_regs) {
543 if (!mod->arch.tramp) {
545 pr_err("No ftrace trampoline\n");
549 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
550 if (rec->flags & FTRACE_FL_REGS)
551 tramp = mod->arch.tramp_regs;
554 tramp = mod->arch.tramp;
556 if (module_trampoline_target(mod, tramp, &ptr)) {
557 pr_err("Failed to get trampoline target\n");
561 pr_devel("trampoline target %lx", ptr);
563 entry = ppc_global_function_entry((void *)addr);
564 /* This should match what was called */
566 pr_err("addr %lx does not match expected %lx\n", ptr, entry);
570 /* Ensure branch is within 24 bits */
571 if (create_branch(&instr, ip, tramp, BRANCH_SET_LINK)) {
572 pr_err("Branch out of range\n");
576 if (patch_branch(ip, tramp, BRANCH_SET_LINK)) {
577 pr_err("REL24 out of range!\n");
584 #else /* !CONFIG_PPC64: */
586 __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
590 u32 *ip = (u32 *)rec->ip;
592 /* read where this goes */
593 if (copy_inst_from_kernel_nofault(&op, ip))
596 /* It should be pointing to a nop */
597 if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_NOP()))) {
598 pr_err("Expected NOP but have %s\n", ppc_inst_as_str(op));
602 /* If we never set up a trampoline to ftrace_caller, then bail */
603 if (!rec->arch.mod->arch.tramp) {
604 pr_err("No ftrace trampoline\n");
608 /* create the branch to the trampoline */
609 err = create_branch(&op, ip, rec->arch.mod->arch.tramp, BRANCH_SET_LINK);
611 pr_err("REL24 out of range!\n");
615 pr_devel("write to %lx\n", rec->ip);
617 if (patch_instruction(ip, op))
622 #endif /* CONFIG_PPC64 */
623 #endif /* CONFIG_MODULES */
625 static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long addr)
628 void *ip = (void *)rec->ip;
629 unsigned long tramp, entry, ptr;
631 /* Make sure we're being asked to patch branch to a known ftrace addr */
632 entry = ppc_global_function_entry((void *)ftrace_caller);
633 ptr = ppc_global_function_entry((void *)addr);
636 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
637 entry = ppc_global_function_entry((void *)ftrace_regs_caller);
640 pr_err("Unknown ftrace addr to patch: %ps\n", (void *)ptr);
642 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
647 /* Make sure we have a nop */
648 if (copy_inst_from_kernel_nofault(&op, ip)) {
649 pr_err("Unable to read ftrace location %p\n", ip);
653 if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_NOP()))) {
654 pr_err("Unexpected call sequence at %p: %s\n", ip, ppc_inst_as_str(op));
658 tramp = find_ftrace_tramp((unsigned long)ip);
660 pr_err("No ftrace trampolines reachable from %ps\n", ip);
664 if (patch_branch(ip, tramp, BRANCH_SET_LINK)) {
665 pr_err("Error patching branch to ftrace tramp!\n");
672 int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
674 unsigned long ip = rec->ip;
675 struct ppc_inst old, new;
678 * If the calling address is more that 24 bits away,
679 * then we had to use a trampoline to make the call.
680 * Otherwise just update the call site.
682 if (test_24bit_addr(ip, addr)) {
684 old = ppc_inst(PPC_RAW_NOP());
685 new = ftrace_call_replace(ip, addr, 1);
686 return ftrace_modify_code(ip, old, new);
687 } else if (core_kernel_text(ip))
688 return __ftrace_make_call_kernel(rec, addr);
690 #ifdef CONFIG_MODULES
692 * Out of range jumps are called from modules.
693 * Being that we are converting from nop, it had better
694 * already have a module defined.
696 if (!rec->arch.mod) {
697 pr_err("No module loaded\n");
701 return __ftrace_make_call(rec, addr);
703 /* We should not get here without modules */
705 #endif /* CONFIG_MODULES */
708 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
709 #ifdef CONFIG_MODULES
711 __ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
715 unsigned long ip = rec->ip;
716 unsigned long entry, ptr, tramp;
717 struct module *mod = rec->arch.mod;
719 /* If we never set up ftrace trampolines, then bail */
720 if (!mod->arch.tramp || !mod->arch.tramp_regs) {
721 pr_err("No ftrace trampoline\n");
725 /* read where this goes */
726 if (copy_inst_from_kernel_nofault(&op, (void *)ip)) {
727 pr_err("Fetching opcode failed.\n");
731 /* Make sure that that this is still a 24bit jump */
733 pr_err("Not expected bl: opcode is %s\n", ppc_inst_as_str(op));
737 /* lets find where the pointer goes */
738 tramp = find_bl_target(ip, op);
739 entry = ppc_global_function_entry((void *)old_addr);
741 pr_devel("ip:%lx jumps to %lx", ip, tramp);
743 if (tramp != entry) {
744 /* old_addr is not within range, so we must have used a trampoline */
745 if (module_trampoline_target(mod, tramp, &ptr)) {
746 pr_err("Failed to get trampoline target\n");
750 pr_devel("trampoline target %lx", ptr);
752 /* This should match what was called */
754 pr_err("addr %lx does not match expected %lx\n", ptr, entry);
759 /* The new target may be within range */
760 if (test_24bit_addr(ip, addr)) {
762 if (patch_branch((u32 *)ip, addr, BRANCH_SET_LINK)) {
763 pr_err("REL24 out of range!\n");
770 if (rec->flags & FTRACE_FL_REGS)
771 tramp = mod->arch.tramp_regs;
773 tramp = mod->arch.tramp;
775 if (module_trampoline_target(mod, tramp, &ptr)) {
776 pr_err("Failed to get trampoline target\n");
780 pr_devel("trampoline target %lx", ptr);
782 entry = ppc_global_function_entry((void *)addr);
783 /* This should match what was called */
785 pr_err("addr %lx does not match expected %lx\n", ptr, entry);
789 /* Ensure branch is within 24 bits */
790 if (create_branch(&op, (u32 *)ip, tramp, BRANCH_SET_LINK)) {
791 pr_err("Branch out of range\n");
795 if (patch_branch((u32 *)ip, tramp, BRANCH_SET_LINK)) {
796 pr_err("REL24 out of range!\n");
804 int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
807 unsigned long ip = rec->ip;
808 struct ppc_inst old, new;
811 * If the calling address is more that 24 bits away,
812 * then we had to use a trampoline to make the call.
813 * Otherwise just update the call site.
815 if (test_24bit_addr(ip, addr) && test_24bit_addr(ip, old_addr)) {
817 old = ftrace_call_replace(ip, old_addr, 1);
818 new = ftrace_call_replace(ip, addr, 1);
819 return ftrace_modify_code(ip, old, new);
820 } else if (core_kernel_text(ip)) {
822 * We always patch out of range locations to go to the regs
823 * variant, so there is nothing to do here
828 #ifdef CONFIG_MODULES
830 * Out of range jumps are called from modules.
832 if (!rec->arch.mod) {
833 pr_err("No module loaded\n");
837 return __ftrace_modify_call(rec, old_addr, addr);
839 /* We should not get here without modules */
841 #endif /* CONFIG_MODULES */
845 int ftrace_update_ftrace_func(ftrace_func_t func)
847 unsigned long ip = (unsigned long)(&ftrace_call);
848 struct ppc_inst old, new;
851 old = ppc_inst_read((u32 *)&ftrace_call);
852 new = ftrace_call_replace(ip, (unsigned long)func, 1);
853 ret = ftrace_modify_code(ip, old, new);
855 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
856 /* Also update the regs callback function */
858 ip = (unsigned long)(&ftrace_regs_call);
859 old = ppc_inst_read((u32 *)&ftrace_regs_call);
860 new = ftrace_call_replace(ip, (unsigned long)func, 1);
861 ret = ftrace_modify_code(ip, old, new);
869 * Use the default ftrace_modify_all_code, but without
872 void arch_ftrace_update_code(int command)
874 ftrace_modify_all_code(command);
878 #define PACATOC offsetof(struct paca_struct, kernel_toc)
880 extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[];
882 void ftrace_free_init_tramp(void)
886 for (i = 0; i < NUM_FTRACE_TRAMPS && ftrace_tramps[i]; i++)
887 if (ftrace_tramps[i] == (unsigned long)ftrace_tramp_init) {
888 ftrace_tramps[i] = 0;
893 int __init ftrace_dyn_arch_init(void)
896 unsigned int *tramp[] = { ftrace_tramp_text, ftrace_tramp_init };
898 0xe98d0000 | PACATOC, /* ld r12,PACATOC(r13) */
899 0x3d8c0000, /* addis r12,r12,<high> */
900 0x398c0000, /* addi r12,r12,<low> */
901 0x7d8903a6, /* mtctr r12 */
902 0x4e800420, /* bctr */
904 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
905 unsigned long addr = ppc_global_function_entry((void *)ftrace_regs_caller);
907 unsigned long addr = ppc_global_function_entry((void *)ftrace_caller);
909 long reladdr = addr - kernel_toc_addr();
911 if (reladdr > 0x7FFFFFFF || reladdr < -(0x80000000L)) {
912 pr_err("Address of %ps out of range of kernel_toc.\n",
917 for (i = 0; i < 2; i++) {
918 memcpy(tramp[i], stub_insns, sizeof(stub_insns));
919 tramp[i][1] |= PPC_HA(reladdr);
920 tramp[i][2] |= PPC_LO(reladdr);
921 add_ftrace_tramp((unsigned long)tramp[i]);
927 int __init ftrace_dyn_arch_init(void)
932 #endif /* CONFIG_DYNAMIC_FTRACE */
934 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
936 extern void ftrace_graph_call(void);
937 extern void ftrace_graph_stub(void);
939 int ftrace_enable_ftrace_graph_caller(void)
941 unsigned long ip = (unsigned long)(&ftrace_graph_call);
942 unsigned long addr = (unsigned long)(&ftrace_graph_caller);
943 unsigned long stub = (unsigned long)(&ftrace_graph_stub);
944 struct ppc_inst old, new;
946 old = ftrace_call_replace(ip, stub, 0);
947 new = ftrace_call_replace(ip, addr, 0);
949 return ftrace_modify_code(ip, old, new);
952 int ftrace_disable_ftrace_graph_caller(void)
954 unsigned long ip = (unsigned long)(&ftrace_graph_call);
955 unsigned long addr = (unsigned long)(&ftrace_graph_caller);
956 unsigned long stub = (unsigned long)(&ftrace_graph_stub);
957 struct ppc_inst old, new;
959 old = ftrace_call_replace(ip, addr, 0);
960 new = ftrace_call_replace(ip, stub, 0);
962 return ftrace_modify_code(ip, old, new);
966 * Hook the return address and push it in the stack of return addrs
967 * in current thread info. Return the address we want to divert to.
969 unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
972 unsigned long return_hooker;
974 if (unlikely(ftrace_graph_is_dead()))
977 if (unlikely(atomic_read(¤t->tracing_graph_pause)))
980 return_hooker = ppc_function_entry(return_to_handler);
982 if (!function_graph_enter(parent, ip, 0, (unsigned long *)sp))
983 parent = return_hooker;
987 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
989 #ifdef PPC64_ELF_ABI_v1
990 char *arch_ftrace_match_adjust(char *str, const char *search)
992 if (str[0] == '.' && search[0] != '.')
997 #endif /* PPC64_ELF_ABI_v1 */