ftrace.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Ftrace header. For implementation details beyond the random comments
  4. * scattered below, see: Documentation/trace/ftrace-design.rst
  5. */
  6. #ifndef _LINUX_FTRACE_H
  7. #define _LINUX_FTRACE_H
  8. #include <linux/trace_recursion.h>
  9. #include <linux/trace_clock.h>
  10. #include <linux/jump_label.h>
  11. #include <linux/kallsyms.h>
  12. #include <linux/linkage.h>
  13. #include <linux/bitops.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/ktime.h>
  16. #include <linux/sched.h>
  17. #include <linux/types.h>
  18. #include <linux/init.h>
  19. #include <linux/fs.h>
  20. #include <asm/ftrace.h>
  21. /*
  22. * If the arch supports passing the variable contents of
  23. * function_trace_op as the third parameter back from the
  24. * mcount call, then the arch should define this as 1.
  25. */
  26. #ifndef ARCH_SUPPORTS_FTRACE_OPS
  27. #define ARCH_SUPPORTS_FTRACE_OPS 0
  28. #endif
  29. #ifdef CONFIG_TRACING
  30. extern void ftrace_boot_snapshot(void);
  31. #else
  32. static inline void ftrace_boot_snapshot(void) { }
  33. #endif
  34. #ifdef CONFIG_FUNCTION_TRACER
  35. struct ftrace_ops;
  36. struct ftrace_regs;
  37. /*
  38. * If the arch's mcount caller does not support all of ftrace's
  39. * features, then it must call an indirect function that
  40. * does. Or at least does enough to prevent any unwelcome side effects.
  41. *
  42. * Also define the function prototype that these architectures use
  43. * to call the ftrace_ops_list_func().
  44. */
  45. #if !ARCH_SUPPORTS_FTRACE_OPS
  46. # define FTRACE_FORCE_LIST_FUNC 1
  47. void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip);
  48. #else
  49. # define FTRACE_FORCE_LIST_FUNC 0
  50. void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
  51. struct ftrace_ops *op, struct ftrace_regs *fregs);
  52. #endif
  53. #endif /* CONFIG_FUNCTION_TRACER */
  54. /* Main tracing buffer and events set up */
  55. #ifdef CONFIG_TRACING
  56. void trace_init(void);
  57. void early_trace_init(void);
  58. #else
  59. static inline void trace_init(void) { }
  60. static inline void early_trace_init(void) { }
  61. #endif
  62. struct module;
  63. struct ftrace_hash;
  64. struct ftrace_direct_func;
  65. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_MODULES) && \
  66. defined(CONFIG_DYNAMIC_FTRACE)
  67. const char *
  68. ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
  69. unsigned long *off, char **modname, char *sym);
  70. #else
  71. static inline const char *
  72. ftrace_mod_address_lookup(unsigned long addr, unsigned long *size,
  73. unsigned long *off, char **modname, char *sym)
  74. {
  75. return NULL;
  76. }
  77. #endif
  78. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  79. int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
  80. char *type, char *name,
  81. char *module_name, int *exported);
  82. #else
  83. static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *value,
  84. char *type, char *name,
  85. char *module_name, int *exported)
  86. {
  87. return -1;
  88. }
  89. #endif
  90. #ifdef CONFIG_FUNCTION_TRACER
  91. extern int ftrace_enabled;
  92. #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
  93. struct ftrace_regs {
  94. struct pt_regs regs;
  95. };
  96. #define arch_ftrace_get_regs(fregs) (&(fregs)->regs)
  97. /*
  98. * ftrace_instruction_pointer_set() is to be defined by the architecture
  99. * if to allow setting of the instruction pointer from the ftrace_regs
  100. * when HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports
  101. * live kernel patching.
  102. */
  103. #define ftrace_instruction_pointer_set(fregs, ip) do { } while (0)
  104. #endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
  105. static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs)
  106. {
  107. if (!fregs)
  108. return NULL;
  109. return arch_ftrace_get_regs(fregs);
  110. }
  111. typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
  112. struct ftrace_ops *op, struct ftrace_regs *fregs);
  113. ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
  114. /*
  115. * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
  116. * set in the flags member.
  117. * CONTROL, SAVE_REGS, SAVE_REGS_IF_SUPPORTED, RECURSION, STUB and
  118. * IPMODIFY are a kind of attribute flags which can be set only before
  119. * registering the ftrace_ops, and can not be modified while registered.
  120. * Changing those attribute flags after registering ftrace_ops will
  121. * cause unexpected results.
  122. *
  123. * ENABLED - set/unset when ftrace_ops is registered/unregistered
  124. * DYNAMIC - set when ftrace_ops is registered to denote dynamically
  125. * allocated ftrace_ops which need special care
  126. * SAVE_REGS - The ftrace_ops wants regs saved at each function called
  127. * and passed to the callback. If this flag is set, but the
  128. * architecture does not support passing regs
  129. * (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
  130. * ftrace_ops will fail to register, unless the next flag
  131. * is set.
  132. * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
  133. * handler can handle an arch that does not save regs
  134. * (the handler tests if regs == NULL), then it can set
  135. * this flag instead. It will not fail registering the ftrace_ops
  136. * but, the regs field will be NULL if the arch does not support
  137. * passing regs to the handler.
  138. * Note, if this flag is set, the SAVE_REGS flag will automatically
  139. * get set upon registering the ftrace_ops, if the arch supports it.
  140. * RECURSION - The ftrace_ops can set this to tell the ftrace infrastructure
  141. * that the call back needs recursion protection. If it does
  142. * not set this, then the ftrace infrastructure will assume
  143. * that the callback can handle recursion on its own.
  144. * STUB - The ftrace_ops is just a place holder.
  145. * INITIALIZED - The ftrace_ops has already been initialized (first use time
  146. * register_ftrace_function() is called, it will initialized the ops)
  147. * DELETED - The ops are being deleted, do not let them be registered again.
  148. * ADDING - The ops is in the process of being added.
  149. * REMOVING - The ops is in the process of being removed.
  150. * MODIFYING - The ops is in the process of changing its filter functions.
  151. * ALLOC_TRAMP - A dynamic trampoline was allocated by the core code.
  152. * The arch specific code sets this flag when it allocated a
  153. * trampoline. This lets the arch know that it can update the
  154. * trampoline in case the callback function changes.
  155. * The ftrace_ops trampoline can be set by the ftrace users, and
  156. * in such cases the arch must not modify it. Only the arch ftrace
  157. * core code should set this flag.
  158. * IPMODIFY - The ops can modify the IP register. This can only be set with
  159. * SAVE_REGS. If another ops with this flag set is already registered
  160. * for any of the functions that this ops will be registered for, then
  161. * this ops will fail to register or set_filter_ip.
  162. * PID - Is affected by set_ftrace_pid (allows filtering on those pids)
  163. * RCU - Set when the ops can only be called when RCU is watching.
  164. * TRACE_ARRAY - The ops->private points to a trace_array descriptor.
  165. * PERMANENT - Set when the ops is permanent and should not be affected by
  166. * ftrace_enabled.
  167. * DIRECT - Used by the direct ftrace_ops helper for direct functions
  168. * (internal ftrace only, should not be used by others)
  169. */
  170. enum {
  171. FTRACE_OPS_FL_ENABLED = BIT(0),
  172. FTRACE_OPS_FL_DYNAMIC = BIT(1),
  173. FTRACE_OPS_FL_SAVE_REGS = BIT(2),
  174. FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = BIT(3),
  175. FTRACE_OPS_FL_RECURSION = BIT(4),
  176. FTRACE_OPS_FL_STUB = BIT(5),
  177. FTRACE_OPS_FL_INITIALIZED = BIT(6),
  178. FTRACE_OPS_FL_DELETED = BIT(7),
  179. FTRACE_OPS_FL_ADDING = BIT(8),
  180. FTRACE_OPS_FL_REMOVING = BIT(9),
  181. FTRACE_OPS_FL_MODIFYING = BIT(10),
  182. FTRACE_OPS_FL_ALLOC_TRAMP = BIT(11),
  183. FTRACE_OPS_FL_IPMODIFY = BIT(12),
  184. FTRACE_OPS_FL_PID = BIT(13),
  185. FTRACE_OPS_FL_RCU = BIT(14),
  186. FTRACE_OPS_FL_TRACE_ARRAY = BIT(15),
  187. FTRACE_OPS_FL_PERMANENT = BIT(16),
  188. FTRACE_OPS_FL_DIRECT = BIT(17),
  189. };
  190. /*
  191. * FTRACE_OPS_CMD_* commands allow the ftrace core logic to request changes
  192. * to a ftrace_ops. Note, the requests may fail.
  193. *
  194. * ENABLE_SHARE_IPMODIFY_SELF - enable a DIRECT ops to work on the same
  195. * function as an ops with IPMODIFY. Called
  196. * when the DIRECT ops is being registered.
  197. * This is called with both direct_mutex and
  198. * ftrace_lock are locked.
  199. *
  200. * ENABLE_SHARE_IPMODIFY_PEER - enable a DIRECT ops to work on the same
  201. * function as an ops with IPMODIFY. Called
  202. * when the other ops (the one with IPMODIFY)
  203. * is being registered.
  204. * This is called with direct_mutex locked.
  205. *
  206. * DISABLE_SHARE_IPMODIFY_PEER - disable a DIRECT ops to work on the same
  207. * function as an ops with IPMODIFY. Called
  208. * when the other ops (the one with IPMODIFY)
  209. * is being unregistered.
  210. * This is called with direct_mutex locked.
  211. */
  212. enum ftrace_ops_cmd {
  213. FTRACE_OPS_CMD_ENABLE_SHARE_IPMODIFY_SELF,
  214. FTRACE_OPS_CMD_ENABLE_SHARE_IPMODIFY_PEER,
  215. FTRACE_OPS_CMD_DISABLE_SHARE_IPMODIFY_PEER,
  216. };
  217. /*
  218. * For most ftrace_ops_cmd,
  219. * Returns:
  220. * 0 - Success.
  221. * Negative on failure. The return value is dependent on the
  222. * callback.
  223. */
  224. typedef int (*ftrace_ops_func_t)(struct ftrace_ops *op, enum ftrace_ops_cmd cmd);
  225. #ifdef CONFIG_DYNAMIC_FTRACE
  226. /* The hash used to know what functions callbacks trace */
  227. struct ftrace_ops_hash {
  228. struct ftrace_hash __rcu *notrace_hash;
  229. struct ftrace_hash __rcu *filter_hash;
  230. struct mutex regex_lock;
  231. };
  232. void ftrace_free_init_mem(void);
  233. void ftrace_free_mem(struct module *mod, void *start, void *end);
  234. #else
  235. static inline void ftrace_free_init_mem(void)
  236. {
  237. ftrace_boot_snapshot();
  238. }
  239. static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
  240. #endif
  241. /*
  242. * Note, ftrace_ops can be referenced outside of RCU protection, unless
  243. * the RCU flag is set. If ftrace_ops is allocated and not part of kernel
  244. * core data, the unregistering of it will perform a scheduling on all CPUs
  245. * to make sure that there are no more users. Depending on the load of the
  246. * system that may take a bit of time.
  247. *
  248. * Any private data added must also take care not to be freed and if private
  249. * data is added to a ftrace_ops that is in core code, the user of the
  250. * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
  251. */
  252. struct ftrace_ops {
  253. ftrace_func_t func;
  254. struct ftrace_ops __rcu *next;
  255. unsigned long flags;
  256. void *private;
  257. ftrace_func_t saved_func;
  258. #ifdef CONFIG_DYNAMIC_FTRACE
  259. struct ftrace_ops_hash local_hash;
  260. struct ftrace_ops_hash *func_hash;
  261. struct ftrace_ops_hash old_hash;
  262. unsigned long trampoline;
  263. unsigned long trampoline_size;
  264. struct list_head list;
  265. ftrace_ops_func_t ops_func;
  266. #endif
  267. };
  268. extern struct ftrace_ops __rcu *ftrace_ops_list;
  269. extern struct ftrace_ops ftrace_list_end;
  270. /*
  271. * Traverse the ftrace_ops_list, invoking all entries. The reason that we
  272. * can use rcu_dereference_raw_check() is that elements removed from this list
  273. * are simply leaked, so there is no need to interact with a grace-period
  274. * mechanism. The rcu_dereference_raw_check() calls are needed to handle
  275. * concurrent insertions into the ftrace_ops_list.
  276. *
  277. * Silly Alpha and silly pointer-speculation compiler optimizations!
  278. */
  279. #define do_for_each_ftrace_op(op, list) \
  280. op = rcu_dereference_raw_check(list); \
  281. do
  282. /*
  283. * Optimized for just a single item in the list (as that is the normal case).
  284. */
  285. #define while_for_each_ftrace_op(op) \
  286. while (likely(op = rcu_dereference_raw_check((op)->next)) && \
  287. unlikely((op) != &ftrace_list_end))
  288. /*
  289. * Type of the current tracing.
  290. */
  291. enum ftrace_tracing_type_t {
  292. FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  293. FTRACE_TYPE_RETURN, /* Hook the return of the function */
  294. };
  295. /* Current tracing type, default is FTRACE_TYPE_ENTER */
  296. extern enum ftrace_tracing_type_t ftrace_tracing_type;
  297. /*
  298. * The ftrace_ops must be a static and should also
  299. * be read_mostly. These functions do modify read_mostly variables
  300. * so use them sparely. Never free an ftrace_op or modify the
  301. * next pointer after it has been registered. Even after unregistering
  302. * it, the next pointer may still be used internally.
  303. */
  304. int register_ftrace_function(struct ftrace_ops *ops);
  305. int unregister_ftrace_function(struct ftrace_ops *ops);
  306. extern void ftrace_stub(unsigned long a0, unsigned long a1,
  307. struct ftrace_ops *op, struct ftrace_regs *fregs);
  308. int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *addrs);
  309. #else /* !CONFIG_FUNCTION_TRACER */
  310. /*
  311. * (un)register_ftrace_function must be a macro since the ops parameter
  312. * must not be evaluated.
  313. */
  314. #define register_ftrace_function(ops) ({ 0; })
  315. #define unregister_ftrace_function(ops) ({ 0; })
  316. static inline void ftrace_kill(void) { }
  317. static inline void ftrace_free_init_mem(void) { }
  318. static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
  319. static inline int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *addrs)
  320. {
  321. return -EOPNOTSUPP;
  322. }
  323. #endif /* CONFIG_FUNCTION_TRACER */
  324. struct ftrace_func_entry {
  325. struct hlist_node hlist;
  326. unsigned long ip;
  327. unsigned long direct; /* for direct lookup only */
  328. };
  329. struct dyn_ftrace;
  330. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  331. extern int ftrace_direct_func_count;
  332. int register_ftrace_direct(unsigned long ip, unsigned long addr);
  333. int unregister_ftrace_direct(unsigned long ip, unsigned long addr);
  334. int modify_ftrace_direct(unsigned long ip, unsigned long old_addr, unsigned long new_addr);
  335. struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr);
  336. int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
  337. struct dyn_ftrace *rec,
  338. unsigned long old_addr,
  339. unsigned long new_addr);
  340. unsigned long ftrace_find_rec_direct(unsigned long ip);
  341. int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
  342. int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
  343. int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
  344. int modify_ftrace_direct_multi_nolock(struct ftrace_ops *ops, unsigned long addr);
  345. #else
  346. struct ftrace_ops;
  347. # define ftrace_direct_func_count 0
  348. static inline int register_ftrace_direct(unsigned long ip, unsigned long addr)
  349. {
  350. return -ENOTSUPP;
  351. }
  352. static inline int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
  353. {
  354. return -ENOTSUPP;
  355. }
  356. static inline int modify_ftrace_direct(unsigned long ip,
  357. unsigned long old_addr, unsigned long new_addr)
  358. {
  359. return -ENOTSUPP;
  360. }
  361. static inline struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr)
  362. {
  363. return NULL;
  364. }
  365. static inline int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
  366. struct dyn_ftrace *rec,
  367. unsigned long old_addr,
  368. unsigned long new_addr)
  369. {
  370. return -ENODEV;
  371. }
  372. static inline unsigned long ftrace_find_rec_direct(unsigned long ip)
  373. {
  374. return 0;
  375. }
  376. static inline int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
  377. {
  378. return -ENODEV;
  379. }
  380. static inline int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
  381. {
  382. return -ENODEV;
  383. }
  384. static inline int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
  385. {
  386. return -ENODEV;
  387. }
  388. static inline int modify_ftrace_direct_multi_nolock(struct ftrace_ops *ops, unsigned long addr)
  389. {
  390. return -ENODEV;
  391. }
  392. #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
  393. #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  394. /*
  395. * This must be implemented by the architecture.
  396. * It is the way the ftrace direct_ops helper, when called
  397. * via ftrace (because there's other callbacks besides the
  398. * direct call), can inform the architecture's trampoline that this
  399. * routine has a direct caller, and what the caller is.
  400. *
  401. * For example, in x86, it returns the direct caller
  402. * callback function via the regs->orig_ax parameter.
  403. * Then in the ftrace trampoline, if this is set, it makes
  404. * the return from the trampoline jump to the direct caller
  405. * instead of going back to the function it just traced.
  406. */
  407. static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs,
  408. unsigned long addr) { }
  409. #endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
  410. #ifdef CONFIG_STACK_TRACER
  411. extern int stack_tracer_enabled;
  412. int stack_trace_sysctl(struct ctl_table *table, int write, void *buffer,
  413. size_t *lenp, loff_t *ppos);
  414. /* DO NOT MODIFY THIS VARIABLE DIRECTLY! */
  415. DECLARE_PER_CPU(int, disable_stack_tracer);
  416. /**
  417. * stack_tracer_disable - temporarily disable the stack tracer
  418. *
  419. * There's a few locations (namely in RCU) where stack tracing
  420. * cannot be executed. This function is used to disable stack
  421. * tracing during those critical sections.
  422. *
  423. * This function must be called with preemption or interrupts
  424. * disabled and stack_tracer_enable() must be called shortly after
  425. * while preemption or interrupts are still disabled.
  426. */
  427. static inline void stack_tracer_disable(void)
  428. {
  429. /* Preemption or interrupts must be disabled */
  430. if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
  431. WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
  432. this_cpu_inc(disable_stack_tracer);
  433. }
  434. /**
  435. * stack_tracer_enable - re-enable the stack tracer
  436. *
  437. * After stack_tracer_disable() is called, stack_tracer_enable()
  438. * must be called shortly afterward.
  439. */
  440. static inline void stack_tracer_enable(void)
  441. {
  442. if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
  443. WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
  444. this_cpu_dec(disable_stack_tracer);
  445. }
  446. #else
  447. static inline void stack_tracer_disable(void) { }
  448. static inline void stack_tracer_enable(void) { }
  449. #endif
  450. #ifdef CONFIG_DYNAMIC_FTRACE
  451. void ftrace_arch_code_modify_prepare(void);
  452. void ftrace_arch_code_modify_post_process(void);
  453. enum ftrace_bug_type {
  454. FTRACE_BUG_UNKNOWN,
  455. FTRACE_BUG_INIT,
  456. FTRACE_BUG_NOP,
  457. FTRACE_BUG_CALL,
  458. FTRACE_BUG_UPDATE,
  459. };
  460. extern enum ftrace_bug_type ftrace_bug_type;
  461. /*
  462. * Archs can set this to point to a variable that holds the value that was
  463. * expected at the call site before calling ftrace_bug().
  464. */
  465. extern const void *ftrace_expected;
  466. void ftrace_bug(int err, struct dyn_ftrace *rec);
  467. struct seq_file;
  468. extern int ftrace_text_reserved(const void *start, const void *end);
  469. struct ftrace_ops *ftrace_ops_trampoline(unsigned long addr);
  470. bool is_ftrace_trampoline(unsigned long addr);
  471. /*
  472. * The dyn_ftrace record's flags field is split into two parts.
  473. * the first part which is '0-FTRACE_REF_MAX' is a counter of
  474. * the number of callbacks that have registered the function that
  475. * the dyn_ftrace descriptor represents.
  476. *
  477. * The second part is a mask:
  478. * ENABLED - the function is being traced
  479. * REGS - the record wants the function to save regs
  480. * REGS_EN - the function is set up to save regs.
  481. * IPMODIFY - the record allows for the IP address to be changed.
  482. * DISABLED - the record is not ready to be touched yet
  483. * DIRECT - there is a direct function to call
  484. *
  485. * When a new ftrace_ops is registered and wants a function to save
  486. * pt_regs, the rec->flags REGS is set. When the function has been
  487. * set up to save regs, the REG_EN flag is set. Once a function
  488. * starts saving regs it will do so until all ftrace_ops are removed
  489. * from tracing that function.
  490. */
  491. enum {
  492. FTRACE_FL_ENABLED = (1UL << 31),
  493. FTRACE_FL_REGS = (1UL << 30),
  494. FTRACE_FL_REGS_EN = (1UL << 29),
  495. FTRACE_FL_TRAMP = (1UL << 28),
  496. FTRACE_FL_TRAMP_EN = (1UL << 27),
  497. FTRACE_FL_IPMODIFY = (1UL << 26),
  498. FTRACE_FL_DISABLED = (1UL << 25),
  499. FTRACE_FL_DIRECT = (1UL << 24),
  500. FTRACE_FL_DIRECT_EN = (1UL << 23),
  501. };
  502. #define FTRACE_REF_MAX_SHIFT 23
  503. #define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
  504. #define ftrace_rec_count(rec) ((rec)->flags & FTRACE_REF_MAX)
  505. struct dyn_ftrace {
  506. unsigned long ip; /* address of mcount call-site */
  507. unsigned long flags;
  508. struct dyn_arch_ftrace arch;
  509. };
  510. int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
  511. int remove, int reset);
  512. int ftrace_set_filter_ips(struct ftrace_ops *ops, unsigned long *ips,
  513. unsigned int cnt, int remove, int reset);
  514. int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  515. int len, int reset);
  516. int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  517. int len, int reset);
  518. void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  519. void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
  520. void ftrace_free_filter(struct ftrace_ops *ops);
  521. void ftrace_ops_set_global_filter(struct ftrace_ops *ops);
  522. enum {
  523. FTRACE_UPDATE_CALLS = (1 << 0),
  524. FTRACE_DISABLE_CALLS = (1 << 1),
  525. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  526. FTRACE_START_FUNC_RET = (1 << 3),
  527. FTRACE_STOP_FUNC_RET = (1 << 4),
  528. FTRACE_MAY_SLEEP = (1 << 5),
  529. };
  530. /*
  531. * The FTRACE_UPDATE_* enum is used to pass information back
  532. * from the ftrace_update_record() and ftrace_test_record()
  533. * functions. These are called by the code update routines
  534. * to find out what is to be done for a given function.
  535. *
  536. * IGNORE - The function is already what we want it to be
  537. * MAKE_CALL - Start tracing the function
  538. * MODIFY_CALL - Stop saving regs for the function
  539. * MAKE_NOP - Stop tracing the function
  540. */
  541. enum {
  542. FTRACE_UPDATE_IGNORE,
  543. FTRACE_UPDATE_MAKE_CALL,
  544. FTRACE_UPDATE_MODIFY_CALL,
  545. FTRACE_UPDATE_MAKE_NOP,
  546. };
  547. enum {
  548. FTRACE_ITER_FILTER = (1 << 0),
  549. FTRACE_ITER_NOTRACE = (1 << 1),
  550. FTRACE_ITER_PRINTALL = (1 << 2),
  551. FTRACE_ITER_DO_PROBES = (1 << 3),
  552. FTRACE_ITER_PROBE = (1 << 4),
  553. FTRACE_ITER_MOD = (1 << 5),
  554. FTRACE_ITER_ENABLED = (1 << 6),
  555. };
  556. void arch_ftrace_update_code(int command);
  557. void arch_ftrace_update_trampoline(struct ftrace_ops *ops);
  558. void *arch_ftrace_trampoline_func(struct ftrace_ops *ops, struct dyn_ftrace *rec);
  559. void arch_ftrace_trampoline_free(struct ftrace_ops *ops);
  560. struct ftrace_rec_iter;
  561. struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  562. struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  563. struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
  564. #define for_ftrace_rec_iter(iter) \
  565. for (iter = ftrace_rec_iter_start(); \
  566. iter; \
  567. iter = ftrace_rec_iter_next(iter))
  568. int ftrace_update_record(struct dyn_ftrace *rec, bool enable);
  569. int ftrace_test_record(struct dyn_ftrace *rec, bool enable);
  570. void ftrace_run_stop_machine(int command);
  571. unsigned long ftrace_location(unsigned long ip);
  572. unsigned long ftrace_location_range(unsigned long start, unsigned long end);
  573. unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
  574. unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
  575. extern ftrace_func_t ftrace_trace_function;
  576. int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  577. struct inode *inode, struct file *file);
  578. ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  579. size_t cnt, loff_t *ppos);
  580. ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  581. size_t cnt, loff_t *ppos);
  582. int ftrace_regex_release(struct inode *inode, struct file *file);
  583. void __init
  584. ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
  585. /* defined in arch */
  586. extern int ftrace_ip_converted(unsigned long ip);
  587. extern int ftrace_dyn_arch_init(void);
  588. extern void ftrace_replace_code(int enable);
  589. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  590. extern void ftrace_caller(void);
  591. extern void ftrace_regs_caller(void);
  592. extern void ftrace_call(void);
  593. extern void ftrace_regs_call(void);
  594. extern void mcount_call(void);
  595. void ftrace_modify_all_code(int command);
  596. #ifndef FTRACE_ADDR
  597. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  598. #endif
  599. #ifndef FTRACE_GRAPH_ADDR
  600. #define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
  601. #endif
  602. #ifndef FTRACE_REGS_ADDR
  603. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  604. # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
  605. #else
  606. # define FTRACE_REGS_ADDR FTRACE_ADDR
  607. #endif
  608. #endif
  609. /*
  610. * If an arch would like functions that are only traced
  611. * by the function graph tracer to jump directly to its own
  612. * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
  613. * to be that address to jump to.
  614. */
  615. #ifndef FTRACE_GRAPH_TRAMP_ADDR
  616. #define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
  617. #endif
  618. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  619. extern void ftrace_graph_caller(void);
  620. extern int ftrace_enable_ftrace_graph_caller(void);
  621. extern int ftrace_disable_ftrace_graph_caller(void);
  622. #else
  623. static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  624. static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
  625. #endif
  626. /**
  627. * ftrace_make_nop - convert code into nop
  628. * @mod: module structure if called by module load initialization
  629. * @rec: the call site record (e.g. mcount/fentry)
  630. * @addr: the address that the call site should be calling
  631. *
  632. * This is a very sensitive operation and great care needs
  633. * to be taken by the arch. The operation should carefully
  634. * read the location, check to see if what is read is indeed
  635. * what we expect it to be, and then on success of the compare,
  636. * it should write to the location.
  637. *
  638. * The code segment at @rec->ip should be a caller to @addr
  639. *
  640. * Return must be:
  641. * 0 on success
  642. * -EFAULT on error reading the location
  643. * -EINVAL on a failed compare of the contents
  644. * -EPERM on error writing to the location
  645. * Any other value will be considered a failure.
  646. */
  647. extern int ftrace_make_nop(struct module *mod,
  648. struct dyn_ftrace *rec, unsigned long addr);
  649. /**
  650. * ftrace_need_init_nop - return whether nop call sites should be initialized
  651. *
  652. * Normally the compiler's -mnop-mcount generates suitable nops, so we don't
  653. * need to call ftrace_init_nop() if the code is built with that flag.
  654. * Architectures where this is not always the case may define their own
  655. * condition.
  656. *
  657. * Return must be:
  658. * 0 if ftrace_init_nop() should be called
  659. * Nonzero if ftrace_init_nop() should not be called
  660. */
  661. #ifndef ftrace_need_init_nop
  662. #define ftrace_need_init_nop() (!__is_defined(CC_USING_NOP_MCOUNT))
  663. #endif
  664. /**
  665. * ftrace_init_nop - initialize a nop call site
  666. * @mod: module structure if called by module load initialization
  667. * @rec: the call site record (e.g. mcount/fentry)
  668. *
  669. * This is a very sensitive operation and great care needs
  670. * to be taken by the arch. The operation should carefully
  671. * read the location, check to see if what is read is indeed
  672. * what we expect it to be, and then on success of the compare,
  673. * it should write to the location.
  674. *
  675. * The code segment at @rec->ip should contain the contents created by
  676. * the compiler
  677. *
  678. * Return must be:
  679. * 0 on success
  680. * -EFAULT on error reading the location
  681. * -EINVAL on a failed compare of the contents
  682. * -EPERM on error writing to the location
  683. * Any other value will be considered a failure.
  684. */
  685. #ifndef ftrace_init_nop
  686. static inline int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
  687. {
  688. return ftrace_make_nop(mod, rec, MCOUNT_ADDR);
  689. }
  690. #endif
  691. /**
  692. * ftrace_make_call - convert a nop call site into a call to addr
  693. * @rec: the call site record (e.g. mcount/fentry)
  694. * @addr: the address that the call site should call
  695. *
  696. * This is a very sensitive operation and great care needs
  697. * to be taken by the arch. The operation should carefully
  698. * read the location, check to see if what is read is indeed
  699. * what we expect it to be, and then on success of the compare,
  700. * it should write to the location.
  701. *
  702. * The code segment at @rec->ip should be a nop
  703. *
  704. * Return must be:
  705. * 0 on success
  706. * -EFAULT on error reading the location
  707. * -EINVAL on a failed compare of the contents
  708. * -EPERM on error writing to the location
  709. * Any other value will be considered a failure.
  710. */
  711. extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
  712. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  713. /**
  714. * ftrace_modify_call - convert from one addr to another (no nop)
  715. * @rec: the call site record (e.g. mcount/fentry)
  716. * @old_addr: the address expected to be currently called to
  717. * @addr: the address to change to
  718. *
  719. * This is a very sensitive operation and great care needs
  720. * to be taken by the arch. The operation should carefully
  721. * read the location, check to see if what is read is indeed
  722. * what we expect it to be, and then on success of the compare,
  723. * it should write to the location.
  724. *
  725. * The code segment at @rec->ip should be a caller to @old_addr
  726. *
  727. * Return must be:
  728. * 0 on success
  729. * -EFAULT on error reading the location
  730. * -EINVAL on a failed compare of the contents
  731. * -EPERM on error writing to the location
  732. * Any other value will be considered a failure.
  733. */
  734. extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  735. unsigned long addr);
  736. #else
  737. /* Should never be called */
  738. static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  739. unsigned long addr)
  740. {
  741. return -EINVAL;
  742. }
  743. #endif
  744. /* May be defined in arch */
  745. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  746. extern int skip_trace(unsigned long ip);
  747. extern void ftrace_module_init(struct module *mod);
  748. extern void ftrace_module_enable(struct module *mod);
  749. extern void ftrace_release_mod(struct module *mod);
  750. extern void ftrace_disable_daemon(void);
  751. extern void ftrace_enable_daemon(void);
  752. #else /* CONFIG_DYNAMIC_FTRACE */
  753. static inline int skip_trace(unsigned long ip) { return 0; }
  754. static inline void ftrace_disable_daemon(void) { }
  755. static inline void ftrace_enable_daemon(void) { }
  756. static inline void ftrace_module_init(struct module *mod) { }
  757. static inline void ftrace_module_enable(struct module *mod) { }
  758. static inline void ftrace_release_mod(struct module *mod) { }
  759. static inline int ftrace_text_reserved(const void *start, const void *end)
  760. {
  761. return 0;
  762. }
  763. static inline unsigned long ftrace_location(unsigned long ip)
  764. {
  765. return 0;
  766. }
  767. /*
  768. * Again users of functions that have ftrace_ops may not
  769. * have them defined when ftrace is not enabled, but these
  770. * functions may still be called. Use a macro instead of inline.
  771. */
  772. #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  773. #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
  774. #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
  775. #define ftrace_set_filter_ips(ops, ips, cnt, remove, reset) ({ -ENODEV; })
  776. #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  777. #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  778. #define ftrace_free_filter(ops) do { } while (0)
  779. #define ftrace_ops_set_global_filter(ops) do { } while (0)
  780. static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  781. size_t cnt, loff_t *ppos) { return -ENODEV; }
  782. static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  783. size_t cnt, loff_t *ppos) { return -ENODEV; }
  784. static inline int
  785. ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
  786. static inline bool is_ftrace_trampoline(unsigned long addr)
  787. {
  788. return false;
  789. }
  790. #endif /* CONFIG_DYNAMIC_FTRACE */
  791. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  792. #ifndef ftrace_graph_func
  793. #define ftrace_graph_func ftrace_stub
  794. #define FTRACE_OPS_GRAPH_STUB FTRACE_OPS_FL_STUB
  795. #else
  796. #define FTRACE_OPS_GRAPH_STUB 0
  797. #endif
  798. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  799. /* totally disable ftrace - can not re-enable after this */
  800. void ftrace_kill(void);
  801. static inline void tracer_disable(void)
  802. {
  803. #ifdef CONFIG_FUNCTION_TRACER
  804. ftrace_enabled = 0;
  805. #endif
  806. }
  807. /*
  808. * Ftrace disable/restore without lock. Some synchronization mechanism
  809. * must be used to prevent ftrace_enabled to be changed between
  810. * disable/restore.
  811. */
  812. static inline int __ftrace_enabled_save(void)
  813. {
  814. #ifdef CONFIG_FUNCTION_TRACER
  815. int saved_ftrace_enabled = ftrace_enabled;
  816. ftrace_enabled = 0;
  817. return saved_ftrace_enabled;
  818. #else
  819. return 0;
  820. #endif
  821. }
  822. static inline void __ftrace_enabled_restore(int enabled)
  823. {
  824. #ifdef CONFIG_FUNCTION_TRACER
  825. ftrace_enabled = enabled;
  826. #endif
  827. }
  828. /* All archs should have this, but we define it for consistency */
  829. #ifndef ftrace_return_address0
  830. # define ftrace_return_address0 __builtin_return_address(0)
  831. #endif
  832. /* Archs may use other ways for ADDR1 and beyond */
  833. #ifndef ftrace_return_address
  834. # ifdef CONFIG_FRAME_POINTER
  835. # define ftrace_return_address(n) __builtin_return_address(n)
  836. # else
  837. # define ftrace_return_address(n) 0UL
  838. # endif
  839. #endif
  840. #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
  841. #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
  842. #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
  843. #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
  844. #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
  845. #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  846. #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
  847. static __always_inline unsigned long get_lock_parent_ip(void)
  848. {
  849. unsigned long addr = CALLER_ADDR0;
  850. if (!in_lock_functions(addr))
  851. return addr;
  852. addr = CALLER_ADDR1;
  853. if (!in_lock_functions(addr))
  854. return addr;
  855. return CALLER_ADDR2;
  856. }
  857. #ifdef CONFIG_TRACE_PREEMPT_TOGGLE
  858. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  859. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  860. #else
  861. /*
  862. * Use defines instead of static inlines because some arches will make code out
  863. * of the CALLER_ADDR, when we really want these to be a real nop.
  864. */
  865. # define trace_preempt_on(a0, a1) do { } while (0)
  866. # define trace_preempt_off(a0, a1) do { } while (0)
  867. #endif
  868. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  869. extern void ftrace_init(void);
  870. #ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
  871. #define FTRACE_CALLSITE_SECTION "__patchable_function_entries"
  872. #else
  873. #define FTRACE_CALLSITE_SECTION "__mcount_loc"
  874. #endif
  875. #else
  876. static inline void ftrace_init(void) { }
  877. #endif
  878. /*
  879. * Structure that defines an entry function trace.
  880. * It's already packed but the attribute "packed" is needed
  881. * to remove extra padding at the end.
  882. */
  883. struct ftrace_graph_ent {
  884. unsigned long func; /* Current function */
  885. int depth;
  886. } __packed;
  887. /*
  888. * Structure that defines a return function trace.
  889. * It's already packed but the attribute "packed" is needed
  890. * to remove extra padding at the end.
  891. */
  892. struct ftrace_graph_ret {
  893. unsigned long func; /* Current function */
  894. int depth;
  895. /* Number of functions that overran the depth limit for current task */
  896. unsigned int overrun;
  897. unsigned long long calltime;
  898. unsigned long long rettime;
  899. } __packed;
  900. /* Type of the callback handlers for tracing function graph*/
  901. typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  902. typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
  903. extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
  904. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  905. struct fgraph_ops {
  906. trace_func_graph_ent_t entryfunc;
  907. trace_func_graph_ret_t retfunc;
  908. };
  909. /*
  910. * Stack of return addresses for functions
  911. * of a thread.
  912. * Used in struct thread_info
  913. */
  914. struct ftrace_ret_stack {
  915. unsigned long ret;
  916. unsigned long func;
  917. unsigned long long calltime;
  918. #ifdef CONFIG_FUNCTION_PROFILER
  919. unsigned long long subtime;
  920. #endif
  921. #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
  922. unsigned long fp;
  923. #endif
  924. #ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
  925. unsigned long *retp;
  926. #endif
  927. };
  928. /*
  929. * Primary handler of a function return.
  930. * It relays on ftrace_return_to_handler.
  931. * Defined in entry_32/64.S
  932. */
  933. extern void return_to_handler(void);
  934. extern int
  935. function_graph_enter(unsigned long ret, unsigned long func,
  936. unsigned long frame_pointer, unsigned long *retp);
  937. struct ftrace_ret_stack *
  938. ftrace_graph_get_ret_stack(struct task_struct *task, int idx);
  939. unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
  940. unsigned long ret, unsigned long *retp);
  941. /*
  942. * Sometimes we don't want to trace a function with the function
  943. * graph tracer but we want them to keep traced by the usual function
  944. * tracer if the function graph tracer is not configured.
  945. */
  946. #define __notrace_funcgraph notrace
  947. #define FTRACE_RETFUNC_DEPTH 50
  948. #define FTRACE_RETSTACK_ALLOC_SIZE 32
  949. extern int register_ftrace_graph(struct fgraph_ops *ops);
  950. extern void unregister_ftrace_graph(struct fgraph_ops *ops);
  951. /**
  952. * ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
  953. *
  954. * ftrace_graph_stop() is called when a severe error is detected in
  955. * the function graph tracing. This function is called by the critical
  956. * paths of function graph to keep those paths from doing any more harm.
  957. */
  958. DECLARE_STATIC_KEY_FALSE(kill_ftrace_graph);
  959. static inline bool ftrace_graph_is_dead(void)
  960. {
  961. return static_branch_unlikely(&kill_ftrace_graph);
  962. }
  963. extern void ftrace_graph_stop(void);
  964. /* The current handlers in use */
  965. extern trace_func_graph_ret_t ftrace_graph_return;
  966. extern trace_func_graph_ent_t ftrace_graph_entry;
  967. extern void ftrace_graph_init_task(struct task_struct *t);
  968. extern void ftrace_graph_exit_task(struct task_struct *t);
  969. extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
  970. static inline void pause_graph_tracing(void)
  971. {
  972. atomic_inc(&current->tracing_graph_pause);
  973. }
  974. static inline void unpause_graph_tracing(void)
  975. {
  976. atomic_dec(&current->tracing_graph_pause);
  977. }
  978. #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
  979. #define __notrace_funcgraph
  980. static inline void ftrace_graph_init_task(struct task_struct *t) { }
  981. static inline void ftrace_graph_exit_task(struct task_struct *t) { }
  982. static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
  983. /* Define as macros as fgraph_ops may not be defined */
  984. #define register_ftrace_graph(ops) ({ -1; })
  985. #define unregister_ftrace_graph(ops) do { } while (0)
  986. static inline unsigned long
  987. ftrace_graph_ret_addr(struct task_struct *task, int *idx, unsigned long ret,
  988. unsigned long *retp)
  989. {
  990. return ret;
  991. }
  992. static inline void pause_graph_tracing(void) { }
  993. static inline void unpause_graph_tracing(void) { }
  994. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  995. #ifdef CONFIG_TRACING
  996. enum ftrace_dump_mode;
  997. extern enum ftrace_dump_mode ftrace_dump_on_oops;
  998. extern int tracepoint_printk;
  999. extern void disable_trace_on_warning(void);
  1000. extern int __disable_trace_on_warning;
  1001. int tracepoint_printk_sysctl(struct ctl_table *table, int write,
  1002. void *buffer, size_t *lenp, loff_t *ppos);
  1003. #else /* CONFIG_TRACING */
  1004. static inline void disable_trace_on_warning(void) { }
  1005. #endif /* CONFIG_TRACING */
  1006. #ifdef CONFIG_FTRACE_SYSCALLS
  1007. unsigned long arch_syscall_addr(int nr);
  1008. #endif /* CONFIG_FTRACE_SYSCALLS */
  1009. #endif /* _LINUX_FTRACE_H */