Commit 768ae440 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

x86/ftrace: Use text_poke()

Move ftrace over to using the generic x86 text_poke functions; this
avoids having a second/different copy of that code around.

This also avoids ftrace violating the (new) W^X rule and avoids
fragmenting the kernel text page-tables, due to no longer having to
toggle them RW.
Tested-by: default avatarAlexei Starovoitov <ast@kernel.org>
Tested-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20191111132457.761255803@infradead.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 63f62add
...@@ -34,8 +34,6 @@ struct dyn_arch_ftrace { ...@@ -34,8 +34,6 @@ struct dyn_arch_ftrace {
/* No extra data needed for x86 */ /* No extra data needed for x86 */
}; };
int ftrace_int3_handler(struct pt_regs *regs);
#define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR #define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR
#endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* CONFIG_DYNAMIC_FTRACE */
......
...@@ -949,7 +949,7 @@ static struct bp_patching_desc { ...@@ -949,7 +949,7 @@ static struct bp_patching_desc {
int nr_entries; int nr_entries;
} bp_patching; } bp_patching;
static int patch_cmp(const void *key, const void *elt) static int notrace patch_cmp(const void *key, const void *elt)
{ {
struct text_poke_loc *tp = (struct text_poke_loc *) elt; struct text_poke_loc *tp = (struct text_poke_loc *) elt;
...@@ -961,7 +961,7 @@ static int patch_cmp(const void *key, const void *elt) ...@@ -961,7 +961,7 @@ static int patch_cmp(const void *key, const void *elt)
} }
NOKPROBE_SYMBOL(patch_cmp); NOKPROBE_SYMBOL(patch_cmp);
int poke_int3_handler(struct pt_regs *regs) int notrace poke_int3_handler(struct pt_regs *regs)
{ {
struct text_poke_loc *tp; struct text_poke_loc *tp;
void *ip; void *ip;
...@@ -1209,10 +1209,15 @@ void text_poke_finish(void) ...@@ -1209,10 +1209,15 @@ void text_poke_finish(void)
text_poke_flush(NULL); text_poke_flush(NULL);
} }
void text_poke_queue(void *addr, const void *opcode, size_t len, const void *emulate) void __ref text_poke_queue(void *addr, const void *opcode, size_t len, const void *emulate)
{ {
struct text_poke_loc *tp; struct text_poke_loc *tp;
if (unlikely(system_state == SYSTEM_BOOTING)) {
text_poke_early(addr, opcode, len);
return;
}
text_poke_flush(addr); text_poke_flush(addr);
tp = &tp_vec[tp_vec_nr++]; tp = &tp_vec[tp_vec_nr++];
...@@ -1230,10 +1235,15 @@ void text_poke_queue(void *addr, const void *opcode, size_t len, const void *emu ...@@ -1230,10 +1235,15 @@ void text_poke_queue(void *addr, const void *opcode, size_t len, const void *emu
* dynamically allocated memory. This function should be used when it is * dynamically allocated memory. This function should be used when it is
* not possible to allocate memory. * not possible to allocate memory.
*/ */
void text_poke_bp(void *addr, const void *opcode, size_t len, const void *emulate) void __ref text_poke_bp(void *addr, const void *opcode, size_t len, const void *emulate)
{ {
struct text_poke_loc tp; struct text_poke_loc tp;
if (unlikely(system_state == SYSTEM_BOOTING)) {
text_poke_early(addr, opcode, len);
return;
}
text_poke_loc_init(&tp, addr, opcode, len, emulate); text_poke_loc_init(&tp, addr, opcode, len, emulate);
text_poke_bp_batch(&tp, 1); text_poke_bp_batch(&tp, 1);
} }
......
This diff is collapsed.
...@@ -563,15 +563,6 @@ NOKPROBE_SYMBOL(do_general_protection); ...@@ -563,15 +563,6 @@ NOKPROBE_SYMBOL(do_general_protection);
dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code) dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
{ {
#ifdef CONFIG_DYNAMIC_FTRACE
/*
* ftrace must be first, everything else may cause a recursive crash.
* See note by declaration of modifying_ftrace_code in ftrace.c
*/
if (unlikely(atomic_read(&modifying_ftrace_code)) &&
ftrace_int3_handler(regs))
return;
#endif
if (poke_int3_handler(regs)) if (poke_int3_handler(regs))
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment