ftrace.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Dynamic function tracing support.
  4. *
  5. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  6. *
  7. * Thanks goes to Ingo Molnar, for suggesting the idea.
  8. * Mathieu Desnoyers, for suggesting postponing the modifications.
  9. * Arjan van de Ven, for keeping me straight, and explaining to me
  10. * the dangers of modifying code on the run.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/spinlock.h>
  14. #include <linux/hardirq.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/ftrace.h>
  17. #include <linux/percpu.h>
  18. #include <linux/sched.h>
  19. #include <linux/slab.h>
  20. #include <linux/init.h>
  21. #include <linux/list.h>
  22. #include <linux/module.h>
  23. #include <linux/memory.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/set_memory.h>
  26. #include <linux/execmem.h>
  27. #include <trace/syscall.h>
  28. #include <asm/kprobes.h>
  29. #include <asm/ftrace.h>
  30. #include <asm/nops.h>
  31. #include <asm/text-patching.h>
  32. #ifdef CONFIG_DYNAMIC_FTRACE
  33. static int ftrace_poke_late = 0;
  34. void ftrace_arch_code_modify_prepare(void)
  35. __acquires(&text_mutex)
  36. {
  37. /*
  38. * Need to grab text_mutex to prevent a race from module loading
  39. * and live kernel patching from changing the text permissions while
  40. * ftrace has it set to "read/write".
  41. */
  42. mutex_lock(&text_mutex);
  43. ftrace_poke_late = 1;
  44. }
  45. void ftrace_arch_code_modify_post_process(void)
  46. __releases(&text_mutex)
  47. {
  48. /*
  49. * ftrace_make_{call,nop}() may be called during
  50. * module load, and we need to finish the text_poke_queue()
  51. * that they do, here.
  52. */
  53. text_poke_finish();
  54. ftrace_poke_late = 0;
  55. mutex_unlock(&text_mutex);
  56. }
  57. static const char *ftrace_nop_replace(void)
  58. {
  59. return x86_nops[5];
  60. }
  61. static const char *ftrace_call_replace(unsigned long ip, unsigned long addr)
  62. {
  63. /*
  64. * No need to translate into a callthunk. The trampoline does
  65. * the depth accounting itself.
  66. */
  67. return text_gen_insn(CALL_INSN_OPCODE, (void *)ip, (void *)addr);
  68. }
  69. static int ftrace_verify_code(unsigned long ip, const char *old_code)
  70. {
  71. char cur_code[MCOUNT_INSN_SIZE];
  72. /*
  73. * Note:
  74. * We are paranoid about modifying text, as if a bug was to happen, it
  75. * could cause us to read or write to someplace that could cause harm.
  76. * Carefully read and modify the code with probe_kernel_*(), and make
  77. * sure what we read is what we expected it to be before modifying it.
  78. */
  79. /* read the text we want to modify */
  80. if (copy_from_kernel_nofault(cur_code, (void *)ip, MCOUNT_INSN_SIZE)) {
  81. WARN_ON(1);
  82. return -EFAULT;
  83. }
  84. /* Make sure it is what we expect it to be */
  85. if (memcmp(cur_code, old_code, MCOUNT_INSN_SIZE) != 0) {
  86. ftrace_expected = old_code;
  87. WARN_ON(1);
  88. return -EINVAL;
  89. }
  90. return 0;
  91. }
  92. /*
  93. * Marked __ref because it calls text_poke_early() which is .init.text. That is
  94. * ok because that call will happen early, during boot, when .init sections are
  95. * still present.
  96. */
  97. static int __ref
  98. ftrace_modify_code_direct(unsigned long ip, const char *old_code,
  99. const char *new_code)
  100. {
  101. int ret = ftrace_verify_code(ip, old_code);
  102. if (ret)
  103. return ret;
  104. /* replace the text with the new text */
  105. if (ftrace_poke_late)
  106. text_poke_queue((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL);
  107. else
  108. text_poke_early((void *)ip, new_code, MCOUNT_INSN_SIZE);
  109. return 0;
  110. }
  111. int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr)
  112. {
  113. unsigned long ip = rec->ip;
  114. const char *new, *old;
  115. old = ftrace_call_replace(ip, addr);
  116. new = ftrace_nop_replace();
  117. /*
  118. * On boot up, and when modules are loaded, the MCOUNT_ADDR
  119. * is converted to a nop, and will never become MCOUNT_ADDR
  120. * again. This code is either running before SMP (on boot up)
  121. * or before the code will ever be executed (module load).
  122. * We do not want to use the breakpoint version in this case,
  123. * just modify the code directly.
  124. */
  125. if (addr == MCOUNT_ADDR)
  126. return ftrace_modify_code_direct(ip, old, new);
  127. /*
  128. * x86 overrides ftrace_replace_code -- this function will never be used
  129. * in this case.
  130. */
  131. WARN_ONCE(1, "invalid use of ftrace_make_nop");
  132. return -EINVAL;
  133. }
  134. int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
  135. {
  136. unsigned long ip = rec->ip;
  137. const char *new, *old;
  138. old = ftrace_nop_replace();
  139. new = ftrace_call_replace(ip, addr);
  140. /* Should only be called when module is loaded */
  141. return ftrace_modify_code_direct(rec->ip, old, new);
  142. }
  143. /*
  144. * Should never be called:
  145. * As it is only called by __ftrace_replace_code() which is called by
  146. * ftrace_replace_code() that x86 overrides, and by ftrace_update_code()
  147. * which is called to turn mcount into nops or nops into function calls
  148. * but not to convert a function from not using regs to one that uses
  149. * regs, which ftrace_modify_call() is for.
  150. */
  151. int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  152. unsigned long addr)
  153. {
  154. WARN_ON(1);
  155. return -EINVAL;
  156. }
  157. int ftrace_update_ftrace_func(ftrace_func_t func)
  158. {
  159. unsigned long ip;
  160. const char *new;
  161. ip = (unsigned long)(&ftrace_call);
  162. new = ftrace_call_replace(ip, (unsigned long)func);
  163. text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL);
  164. ip = (unsigned long)(&ftrace_regs_call);
  165. new = ftrace_call_replace(ip, (unsigned long)func);
  166. text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL);
  167. return 0;
  168. }
  169. void ftrace_replace_code(int enable)
  170. {
  171. struct ftrace_rec_iter *iter;
  172. struct dyn_ftrace *rec;
  173. const char *new, *old;
  174. int ret;
  175. for_ftrace_rec_iter(iter) {
  176. rec = ftrace_rec_iter_record(iter);
  177. switch (ftrace_test_record(rec, enable)) {
  178. case FTRACE_UPDATE_IGNORE:
  179. default:
  180. continue;
  181. case FTRACE_UPDATE_MAKE_CALL:
  182. old = ftrace_nop_replace();
  183. break;
  184. case FTRACE_UPDATE_MODIFY_CALL:
  185. case FTRACE_UPDATE_MAKE_NOP:
  186. old = ftrace_call_replace(rec->ip, ftrace_get_addr_curr(rec));
  187. break;
  188. }
  189. ret = ftrace_verify_code(rec->ip, old);
  190. if (ret) {
  191. ftrace_expected = old;
  192. ftrace_bug(ret, rec);
  193. ftrace_expected = NULL;
  194. return;
  195. }
  196. }
  197. for_ftrace_rec_iter(iter) {
  198. rec = ftrace_rec_iter_record(iter);
  199. switch (ftrace_test_record(rec, enable)) {
  200. case FTRACE_UPDATE_IGNORE:
  201. default:
  202. continue;
  203. case FTRACE_UPDATE_MAKE_CALL:
  204. case FTRACE_UPDATE_MODIFY_CALL:
  205. new = ftrace_call_replace(rec->ip, ftrace_get_addr_new(rec));
  206. break;
  207. case FTRACE_UPDATE_MAKE_NOP:
  208. new = ftrace_nop_replace();
  209. break;
  210. }
  211. text_poke_queue((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL);
  212. ftrace_update_record(rec, enable);
  213. }
  214. text_poke_finish();
  215. }
  216. void arch_ftrace_update_code(int command)
  217. {
  218. ftrace_modify_all_code(command);
  219. }
  220. /* Currently only x86_64 supports dynamic trampolines */
  221. #ifdef CONFIG_X86_64
  222. static inline void *alloc_tramp(unsigned long size)
  223. {
  224. return execmem_alloc(EXECMEM_FTRACE, size);
  225. }
  226. static inline void tramp_free(void *tramp)
  227. {
  228. execmem_free(tramp);
  229. }
  230. /* Defined as markers to the end of the ftrace default trampolines */
  231. extern void ftrace_regs_caller_end(void);
  232. extern void ftrace_caller_end(void);
  233. extern void ftrace_caller_op_ptr(void);
  234. extern void ftrace_regs_caller_op_ptr(void);
  235. extern void ftrace_regs_caller_jmp(void);
  236. /* movq function_trace_op(%rip), %rdx */
  237. /* 0x48 0x8b 0x15 <offset-to-ftrace_trace_op (4 bytes)> */
  238. #define OP_REF_SIZE 7
  239. /*
  240. * The ftrace_ops is passed to the function callback. Since the
  241. * trampoline only services a single ftrace_ops, we can pass in
  242. * that ops directly.
  243. *
  244. * The ftrace_op_code_union is used to create a pointer to the
  245. * ftrace_ops that will be passed to the callback function.
  246. */
  247. union ftrace_op_code_union {
  248. char code[OP_REF_SIZE];
  249. struct {
  250. char op[3];
  251. int offset;
  252. } __attribute__((packed));
  253. };
  254. #define RET_SIZE \
  255. (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) ? 5 : 1 + IS_ENABLED(CONFIG_MITIGATION_SLS))
  256. static unsigned long
  257. create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
  258. {
  259. unsigned long start_offset;
  260. unsigned long end_offset;
  261. unsigned long op_offset;
  262. unsigned long call_offset;
  263. unsigned long jmp_offset;
  264. unsigned long offset;
  265. unsigned long npages;
  266. unsigned long size;
  267. unsigned long *ptr;
  268. void *trampoline;
  269. void *ip, *dest;
  270. /* 48 8b 15 <offset> is movq <offset>(%rip), %rdx */
  271. unsigned const char op_ref[] = { 0x48, 0x8b, 0x15 };
  272. unsigned const char retq[] = { RET_INSN_OPCODE, INT3_INSN_OPCODE };
  273. union ftrace_op_code_union op_ptr;
  274. int ret;
  275. if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) {
  276. start_offset = (unsigned long)ftrace_regs_caller;
  277. end_offset = (unsigned long)ftrace_regs_caller_end;
  278. op_offset = (unsigned long)ftrace_regs_caller_op_ptr;
  279. call_offset = (unsigned long)ftrace_regs_call;
  280. jmp_offset = (unsigned long)ftrace_regs_caller_jmp;
  281. } else {
  282. start_offset = (unsigned long)ftrace_caller;
  283. end_offset = (unsigned long)ftrace_caller_end;
  284. op_offset = (unsigned long)ftrace_caller_op_ptr;
  285. call_offset = (unsigned long)ftrace_call;
  286. jmp_offset = 0;
  287. }
  288. size = end_offset - start_offset;
  289. /*
  290. * Allocate enough size to store the ftrace_caller code,
  291. * the iret , as well as the address of the ftrace_ops this
  292. * trampoline is used for.
  293. */
  294. trampoline = alloc_tramp(size + RET_SIZE + sizeof(void *));
  295. if (!trampoline)
  296. return 0;
  297. *tramp_size = size + RET_SIZE + sizeof(void *);
  298. npages = DIV_ROUND_UP(*tramp_size, PAGE_SIZE);
  299. /* Copy ftrace_caller onto the trampoline memory */
  300. ret = copy_from_kernel_nofault(trampoline, (void *)start_offset, size);
  301. if (WARN_ON(ret < 0))
  302. goto fail;
  303. ip = trampoline + size;
  304. if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
  305. __text_gen_insn(ip, JMP32_INSN_OPCODE, ip, x86_return_thunk, JMP32_INSN_SIZE);
  306. else
  307. memcpy(ip, retq, sizeof(retq));
  308. /* No need to test direct calls on created trampolines */
  309. if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) {
  310. /* NOP the jnz 1f; but make sure it's a 2 byte jnz */
  311. ip = trampoline + (jmp_offset - start_offset);
  312. if (WARN_ON(*(char *)ip != 0x75))
  313. goto fail;
  314. ret = copy_from_kernel_nofault(ip, x86_nops[2], 2);
  315. if (ret < 0)
  316. goto fail;
  317. }
  318. /*
  319. * The address of the ftrace_ops that is used for this trampoline
  320. * is stored at the end of the trampoline. This will be used to
  321. * load the third parameter for the callback. Basically, that
  322. * location at the end of the trampoline takes the place of
  323. * the global function_trace_op variable.
  324. */
  325. ptr = (unsigned long *)(trampoline + size + RET_SIZE);
  326. *ptr = (unsigned long)ops;
  327. op_offset -= start_offset;
  328. memcpy(&op_ptr, trampoline + op_offset, OP_REF_SIZE);
  329. /* Are we pointing to the reference? */
  330. if (WARN_ON(memcmp(op_ptr.op, op_ref, 3) != 0))
  331. goto fail;
  332. /* Load the contents of ptr into the callback parameter */
  333. offset = (unsigned long)ptr;
  334. offset -= (unsigned long)trampoline + op_offset + OP_REF_SIZE;
  335. op_ptr.offset = offset;
  336. /* put in the new offset to the ftrace_ops */
  337. memcpy(trampoline + op_offset, &op_ptr, OP_REF_SIZE);
  338. /* put in the call to the function */
  339. mutex_lock(&text_mutex);
  340. call_offset -= start_offset;
  341. /*
  342. * No need to translate into a callthunk. The trampoline does
  343. * the depth accounting before the call already.
  344. */
  345. dest = ftrace_ops_get_func(ops);
  346. memcpy(trampoline + call_offset,
  347. text_gen_insn(CALL_INSN_OPCODE, trampoline + call_offset, dest),
  348. CALL_INSN_SIZE);
  349. mutex_unlock(&text_mutex);
  350. /* ALLOC_TRAMP flags lets us know we created it */
  351. ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP;
  352. set_memory_rox((unsigned long)trampoline, npages);
  353. return (unsigned long)trampoline;
  354. fail:
  355. tramp_free(trampoline);
  356. return 0;
  357. }
  358. void set_ftrace_ops_ro(void)
  359. {
  360. struct ftrace_ops *ops;
  361. unsigned long start_offset;
  362. unsigned long end_offset;
  363. unsigned long npages;
  364. unsigned long size;
  365. do_for_each_ftrace_op(ops, ftrace_ops_list) {
  366. if (!(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP))
  367. continue;
  368. if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) {
  369. start_offset = (unsigned long)ftrace_regs_caller;
  370. end_offset = (unsigned long)ftrace_regs_caller_end;
  371. } else {
  372. start_offset = (unsigned long)ftrace_caller;
  373. end_offset = (unsigned long)ftrace_caller_end;
  374. }
  375. size = end_offset - start_offset;
  376. size = size + RET_SIZE + sizeof(void *);
  377. npages = DIV_ROUND_UP(size, PAGE_SIZE);
  378. set_memory_ro((unsigned long)ops->trampoline, npages);
  379. } while_for_each_ftrace_op(ops);
  380. }
  381. static unsigned long calc_trampoline_call_offset(bool save_regs)
  382. {
  383. unsigned long start_offset;
  384. unsigned long call_offset;
  385. if (save_regs) {
  386. start_offset = (unsigned long)ftrace_regs_caller;
  387. call_offset = (unsigned long)ftrace_regs_call;
  388. } else {
  389. start_offset = (unsigned long)ftrace_caller;
  390. call_offset = (unsigned long)ftrace_call;
  391. }
  392. return call_offset - start_offset;
  393. }
  394. void arch_ftrace_update_trampoline(struct ftrace_ops *ops)
  395. {
  396. ftrace_func_t func;
  397. unsigned long offset;
  398. unsigned long ip;
  399. unsigned int size;
  400. const char *new;
  401. if (!ops->trampoline) {
  402. ops->trampoline = create_trampoline(ops, &size);
  403. if (!ops->trampoline)
  404. return;
  405. ops->trampoline_size = size;
  406. return;
  407. }
  408. /*
  409. * The ftrace_ops caller may set up its own trampoline.
  410. * In such a case, this code must not modify it.
  411. */
  412. if (!(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP))
  413. return;
  414. offset = calc_trampoline_call_offset(ops->flags & FTRACE_OPS_FL_SAVE_REGS);
  415. ip = ops->trampoline + offset;
  416. func = ftrace_ops_get_func(ops);
  417. mutex_lock(&text_mutex);
  418. /* Do a safe modify in case the trampoline is executing */
  419. new = ftrace_call_replace(ip, (unsigned long)func);
  420. text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL);
  421. mutex_unlock(&text_mutex);
  422. }
  423. /* Return the address of the function the trampoline calls */
  424. static void *addr_from_call(void *ptr)
  425. {
  426. union text_poke_insn call;
  427. int ret;
  428. ret = copy_from_kernel_nofault(&call, ptr, CALL_INSN_SIZE);
  429. if (WARN_ON_ONCE(ret < 0))
  430. return NULL;
  431. /* Make sure this is a call */
  432. if (WARN_ON_ONCE(call.opcode != CALL_INSN_OPCODE)) {
  433. pr_warn("Expected E8, got %x\n", call.opcode);
  434. return NULL;
  435. }
  436. return ptr + CALL_INSN_SIZE + call.disp;
  437. }
  438. /*
  439. * If the ops->trampoline was not allocated, then it probably
  440. * has a static trampoline func, or is the ftrace caller itself.
  441. */
  442. static void *static_tramp_func(struct ftrace_ops *ops, struct dyn_ftrace *rec)
  443. {
  444. unsigned long offset;
  445. bool save_regs = rec->flags & FTRACE_FL_REGS_EN;
  446. void *ptr;
  447. if (ops && ops->trampoline) {
  448. #if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) && \
  449. defined(CONFIG_FUNCTION_GRAPH_TRACER)
  450. /*
  451. * We only know about function graph tracer setting as static
  452. * trampoline.
  453. */
  454. if (ops->trampoline == FTRACE_GRAPH_ADDR)
  455. return (void *)prepare_ftrace_return;
  456. #endif
  457. return NULL;
  458. }
  459. offset = calc_trampoline_call_offset(save_regs);
  460. if (save_regs)
  461. ptr = (void *)FTRACE_REGS_ADDR + offset;
  462. else
  463. ptr = (void *)FTRACE_ADDR + offset;
  464. return addr_from_call(ptr);
  465. }
  466. void *arch_ftrace_trampoline_func(struct ftrace_ops *ops, struct dyn_ftrace *rec)
  467. {
  468. unsigned long offset;
  469. /* If we didn't allocate this trampoline, consider it static */
  470. if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP))
  471. return static_tramp_func(ops, rec);
  472. offset = calc_trampoline_call_offset(ops->flags & FTRACE_OPS_FL_SAVE_REGS);
  473. return addr_from_call((void *)ops->trampoline + offset);
  474. }
  475. void arch_ftrace_trampoline_free(struct ftrace_ops *ops)
  476. {
  477. if (!ops || !(ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP))
  478. return;
  479. tramp_free((void *)ops->trampoline);
  480. ops->trampoline = 0;
  481. }
  482. #endif /* CONFIG_X86_64 */
  483. #endif /* CONFIG_DYNAMIC_FTRACE */
  484. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  485. #if defined(CONFIG_DYNAMIC_FTRACE) && !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS)
  486. extern void ftrace_graph_call(void);
  487. static const char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
  488. {
  489. return text_gen_insn(JMP32_INSN_OPCODE, (void *)ip, (void *)addr);
  490. }
  491. static int ftrace_mod_jmp(unsigned long ip, void *func)
  492. {
  493. const char *new;
  494. new = ftrace_jmp_replace(ip, (unsigned long)func);
  495. text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL);
  496. return 0;
  497. }
  498. int ftrace_enable_ftrace_graph_caller(void)
  499. {
  500. unsigned long ip = (unsigned long)(&ftrace_graph_call);
  501. return ftrace_mod_jmp(ip, &ftrace_graph_caller);
  502. }
  503. int ftrace_disable_ftrace_graph_caller(void)
  504. {
  505. unsigned long ip = (unsigned long)(&ftrace_graph_call);
  506. return ftrace_mod_jmp(ip, &ftrace_stub);
  507. }
  508. #endif /* CONFIG_DYNAMIC_FTRACE && !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
  509. /*
  510. * Hook the return address and push it in the stack of return addrs
  511. * in current thread info.
  512. */
  513. void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
  514. unsigned long frame_pointer)
  515. {
  516. unsigned long return_hooker = (unsigned long)&return_to_handler;
  517. int bit;
  518. /*
  519. * When resuming from suspend-to-ram, this function can be indirectly
  520. * called from early CPU startup code while the CPU is in real mode,
  521. * which would fail miserably. Make sure the stack pointer is a
  522. * virtual address.
  523. *
  524. * This check isn't as accurate as virt_addr_valid(), but it should be
  525. * good enough for this purpose, and it's fast.
  526. */
  527. if (unlikely((long)__builtin_frame_address(0) >= 0))
  528. return;
  529. if (unlikely(ftrace_graph_is_dead()))
  530. return;
  531. if (unlikely(atomic_read(&current->tracing_graph_pause)))
  532. return;
  533. bit = ftrace_test_recursion_trylock(ip, *parent);
  534. if (bit < 0)
  535. return;
  536. if (!function_graph_enter(*parent, ip, frame_pointer, parent))
  537. *parent = return_hooker;
  538. ftrace_test_recursion_unlock(bit);
  539. }
  540. #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
  541. void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
  542. struct ftrace_ops *op, struct ftrace_regs *fregs)
  543. {
  544. struct pt_regs *regs = &fregs->regs;
  545. unsigned long *stack = (unsigned long *)kernel_stack_pointer(regs);
  546. prepare_ftrace_return(ip, (unsigned long *)stack, 0);
  547. }
  548. #endif
  549. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */