diff options
Diffstat (limited to 'arch/x86/kernel/ftrace.c')
-rw-r--r-- | arch/x86/kernel/ftrace.c | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 4151c91254e8..082d99642622 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
13 | #include <linux/hardirq.h> | 13 | #include <linux/hardirq.h> |
14 | #include <linux/uaccess.h> | ||
14 | #include <linux/ftrace.h> | 15 | #include <linux/ftrace.h> |
15 | #include <linux/percpu.h> | 16 | #include <linux/percpu.h> |
16 | #include <linux/init.h> | 17 | #include <linux/init.h> |
@@ -60,11 +61,7 @@ notrace int | |||
60 | ftrace_modify_code(unsigned long ip, unsigned char *old_code, | 61 | ftrace_modify_code(unsigned long ip, unsigned char *old_code, |
61 | unsigned char *new_code) | 62 | unsigned char *new_code) |
62 | { | 63 | { |
63 | unsigned replaced; | 64 | unsigned char replaced[MCOUNT_INSN_SIZE]; |
64 | unsigned old = *(unsigned *)old_code; /* 4 bytes */ | ||
65 | unsigned new = *(unsigned *)new_code; /* 4 bytes */ | ||
66 | unsigned char newch = new_code[4]; | ||
67 | int faulted = 0; | ||
68 | 65 | ||
69 | /* | 66 | /* |
70 | * Note: Due to modules and __init, code can | 67 | * Note: Due to modules and __init, code can |
@@ -72,29 +69,20 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code, | |||
72 | * as well as code changing. | 69 | * as well as code changing. |
73 | * | 70 | * |
74 | * No real locking needed, this code is run through | 71 | * No real locking needed, this code is run through |
75 | * kstop_machine. | 72 | * kstop_machine, or before SMP starts. |
76 | */ | 73 | */ |
77 | asm volatile ( | 74 | if (__copy_from_user(replaced, (char __user *)ip, MCOUNT_INSN_SIZE)) |
78 | "1: lock\n" | 75 | return 1; |
79 | " cmpxchg %3, (%2)\n" | ||
80 | " jnz 2f\n" | ||
81 | " movb %b4, 4(%2)\n" | ||
82 | "2:\n" | ||
83 | ".section .fixup, \"ax\"\n" | ||
84 | "3: movl $1, %0\n" | ||
85 | " jmp 2b\n" | ||
86 | ".previous\n" | ||
87 | _ASM_EXTABLE(1b, 3b) | ||
88 | : "=r"(faulted), "=a"(replaced) | ||
89 | : "r"(ip), "r"(new), "c"(newch), | ||
90 | "0"(faulted), "a"(old) | ||
91 | : "memory"); | ||
92 | sync_core(); | ||
93 | 76 | ||
94 | if (replaced != old && replaced != new) | 77 | if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) |
95 | faulted = 2; | 78 | return 2; |
96 | 79 | ||
97 | return faulted; | 80 | WARN_ON_ONCE(__copy_to_user((char __user *)ip, new_code, |
81 | MCOUNT_INSN_SIZE)); | ||
82 | |||
83 | sync_core(); | ||
84 | |||
85 | return 0; | ||
98 | } | 86 | } |
99 | 87 | ||
100 | notrace int ftrace_update_ftrace_func(ftrace_func_t func) | 88 | notrace int ftrace_update_ftrace_func(ftrace_func_t func) |