ftrace.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /*
  2. * Ftrace header. For implementation details beyond the random comments
  3. * scattered below, see: Documentation/trace/ftrace-design.txt
  4. */
  5. #ifndef _LINUX_FTRACE_H
  6. #define _LINUX_FTRACE_H
  7. #include <linux/trace_clock.h>
  8. #include <linux/kallsyms.h>
  9. #include <linux/linkage.h>
  10. #include <linux/bitops.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/ktime.h>
  13. #include <linux/sched.h>
  14. #include <linux/types.h>
  15. #include <linux/init.h>
  16. #include <linux/fs.h>
  17. #include <asm/ftrace.h>
  18. /*
  19. * If the arch supports passing the variable contents of
  20. * function_trace_op as the third parameter back from the
  21. * mcount call, then the arch should define this as 1.
  22. */
  23. #ifndef ARCH_SUPPORTS_FTRACE_OPS
  24. #define ARCH_SUPPORTS_FTRACE_OPS 0
  25. #endif
  26. /*
  27. * If the arch's mcount caller does not support all of ftrace's
  28. * features, then it must call an indirect function that
  29. * does. Or at least does enough to prevent any unwelcomed side effects.
  30. */
  31. #if !ARCH_SUPPORTS_FTRACE_OPS
  32. # define FTRACE_FORCE_LIST_FUNC 1
  33. #else
  34. # define FTRACE_FORCE_LIST_FUNC 0
  35. #endif
  36. /* Main tracing buffer and events set up */
  37. #ifdef CONFIG_TRACING
  38. void trace_init(void);
  39. #else
  40. static inline void trace_init(void) { }
  41. #endif
  42. struct module;
  43. struct ftrace_hash;
  44. #ifdef CONFIG_FUNCTION_TRACER
  45. extern int ftrace_enabled;
  46. extern int
  47. ftrace_enable_sysctl(struct ctl_table *table, int write,
  48. void __user *buffer, size_t *lenp,
  49. loff_t *ppos);
  50. struct ftrace_ops;
  51. typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
  52. struct ftrace_ops *op, struct pt_regs *regs);
  53. ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
  54. /*
  55. * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
  56. * set in the flags member.
  57. * CONTROL, SAVE_REGS, SAVE_REGS_IF_SUPPORTED, RECURSION_SAFE, STUB and
  58. * IPMODIFY are a kind of attribute flags which can be set only before
  59. * registering the ftrace_ops, and can not be modified while registered.
  60. * Changing those attribute flags after regsitering ftrace_ops will
  61. * cause unexpected results.
  62. *
  63. * ENABLED - set/unset when ftrace_ops is registered/unregistered
  64. * DYNAMIC - set when ftrace_ops is registered to denote dynamically
  65. * allocated ftrace_ops which need special care
  66. * PER_CPU - set manualy by ftrace_ops user to denote the ftrace_ops
  67. * could be controlled by following calls:
  68. * ftrace_function_local_enable
  69. * ftrace_function_local_disable
  70. * SAVE_REGS - The ftrace_ops wants regs saved at each function called
  71. * and passed to the callback. If this flag is set, but the
  72. * architecture does not support passing regs
  73. * (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
  74. * ftrace_ops will fail to register, unless the next flag
  75. * is set.
  76. * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
  77. * handler can handle an arch that does not save regs
  78. * (the handler tests if regs == NULL), then it can set
  79. * this flag instead. It will not fail registering the ftrace_ops
  80. * but, the regs field will be NULL if the arch does not support
  81. * passing regs to the handler.
  82. * Note, if this flag is set, the SAVE_REGS flag will automatically
  83. * get set upon registering the ftrace_ops, if the arch supports it.
  84. * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
  85. * that the call back has its own recursion protection. If it does
  86. * not set this, then the ftrace infrastructure will add recursion
  87. * protection for the caller.
  88. * STUB - The ftrace_ops is just a place holder.
  89. * INITIALIZED - The ftrace_ops has already been initialized (first use time
  90. * register_ftrace_function() is called, it will initialized the ops)
  91. * DELETED - The ops are being deleted, do not let them be registered again.
  92. * ADDING - The ops is in the process of being added.
  93. * REMOVING - The ops is in the process of being removed.
  94. * MODIFYING - The ops is in the process of changing its filter functions.
  95. * ALLOC_TRAMP - A dynamic trampoline was allocated by the core code.
  96. * The arch specific code sets this flag when it allocated a
  97. * trampoline. This lets the arch know that it can update the
  98. * trampoline in case the callback function changes.
  99. * The ftrace_ops trampoline can be set by the ftrace users, and
  100. * in such cases the arch must not modify it. Only the arch ftrace
  101. * core code should set this flag.
  102. * IPMODIFY - The ops can modify the IP register. This can only be set with
  103. * SAVE_REGS. If another ops with this flag set is already registered
  104. * for any of the functions that this ops will be registered for, then
  105. * this ops will fail to register or set_filter_ip.
  106. * PID - Is affected by set_ftrace_pid (allows filtering on those pids)
  107. */
  108. enum {
  109. FTRACE_OPS_FL_ENABLED = 1 << 0,
  110. FTRACE_OPS_FL_DYNAMIC = 1 << 1,
  111. FTRACE_OPS_FL_PER_CPU = 1 << 2,
  112. FTRACE_OPS_FL_SAVE_REGS = 1 << 3,
  113. FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 4,
  114. FTRACE_OPS_FL_RECURSION_SAFE = 1 << 5,
  115. FTRACE_OPS_FL_STUB = 1 << 6,
  116. FTRACE_OPS_FL_INITIALIZED = 1 << 7,
  117. FTRACE_OPS_FL_DELETED = 1 << 8,
  118. FTRACE_OPS_FL_ADDING = 1 << 9,
  119. FTRACE_OPS_FL_REMOVING = 1 << 10,
  120. FTRACE_OPS_FL_MODIFYING = 1 << 11,
  121. FTRACE_OPS_FL_ALLOC_TRAMP = 1 << 12,
  122. FTRACE_OPS_FL_IPMODIFY = 1 << 13,
  123. FTRACE_OPS_FL_PID = 1 << 14,
  124. FTRACE_OPS_FL_RCU = 1 << 15,
  125. };
  126. #ifdef CONFIG_DYNAMIC_FTRACE
  127. /* The hash used to know what functions callbacks trace */
  128. struct ftrace_ops_hash {
  129. struct ftrace_hash *notrace_hash;
  130. struct ftrace_hash *filter_hash;
  131. struct mutex regex_lock;
  132. };
  133. #endif
  134. /*
  135. * Note, ftrace_ops can be referenced outside of RCU protection, unless
  136. * the RCU flag is set. If ftrace_ops is allocated and not part of kernel
  137. * core data, the unregistering of it will perform a scheduling on all CPUs
  138. * to make sure that there are no more users. Depending on the load of the
  139. * system that may take a bit of time.
  140. *
  141. * Any private data added must also take care not to be freed and if private
  142. * data is added to a ftrace_ops that is in core code, the user of the
  143. * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
  144. */
  145. struct ftrace_ops {
  146. ftrace_func_t func;
  147. struct ftrace_ops *next;
  148. unsigned long flags;
  149. void *private;
  150. ftrace_func_t saved_func;
  151. int __percpu *disabled;
  152. #ifdef CONFIG_DYNAMIC_FTRACE
  153. int nr_trampolines;
  154. struct ftrace_ops_hash local_hash;
  155. struct ftrace_ops_hash *func_hash;
  156. struct ftrace_ops_hash old_hash;
  157. unsigned long trampoline;
  158. unsigned long trampoline_size;
  159. #endif
  160. };
  161. /*
  162. * Type of the current tracing.
  163. */
  164. enum ftrace_tracing_type_t {
  165. FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  166. FTRACE_TYPE_RETURN, /* Hook the return of the function */
  167. };
  168. /* Current tracing type, default is FTRACE_TYPE_ENTER */
  169. extern enum ftrace_tracing_type_t ftrace_tracing_type;
  170. /*
  171. * The ftrace_ops must be a static and should also
  172. * be read_mostly. These functions do modify read_mostly variables
  173. * so use them sparely. Never free an ftrace_op or modify the
  174. * next pointer after it has been registered. Even after unregistering
  175. * it, the next pointer may still be used internally.
  176. */
  177. int register_ftrace_function(struct ftrace_ops *ops);
  178. int unregister_ftrace_function(struct ftrace_ops *ops);
  179. void clear_ftrace_function(void);
  180. /**
  181. * ftrace_function_local_enable - enable ftrace_ops on current cpu
  182. *
  183. * This function enables tracing on current cpu by decreasing
  184. * the per cpu control variable.
  185. * It must be called with preemption disabled and only on ftrace_ops
  186. * registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
  187. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  188. */
  189. static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
  190. {
  191. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU)))
  192. return;
  193. (*this_cpu_ptr(ops->disabled))--;
  194. }
  195. /**
  196. * ftrace_function_local_disable - disable ftrace_ops on current cpu
  197. *
  198. * This function disables tracing on current cpu by increasing
  199. * the per cpu control variable.
  200. * It must be called with preemption disabled and only on ftrace_ops
  201. * registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
  202. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  203. */
  204. static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
  205. {
  206. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU)))
  207. return;
  208. (*this_cpu_ptr(ops->disabled))++;
  209. }
  210. /**
  211. * ftrace_function_local_disabled - returns ftrace_ops disabled value
  212. * on current cpu
  213. *
  214. * This function returns value of ftrace_ops::disabled on current cpu.
  215. * It must be called with preemption disabled and only on ftrace_ops
  216. * registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
  217. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  218. */
  219. static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
  220. {
  221. WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU));
  222. return *this_cpu_ptr(ops->disabled);
  223. }
  224. extern void ftrace_stub(unsigned long a0, unsigned long a1,
  225. struct ftrace_ops *op, struct pt_regs *regs);
  226. #else /* !CONFIG_FUNCTION_TRACER */
  227. /*
  228. * (un)register_ftrace_function must be a macro since the ops parameter
  229. * must not be evaluated.
  230. */
  231. #define register_ftrace_function(ops) ({ 0; })
  232. #define unregister_ftrace_function(ops) ({ 0; })
  233. static inline int ftrace_nr_registered_ops(void)
  234. {
  235. return 0;
  236. }
  237. static inline void clear_ftrace_function(void) { }
  238. static inline void ftrace_kill(void) { }
  239. #endif /* CONFIG_FUNCTION_TRACER */
  240. #ifdef CONFIG_STACK_TRACER
  241. #define STACK_TRACE_ENTRIES 500
  242. struct stack_trace;
  243. extern unsigned stack_trace_index[];
  244. extern struct stack_trace stack_trace_max;
  245. extern unsigned long stack_trace_max_size;
  246. extern arch_spinlock_t stack_trace_max_lock;
  247. extern int stack_tracer_enabled;
  248. void stack_trace_print(void);
  249. int
  250. stack_trace_sysctl(struct ctl_table *table, int write,
  251. void __user *buffer, size_t *lenp,
  252. loff_t *ppos);
  253. #endif
  254. struct ftrace_func_command {
  255. struct list_head list;
  256. char *name;
  257. int (*func)(struct ftrace_hash *hash,
  258. char *func, char *cmd,
  259. char *params, int enable);
  260. };
  261. #ifdef CONFIG_DYNAMIC_FTRACE
  262. int ftrace_arch_code_modify_prepare(void);
  263. int ftrace_arch_code_modify_post_process(void);
  264. struct dyn_ftrace;
  265. enum ftrace_bug_type {
  266. FTRACE_BUG_UNKNOWN,
  267. FTRACE_BUG_INIT,
  268. FTRACE_BUG_NOP,
  269. FTRACE_BUG_CALL,
  270. FTRACE_BUG_UPDATE,
  271. };
  272. extern enum ftrace_bug_type ftrace_bug_type;
  273. /*
  274. * Archs can set this to point to a variable that holds the value that was
  275. * expected at the call site before calling ftrace_bug().
  276. */
  277. extern const void *ftrace_expected;
  278. void ftrace_bug(int err, struct dyn_ftrace *rec);
  279. struct seq_file;
  280. struct ftrace_probe_ops {
  281. void (*func)(unsigned long ip,
  282. unsigned long parent_ip,
  283. void **data);
  284. int (*init)(struct ftrace_probe_ops *ops,
  285. unsigned long ip, void **data);
  286. void (*free)(struct ftrace_probe_ops *ops,
  287. unsigned long ip, void **data);
  288. int (*print)(struct seq_file *m,
  289. unsigned long ip,
  290. struct ftrace_probe_ops *ops,
  291. void *data);
  292. };
  293. extern int
  294. register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  295. void *data);
  296. extern void
  297. unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  298. void *data);
  299. extern void
  300. unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
  301. extern void unregister_ftrace_function_probe_all(char *glob);
  302. extern int ftrace_text_reserved(const void *start, const void *end);
  303. extern int ftrace_nr_registered_ops(void);
  304. bool is_ftrace_trampoline(unsigned long addr);
  305. /*
  306. * The dyn_ftrace record's flags field is split into two parts.
  307. * the first part which is '0-FTRACE_REF_MAX' is a counter of
  308. * the number of callbacks that have registered the function that
  309. * the dyn_ftrace descriptor represents.
  310. *
  311. * The second part is a mask:
  312. * ENABLED - the function is being traced
  313. * REGS - the record wants the function to save regs
  314. * REGS_EN - the function is set up to save regs.
  315. * IPMODIFY - the record allows for the IP address to be changed.
  316. * DISABLED - the record is not ready to be touched yet
  317. *
  318. * When a new ftrace_ops is registered and wants a function to save
  319. * pt_regs, the rec->flag REGS is set. When the function has been
  320. * set up to save regs, the REG_EN flag is set. Once a function
  321. * starts saving regs it will do so until all ftrace_ops are removed
  322. * from tracing that function.
  323. */
  324. enum {
  325. FTRACE_FL_ENABLED = (1UL << 31),
  326. FTRACE_FL_REGS = (1UL << 30),
  327. FTRACE_FL_REGS_EN = (1UL << 29),
  328. FTRACE_FL_TRAMP = (1UL << 28),
  329. FTRACE_FL_TRAMP_EN = (1UL << 27),
  330. FTRACE_FL_IPMODIFY = (1UL << 26),
  331. FTRACE_FL_DISABLED = (1UL << 25),
  332. };
  333. #define FTRACE_REF_MAX_SHIFT 25
  334. #define FTRACE_FL_BITS 7
  335. #define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1)
  336. #define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
  337. #define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
  338. #define ftrace_rec_count(rec) ((rec)->flags & ~FTRACE_FL_MASK)
  339. struct dyn_ftrace {
  340. unsigned long ip; /* address of mcount call-site */
  341. unsigned long flags;
  342. struct dyn_arch_ftrace arch;
  343. };
  344. int ftrace_force_update(void);
  345. int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
  346. int remove, int reset);
  347. int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  348. int len, int reset);
  349. int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  350. int len, int reset);
  351. void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  352. void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
  353. void ftrace_free_filter(struct ftrace_ops *ops);
  354. int register_ftrace_command(struct ftrace_func_command *cmd);
  355. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  356. enum {
  357. FTRACE_UPDATE_CALLS = (1 << 0),
  358. FTRACE_DISABLE_CALLS = (1 << 1),
  359. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  360. FTRACE_START_FUNC_RET = (1 << 3),
  361. FTRACE_STOP_FUNC_RET = (1 << 4),
  362. };
  363. /*
  364. * The FTRACE_UPDATE_* enum is used to pass information back
  365. * from the ftrace_update_record() and ftrace_test_record()
  366. * functions. These are called by the code update routines
  367. * to find out what is to be done for a given function.
  368. *
  369. * IGNORE - The function is already what we want it to be
  370. * MAKE_CALL - Start tracing the function
  371. * MODIFY_CALL - Stop saving regs for the function
  372. * MAKE_NOP - Stop tracing the function
  373. */
  374. enum {
  375. FTRACE_UPDATE_IGNORE,
  376. FTRACE_UPDATE_MAKE_CALL,
  377. FTRACE_UPDATE_MODIFY_CALL,
  378. FTRACE_UPDATE_MAKE_NOP,
  379. };
  380. enum {
  381. FTRACE_ITER_FILTER = (1 << 0),
  382. FTRACE_ITER_NOTRACE = (1 << 1),
  383. FTRACE_ITER_PRINTALL = (1 << 2),
  384. FTRACE_ITER_DO_HASH = (1 << 3),
  385. FTRACE_ITER_HASH = (1 << 4),
  386. FTRACE_ITER_ENABLED = (1 << 5),
  387. };
  388. void arch_ftrace_update_code(int command);
  389. struct ftrace_rec_iter;
  390. struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  391. struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  392. struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
  393. #define for_ftrace_rec_iter(iter) \
  394. for (iter = ftrace_rec_iter_start(); \
  395. iter; \
  396. iter = ftrace_rec_iter_next(iter))
  397. int ftrace_update_record(struct dyn_ftrace *rec, int enable);
  398. int ftrace_test_record(struct dyn_ftrace *rec, int enable);
  399. void ftrace_run_stop_machine(int command);
  400. unsigned long ftrace_location(unsigned long ip);
  401. unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
  402. unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
  403. extern ftrace_func_t ftrace_trace_function;
  404. int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  405. struct inode *inode, struct file *file);
  406. ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  407. size_t cnt, loff_t *ppos);
  408. ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  409. size_t cnt, loff_t *ppos);
  410. int ftrace_regex_release(struct inode *inode, struct file *file);
  411. void __init
  412. ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
  413. /* defined in arch */
  414. extern int ftrace_ip_converted(unsigned long ip);
  415. extern int ftrace_dyn_arch_init(void);
  416. extern void ftrace_replace_code(int enable);
  417. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  418. extern void ftrace_caller(void);
  419. extern void ftrace_regs_caller(void);
  420. extern void ftrace_call(void);
  421. extern void ftrace_regs_call(void);
  422. extern void mcount_call(void);
  423. void ftrace_modify_all_code(int command);
  424. #ifndef FTRACE_ADDR
  425. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  426. #endif
  427. #ifndef FTRACE_GRAPH_ADDR
  428. #define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
  429. #endif
  430. #ifndef FTRACE_REGS_ADDR
  431. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  432. # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
  433. #else
  434. # define FTRACE_REGS_ADDR FTRACE_ADDR
  435. #endif
  436. #endif
  437. /*
  438. * If an arch would like functions that are only traced
  439. * by the function graph tracer to jump directly to its own
  440. * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
  441. * to be that address to jump to.
  442. */
  443. #ifndef FTRACE_GRAPH_TRAMP_ADDR
  444. #define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
  445. #endif
  446. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  447. extern void ftrace_graph_caller(void);
  448. extern int ftrace_enable_ftrace_graph_caller(void);
  449. extern int ftrace_disable_ftrace_graph_caller(void);
  450. #else
  451. static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  452. static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
  453. #endif
  454. /**
  455. * ftrace_make_nop - convert code into nop
  456. * @mod: module structure if called by module load initialization
  457. * @rec: the mcount call site record
  458. * @addr: the address that the call site should be calling
  459. *
  460. * This is a very sensitive operation and great care needs
  461. * to be taken by the arch. The operation should carefully
  462. * read the location, check to see if what is read is indeed
  463. * what we expect it to be, and then on success of the compare,
  464. * it should write to the location.
  465. *
  466. * The code segment at @rec->ip should be a caller to @addr
  467. *
  468. * Return must be:
  469. * 0 on success
  470. * -EFAULT on error reading the location
  471. * -EINVAL on a failed compare of the contents
  472. * -EPERM on error writing to the location
  473. * Any other value will be considered a failure.
  474. */
  475. extern int ftrace_make_nop(struct module *mod,
  476. struct dyn_ftrace *rec, unsigned long addr);
  477. /**
  478. * ftrace_make_call - convert a nop call site into a call to addr
  479. * @rec: the mcount call site record
  480. * @addr: the address that the call site should call
  481. *
  482. * This is a very sensitive operation and great care needs
  483. * to be taken by the arch. The operation should carefully
  484. * read the location, check to see if what is read is indeed
  485. * what we expect it to be, and then on success of the compare,
  486. * it should write to the location.
  487. *
  488. * The code segment at @rec->ip should be a nop
  489. *
  490. * Return must be:
  491. * 0 on success
  492. * -EFAULT on error reading the location
  493. * -EINVAL on a failed compare of the contents
  494. * -EPERM on error writing to the location
  495. * Any other value will be considered a failure.
  496. */
  497. extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
  498. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  499. /**
  500. * ftrace_modify_call - convert from one addr to another (no nop)
  501. * @rec: the mcount call site record
  502. * @old_addr: the address expected to be currently called to
  503. * @addr: the address to change to
  504. *
  505. * This is a very sensitive operation and great care needs
  506. * to be taken by the arch. The operation should carefully
  507. * read the location, check to see if what is read is indeed
  508. * what we expect it to be, and then on success of the compare,
  509. * it should write to the location.
  510. *
  511. * The code segment at @rec->ip should be a caller to @old_addr
  512. *
  513. * Return must be:
  514. * 0 on success
  515. * -EFAULT on error reading the location
  516. * -EINVAL on a failed compare of the contents
  517. * -EPERM on error writing to the location
  518. * Any other value will be considered a failure.
  519. */
  520. extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  521. unsigned long addr);
  522. #else
  523. /* Should never be called */
  524. static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  525. unsigned long addr)
  526. {
  527. return -EINVAL;
  528. }
  529. #endif
  530. /* May be defined in arch */
  531. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  532. extern int skip_trace(unsigned long ip);
  533. extern void ftrace_module_init(struct module *mod);
  534. extern void ftrace_release_mod(struct module *mod);
  535. extern void ftrace_disable_daemon(void);
  536. extern void ftrace_enable_daemon(void);
  537. #else /* CONFIG_DYNAMIC_FTRACE */
  538. static inline int skip_trace(unsigned long ip) { return 0; }
  539. static inline int ftrace_force_update(void) { return 0; }
  540. static inline void ftrace_disable_daemon(void) { }
  541. static inline void ftrace_enable_daemon(void) { }
  542. static inline void ftrace_release_mod(struct module *mod) {}
  543. static inline void ftrace_module_init(struct module *mod) {}
  544. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  545. {
  546. return -EINVAL;
  547. }
  548. static inline __init int unregister_ftrace_command(char *cmd_name)
  549. {
  550. return -EINVAL;
  551. }
  552. static inline int ftrace_text_reserved(const void *start, const void *end)
  553. {
  554. return 0;
  555. }
  556. static inline unsigned long ftrace_location(unsigned long ip)
  557. {
  558. return 0;
  559. }
  560. /*
  561. * Again users of functions that have ftrace_ops may not
  562. * have them defined when ftrace is not enabled, but these
  563. * functions may still be called. Use a macro instead of inline.
  564. */
  565. #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  566. #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
  567. #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
  568. #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  569. #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  570. #define ftrace_free_filter(ops) do { } while (0)
  571. static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  572. size_t cnt, loff_t *ppos) { return -ENODEV; }
  573. static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  574. size_t cnt, loff_t *ppos) { return -ENODEV; }
  575. static inline int
  576. ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
  577. static inline bool is_ftrace_trampoline(unsigned long addr)
  578. {
  579. return false;
  580. }
  581. #endif /* CONFIG_DYNAMIC_FTRACE */
  582. /* totally disable ftrace - can not re-enable after this */
  583. void ftrace_kill(void);
  584. static inline void tracer_disable(void)
  585. {
  586. #ifdef CONFIG_FUNCTION_TRACER
  587. ftrace_enabled = 0;
  588. #endif
  589. }
  590. /*
  591. * Ftrace disable/restore without lock. Some synchronization mechanism
  592. * must be used to prevent ftrace_enabled to be changed between
  593. * disable/restore.
  594. */
  595. static inline int __ftrace_enabled_save(void)
  596. {
  597. #ifdef CONFIG_FUNCTION_TRACER
  598. int saved_ftrace_enabled = ftrace_enabled;
  599. ftrace_enabled = 0;
  600. return saved_ftrace_enabled;
  601. #else
  602. return 0;
  603. #endif
  604. }
  605. static inline void __ftrace_enabled_restore(int enabled)
  606. {
  607. #ifdef CONFIG_FUNCTION_TRACER
  608. ftrace_enabled = enabled;
  609. #endif
  610. }
  611. /* All archs should have this, but we define it for consistency */
  612. #ifndef ftrace_return_address0
  613. # define ftrace_return_address0 __builtin_return_address(0)
  614. #endif
  615. /* Archs may use other ways for ADDR1 and beyond */
  616. #ifndef ftrace_return_address
  617. # ifdef CONFIG_FRAME_POINTER
  618. # define ftrace_return_address(n) __builtin_return_address(n)
  619. # else
  620. # define ftrace_return_address(n) 0UL
  621. # endif
  622. #endif
  623. #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
  624. #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
  625. #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
  626. #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
  627. #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
  628. #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  629. #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
  630. #ifdef CONFIG_IRQSOFF_TRACER
  631. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  632. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  633. #else
  634. static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
  635. static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
  636. #endif
  637. #ifdef CONFIG_PREEMPT_TRACER
  638. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  639. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  640. #else
  641. /*
  642. * Use defines instead of static inlines because some arches will make code out
  643. * of the CALLER_ADDR, when we really want these to be a real nop.
  644. */
  645. # define trace_preempt_on(a0, a1) do { } while (0)
  646. # define trace_preempt_off(a0, a1) do { } while (0)
  647. #endif
  648. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  649. extern void ftrace_init(void);
  650. #else
  651. static inline void ftrace_init(void) { }
  652. #endif
  653. /*
  654. * Structure that defines an entry function trace.
  655. */
  656. struct ftrace_graph_ent {
  657. unsigned long func; /* Current function */
  658. int depth;
  659. };
  660. /*
  661. * Structure that defines a return function trace.
  662. */
  663. struct ftrace_graph_ret {
  664. unsigned long func; /* Current function */
  665. unsigned long long calltime;
  666. unsigned long long rettime;
  667. /* Number of functions that overran the depth limit for current task */
  668. unsigned long overrun;
  669. int depth;
  670. };
  671. /* Type of the callback handlers for tracing function graph*/
  672. typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  673. typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
  674. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  675. /* for init task */
  676. #define INIT_FTRACE_GRAPH .ret_stack = NULL,
  677. /*
  678. * Stack of return addresses for functions
  679. * of a thread.
  680. * Used in struct thread_info
  681. */
  682. struct ftrace_ret_stack {
  683. unsigned long ret;
  684. unsigned long func;
  685. unsigned long long calltime;
  686. unsigned long long subtime;
  687. unsigned long fp;
  688. };
  689. /*
  690. * Primary handler of a function return.
  691. * It relays on ftrace_return_to_handler.
  692. * Defined in entry_32/64.S
  693. */
  694. extern void return_to_handler(void);
  695. extern int
  696. ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
  697. unsigned long frame_pointer);
  698. /*
  699. * Sometimes we don't want to trace a function with the function
  700. * graph tracer but we want them to keep traced by the usual function
  701. * tracer if the function graph tracer is not configured.
  702. */
  703. #define __notrace_funcgraph notrace
  704. /*
  705. * We want to which function is an entrypoint of a hardirq.
  706. * That will help us to put a signal on output.
  707. */
  708. #define __irq_entry __attribute__((__section__(".irqentry.text")))
  709. /* Limits of hardirq entrypoints */
  710. extern char __irqentry_text_start[];
  711. extern char __irqentry_text_end[];
  712. #define FTRACE_NOTRACE_DEPTH 65536
  713. #define FTRACE_RETFUNC_DEPTH 50
  714. #define FTRACE_RETSTACK_ALLOC_SIZE 32
  715. extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  716. trace_func_graph_ent_t entryfunc);
  717. extern bool ftrace_graph_is_dead(void);
  718. extern void ftrace_graph_stop(void);
  719. /* The current handlers in use */
  720. extern trace_func_graph_ret_t ftrace_graph_return;
  721. extern trace_func_graph_ent_t ftrace_graph_entry;
  722. extern void unregister_ftrace_graph(void);
  723. extern void ftrace_graph_init_task(struct task_struct *t);
  724. extern void ftrace_graph_exit_task(struct task_struct *t);
  725. extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
  726. static inline int task_curr_ret_stack(struct task_struct *t)
  727. {
  728. return t->curr_ret_stack;
  729. }
  730. static inline void pause_graph_tracing(void)
  731. {
  732. atomic_inc(&current->tracing_graph_pause);
  733. }
  734. static inline void unpause_graph_tracing(void)
  735. {
  736. atomic_dec(&current->tracing_graph_pause);
  737. }
  738. #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
  739. #define __notrace_funcgraph
  740. #define __irq_entry
  741. #define INIT_FTRACE_GRAPH
  742. static inline void ftrace_graph_init_task(struct task_struct *t) { }
  743. static inline void ftrace_graph_exit_task(struct task_struct *t) { }
  744. static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
  745. static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  746. trace_func_graph_ent_t entryfunc)
  747. {
  748. return -1;
  749. }
  750. static inline void unregister_ftrace_graph(void) { }
  751. static inline int task_curr_ret_stack(struct task_struct *tsk)
  752. {
  753. return -1;
  754. }
  755. static inline void pause_graph_tracing(void) { }
  756. static inline void unpause_graph_tracing(void) { }
  757. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  758. #ifdef CONFIG_TRACING
  759. /* flags for current->trace */
  760. enum {
  761. TSK_TRACE_FL_TRACE_BIT = 0,
  762. TSK_TRACE_FL_GRAPH_BIT = 1,
  763. };
  764. enum {
  765. TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
  766. TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
  767. };
  768. static inline void set_tsk_trace_trace(struct task_struct *tsk)
  769. {
  770. set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  771. }
  772. static inline void clear_tsk_trace_trace(struct task_struct *tsk)
  773. {
  774. clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  775. }
  776. static inline int test_tsk_trace_trace(struct task_struct *tsk)
  777. {
  778. return tsk->trace & TSK_TRACE_FL_TRACE;
  779. }
  780. static inline void set_tsk_trace_graph(struct task_struct *tsk)
  781. {
  782. set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  783. }
  784. static inline void clear_tsk_trace_graph(struct task_struct *tsk)
  785. {
  786. clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  787. }
  788. static inline int test_tsk_trace_graph(struct task_struct *tsk)
  789. {
  790. return tsk->trace & TSK_TRACE_FL_GRAPH;
  791. }
  792. enum ftrace_dump_mode;
  793. extern enum ftrace_dump_mode ftrace_dump_on_oops;
  794. extern int tracepoint_printk;
  795. extern void disable_trace_on_warning(void);
  796. extern int __disable_trace_on_warning;
  797. #ifdef CONFIG_PREEMPT
  798. #define INIT_TRACE_RECURSION .trace_recursion = 0,
  799. #endif
  800. #else /* CONFIG_TRACING */
  801. static inline void disable_trace_on_warning(void) { }
  802. #endif /* CONFIG_TRACING */
  803. #ifndef INIT_TRACE_RECURSION
  804. #define INIT_TRACE_RECURSION
  805. #endif
  806. #ifdef CONFIG_FTRACE_SYSCALLS
  807. unsigned long arch_syscall_addr(int nr);
  808. #endif /* CONFIG_FTRACE_SYSCALLS */
  809. #endif /* _LINUX_FTRACE_H */