aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Cohen <wcohen@redhat.com>2016-07-08 12:35:52 -0400
committerCatalin Marinas <catalin.marinas@arm.com>2016-07-19 10:03:22 -0400
commitda6a91252ad98d49b49e83b76c1f032cdf6e5258 (patch)
tree725a7b6d7c2b67a7b90e2270f04a0303232a9cc3
parent39a67d49ba353630d144a8eb775500c041c89e7a (diff)
arm64: Add trampoline code for kretprobes
The trampoline code is used by kretprobes to capture a return from a probed function. This is done by saving the registers, calling the handler, and restoring the registers. The code then returns to the original saved caller return address. It is necessary to do this directly instead of using a software breakpoint because the code used in processing that breakpoint could itself be kprobe'd and cause a problematic reentry into the debug exception handler. Signed-off-by: William Cohen <wcohen@redhat.com> Signed-off-by: David A. Long <dave.long@linaro.org> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> [catalin.marinas@arm.com: removed unnecessary masking of the PSTATE bits] Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
-rw-r--r--arch/arm64/include/asm/kprobes.h2
-rw-r--r--arch/arm64/kernel/asm-offsets.c11
-rw-r--r--arch/arm64/kernel/probes/Makefile1
-rw-r--r--arch/arm64/kernel/probes/kprobes.c5
-rw-r--r--arch/arm64/kernel/probes/kprobes_trampoline.S81
5 files changed, 100 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/kprobes.h b/arch/arm64/include/asm/kprobes.h
index 79c9511612b5..61b49150dfa3 100644
--- a/arch/arm64/include/asm/kprobes.h
+++ b/arch/arm64/include/asm/kprobes.h
@@ -56,5 +56,7 @@ int kprobe_exceptions_notify(struct notifier_block *self,
56 unsigned long val, void *data); 56 unsigned long val, void *data);
57int kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr); 57int kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr);
58int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr); 58int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);
59void kretprobe_trampoline(void);
60void __kprobes *trampoline_probe_handler(struct pt_regs *regs);
59 61
60#endif /* _ARM_KPROBES_H */ 62#endif /* _ARM_KPROBES_H */
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index f8e5d47f0880..03dfa27ccf0f 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -51,6 +51,17 @@ int main(void)
51 DEFINE(S_X5, offsetof(struct pt_regs, regs[5])); 51 DEFINE(S_X5, offsetof(struct pt_regs, regs[5]));
52 DEFINE(S_X6, offsetof(struct pt_regs, regs[6])); 52 DEFINE(S_X6, offsetof(struct pt_regs, regs[6]));
53 DEFINE(S_X7, offsetof(struct pt_regs, regs[7])); 53 DEFINE(S_X7, offsetof(struct pt_regs, regs[7]));
54 DEFINE(S_X8, offsetof(struct pt_regs, regs[8]));
55 DEFINE(S_X10, offsetof(struct pt_regs, regs[10]));
56 DEFINE(S_X12, offsetof(struct pt_regs, regs[12]));
57 DEFINE(S_X14, offsetof(struct pt_regs, regs[14]));
58 DEFINE(S_X16, offsetof(struct pt_regs, regs[16]));
59 DEFINE(S_X18, offsetof(struct pt_regs, regs[18]));
60 DEFINE(S_X20, offsetof(struct pt_regs, regs[20]));
61 DEFINE(S_X22, offsetof(struct pt_regs, regs[22]));
62 DEFINE(S_X24, offsetof(struct pt_regs, regs[24]));
63 DEFINE(S_X26, offsetof(struct pt_regs, regs[26]));
64 DEFINE(S_X28, offsetof(struct pt_regs, regs[28]));
54 DEFINE(S_LR, offsetof(struct pt_regs, regs[30])); 65 DEFINE(S_LR, offsetof(struct pt_regs, regs[30]));
55 DEFINE(S_SP, offsetof(struct pt_regs, sp)); 66 DEFINE(S_SP, offsetof(struct pt_regs, sp));
56#ifdef CONFIG_COMPAT 67#ifdef CONFIG_COMPAT
diff --git a/arch/arm64/kernel/probes/Makefile b/arch/arm64/kernel/probes/Makefile
index e184d00ebf01..ce06312e3d34 100644
--- a/arch/arm64/kernel/probes/Makefile
+++ b/arch/arm64/kernel/probes/Makefile
@@ -1,2 +1,3 @@
1obj-$(CONFIG_KPROBES) += kprobes.o decode-insn.o \ 1obj-$(CONFIG_KPROBES) += kprobes.o decode-insn.o \
2 kprobes_trampoline.o \
2 simulate-insn.o 3 simulate-insn.o
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 63eb0a14d8e9..be1f074b5736 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -576,6 +576,11 @@ bool arch_within_kprobe_blacklist(unsigned long addr)
576 return false; 576 return false;
577} 577}
578 578
579void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs)
580{
581 return NULL;
582}
583
579int __init arch_init_kprobes(void) 584int __init arch_init_kprobes(void)
580{ 585{
581 return 0; 586 return 0;
diff --git a/arch/arm64/kernel/probes/kprobes_trampoline.S b/arch/arm64/kernel/probes/kprobes_trampoline.S
new file mode 100644
index 000000000000..5d6e7f14638c
--- /dev/null
+++ b/arch/arm64/kernel/probes/kprobes_trampoline.S
@@ -0,0 +1,81 @@
1/*
2 * trampoline entry and return code for kretprobes.
3 */
4
5#include <linux/linkage.h>
6#include <asm/asm-offsets.h>
7#include <asm/assembler.h>
8
9 .text
10
11 .macro save_all_base_regs
12 stp x0, x1, [sp, #S_X0]
13 stp x2, x3, [sp, #S_X2]
14 stp x4, x5, [sp, #S_X4]
15 stp x6, x7, [sp, #S_X6]
16 stp x8, x9, [sp, #S_X8]
17 stp x10, x11, [sp, #S_X10]
18 stp x12, x13, [sp, #S_X12]
19 stp x14, x15, [sp, #S_X14]
20 stp x16, x17, [sp, #S_X16]
21 stp x18, x19, [sp, #S_X18]
22 stp x20, x21, [sp, #S_X20]
23 stp x22, x23, [sp, #S_X22]
24 stp x24, x25, [sp, #S_X24]
25 stp x26, x27, [sp, #S_X26]
26 stp x28, x29, [sp, #S_X28]
27 add x0, sp, #S_FRAME_SIZE
28 stp lr, x0, [sp, #S_LR]
29 /*
30 * Construct a useful saved PSTATE
31 */
32 mrs x0, nzcv
33 mrs x1, daif
34 orr x0, x0, x1
35 mrs x1, CurrentEL
36 orr x0, x0, x1
37 mrs x1, SPSel
38 orr x0, x0, x1
39 stp xzr, x0, [sp, #S_PC]
40 .endm
41
42 .macro restore_all_base_regs
43 ldr x0, [sp, #S_PSTATE]
44 and x0, x0, #(PSR_N_BIT | PSR_Z_BIT | PSR_C_BIT | PSR_V_BIT)
45 msr nzcv, x0
46 ldp x0, x1, [sp, #S_X0]
47 ldp x2, x3, [sp, #S_X2]
48 ldp x4, x5, [sp, #S_X4]
49 ldp x6, x7, [sp, #S_X6]
50 ldp x8, x9, [sp, #S_X8]
51 ldp x10, x11, [sp, #S_X10]
52 ldp x12, x13, [sp, #S_X12]
53 ldp x14, x15, [sp, #S_X14]
54 ldp x16, x17, [sp, #S_X16]
55 ldp x18, x19, [sp, #S_X18]
56 ldp x20, x21, [sp, #S_X20]
57 ldp x22, x23, [sp, #S_X22]
58 ldp x24, x25, [sp, #S_X24]
59 ldp x26, x27, [sp, #S_X26]
60 ldp x28, x29, [sp, #S_X28]
61 .endm
62
63ENTRY(kretprobe_trampoline)
64 sub sp, sp, #S_FRAME_SIZE
65
66 save_all_base_regs
67
68 mov x0, sp
69 bl trampoline_probe_handler
70 /*
71 * Replace trampoline address in lr with actual orig_ret_addr return
72 * address.
73 */
74 mov lr, x0
75
76 restore_all_base_regs
77
78 add sp, sp, #S_FRAME_SIZE
79 ret
80
81ENDPROC(kretprobe_trampoline)