kprobes: x86: support kprobes jump optimization on x86
RFC PATCH 6/7 kprobes: x86: support kprobes jump optimization on x86
Introduce x86 arch-specific optimization code, which supports both of x86-32 and x86-64.
Signed-off-by Masami Hiramatsu <[email protected]>
---
arch/x86/Kconfig | 1 arch/x86/include/asm/kprobes.h | 25 +++- arch/x86/kernel/kprobes.c | 280 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 290 insertions(+), 16 deletions(-)
arch/x86/Kconfig +1 -0
@@ -29,6 +29,7 @@ config X86 select ARCH_WANT_OPTIONAL_GPIOLIB select ARCH_WANT_FRAME_POINTERS select HAVE_KRETPROBES + select HAVE_OPTPROBES select HAVE_FTRACE_MCOUNT_RECORD select HAVE_DYNAMIC_FTRACE select HAVE_FUNCTION_TRACER
arch/x86/include/asm/kprobes.h +24 -1
@@ -32,7 +32,10 @@ struct kprobe;typedef u8 kprobe_opcode_t ;#define BREAKPOINT_INSTRUCTION 0xcc -#define RELATIVEJUMP_INSTRUCTION 0xe9 +#define RELATIVEJUMP_OPCODE 0xe9 +#define RELATIVECALL_OPCODE 0xe8 +#define RELATIVE_ADDR_SIZE 4 +#define RELATIVE_JUMP_SIZE (sizeof(kprobe_opcode_t) + RELATIVE_ADDR_SIZE)#define MAX_INSN_SIZE 16#define MAX_STACK_SIZE 64#define MIN_STACK_SIZE (ADDR ) \
@@ -44,6 +47,17 @@ typedef u8 kprobe_opcode_t;#define flush_insn_slot (p) do { } while (0) +/* optinsn template addresses */ +extern kprobe_opcode_t optprobe_template_entry; +extern kprobe_opcode_t optprobe_template_val; +extern kprobe_opcode_t optprobe_template_call; +extern kprobe_opcode_t optprobe_template_end; +#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE) +#define MAX_OPTINSN_SIZE \ + (((unsigned long)&optprobe_template_end - \ + (unsigned long)&optprobe_template_entry) + \ + MAX_OPTIMIZED_LENGTH + RELATIVE_JUMP_SIZE) +extern const int kretprobe_blacklist_size;void arch_remove_kprobe (struct kprobe *p);
@@ -64,6 +78,15 @@ struct arch_specific_insn {int boostable; }; +struct arch_optimized_insn { +/* copy of the original instructions */ +kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE ]; +/* detour code buffer */ +kprobe_opcode_t *insn; +/* length of copied instructions */ +int length; +}; +struct prev_kprobe {struct kprobe *kp;unsigned long status;
arch/x86/kernel/kprobes.c +265 -15
320 lines not on this page · raw message
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America) Inc. Software Solutions Division e-mail: [email protected]