ftrace: x86 use copy to and from user functions
The modification of code is performed either by kstop_machine, before SMP starts, or on module code before the module is executed. There is no reason to do the modifications from assembly. The copy to and from user functions are sufficient and produces cleaner and easier to read code. Thanks to Benjamin Herrenschmidt for suggesting the idea. Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Родитель
8feff1cacc
Коммит
6f93fc076a
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/hardirq.h>
|
#include <linux/hardirq.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
#include <linux/ftrace.h>
|
#include <linux/ftrace.h>
|
||||||
#include <linux/percpu.h>
|
#include <linux/percpu.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
@ -60,11 +61,7 @@ notrace int
|
||||||
ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
||||||
unsigned char *new_code)
|
unsigned char *new_code)
|
||||||
{
|
{
|
||||||
unsigned replaced;
|
unsigned char replaced[MCOUNT_INSN_SIZE];
|
||||||
unsigned old = *(unsigned *)old_code; /* 4 bytes */
|
|
||||||
unsigned new = *(unsigned *)new_code; /* 4 bytes */
|
|
||||||
unsigned char newch = new_code[4];
|
|
||||||
int faulted = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: Due to modules and __init, code can
|
* Note: Due to modules and __init, code can
|
||||||
|
@ -72,29 +69,20 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
||||||
* as well as code changing.
|
* as well as code changing.
|
||||||
*
|
*
|
||||||
* No real locking needed, this code is run through
|
* No real locking needed, this code is run through
|
||||||
* kstop_machine.
|
* kstop_machine, or before SMP starts.
|
||||||
*/
|
*/
|
||||||
asm volatile (
|
if (__copy_from_user(replaced, (char __user *)ip, MCOUNT_INSN_SIZE))
|
||||||
"1: lock\n"
|
return 1;
|
||||||
" cmpxchg %3, (%2)\n"
|
|
||||||
" jnz 2f\n"
|
if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
|
||||||
" movb %b4, 4(%2)\n"
|
return 2;
|
||||||
"2:\n"
|
|
||||||
".section .fixup, \"ax\"\n"
|
WARN_ON_ONCE(__copy_to_user((char __user *)ip, new_code,
|
||||||
"3: movl $1, %0\n"
|
MCOUNT_INSN_SIZE));
|
||||||
" jmp 2b\n"
|
|
||||||
".previous\n"
|
|
||||||
_ASM_EXTABLE(1b, 3b)
|
|
||||||
: "=r"(faulted), "=a"(replaced)
|
|
||||||
: "r"(ip), "r"(new), "c"(newch),
|
|
||||||
"0"(faulted), "a"(old)
|
|
||||||
: "memory");
|
|
||||||
sync_core();
|
sync_core();
|
||||||
|
|
||||||
if (replaced != old && replaced != new)
|
return 0;
|
||||||
faulted = 2;
|
|
||||||
|
|
||||||
return faulted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notrace int ftrace_update_ftrace_func(ftrace_func_t func)
|
notrace int ftrace_update_ftrace_func(ftrace_func_t func)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче