ftrace.h 29 KB

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