kprobes.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * Kernel Probes (KProbes)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright (C) IBM Corporation, 2002, 2004
  19. *
  20. * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
  21. * Probes initial implementation ( includes contributions from
  22. * Rusty Russell).
  23. * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
  24. * interface to access function arguments.
  25. * 2004-Nov Ananth N Mavinakayanahalli <ananth@in.ibm.com> kprobes port
  26. * for PPC64
  27. */
  28. #include <linux/kprobes.h>
  29. #include <linux/ptrace.h>
  30. #include <linux/preempt.h>
  31. #include <linux/extable.h>
  32. #include <linux/kdebug.h>
  33. #include <linux/slab.h>
  34. #include <asm/code-patching.h>
  35. #include <asm/cacheflush.h>
  36. #include <asm/sstep.h>
  37. #include <asm/sections.h>
  38. #include <linux/uaccess.h>
  39. DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
  40. DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
  41. struct kretprobe_blackpoint kretprobe_blacklist[] = {{NULL, NULL}};
  42. bool arch_within_kprobe_blacklist(unsigned long addr)
  43. {
  44. return (addr >= (unsigned long)__kprobes_text_start &&
  45. addr < (unsigned long)__kprobes_text_end) ||
  46. (addr >= (unsigned long)_stext &&
  47. addr < (unsigned long)__head_end);
  48. }
  49. kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)
  50. {
  51. kprobe_opcode_t *addr = NULL;
  52. #ifdef PPC64_ELF_ABI_v2
  53. /* PPC64 ABIv2 needs local entry point */
  54. addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
  55. if (addr && !offset) {
  56. #ifdef CONFIG_KPROBES_ON_FTRACE
  57. unsigned long faddr;
  58. /*
  59. * Per livepatch.h, ftrace location is always within the first
  60. * 16 bytes of a function on powerpc with -mprofile-kernel.
  61. */
  62. faddr = ftrace_location_range((unsigned long)addr,
  63. (unsigned long)addr + 16);
  64. if (faddr)
  65. addr = (kprobe_opcode_t *)faddr;
  66. else
  67. #endif
  68. addr = (kprobe_opcode_t *)ppc_function_entry(addr);
  69. }
  70. #elif defined(PPC64_ELF_ABI_v1)
  71. /*
  72. * 64bit powerpc ABIv1 uses function descriptors:
  73. * - Check for the dot variant of the symbol first.
  74. * - If that fails, try looking up the symbol provided.
  75. *
  76. * This ensures we always get to the actual symbol and not
  77. * the descriptor.
  78. *
  79. * Also handle <module:symbol> format.
  80. */
  81. char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN];
  82. bool dot_appended = false;
  83. const char *c;
  84. ssize_t ret = 0;
  85. int len = 0;
  86. if ((c = strnchr(name, MODULE_NAME_LEN, ':')) != NULL) {
  87. c++;
  88. len = c - name;
  89. memcpy(dot_name, name, len);
  90. } else
  91. c = name;
  92. if (*c != '\0' && *c != '.') {
  93. dot_name[len++] = '.';
  94. dot_appended = true;
  95. }
  96. ret = strscpy(dot_name + len, c, KSYM_NAME_LEN);
  97. if (ret > 0)
  98. addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name);
  99. /* Fallback to the original non-dot symbol lookup */
  100. if (!addr && dot_appended)
  101. addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
  102. #else
  103. addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
  104. #endif
  105. return addr;
  106. }
  107. int arch_prepare_kprobe(struct kprobe *p)
  108. {
  109. int ret = 0;
  110. kprobe_opcode_t insn = *p->addr;
  111. if ((unsigned long)p->addr & 0x03) {
  112. printk("Attempt to register kprobe at an unaligned address\n");
  113. ret = -EINVAL;
  114. } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) {
  115. printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n");
  116. ret = -EINVAL;
  117. }
  118. /* insn must be on a special executable page on ppc64. This is
  119. * not explicitly required on ppc32 (right now), but it doesn't hurt */
  120. if (!ret) {
  121. p->ainsn.insn = get_insn_slot();
  122. if (!p->ainsn.insn)
  123. ret = -ENOMEM;
  124. }
  125. if (!ret) {
  126. memcpy(p->ainsn.insn, p->addr,
  127. MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
  128. p->opcode = *p->addr;
  129. flush_icache_range((unsigned long)p->ainsn.insn,
  130. (unsigned long)p->ainsn.insn + sizeof(kprobe_opcode_t));
  131. }
  132. p->ainsn.boostable = 0;
  133. return ret;
  134. }
  135. NOKPROBE_SYMBOL(arch_prepare_kprobe);
  136. void arch_arm_kprobe(struct kprobe *p)
  137. {
  138. patch_instruction(p->addr, BREAKPOINT_INSTRUCTION);
  139. }
  140. NOKPROBE_SYMBOL(arch_arm_kprobe);
  141. void arch_disarm_kprobe(struct kprobe *p)
  142. {
  143. patch_instruction(p->addr, p->opcode);
  144. }
  145. NOKPROBE_SYMBOL(arch_disarm_kprobe);
  146. void arch_remove_kprobe(struct kprobe *p)
  147. {
  148. if (p->ainsn.insn) {
  149. free_insn_slot(p->ainsn.insn, 0);
  150. p->ainsn.insn = NULL;
  151. }
  152. }
  153. NOKPROBE_SYMBOL(arch_remove_kprobe);
  154. static nokprobe_inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
  155. {
  156. enable_single_step(regs);
  157. /*
  158. * On powerpc we should single step on the original
  159. * instruction even if the probed insn is a trap
  160. * variant as values in regs could play a part in
  161. * if the trap is taken or not
  162. */
  163. regs->nip = (unsigned long)p->ainsn.insn;
  164. }
  165. static nokprobe_inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
  166. {
  167. kcb->prev_kprobe.kp = kprobe_running();
  168. kcb->prev_kprobe.status = kcb->kprobe_status;
  169. kcb->prev_kprobe.saved_msr = kcb->kprobe_saved_msr;
  170. }
  171. static nokprobe_inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
  172. {
  173. __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
  174. kcb->kprobe_status = kcb->prev_kprobe.status;
  175. kcb->kprobe_saved_msr = kcb->prev_kprobe.saved_msr;
  176. }
  177. static nokprobe_inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
  178. struct kprobe_ctlblk *kcb)
  179. {
  180. __this_cpu_write(current_kprobe, p);
  181. kcb->kprobe_saved_msr = regs->msr;
  182. }
  183. bool arch_kprobe_on_func_entry(unsigned long offset)
  184. {
  185. #ifdef PPC64_ELF_ABI_v2
  186. #ifdef CONFIG_KPROBES_ON_FTRACE
  187. return offset <= 16;
  188. #else
  189. return offset <= 8;
  190. #endif
  191. #else
  192. return !offset;
  193. #endif
  194. }
  195. void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs)
  196. {
  197. ri->ret_addr = (kprobe_opcode_t *)regs->link;
  198. /* Replace the return addr with trampoline addr */
  199. regs->link = (unsigned long)kretprobe_trampoline;
  200. }
  201. NOKPROBE_SYMBOL(arch_prepare_kretprobe);
  202. static int try_to_emulate(struct kprobe *p, struct pt_regs *regs)
  203. {
  204. int ret;
  205. unsigned int insn = *p->ainsn.insn;
  206. /* regs->nip is also adjusted if emulate_step returns 1 */
  207. ret = emulate_step(regs, insn);
  208. if (ret > 0) {
  209. /*
  210. * Once this instruction has been boosted
  211. * successfully, set the boostable flag
  212. */
  213. if (unlikely(p->ainsn.boostable == 0))
  214. p->ainsn.boostable = 1;
  215. } else if (ret < 0) {
  216. /*
  217. * We don't allow kprobes on mtmsr(d)/rfi(d), etc.
  218. * So, we should never get here... but, its still
  219. * good to catch them, just in case...
  220. */
  221. printk("Can't step on instruction %x\n", insn);
  222. BUG();
  223. } else {
  224. /*
  225. * If we haven't previously emulated this instruction, then it
  226. * can't be boosted. Note it down so we don't try to do so again.
  227. *
  228. * If, however, we had emulated this instruction in the past,
  229. * then this is just an error with the current run (for
  230. * instance, exceptions due to a load/store). We return 0 so
  231. * that this is now single-stepped, but continue to try
  232. * emulating it in subsequent probe hits.
  233. */
  234. if (unlikely(p->ainsn.boostable != 1))
  235. p->ainsn.boostable = -1;
  236. }
  237. return ret;
  238. }
  239. NOKPROBE_SYMBOL(try_to_emulate);
  240. int kprobe_handler(struct pt_regs *regs)
  241. {
  242. struct kprobe *p;
  243. int ret = 0;
  244. unsigned int *addr = (unsigned int *)regs->nip;
  245. struct kprobe_ctlblk *kcb;
  246. if (user_mode(regs))
  247. return 0;
  248. /*
  249. * We don't want to be preempted for the entire
  250. * duration of kprobe processing
  251. */
  252. preempt_disable();
  253. kcb = get_kprobe_ctlblk();
  254. /* Check we're not actually recursing */
  255. if (kprobe_running()) {
  256. p = get_kprobe(addr);
  257. if (p) {
  258. kprobe_opcode_t insn = *p->ainsn.insn;
  259. if (kcb->kprobe_status == KPROBE_HIT_SS &&
  260. is_trap(insn)) {
  261. /* Turn off 'trace' bits */
  262. regs->msr &= ~MSR_SINGLESTEP;
  263. regs->msr |= kcb->kprobe_saved_msr;
  264. goto no_kprobe;
  265. }
  266. /* We have reentered the kprobe_handler(), since
  267. * another probe was hit while within the handler.
  268. * We here save the original kprobes variables and
  269. * just single step on the instruction of the new probe
  270. * without calling any user handlers.
  271. */
  272. save_previous_kprobe(kcb);
  273. set_current_kprobe(p, regs, kcb);
  274. kprobes_inc_nmissed_count(p);
  275. kcb->kprobe_status = KPROBE_REENTER;
  276. if (p->ainsn.boostable >= 0) {
  277. ret = try_to_emulate(p, regs);
  278. if (ret > 0) {
  279. restore_previous_kprobe(kcb);
  280. preempt_enable_no_resched();
  281. return 1;
  282. }
  283. }
  284. prepare_singlestep(p, regs);
  285. return 1;
  286. } else {
  287. if (*addr != BREAKPOINT_INSTRUCTION) {
  288. /* If trap variant, then it belongs not to us */
  289. kprobe_opcode_t cur_insn = *addr;
  290. if (is_trap(cur_insn))
  291. goto no_kprobe;
  292. /* The breakpoint instruction was removed by
  293. * another cpu right after we hit, no further
  294. * handling of this interrupt is appropriate
  295. */
  296. ret = 1;
  297. goto no_kprobe;
  298. }
  299. p = __this_cpu_read(current_kprobe);
  300. if (p->break_handler && p->break_handler(p, regs)) {
  301. if (!skip_singlestep(p, regs, kcb))
  302. goto ss_probe;
  303. ret = 1;
  304. }
  305. }
  306. goto no_kprobe;
  307. }
  308. p = get_kprobe(addr);
  309. if (!p) {
  310. if (*addr != BREAKPOINT_INSTRUCTION) {
  311. /*
  312. * PowerPC has multiple variants of the "trap"
  313. * instruction. If the current instruction is a
  314. * trap variant, it could belong to someone else
  315. */
  316. kprobe_opcode_t cur_insn = *addr;
  317. if (is_trap(cur_insn))
  318. goto no_kprobe;
  319. /*
  320. * The breakpoint instruction was removed right
  321. * after we hit it. Another cpu has removed
  322. * either a probepoint or a debugger breakpoint
  323. * at this address. In either case, no further
  324. * handling of this interrupt is appropriate.
  325. */
  326. ret = 1;
  327. }
  328. /* Not one of ours: let kernel handle it */
  329. goto no_kprobe;
  330. }
  331. kcb->kprobe_status = KPROBE_HIT_ACTIVE;
  332. set_current_kprobe(p, regs, kcb);
  333. if (p->pre_handler && p->pre_handler(p, regs))
  334. /* handler has already set things up, so skip ss setup */
  335. return 1;
  336. ss_probe:
  337. if (p->ainsn.boostable >= 0) {
  338. ret = try_to_emulate(p, regs);
  339. if (ret > 0) {
  340. if (p->post_handler)
  341. p->post_handler(p, regs, 0);
  342. kcb->kprobe_status = KPROBE_HIT_SSDONE;
  343. reset_current_kprobe();
  344. preempt_enable_no_resched();
  345. return 1;
  346. }
  347. }
  348. prepare_singlestep(p, regs);
  349. kcb->kprobe_status = KPROBE_HIT_SS;
  350. return 1;
  351. no_kprobe:
  352. preempt_enable_no_resched();
  353. return ret;
  354. }
  355. NOKPROBE_SYMBOL(kprobe_handler);
  356. /*
  357. * Function return probe trampoline:
  358. * - init_kprobes() establishes a probepoint here
  359. * - When the probed function returns, this probe
  360. * causes the handlers to fire
  361. */
  362. asm(".global kretprobe_trampoline\n"
  363. ".type kretprobe_trampoline, @function\n"
  364. "kretprobe_trampoline:\n"
  365. "nop\n"
  366. "blr\n"
  367. ".size kretprobe_trampoline, .-kretprobe_trampoline\n");
  368. /*
  369. * Called when the probe at kretprobe trampoline is hit
  370. */
  371. static int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
  372. {
  373. struct kretprobe_instance *ri = NULL;
  374. struct hlist_head *head, empty_rp;
  375. struct hlist_node *tmp;
  376. unsigned long flags, orig_ret_address = 0;
  377. unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
  378. INIT_HLIST_HEAD(&empty_rp);
  379. kretprobe_hash_lock(current, &head, &flags);
  380. /*
  381. * It is possible to have multiple instances associated with a given
  382. * task either because an multiple functions in the call path
  383. * have a return probe installed on them, and/or more than one return
  384. * return probe was registered for a target function.
  385. *
  386. * We can handle this because:
  387. * - instances are always inserted at the head of the list
  388. * - when multiple return probes are registered for the same
  389. * function, the first instance's ret_addr will point to the
  390. * real return address, and all the rest will point to
  391. * kretprobe_trampoline
  392. */
  393. hlist_for_each_entry_safe(ri, tmp, head, hlist) {
  394. if (ri->task != current)
  395. /* another task is sharing our hash bucket */
  396. continue;
  397. if (ri->rp && ri->rp->handler)
  398. ri->rp->handler(ri, regs);
  399. orig_ret_address = (unsigned long)ri->ret_addr;
  400. recycle_rp_inst(ri, &empty_rp);
  401. if (orig_ret_address != trampoline_address)
  402. /*
  403. * This is the real return address. Any other
  404. * instances associated with this task are for
  405. * other calls deeper on the call stack
  406. */
  407. break;
  408. }
  409. kretprobe_assert(ri, orig_ret_address, trampoline_address);
  410. regs->nip = orig_ret_address;
  411. /*
  412. * Make LR point to the orig_ret_address.
  413. * When the 'nop' inside the kretprobe_trampoline
  414. * is optimized, we can do a 'blr' after executing the
  415. * detour buffer code.
  416. */
  417. regs->link = orig_ret_address;
  418. reset_current_kprobe();
  419. kretprobe_hash_unlock(current, &flags);
  420. preempt_enable_no_resched();
  421. hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
  422. hlist_del(&ri->hlist);
  423. kfree(ri);
  424. }
  425. /*
  426. * By returning a non-zero value, we are telling
  427. * kprobe_handler() that we don't want the post_handler
  428. * to run (and have re-enabled preemption)
  429. */
  430. return 1;
  431. }
  432. NOKPROBE_SYMBOL(trampoline_probe_handler);
  433. /*
  434. * Called after single-stepping. p->addr is the address of the
  435. * instruction whose first byte has been replaced by the "breakpoint"
  436. * instruction. To avoid the SMP problems that can occur when we
  437. * temporarily put back the original opcode to single-step, we
  438. * single-stepped a copy of the instruction. The address of this
  439. * copy is p->ainsn.insn.
  440. */
  441. int kprobe_post_handler(struct pt_regs *regs)
  442. {
  443. struct kprobe *cur = kprobe_running();
  444. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  445. if (!cur || user_mode(regs))
  446. return 0;
  447. /* make sure we got here for instruction we have a kprobe on */
  448. if (((unsigned long)cur->ainsn.insn + 4) != regs->nip)
  449. return 0;
  450. if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
  451. kcb->kprobe_status = KPROBE_HIT_SSDONE;
  452. cur->post_handler(cur, regs, 0);
  453. }
  454. /* Adjust nip to after the single-stepped instruction */
  455. regs->nip = (unsigned long)cur->addr + 4;
  456. regs->msr |= kcb->kprobe_saved_msr;
  457. /*Restore back the original saved kprobes variables and continue. */
  458. if (kcb->kprobe_status == KPROBE_REENTER) {
  459. restore_previous_kprobe(kcb);
  460. goto out;
  461. }
  462. reset_current_kprobe();
  463. out:
  464. preempt_enable_no_resched();
  465. /*
  466. * if somebody else is singlestepping across a probe point, msr
  467. * will have DE/SE set, in which case, continue the remaining processing
  468. * of do_debug, as if this is not a probe hit.
  469. */
  470. if (regs->msr & MSR_SINGLESTEP)
  471. return 0;
  472. return 1;
  473. }
  474. NOKPROBE_SYMBOL(kprobe_post_handler);
  475. int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
  476. {
  477. struct kprobe *cur = kprobe_running();
  478. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  479. const struct exception_table_entry *entry;
  480. switch(kcb->kprobe_status) {
  481. case KPROBE_HIT_SS:
  482. case KPROBE_REENTER:
  483. /*
  484. * We are here because the instruction being single
  485. * stepped caused a page fault. We reset the current
  486. * kprobe and the nip points back to the probe address
  487. * and allow the page fault handler to continue as a
  488. * normal page fault.
  489. */
  490. regs->nip = (unsigned long)cur->addr;
  491. regs->msr &= ~MSR_SINGLESTEP; /* Turn off 'trace' bits */
  492. regs->msr |= kcb->kprobe_saved_msr;
  493. if (kcb->kprobe_status == KPROBE_REENTER)
  494. restore_previous_kprobe(kcb);
  495. else
  496. reset_current_kprobe();
  497. preempt_enable_no_resched();
  498. break;
  499. case KPROBE_HIT_ACTIVE:
  500. case KPROBE_HIT_SSDONE:
  501. /*
  502. * We increment the nmissed count for accounting,
  503. * we can also use npre/npostfault count for accounting
  504. * these specific fault cases.
  505. */
  506. kprobes_inc_nmissed_count(cur);
  507. /*
  508. * We come here because instructions in the pre/post
  509. * handler caused the page_fault, this could happen
  510. * if handler tries to access user space by
  511. * copy_from_user(), get_user() etc. Let the
  512. * user-specified handler try to fix it first.
  513. */
  514. if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
  515. return 1;
  516. /*
  517. * In case the user-specified fault handler returned
  518. * zero, try to fix up.
  519. */
  520. if ((entry = search_exception_tables(regs->nip)) != NULL) {
  521. regs->nip = extable_fixup(entry);
  522. return 1;
  523. }
  524. /*
  525. * fixup_exception() could not handle it,
  526. * Let do_page_fault() fix it.
  527. */
  528. break;
  529. default:
  530. break;
  531. }
  532. return 0;
  533. }
  534. NOKPROBE_SYMBOL(kprobe_fault_handler);
  535. unsigned long arch_deref_entry_point(void *entry)
  536. {
  537. #ifdef PPC64_ELF_ABI_v1
  538. if (!kernel_text_address((unsigned long)entry))
  539. return ppc_global_function_entry(entry);
  540. else
  541. #endif
  542. return (unsigned long)entry;
  543. }
  544. NOKPROBE_SYMBOL(arch_deref_entry_point);
  545. int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
  546. {
  547. struct jprobe *jp = container_of(p, struct jprobe, kp);
  548. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  549. memcpy(&kcb->jprobe_saved_regs, regs, sizeof(struct pt_regs));
  550. /* setup return addr to the jprobe handler routine */
  551. regs->nip = arch_deref_entry_point(jp->entry);
  552. #ifdef PPC64_ELF_ABI_v2
  553. regs->gpr[12] = (unsigned long)jp->entry;
  554. #elif defined(PPC64_ELF_ABI_v1)
  555. regs->gpr[2] = (unsigned long)(((func_descr_t *)jp->entry)->toc);
  556. #endif
  557. /*
  558. * jprobes use jprobe_return() which skips the normal return
  559. * path of the function, and this messes up the accounting of the
  560. * function graph tracer.
  561. *
  562. * Pause function graph tracing while performing the jprobe function.
  563. */
  564. pause_graph_tracing();
  565. return 1;
  566. }
  567. NOKPROBE_SYMBOL(setjmp_pre_handler);
  568. void __used jprobe_return(void)
  569. {
  570. asm volatile("jprobe_return_trap:\n"
  571. "trap\n"
  572. ::: "memory");
  573. }
  574. NOKPROBE_SYMBOL(jprobe_return);
  575. int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
  576. {
  577. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  578. if (regs->nip != ppc_kallsyms_lookup_name("jprobe_return_trap")) {
  579. pr_debug("longjmp_break_handler NIP (0x%lx) does not match jprobe_return_trap (0x%lx)\n",
  580. regs->nip, ppc_kallsyms_lookup_name("jprobe_return_trap"));
  581. return 0;
  582. }
  583. memcpy(regs, &kcb->jprobe_saved_regs, sizeof(struct pt_regs));
  584. /* It's OK to start function graph tracing again */
  585. unpause_graph_tracing();
  586. preempt_enable_no_resched();
  587. return 1;
  588. }
  589. NOKPROBE_SYMBOL(longjmp_break_handler);
  590. static struct kprobe trampoline_p = {
  591. .addr = (kprobe_opcode_t *) &kretprobe_trampoline,
  592. .pre_handler = trampoline_probe_handler
  593. };
  594. int __init arch_init_kprobes(void)
  595. {
  596. return register_kprobe(&trampoline_p);
  597. }
  598. int arch_trampoline_kprobe(struct kprobe *p)
  599. {
  600. if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline)
  601. return 1;
  602. return 0;
  603. }
  604. NOKPROBE_SYMBOL(arch_trampoline_kprobe);