[PATCH] powerpc: Print instruction when logging unhandled exceptions

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE4353d

2 messages, 2 authors, 2014-10-02 · open the first message on its own page

[PATCH] powerpc: Print instruction when logging unhandled exceptions

From: Anton Blanchard <hidden>
Date: 2014-09-25 05:05:46

It is often useful to see the instruction that caused an unhandled
exception.

Signed-off-by: Anton Blanchard <redacted>
---
 arch/powerpc/kernel/traps.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 0dc43f9..27e30c8 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -36,10 +36,10 @@
 #include <linux/debugfs.h>
 #include <linux/ratelimit.h>
 #include <linux/context_tracking.h>
+#include <linux/uaccess.h>
 
 #include <asm/emulated_ops.h>
 #include <asm/pgtable.h>
-#include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/machdep.h>
 #include <asm/rtas.h>
@@ -242,9 +242,9 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
 {
 	siginfo_t info;
 	const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \
-			"at %08lx nip %08lx lr %08lx code %x\n";
+			"at %08lx nip %08lx lr %08lx code %x insn %08x\n";
 	const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \
-			"at %016lx nip %016lx lr %016lx code %x\n";
+			"at %016lx nip %016lx lr %016lx code %x insn %08x\n";
 
 	if (!user_mode(regs)) {
 		die("Exception in kernel mode", regs, signr);
@@ -252,9 +252,18 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
 	}
 
 	if (show_unhandled_signals && unhandled_signal(current, signr)) {
+		u32 __user *nia = (u32 __user *)regs->nip;
+		u32 insn = 0;
+
+		pagefault_disable();
+		if (!access_ok(VERIFY_READ, nia, sizeof(*nia)) ||
+		    __get_user_inatomic(insn, nia))
+			insn = 0xffffffffUL;
+		pagefault_enable();
+
 		printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32,
 				   current->comm, current->pid, signr,
-				   addr, regs->nip, regs->link, code);
+				   addr, regs->nip, regs->link, code, insn);
 	}
 
 	if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs))
-- 
1.9.1

Re: powerpc: Print instruction when logging unhandled exceptions

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2014-10-02 07:14:46

On Thu, 2014-25-09 at 05:05:45 UTC, Anton Blanchard wrote:
quoted hunk
It is often useful to see the instruction that caused an unhandled
exception.
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 0dc43f9..27e30c8 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -252,9 +252,18 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
 	}
 
 	if (show_unhandled_signals && unhandled_signal(current, signr)) {
+		u32 __user *nia = (u32 __user *)regs->nip;
+		u32 insn = 0;
+
+		pagefault_disable();
+		if (!access_ok(VERIFY_READ, nia, sizeof(*nia)) ||
+		    __get_user_inatomic(insn, nia))
+			insn = 0xffffffffUL;
+		pagefault_enable();
Can you add a comment explaining that interesting construct?

Looks like we do something similar in the perf callchain code, though without
the access_ok() check?

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help