diff options
Diffstat (limited to 'include/linux/ftrace.h')
| -rw-r--r-- | include/linux/ftrace.h | 158 | 
1 files changed, 148 insertions, 10 deletions
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 55e6d63d46d0..a52f2f4fe030 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h  | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <linux/kallsyms.h> | 10 | #include <linux/kallsyms.h> | 
| 11 | #include <linux/linkage.h> | 11 | #include <linux/linkage.h> | 
| 12 | #include <linux/bitops.h> | 12 | #include <linux/bitops.h> | 
| 13 | #include <linux/ptrace.h> | ||
| 13 | #include <linux/ktime.h> | 14 | #include <linux/ktime.h> | 
| 14 | #include <linux/sched.h> | 15 | #include <linux/sched.h> | 
| 15 | #include <linux/types.h> | 16 | #include <linux/types.h> | 
| @@ -18,6 +19,28 @@ | |||
| 18 | 19 | ||
| 19 | #include <asm/ftrace.h> | 20 | #include <asm/ftrace.h> | 
| 20 | 21 | ||
| 22 | /* | ||
| 23 | * If the arch supports passing the variable contents of | ||
| 24 | * function_trace_op as the third parameter back from the | ||
| 25 | * mcount call, then the arch should define this as 1. | ||
| 26 | */ | ||
| 27 | #ifndef ARCH_SUPPORTS_FTRACE_OPS | ||
| 28 | #define ARCH_SUPPORTS_FTRACE_OPS 0 | ||
| 29 | #endif | ||
| 30 | |||
| 31 | /* | ||
| 32 | * If the arch's mcount caller does not support all of ftrace's | ||
| 33 | * features, then it must call an indirect function that | ||
| 34 | * does. Or at least does enough to prevent any unwelcomed side effects. | ||
| 35 | */ | ||
| 36 | #if !defined(CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST) || \ | ||
| 37 | !ARCH_SUPPORTS_FTRACE_OPS | ||
| 38 | # define FTRACE_FORCE_LIST_FUNC 1 | ||
| 39 | #else | ||
| 40 | # define FTRACE_FORCE_LIST_FUNC 0 | ||
| 41 | #endif | ||
| 42 | |||
| 43 | |||
| 21 | struct module; | 44 | struct module; | 
| 22 | struct ftrace_hash; | 45 | struct ftrace_hash; | 
| 23 | 46 | ||
| @@ -29,7 +52,10 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, | |||
| 29 | void __user *buffer, size_t *lenp, | 52 | void __user *buffer, size_t *lenp, | 
| 30 | loff_t *ppos); | 53 | loff_t *ppos); | 
| 31 | 54 | ||
| 32 | typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip); | 55 | struct ftrace_ops; | 
| 56 | |||
| 57 | typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip, | ||
| 58 | struct ftrace_ops *op, struct pt_regs *regs); | ||
| 33 | 59 | ||
| 34 | /* | 60 | /* | 
| 35 | * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are | 61 | * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are | 
| @@ -45,12 +71,33 @@ typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip); | |||
| 45 | * could be controled by following calls: | 71 | * could be controled by following calls: | 
| 46 | * ftrace_function_local_enable | 72 | * ftrace_function_local_enable | 
| 47 | * ftrace_function_local_disable | 73 | * ftrace_function_local_disable | 
| 74 | * SAVE_REGS - The ftrace_ops wants regs saved at each function called | ||
| 75 | * and passed to the callback. If this flag is set, but the | ||
| 76 | * architecture does not support passing regs | ||
| 77 | * (ARCH_SUPPORTS_FTRACE_SAVE_REGS is not defined), then the | ||
| 78 | * ftrace_ops will fail to register, unless the next flag | ||
| 79 | * is set. | ||
| 80 | * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the | ||
| 81 | * handler can handle an arch that does not save regs | ||
| 82 | * (the handler tests if regs == NULL), then it can set | ||
| 83 | * this flag instead. It will not fail registering the ftrace_ops | ||
| 84 | * but, the regs field will be NULL if the arch does not support | ||
| 85 | * passing regs to the handler. | ||
| 86 | * Note, if this flag is set, the SAVE_REGS flag will automatically | ||
| 87 | * get set upon registering the ftrace_ops, if the arch supports it. | ||
| 88 | * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure | ||
| 89 | * that the call back has its own recursion protection. If it does | ||
| 90 | * not set this, then the ftrace infrastructure will add recursion | ||
| 91 | * protection for the caller. | ||
| 48 | */ | 92 | */ | 
| 49 | enum { | 93 | enum { | 
| 50 | FTRACE_OPS_FL_ENABLED = 1 << 0, | 94 | FTRACE_OPS_FL_ENABLED = 1 << 0, | 
| 51 | FTRACE_OPS_FL_GLOBAL = 1 << 1, | 95 | FTRACE_OPS_FL_GLOBAL = 1 << 1, | 
| 52 | FTRACE_OPS_FL_DYNAMIC = 1 << 2, | 96 | FTRACE_OPS_FL_DYNAMIC = 1 << 2, | 
| 53 | FTRACE_OPS_FL_CONTROL = 1 << 3, | 97 | FTRACE_OPS_FL_CONTROL = 1 << 3, | 
| 98 | FTRACE_OPS_FL_SAVE_REGS = 1 << 4, | ||
| 99 | FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 5, | ||
| 100 | FTRACE_OPS_FL_RECURSION_SAFE = 1 << 6, | ||
| 54 | }; | 101 | }; | 
| 55 | 102 | ||
| 56 | struct ftrace_ops { | 103 | struct ftrace_ops { | 
| @@ -163,7 +210,8 @@ static inline int ftrace_function_local_disabled(struct ftrace_ops *ops) | |||
| 163 | return *this_cpu_ptr(ops->disabled); | 210 | return *this_cpu_ptr(ops->disabled); | 
| 164 | } | 211 | } | 
| 165 | 212 | ||
| 166 | extern void ftrace_stub(unsigned long a0, unsigned long a1); | 213 | extern void ftrace_stub(unsigned long a0, unsigned long a1, | 
| 214 | struct ftrace_ops *op, struct pt_regs *regs); | ||
| 167 | 215 | ||
| 168 | #else /* !CONFIG_FUNCTION_TRACER */ | 216 | #else /* !CONFIG_FUNCTION_TRACER */ | 
| 169 | /* | 217 | /* | 
| @@ -172,6 +220,10 @@ extern void ftrace_stub(unsigned long a0, unsigned long a1); | |||
| 172 | */ | 220 | */ | 
| 173 | #define register_ftrace_function(ops) ({ 0; }) | 221 | #define register_ftrace_function(ops) ({ 0; }) | 
| 174 | #define unregister_ftrace_function(ops) ({ 0; }) | 222 | #define unregister_ftrace_function(ops) ({ 0; }) | 
| 223 | static inline int ftrace_nr_registered_ops(void) | ||
| 224 | { | ||
| 225 | return 0; | ||
| 226 | } | ||
| 175 | static inline void clear_ftrace_function(void) { } | 227 | static inline void clear_ftrace_function(void) { } | 
| 176 | static inline void ftrace_kill(void) { } | 228 | static inline void ftrace_kill(void) { } | 
| 177 | static inline void ftrace_stop(void) { } | 229 | static inline void ftrace_stop(void) { } | 
| @@ -227,12 +279,33 @@ extern void unregister_ftrace_function_probe_all(char *glob); | |||
| 227 | 279 | ||
| 228 | extern int ftrace_text_reserved(void *start, void *end); | 280 | extern int ftrace_text_reserved(void *start, void *end); | 
| 229 | 281 | ||
| 282 | extern int ftrace_nr_registered_ops(void); | ||
| 283 | |||
| 284 | /* | ||
| 285 | * The dyn_ftrace record's flags field is split into two parts. | ||
| 286 | * the first part which is '0-FTRACE_REF_MAX' is a counter of | ||
| 287 | * the number of callbacks that have registered the function that | ||
| 288 | * the dyn_ftrace descriptor represents. | ||
| 289 | * | ||
| 290 | * The second part is a mask: | ||
| 291 | * ENABLED - the function is being traced | ||
| 292 | * REGS - the record wants the function to save regs | ||
| 293 | * REGS_EN - the function is set up to save regs. | ||
| 294 | * | ||
| 295 | * When a new ftrace_ops is registered and wants a function to save | ||
| 296 | * pt_regs, the rec->flag REGS is set. When the function has been | ||
| 297 | * set up to save regs, the REG_EN flag is set. Once a function | ||
| 298 | * starts saving regs it will do so until all ftrace_ops are removed | ||
| 299 | * from tracing that function. | ||
| 300 | */ | ||
| 230 | enum { | 301 | enum { | 
| 231 | FTRACE_FL_ENABLED = (1 << 30), | 302 | FTRACE_FL_ENABLED = (1UL << 29), | 
| 303 | FTRACE_FL_REGS = (1UL << 30), | ||
| 304 | FTRACE_FL_REGS_EN = (1UL << 31) | ||
| 232 | }; | 305 | }; | 
| 233 | 306 | ||
| 234 | #define FTRACE_FL_MASK (0x3UL << 30) | 307 | #define FTRACE_FL_MASK (0x7UL << 29) | 
| 235 | #define FTRACE_REF_MAX ((1 << 30) - 1) | 308 | #define FTRACE_REF_MAX ((1UL << 29) - 1) | 
| 236 | 309 | ||
| 237 | struct dyn_ftrace { | 310 | struct dyn_ftrace { | 
| 238 | union { | 311 | union { | 
| @@ -244,6 +317,8 @@ struct dyn_ftrace { | |||
| 244 | }; | 317 | }; | 
| 245 | 318 | ||
| 246 | int ftrace_force_update(void); | 319 | int ftrace_force_update(void); | 
| 320 | int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip, | ||
| 321 | int remove, int reset); | ||
| 247 | int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf, | 322 | int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf, | 
| 248 | int len, int reset); | 323 | int len, int reset); | 
| 249 | int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf, | 324 | int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf, | 
| @@ -263,9 +338,23 @@ enum { | |||
| 263 | FTRACE_STOP_FUNC_RET = (1 << 4), | 338 | FTRACE_STOP_FUNC_RET = (1 << 4), | 
| 264 | }; | 339 | }; | 
| 265 | 340 | ||
| 341 | /* | ||
| 342 | * The FTRACE_UPDATE_* enum is used to pass information back | ||
| 343 | * from the ftrace_update_record() and ftrace_test_record() | ||
| 344 | * functions. These are called by the code update routines | ||
| 345 | * to find out what is to be done for a given function. | ||
| 346 | * | ||
| 347 | * IGNORE - The function is already what we want it to be | ||
| 348 | * MAKE_CALL - Start tracing the function | ||
| 349 | * MODIFY_CALL - Stop saving regs for the function | ||
| 350 | * MODIFY_CALL_REGS - Start saving regs for the function | ||
| 351 | * MAKE_NOP - Stop tracing the function | ||
| 352 | */ | ||
| 266 | enum { | 353 | enum { | 
| 267 | FTRACE_UPDATE_IGNORE, | 354 | FTRACE_UPDATE_IGNORE, | 
| 268 | FTRACE_UPDATE_MAKE_CALL, | 355 | FTRACE_UPDATE_MAKE_CALL, | 
| 356 | FTRACE_UPDATE_MODIFY_CALL, | ||
| 357 | FTRACE_UPDATE_MODIFY_CALL_REGS, | ||
| 269 | FTRACE_UPDATE_MAKE_NOP, | 358 | FTRACE_UPDATE_MAKE_NOP, | 
| 270 | }; | 359 | }; | 
| 271 | 360 | ||
| @@ -317,7 +406,9 @@ extern int ftrace_dyn_arch_init(void *data); | |||
| 317 | extern void ftrace_replace_code(int enable); | 406 | extern void ftrace_replace_code(int enable); | 
| 318 | extern int ftrace_update_ftrace_func(ftrace_func_t func); | 407 | extern int ftrace_update_ftrace_func(ftrace_func_t func); | 
| 319 | extern void ftrace_caller(void); | 408 | extern void ftrace_caller(void); | 
| 409 | extern void ftrace_regs_caller(void); | ||
| 320 | extern void ftrace_call(void); | 410 | extern void ftrace_call(void); | 
| 411 | extern void ftrace_regs_call(void); | ||
| 321 | extern void mcount_call(void); | 412 | extern void mcount_call(void); | 
| 322 | 413 | ||
| 323 | void ftrace_modify_all_code(int command); | 414 | void ftrace_modify_all_code(int command); | 
| @@ -325,6 +416,15 @@ void ftrace_modify_all_code(int command); | |||
| 325 | #ifndef FTRACE_ADDR | 416 | #ifndef FTRACE_ADDR | 
| 326 | #define FTRACE_ADDR ((unsigned long)ftrace_caller) | 417 | #define FTRACE_ADDR ((unsigned long)ftrace_caller) | 
| 327 | #endif | 418 | #endif | 
| 419 | |||
| 420 | #ifndef FTRACE_REGS_ADDR | ||
| 421 | #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS | ||
| 422 | # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller) | ||
| 423 | #else | ||
| 424 | # define FTRACE_REGS_ADDR FTRACE_ADDR | ||
| 425 | #endif | ||
| 426 | #endif | ||
| 427 | |||
| 328 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 428 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 
| 329 | extern void ftrace_graph_caller(void); | 429 | extern void ftrace_graph_caller(void); | 
| 330 | extern int ftrace_enable_ftrace_graph_caller(void); | 430 | extern int ftrace_enable_ftrace_graph_caller(void); | 
| @@ -380,6 +480,39 @@ extern int ftrace_make_nop(struct module *mod, | |||
| 380 | */ | 480 | */ | 
| 381 | extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr); | 481 | extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr); | 
| 382 | 482 | ||
| 483 | #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS | ||
| 484 | /** | ||
| 485 | * ftrace_modify_call - convert from one addr to another (no nop) | ||
| 486 | * @rec: the mcount call site record | ||
| 487 | * @old_addr: the address expected to be currently called to | ||
| 488 | * @addr: the address to change to | ||
| 489 | * | ||
| 490 | * This is a very sensitive operation and great care needs | ||
| 491 | * to be taken by the arch. The operation should carefully | ||
| 492 | * read the location, check to see if what is read is indeed | ||
| 493 | * what we expect it to be, and then on success of the compare, | ||
| 494 | * it should write to the location. | ||
| 495 | * | ||
| 496 | * The code segment at @rec->ip should be a caller to @old_addr | ||
| 497 | * | ||
| 498 | * Return must be: | ||
| 499 | * 0 on success | ||
| 500 | * -EFAULT on error reading the location | ||
| 501 | * -EINVAL on a failed compare of the contents | ||
| 502 | * -EPERM on error writing to the location | ||
| 503 | * Any other value will be considered a failure. | ||
| 504 | */ | ||
| 505 | extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, | ||
| 506 | unsigned long addr); | ||
| 507 | #else | ||
| 508 | /* Should never be called */ | ||
| 509 | static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, | ||
| 510 | unsigned long addr) | ||
| 511 | { | ||
| 512 | return -EINVAL; | ||
| 513 | } | ||
| 514 | #endif | ||
| 515 | |||
| 383 | /* May be defined in arch */ | 516 | /* May be defined in arch */ | 
| 384 | extern int ftrace_arch_read_dyn_info(char *buf, int size); | 517 | extern int ftrace_arch_read_dyn_info(char *buf, int size); | 
| 385 | 518 | ||
| @@ -387,7 +520,7 @@ extern int skip_trace(unsigned long ip); | |||
| 387 | 520 | ||
| 388 | extern void ftrace_disable_daemon(void); | 521 | extern void ftrace_disable_daemon(void); | 
| 389 | extern void ftrace_enable_daemon(void); | 522 | extern void ftrace_enable_daemon(void); | 
| 390 | #else | 523 | #else /* CONFIG_DYNAMIC_FTRACE */ | 
| 391 | static inline int skip_trace(unsigned long ip) { return 0; } | 524 | static inline int skip_trace(unsigned long ip) { return 0; } | 
| 392 | static inline int ftrace_force_update(void) { return 0; } | 525 | static inline int ftrace_force_update(void) { return 0; } | 
| 393 | static inline void ftrace_disable_daemon(void) { } | 526 | static inline void ftrace_disable_daemon(void) { } | 
| @@ -405,6 +538,10 @@ static inline int ftrace_text_reserved(void *start, void *end) | |||
| 405 | { | 538 | { | 
| 406 | return 0; | 539 | return 0; | 
| 407 | } | 540 | } | 
| 541 | static inline unsigned long ftrace_location(unsigned long ip) | ||
| 542 | { | ||
| 543 | return 0; | ||
| 544 | } | ||
| 408 | 545 | ||
| 409 | /* | 546 | /* | 
| 410 | * Again users of functions that have ftrace_ops may not | 547 | * Again users of functions that have ftrace_ops may not | 
| @@ -413,6 +550,7 @@ static inline int ftrace_text_reserved(void *start, void *end) | |||
| 413 | */ | 550 | */ | 
| 414 | #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; }) | 551 | #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; }) | 
| 415 | #define ftrace_set_early_filter(ops, buf, enable) do { } while (0) | 552 | #define ftrace_set_early_filter(ops, buf, enable) do { } while (0) | 
| 553 | #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; }) | ||
| 416 | #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; }) | 554 | #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; }) | 
| 417 | #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; }) | 555 | #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; }) | 
| 418 | #define ftrace_free_filter(ops) do { } while (0) | 556 | #define ftrace_free_filter(ops) do { } while (0) | 
