[PATCH] kprobes: fix single-step out of line

Ananth N Mavinakayanahalli ananth at in.ibm.com
Thu May 26 03:01:59 EST 2005


Hi,

On Power4 and above, single-step out of line when the instruction copy
is on a kmalloc'ed memory area, fails with an Instruction Access
exception. Here is a patch that fixes it.

Thanks,
Ananth

The single-step out of line fails with an Trap 0x400 (Instruction Access)
if the copy of the instruction is in a kmalloced memory area. Fix that.
While we are there, correct the case of a kprobe on a trap variant.

Signed-off-by: Ananth N Mavinakayanahalli <ananth at in.ibm.com>

 arch/ppc64/kernel/kprobes.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

Index: linux-2.6.12-rc5/arch/ppc64/kernel/kprobes.c
===================================================================
--- linux-2.6.12-rc5.orig/arch/ppc64/kernel/kprobes.c	2005-05-24 23:31:20.000000000 -0400
+++ linux-2.6.12-rc5/arch/ppc64/kernel/kprobes.c	2005-05-25 12:47:33.000000000 -0400
@@ -42,6 +42,7 @@
 static struct kprobe *current_kprobe;
 static unsigned long kprobe_status, kprobe_saved_msr;
 static struct pt_regs jprobe_saved_regs;
+static kprobe_opcode_t stepped_insn;
 
 int arch_prepare_kprobe(struct kprobe *p)
 {
@@ -71,11 +72,14 @@ static inline void disarm_kprobe(struct 
 static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
 {
 	regs->msr |= MSR_SE;
-	/*single step inline if it a breakpoint instruction*/
-	if (p->opcode == BREAKPOINT_INSTRUCTION)
+	stepped_insn = *p->ainsn.insn;
+
+	/* single step inline if it is a trap variant */
+	if (IS_TW(stepped_insn) || IS_TD(stepped_insn) ||
+			IS_TWI(stepped_insn) || IS_TDI(stepped_insn))
 		regs->nip = (unsigned long)p->addr;
 	else
-		regs->nip = (unsigned long)&p->ainsn.insn;
+		regs->nip = (unsigned long)&stepped_insn;
 }
 
 static inline int kprobe_handler(struct pt_regs *regs)



More information about the Linuxppc64-dev mailing list