diff options
Diffstat (limited to 'kernel/trace/ftrace.c')
-rw-r--r-- | kernel/trace/ftrace.c | 105 |
1 files changed, 46 insertions, 59 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 1e6640f80454..83783579378f 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/hardirq.h> | 22 | #include <linux/hardirq.h> |
23 | #include <linux/kthread.h> | 23 | #include <linux/kthread.h> |
24 | #include <linux/uaccess.h> | 24 | #include <linux/uaccess.h> |
25 | #include <linux/kprobes.h> | ||
26 | #include <linux/ftrace.h> | 25 | #include <linux/ftrace.h> |
27 | #include <linux/sysctl.h> | 26 | #include <linux/sysctl.h> |
28 | #include <linux/ctype.h> | 27 | #include <linux/ctype.h> |
@@ -898,36 +897,6 @@ static struct dyn_ftrace *ftrace_free_records; | |||
898 | } \ | 897 | } \ |
899 | } | 898 | } |
900 | 899 | ||
901 | #ifdef CONFIG_KPROBES | ||
902 | |||
903 | static int frozen_record_count; | ||
904 | |||
905 | static inline void freeze_record(struct dyn_ftrace *rec) | ||
906 | { | ||
907 | if (!(rec->flags & FTRACE_FL_FROZEN)) { | ||
908 | rec->flags |= FTRACE_FL_FROZEN; | ||
909 | frozen_record_count++; | ||
910 | } | ||
911 | } | ||
912 | |||
913 | static inline void unfreeze_record(struct dyn_ftrace *rec) | ||
914 | { | ||
915 | if (rec->flags & FTRACE_FL_FROZEN) { | ||
916 | rec->flags &= ~FTRACE_FL_FROZEN; | ||
917 | frozen_record_count--; | ||
918 | } | ||
919 | } | ||
920 | |||
921 | static inline int record_frozen(struct dyn_ftrace *rec) | ||
922 | { | ||
923 | return rec->flags & FTRACE_FL_FROZEN; | ||
924 | } | ||
925 | #else | ||
926 | # define freeze_record(rec) ({ 0; }) | ||
927 | # define unfreeze_record(rec) ({ 0; }) | ||
928 | # define record_frozen(rec) ({ 0; }) | ||
929 | #endif /* CONFIG_KPROBES */ | ||
930 | |||
931 | static void ftrace_free_rec(struct dyn_ftrace *rec) | 900 | static void ftrace_free_rec(struct dyn_ftrace *rec) |
932 | { | 901 | { |
933 | rec->freelist = ftrace_free_records; | 902 | rec->freelist = ftrace_free_records; |
@@ -1025,6 +994,21 @@ static void ftrace_bug(int failed, unsigned long ip) | |||
1025 | } | 994 | } |
1026 | 995 | ||
1027 | 996 | ||
997 | /* Return 1 if the address range is reserved for ftrace */ | ||
998 | int ftrace_text_reserved(void *start, void *end) | ||
999 | { | ||
1000 | struct dyn_ftrace *rec; | ||
1001 | struct ftrace_page *pg; | ||
1002 | |||
1003 | do_for_each_ftrace_rec(pg, rec) { | ||
1004 | if (rec->ip <= (unsigned long)end && | ||
1005 | rec->ip + MCOUNT_INSN_SIZE > (unsigned long)start) | ||
1006 | return 1; | ||
1007 | } while_for_each_ftrace_rec(); | ||
1008 | return 0; | ||
1009 | } | ||
1010 | |||
1011 | |||
1028 | static int | 1012 | static int |
1029 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) | 1013 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) |
1030 | { | 1014 | { |
@@ -1076,14 +1060,6 @@ static void ftrace_replace_code(int enable) | |||
1076 | !(rec->flags & FTRACE_FL_CONVERTED)) | 1060 | !(rec->flags & FTRACE_FL_CONVERTED)) |
1077 | continue; | 1061 | continue; |
1078 | 1062 | ||
1079 | /* ignore updates to this record's mcount site */ | ||
1080 | if (get_kprobe((void *)rec->ip)) { | ||
1081 | freeze_record(rec); | ||
1082 | continue; | ||
1083 | } else { | ||
1084 | unfreeze_record(rec); | ||
1085 | } | ||
1086 | |||
1087 | failed = __ftrace_replace_code(rec, enable); | 1063 | failed = __ftrace_replace_code(rec, enable); |
1088 | if (failed) { | 1064 | if (failed) { |
1089 | rec->flags |= FTRACE_FL_FAILED; | 1065 | rec->flags |= FTRACE_FL_FAILED; |
@@ -2426,6 +2402,7 @@ static const struct file_operations ftrace_notrace_fops = { | |||
2426 | static DEFINE_MUTEX(graph_lock); | 2402 | static DEFINE_MUTEX(graph_lock); |
2427 | 2403 | ||
2428 | int ftrace_graph_count; | 2404 | int ftrace_graph_count; |
2405 | int ftrace_graph_filter_enabled; | ||
2429 | unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly; | 2406 | unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly; |
2430 | 2407 | ||
2431 | static void * | 2408 | static void * |
@@ -2448,7 +2425,7 @@ static void *g_start(struct seq_file *m, loff_t *pos) | |||
2448 | mutex_lock(&graph_lock); | 2425 | mutex_lock(&graph_lock); |
2449 | 2426 | ||
2450 | /* Nothing, tell g_show to print all functions are enabled */ | 2427 | /* Nothing, tell g_show to print all functions are enabled */ |
2451 | if (!ftrace_graph_count && !*pos) | 2428 | if (!ftrace_graph_filter_enabled && !*pos) |
2452 | return (void *)1; | 2429 | return (void *)1; |
2453 | 2430 | ||
2454 | return __g_next(m, pos); | 2431 | return __g_next(m, pos); |
@@ -2494,6 +2471,7 @@ ftrace_graph_open(struct inode *inode, struct file *file) | |||
2494 | mutex_lock(&graph_lock); | 2471 | mutex_lock(&graph_lock); |
2495 | if ((file->f_mode & FMODE_WRITE) && | 2472 | if ((file->f_mode & FMODE_WRITE) && |
2496 | (file->f_flags & O_TRUNC)) { | 2473 | (file->f_flags & O_TRUNC)) { |
2474 | ftrace_graph_filter_enabled = 0; | ||
2497 | ftrace_graph_count = 0; | 2475 | ftrace_graph_count = 0; |
2498 | memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); | 2476 | memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); |
2499 | } | 2477 | } |
@@ -2519,7 +2497,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer) | |||
2519 | struct dyn_ftrace *rec; | 2497 | struct dyn_ftrace *rec; |
2520 | struct ftrace_page *pg; | 2498 | struct ftrace_page *pg; |
2521 | int search_len; | 2499 | int search_len; |
2522 | int found = 0; | 2500 | int fail = 1; |
2523 | int type, not; | 2501 | int type, not; |
2524 | char *search; | 2502 | char *search; |
2525 | bool exists; | 2503 | bool exists; |
@@ -2530,37 +2508,51 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer) | |||
2530 | 2508 | ||
2531 | /* decode regex */ | 2509 | /* decode regex */ |
2532 | type = filter_parse_regex(buffer, strlen(buffer), &search, ¬); | 2510 | type = filter_parse_regex(buffer, strlen(buffer), &search, ¬); |
2533 | if (not) | 2511 | if (!not && *idx >= FTRACE_GRAPH_MAX_FUNCS) |
2534 | return -EINVAL; | 2512 | return -EBUSY; |
2535 | 2513 | ||
2536 | search_len = strlen(search); | 2514 | search_len = strlen(search); |
2537 | 2515 | ||
2538 | mutex_lock(&ftrace_lock); | 2516 | mutex_lock(&ftrace_lock); |
2539 | do_for_each_ftrace_rec(pg, rec) { | 2517 | do_for_each_ftrace_rec(pg, rec) { |
2540 | 2518 | ||
2541 | if (*idx >= FTRACE_GRAPH_MAX_FUNCS) | ||
2542 | break; | ||
2543 | |||
2544 | if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE)) | 2519 | if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE)) |
2545 | continue; | 2520 | continue; |
2546 | 2521 | ||
2547 | if (ftrace_match_record(rec, search, search_len, type)) { | 2522 | if (ftrace_match_record(rec, search, search_len, type)) { |
2548 | /* ensure it is not already in the array */ | 2523 | /* if it is in the array */ |
2549 | exists = false; | 2524 | exists = false; |
2550 | for (i = 0; i < *idx; i++) | 2525 | for (i = 0; i < *idx; i++) { |
2551 | if (array[i] == rec->ip) { | 2526 | if (array[i] == rec->ip) { |
2552 | exists = true; | 2527 | exists = true; |
2553 | break; | 2528 | break; |
2554 | } | 2529 | } |
2555 | if (!exists) | 2530 | } |
2556 | array[(*idx)++] = rec->ip; | 2531 | |
2557 | found = 1; | 2532 | if (!not) { |
2533 | fail = 0; | ||
2534 | if (!exists) { | ||
2535 | array[(*idx)++] = rec->ip; | ||
2536 | if (*idx >= FTRACE_GRAPH_MAX_FUNCS) | ||
2537 | goto out; | ||
2538 | } | ||
2539 | } else { | ||
2540 | if (exists) { | ||
2541 | array[i] = array[--(*idx)]; | ||
2542 | array[*idx] = 0; | ||
2543 | fail = 0; | ||
2544 | } | ||
2545 | } | ||
2558 | } | 2546 | } |
2559 | } while_for_each_ftrace_rec(); | 2547 | } while_for_each_ftrace_rec(); |
2560 | 2548 | out: | |
2561 | mutex_unlock(&ftrace_lock); | 2549 | mutex_unlock(&ftrace_lock); |
2562 | 2550 | ||
2563 | return found ? 0 : -EINVAL; | 2551 | if (fail) |
2552 | return -EINVAL; | ||
2553 | |||
2554 | ftrace_graph_filter_enabled = 1; | ||
2555 | return 0; | ||
2564 | } | 2556 | } |
2565 | 2557 | ||
2566 | static ssize_t | 2558 | static ssize_t |
@@ -2570,16 +2562,11 @@ ftrace_graph_write(struct file *file, const char __user *ubuf, | |||
2570 | struct trace_parser parser; | 2562 | struct trace_parser parser; |
2571 | ssize_t read, ret; | 2563 | ssize_t read, ret; |
2572 | 2564 | ||
2573 | if (!cnt || cnt < 0) | 2565 | if (!cnt) |
2574 | return 0; | 2566 | return 0; |
2575 | 2567 | ||
2576 | mutex_lock(&graph_lock); | 2568 | mutex_lock(&graph_lock); |
2577 | 2569 | ||
2578 | if (ftrace_graph_count >= FTRACE_GRAPH_MAX_FUNCS) { | ||
2579 | ret = -EBUSY; | ||
2580 | goto out_unlock; | ||
2581 | } | ||
2582 | |||
2583 | if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX)) { | 2570 | if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX)) { |
2584 | ret = -ENOMEM; | 2571 | ret = -ENOMEM; |
2585 | goto out_unlock; | 2572 | goto out_unlock; |