diff options
author | Wang Nan <wangnan0@huawei.com> | 2015-01-09 01:37:36 -0500 |
---|---|---|
committer | Jon Medhurst <tixy@linaro.org> | 2015-01-13 11:10:17 -0500 |
commit | 0dc016dbd820260b8ea74337980735b8c88d4ef2 (patch) | |
tree | 0a6408b4181016d41858afec026cc4e93455f852 /arch/arm/include/asm/kprobes.h | |
parent | cbf6ab52add20b845f903decc973afbd5463c527 (diff) |
ARM: kprobes: enable OPTPROBES for ARM 32
This patch introduce kprobeopt for ARM 32.
Limitations:
- Currently only kernel compiled with ARM ISA is supported.
- Offset between probe point and optinsn slot must not larger than
32MiB. Masami Hiramatsu suggests replacing 2 words, it will make
things complex. Futher patch can make such optimization.
Kprobe opt on ARM is relatively simpler than kprobe opt on x86 because
ARM instruction is always 4 bytes aligned and 4 bytes long. This patch
replace probed instruction by a 'b', branch to trampoline code and then
calls optimized_callback(). optimized_callback() calls opt_pre_handler()
to execute kprobe handler. It also emulate/simulate replaced instruction.
When unregistering kprobe, the deferred manner of unoptimizer may leave
branch instruction before optimizer is called. Different from x86_64,
which only copy the probed insn after optprobe_template_end and
reexecute them, this patch call singlestep to emulate/simulate the insn
directly. Futher patch can optimize this behavior.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Will Deacon <will.deacon@arm.com>
Reviewed-by: Jon Medhurst (Tixy) <tixy@linaro.org>
Signed-off-by: Jon Medhurst <tixy@linaro.org>
Diffstat (limited to 'arch/arm/include/asm/kprobes.h')
-rw-r--r-- | arch/arm/include/asm/kprobes.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/arch/arm/include/asm/kprobes.h b/arch/arm/include/asm/kprobes.h index 56f9ac68fbd1..50ff3bc7928e 100644 --- a/arch/arm/include/asm/kprobes.h +++ b/arch/arm/include/asm/kprobes.h | |||
@@ -50,5 +50,34 @@ int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr); | |||
50 | int kprobe_exceptions_notify(struct notifier_block *self, | 50 | int kprobe_exceptions_notify(struct notifier_block *self, |
51 | unsigned long val, void *data); | 51 | unsigned long val, void *data); |
52 | 52 | ||
53 | /* optinsn template addresses */ | ||
54 | extern __visible kprobe_opcode_t optprobe_template_entry; | ||
55 | extern __visible kprobe_opcode_t optprobe_template_val; | ||
56 | extern __visible kprobe_opcode_t optprobe_template_call; | ||
57 | extern __visible kprobe_opcode_t optprobe_template_end; | ||
58 | extern __visible kprobe_opcode_t optprobe_template_sub_sp; | ||
59 | extern __visible kprobe_opcode_t optprobe_template_add_sp; | ||
60 | |||
61 | #define MAX_OPTIMIZED_LENGTH 4 | ||
62 | #define MAX_OPTINSN_SIZE \ | ||
63 | ((unsigned long)&optprobe_template_end - \ | ||
64 | (unsigned long)&optprobe_template_entry) | ||
65 | #define RELATIVEJUMP_SIZE 4 | ||
66 | |||
67 | struct arch_optimized_insn { | ||
68 | /* | ||
69 | * copy of the original instructions. | ||
70 | * Different from x86, ARM kprobe_opcode_t is u32. | ||
71 | */ | ||
72 | #define MAX_COPIED_INSN DIV_ROUND_UP(RELATIVEJUMP_SIZE, sizeof(kprobe_opcode_t)) | ||
73 | kprobe_opcode_t copied_insn[MAX_COPIED_INSN]; | ||
74 | /* detour code buffer */ | ||
75 | kprobe_opcode_t *insn; | ||
76 | /* | ||
77 | * We always copy one instruction on ARM, | ||
78 | * so size will always be 4, and unlike x86, there is no | ||
79 | * need for a size field. | ||
80 | */ | ||
81 | }; | ||
53 | 82 | ||
54 | #endif /* _ARM_KPROBES_H */ | 83 | #endif /* _ARM_KPROBES_H */ |