--- vrfc
+++ v3
@@ -1,167 +1,56 @@
-Detour buffer contains instructions to create an in memory pt_regs.
-After the execution of prehandler a call is made for instruction emulation.
-The NIP is decided after the probed instruction is executed. Hence a branch
-instruction is created to the NIP returned by emulate_step().
+From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
-Signed-off-by: Anju T <anju@linux.vnet.ibm.com>
+Introduce __PPC_SH64() as a 64-bit variant to encode shift field in some
+of the shift and rotate instructions operating on double-words. Convert
+some of the BPF instruction macros to use the same.
+
+Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
- arch/powerpc/include/asm/kprobes.h | 25 +++++++++
- arch/powerpc/kernel/optprobes_head.S | 104 +++++++++++++++++++++++++++++++++++
- 2 files changed, 129 insertions(+)
- create mode 100644 arch/powerpc/kernel/optprobes_head.S
+ arch/powerpc/include/asm/ppc-opcode.h | 1 +
+ arch/powerpc/net/bpf_jit.h | 11 +++++------
+ 2 files changed, 6 insertions(+), 6 deletions(-)
-diff --git a/arch/powerpc/include/asm/kprobes.h b/arch/powerpc/include/asm/kprobes.h
-index 039b583..3e4c998 100644
---- a/arch/powerpc/include/asm/kprobes.h
-+++ b/arch/powerpc/include/asm/kprobes.h
-@@ -38,7 +38,25 @@ struct pt_regs;
- struct kprobe;
+diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
+index 0132831..630127b 100644
+--- a/arch/powerpc/include/asm/ppc-opcode.h
++++ b/arch/powerpc/include/asm/ppc-opcode.h
+@@ -306,6 +306,7 @@
+ #define __PPC_WC(w) (((w) & 0x3) << 21)
+ #define __PPC_WS(w) (((w) & 0x1f) << 11)
+ #define __PPC_SH(s) __PPC_WS(s)
++#define __PPC_SH64(s) (__PPC_SH(s) | (((s) & 0x20) >> 4))
+ #define __PPC_MB(s) (((s) & 0x1f) << 6)
+ #define __PPC_ME(s) (((s) & 0x1f) << 1)
+ #define __PPC_MB64(s) (__PPC_MB(s) | ((s) & 0x20))
+diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
+index 89f7007..30cf03f 100644
+--- a/arch/powerpc/net/bpf_jit.h
++++ b/arch/powerpc/net/bpf_jit.h
+@@ -157,8 +157,7 @@
+ #define PPC_SRAD(d, a, s) EMIT(PPC_INST_SRAD | ___PPC_RA(d) | \
+ ___PPC_RS(a) | ___PPC_RB(s))
+ #define PPC_SRADI(d, a, i) EMIT(PPC_INST_SRADI | ___PPC_RA(d) | \
+- ___PPC_RS(a) | __PPC_SH(i) | \
+- (((i) & 0x20) >> 4))
++ ___PPC_RS(a) | __PPC_SH64(i))
+ #define PPC_RLWINM(d, a, i, mb, me) EMIT(PPC_INST_RLWINM | ___PPC_RA(d) | \
+ ___PPC_RS(a) | __PPC_SH(i) | \
+ __PPC_MB(mb) | __PPC_ME(me))
+@@ -166,11 +165,11 @@
+ ___PPC_RS(a) | __PPC_SH(i) | \
+ __PPC_MB(mb) | __PPC_ME(me))
+ #define PPC_RLDICL(d, a, i, mb) EMIT(PPC_INST_RLDICL | ___PPC_RA(d) | \
+- ___PPC_RS(a) | __PPC_SH(i) | \
+- __PPC_MB64(mb) | (((i) & 0x20) >> 4))
++ ___PPC_RS(a) | __PPC_SH64(i) | \
++ __PPC_MB64(mb))
+ #define PPC_RLDICR(d, a, i, me) EMIT(PPC_INST_RLDICR | ___PPC_RA(d) | \
+- ___PPC_RS(a) | __PPC_SH(i) | \
+- __PPC_ME64(me) | (((i) & 0x20) >> 4))
++ ___PPC_RS(a) | __PPC_SH64(i) | \
++ __PPC_ME64(me))
- typedef ppc_opcode_t kprobe_opcode_t;
-+
-+extern kprobe_opcode_t optinsn_slot;
-+/* Optinsn template address */
-+extern kprobe_opcode_t optprobe_template_entry[];
-+extern kprobe_opcode_t optprobe_template_call_handler[];
-+extern kprobe_opcode_t optprobe_template_call_emulate[];
-+extern kprobe_opcode_t optprobe_template_ret_branch[];
-+extern kprobe_opcode_t optprobe_template_ret[];
-+extern kprobe_opcode_t optprobe_template_insn[];
-+extern kprobe_opcode_t optprobe_template_op_address1[];
-+extern kprobe_opcode_t optprobe_template_op_address2[];
-+extern kprobe_opcode_t optprobe_template_end[];
-+
- #define MAX_INSN_SIZE 1
-+#define MAX_OPTIMIZED_LENGTH 4
-+#define MAX_OPTINSN_SIZE \
-+ ((unsigned long)&optprobe_template_end - \
-+ (unsigned long)&optprobe_template_entry)
-+#define RELATIVEJUMP_SIZE 4
-
- #ifdef CONFIG_PPC64
- #if defined(_CALL_ELF) && _CALL_ELF == 2
-@@ -129,5 +147,12 @@ struct kprobe_ctlblk {
- extern int kprobe_exceptions_notify(struct notifier_block *self,
- unsigned long val, void *data);
- extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
-+
-+struct arch_optimized_insn {
-+ kprobe_opcode_t copied_insn[1];
-+ /* detour buffer */
-+ kprobe_opcode_t *insn;
-+};
-+
- #endif /* __KERNEL__ */
- #endif /* _ASM_POWERPC_KPROBES_H */
-diff --git a/arch/powerpc/kernel/optprobes_head.S b/arch/powerpc/kernel/optprobes_head.S
-new file mode 100644
-index 0000000..025bab7
---- /dev/null
-+++ b/arch/powerpc/kernel/optprobes_head.S
-@@ -0,0 +1,104 @@
-+/*
-+ * Code to prepare detour buffer for optprobes in kernel.
-+ *
-+ * Copyright 2016, Anju T, IBM Corp.
-+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public License
-+ * as published by the Free Software Foundation; either version
-+ * 2 of the License, or (at your option) any later version.
-+ */
-+
-+#include <asm/ppc_asm.h>
-+#include <asm/ptrace.h>
-+#include <asm/asm-offsets.h>
-+
-+.global optprobe_template_entry
-+optprobe_template_entry:
-+ stdu r1,-INT_FRAME_SIZE(r1)
-+ SAVE_GPR(0,r1)
-+ /* Save the previous SP into stack */
-+ addi r0,r1,INT_FRAME_SIZE
-+ std 0,GPR1(r1)
-+ SAVE_2GPRS(2,r1)
-+ SAVE_8GPRS(4,r1)
-+ SAVE_10GPRS(12,r1)
-+ SAVE_10GPRS(22,r1)
-+ /* Save SPRS */
-+ mfcfar r5
-+ std r5,_NIP(r1)
-+ mfmsr r5
-+ std r5,_MSR(r1)
-+ mfctr r5
-+ std r5,_CTR(r1)
-+ mflr r5
-+ std r5,_LINK(r1)
-+ mfspr r5,SPRN_XER
-+ std r5,_XER(r1)
-+ li r5,0
-+ std r5,_TRAP(r1)
-+ mfdar r5
-+ std r5,_DAR(r1)
-+ mfdsisr r5
-+ std r5,_DSISR(r1)
-+ /* Pass parameters for optimized_callback */
-+.global optprobe_template_op_address1
-+optprobe_template_op_address1:
-+ nop
-+ nop
-+ nop
-+ nop
-+ nop
-+ addi r4,r1,STACK_FRAME_OVERHEAD
-+ /* Branch to the prehandler */
-+.global optprobe_template_call_handler
-+optprobe_template_call_handler:
-+ nop
-+ /* Pass parameters for instruction emulation */
-+ addi r3,r1,STACK_FRAME_OVERHEAD
-+.global optprobe_template_insn
-+optprobe_template_insn:
-+ nop
-+ nop
-+ /* Branch to instruction emulation */
-+.global optprobe_template_call_emulate
-+optprobe_template_call_emulate:
-+ nop
-+.global optprobe_template_op_address2
-+optprobe_template_op_address2:
-+ nop
-+ nop
-+ nop
-+ nop
-+ nop
-+ addi r4,r1,STACK_FRAME_OVERHEAD
-+ /* Branch to create_return_branch() function */
-+.global optprobe_template_ret_branch
-+optprobe_template_ret_branch:
-+ nop
-+ /* Restore the registers */
-+ ld r5,_MSR(r1)
-+ mtmsr r5
-+ ld r5,_CTR(r1)
-+ mtctr r5
-+ ld r5,_LINK(r1)
-+ mtlr r5
-+ ld r5,_XER(r1)
-+ mtxer r5
-+ ld r5,_DAR(r1)
-+ mtdar r5
-+ ld r5,_DSISR(r1)
-+ mtdsisr r5
-+ REST_GPR(0,r1)
-+ REST_2GPRS(2,r1)
-+ REST_8GPRS(4,r1)
-+ REST_10GPRS(12,r1)
-+ REST_10GPRS(22,r1)
-+ /* Restore the previous SP */
-+ addi r1,r1,INT_FRAME_SIZE
-+ /* Jump back to the normal workflow from trampoline */
-+.global optprobe_template_ret
-+optprobe_template_ret:
-+ nop
-+.global optprobe_template_end
-+optprobe_template_end:
+ /* slwi = rlwinm Rx, Ry, n, 0, 31-n */
+ #define PPC_SLWI(d, a, i) PPC_RLWINM(d, a, i, 0, 31-(i))
--
-2.1.0
+2.7.4