From: Paul Mackerras <paulus@samba.org>

This patch is from Ananth N Mavinakayanahalli <ananth@in.ibm.com>.

While processing a kprobe, we were currently not handling all available trap
variants available on PowerPC.  This lead to the breakage of BUG() handling in
ppc64.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/ppc64/kernel/kprobes.c |   11 +++++++++--
 25-akpm/include/asm-ppc64/kprobes.h |    5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff -puN arch/ppc64/kernel/kprobes.c~ppc64-kprobes-handle-trap-variants-while-processing-probes arch/ppc64/kernel/kprobes.c
--- 25/arch/ppc64/kernel/kprobes.c~ppc64-kprobes-handle-trap-variants-while-processing-probes	2005-03-07 20:41:25.000000000 -0800
+++ 25-akpm/arch/ppc64/kernel/kprobes.c	2005-03-07 20:41:25.000000000 -0800
@@ -105,9 +105,17 @@ static inline int kprobe_handler(struct 
 	p = get_kprobe(addr);
 	if (!p) {
 		unlock_kprobes();
-#if 0
 		if (*addr != BREAKPOINT_INSTRUCTION) {
 			/*
+			 * PowerPC has multiple variants of the "trap"
+			 * instruction. If the current instruction is a
+			 * trap variant, it could belong to someone else
+			 */
+			kprobe_opcode_t cur_insn = *addr;
+			if (IS_TW(cur_insn) || IS_TD(cur_insn) ||
+					IS_TWI(cur_insn) || IS_TDI(cur_insn))
+		       		goto no_kprobe;
+			/*
 			 * The breakpoint instruction was removed right
 			 * after we hit it.  Another cpu has removed
 			 * either a probepoint or a debugger breakpoint
@@ -116,7 +124,6 @@ static inline int kprobe_handler(struct 
 			 */
 			ret = 1;
 		}
-#endif
 		/* Not one of ours: let kernel handle it */
 		goto no_kprobe;
 	}
diff -puN include/asm-ppc64/kprobes.h~ppc64-kprobes-handle-trap-variants-while-processing-probes include/asm-ppc64/kprobes.h
--- 25/include/asm-ppc64/kprobes.h~ppc64-kprobes-handle-trap-variants-while-processing-probes	2005-03-07 20:41:25.000000000 -0800
+++ 25-akpm/include/asm-ppc64/kprobes.h	2005-03-07 20:41:25.000000000 -0800
@@ -35,6 +35,11 @@ typedef unsigned int kprobe_opcode_t;
 #define BREAKPOINT_INSTRUCTION	0x7fe00008	/* trap */
 #define MAX_INSN_SIZE 1
 
+#define IS_TW(instr)		(((instr) & 0xfc0007fe) == 0x7c000008)
+#define IS_TD(instr)		(((instr) & 0xfc0007fe) == 0x7c000088)
+#define IS_TDI(instr)		(((instr) & 0xfc000000) == 0x08000000)
+#define IS_TWI(instr)		(((instr) & 0xfc000000) == 0x0c000000)
+
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)((func_descr_t *)pentry)
 
 /* Architecture specific copy of original instruction */
_