aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <rostedt@goodmis.org>2008-10-23 09:32:59 -0400
committerIngo Molnar <mingo@elte.hu>2008-10-23 10:00:13 -0400
commit593eb8a2d63e95772a5f22d746f18a997c5ee463 (patch)
tree2a99c61ccffc2c0fd280bb2e5f81ac2f22e2f471
parent34698bcbdf7b0629d6c873b5da7c63073fb45361 (diff)
ftrace: return error on failed modified text.
Have the ftrace_modify_code return error values: -EFAULT on error of reading the address -EINVAL if what is read does not match what it expected -EPERM if the write fails to update after a successful match. Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/ftrace.c14
-rw-r--r--include/linux/ftrace.h24
-rw-r--r--kernel/trace/ftrace.c21
3 files changed, 44 insertions, 15 deletions
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 8821ceabf51d..428291581cb2 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -62,7 +62,6 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
62 unsigned char *new_code) 62 unsigned char *new_code)
63{ 63{
64 unsigned char replaced[MCOUNT_INSN_SIZE]; 64 unsigned char replaced[MCOUNT_INSN_SIZE];
65 int ret;
66 65
67 /* 66 /*
68 * Note: Due to modules and __init, code can 67 * Note: Due to modules and __init, code can
@@ -72,15 +71,16 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
72 * No real locking needed, this code is run through 71 * No real locking needed, this code is run through
73 * kstop_machine, or before SMP starts. 72 * kstop_machine, or before SMP starts.
74 */ 73 */
75 if (__copy_from_user_inatomic(replaced, (char __user *)ip, MCOUNT_INSN_SIZE)) 74 if (__copy_from_user_inatomic(replaced, (char __user *)ip,
76 return 1; 75 MCOUNT_INSN_SIZE))
76 return -EFAULT;
77 77
78 if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) 78 if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
79 return 2; 79 return -EINVAL;
80 80
81 ret = __copy_to_user_inatomic((char __user *)ip, new_code, 81 if (__copy_to_user_inatomic((char __user *)ip, new_code,
82 MCOUNT_INSN_SIZE); 82 MCOUNT_INSN_SIZE))
83 WARN_ON_ONCE(ret); 83 return -EPERM;
84 84
85 sync_core(); 85 sync_core();
86 86
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 0e9529589151..79fa10cbdcfb 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -72,13 +72,33 @@ extern unsigned char *ftrace_nop_replace(void);
72extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr); 72extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
73extern int ftrace_dyn_arch_init(void *data); 73extern int ftrace_dyn_arch_init(void *data);
74extern int ftrace_mcount_set(unsigned long *data); 74extern int ftrace_mcount_set(unsigned long *data);
75extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
76 unsigned char *new_code);
77extern int ftrace_update_ftrace_func(ftrace_func_t func); 75extern int ftrace_update_ftrace_func(ftrace_func_t func);
78extern void ftrace_caller(void); 76extern void ftrace_caller(void);
79extern void ftrace_call(void); 77extern void ftrace_call(void);
80extern void mcount_call(void); 78extern void mcount_call(void);
81 79
80/**
81 * ftrace_modify_code - modify code segment
82 * @ip: the address of the code segment
83 * @old_code: the contents of what is expected to be there
84 * @new_code: the code to patch in
85 *
86 * This is a very sensitive operation and great care needs
87 * to be taken by the arch. The operation should carefully
88 * read the location, check to see if what is read is indeed
89 * what we expect it to be, and then on success of the compare,
90 * it should write to the location.
91 *
92 * Return must be:
93 * 0 on success
94 * -EFAULT on error reading the location
95 * -EINVAL on a failed compare of the contents
96 * -EPERM on error writing to the location
97 * Any other value will be considered a failure.
98 */
99extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
100 unsigned char *new_code);
101
82extern int skip_trace(unsigned long ip); 102extern int skip_trace(unsigned long ip);
83 103
84extern void ftrace_release(void *start, unsigned long size); 104extern void ftrace_release(void *start, unsigned long size);
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1f54a94189fe..b2de8de77356 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -596,22 +596,22 @@ ftrace_code_disable(struct dyn_ftrace *rec)
596{ 596{
597 unsigned long ip; 597 unsigned long ip;
598 unsigned char *nop, *call; 598 unsigned char *nop, *call;
599 int failed; 599 int ret;
600 600
601 ip = rec->ip; 601 ip = rec->ip;
602 602
603 nop = ftrace_nop_replace(); 603 nop = ftrace_nop_replace();
604 call = ftrace_call_replace(ip, mcount_addr); 604 call = ftrace_call_replace(ip, mcount_addr);
605 605
606 failed = ftrace_modify_code(ip, call, nop); 606 ret = ftrace_modify_code(ip, call, nop);
607 if (failed) { 607 if (ret) {
608 switch (failed) { 608 switch (ret) {
609 case 1: 609 case -EFAULT:
610 WARN_ON_ONCE(1); 610 WARN_ON_ONCE(1);
611 pr_info("ftrace faulted on modifying "); 611 pr_info("ftrace faulted on modifying ");
612 print_ip_sym(ip); 612 print_ip_sym(ip);
613 break; 613 break;
614 case 2: 614 case -EINVAL:
615 WARN_ON_ONCE(1); 615 WARN_ON_ONCE(1);
616 pr_info("ftrace failed to modify "); 616 pr_info("ftrace failed to modify ");
617 print_ip_sym(ip); 617 print_ip_sym(ip);
@@ -620,6 +620,15 @@ ftrace_code_disable(struct dyn_ftrace *rec)
620 print_ip_ins(" replace: ", nop); 620 print_ip_ins(" replace: ", nop);
621 printk(KERN_CONT "\n"); 621 printk(KERN_CONT "\n");
622 break; 622 break;
623 case -EPERM:
624 WARN_ON_ONCE(1);
625 pr_info("ftrace faulted on writing ");
626 print_ip_sym(ip);
627 break;
628 default:
629 WARN_ON_ONCE(1);
630 pr_info("ftrace faulted on unknown error ");
631 print_ip_sym(ip);
623 } 632 }
624 633
625 rec->flags |= FTRACE_FL_FAILED; 634 rec->flags |= FTRACE_FL_FAILED;