mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] xtensa: dump userspace code around the exception PC
@ 2023-06-24 13:38 Max Filippov
       [not found] ` <562ff26d-df78-c1cb-6a34-b9a97efdc43e@web.de>
  0 siblings, 1 reply; 2+ messages in thread
From: Max Filippov @ 2023-06-24 13:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Chris Zankel, Max Filippov

In the absence of other debug facilities dumping user code around the
unhandled exception address may help debugging the issue.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 arch/xtensa/Kconfig.debug  |  8 ++++++++
 arch/xtensa/kernel/traps.c | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/arch/xtensa/Kconfig.debug b/arch/xtensa/Kconfig.debug
index 83cc8d12fa0e..e84172a7763c 100644
--- a/arch/xtensa/Kconfig.debug
+++ b/arch/xtensa/Kconfig.debug
@@ -38,3 +38,11 @@ config PRINT_STACK_DEPTH
 	help
 	  This option allows you to set the stack depth that the kernel
 	  prints in stack traces.
+
+config PRINT_USER_CODE_ON_UNHANDLED_EXCEPTION
+	bool "Dump user code around unhandled exception address"
+	help
+	  Enable this option to display user code around PC of the unhandled
+	  exception (starting at address aligned on 16 byte boundary).
+	  This may simplify finding faulting code in the absence of other
+	  debug facilities.
diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c
index a2a9a460ec9e..17eb180eff7c 100644
--- a/arch/xtensa/kernel/traps.c
+++ b/arch/xtensa/kernel/traps.c
@@ -175,6 +175,23 @@ __die_if_kernel(const char *str, struct pt_regs *regs, long err)
 		die(str, regs, err);
 }
 
+#ifdef CONFIG_PRINT_USER_CODE_ON_UNHANDLED_EXCEPTION
+static inline void dump_user_code(struct pt_regs *regs)
+{
+	char buf[32];
+
+	if (copy_from_user(buf, (void __user *)(regs->pc & -16), sizeof(buf)) == 0) {
+		print_hex_dump(KERN_INFO, " ", DUMP_PREFIX_NONE,
+			       32, 1, buf, sizeof(buf), false);
+
+	}
+}
+#else
+static inline void dump_user_code(struct pt_regs *regs)
+{
+}
+#endif
+
 /*
  * Unhandled Exceptions. Kill user task or panic if in kernel space.
  */
@@ -190,6 +207,7 @@ void do_unhandled(struct pt_regs *regs)
 			    "\tEXCCAUSE is %ld\n",
 			    current->comm, task_pid_nr(current), regs->pc,
 			    regs->exccause);
+	dump_user_code(regs);
 	force_sig(SIGILL);
 }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] xtensa: dump userspace code around the exception PC
       [not found] ` <562ff26d-df78-c1cb-6a34-b9a97efdc43e@web.de>
@ 2023-06-26  1:27   ` Max Filippov
  0 siblings, 0 replies; 2+ messages in thread
From: Max Filippov @ 2023-06-26  1:27 UTC (permalink / raw)
  To: Markus Elfring; +Cc: kernel-janitors, Chris Zankel, LKML

Hi Marcus,

On Sun, Jun 25, 2023 at 9:36 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > In the absence of other debug facilities dumping user code around the
> > unhandled exception address may help debugging the issue.
>
> Please choose an imperative change suggestion.

The change itself is so small that it's fully described in the
subject, and I believe
that that description is imperative. This part is the rationale. From
my experience
I cannot guarantee that dumping user code will help, but sometimes it
does, hence
the 'may help'.
Please let me know if you have better wording.

-- 
Thanks.
-- Max

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-26  1:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-24 13:38 [PATCH] xtensa: dump userspace code around the exception PC Max Filippov
     [not found] ` <562ff26d-df78-c1cb-6a34-b9a97efdc43e@web.de>
2023-06-26  1:27   ` Max Filippov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®