Skip to contentSkip to conversation

[[email protected]: kgdb for parisc]

[email protected]: kgdb for parisc Sven Schnelle 2 participants 2 messages Mar 26, 2019 – Mar 27, 2019 PA-RISC architecture

lore
Share & tools
lore
#0 lore raw

Hi List,

i'm working on improving PA-RISC emulation on QEMU. To make it a bit easier to test things on real Hardware, i've started implementing kgdb support for PA-RISC. Most of the things work, however the kgdb test suite is giving me a hard time with testing single stepping.

The log output looks like this:

[    3.942626] kgdb_arch_remove_breakpoint: 40ab6898, restoring insn 08030241
[    3.949518] kgdb_arch_set_breakpoint: 40ab6898
[    3.953967] kgdb_arch_set_breakpoint: saved insn 08030241
[    3.959374] kgdb_arch_handle_exception: trap 9 inbuf c iaoq 402ab520 iir 03ffc01f
[    3.966919] handle_break: 40ab6898
[    3.970419] kgdb_arch_remove_breakpoint: 40ab6898, restoring insn 08030241
[    3.977590] gdb_regs_to_pt_regs: iaoq F 40ab6898 B 40ab689c

KGDB setting front of Instruction queue to 40ab6898

[    3.983178] kgdb_arch_handle_exception: trap 9 inbuf  iaoq 40ab6898 iir 03ffa01f
[    3.990584] kgdb_arch_handle_exception: trap 9 inbuf s iaoq 40ab6898 iir 03ffa01f

It singlesteps...

[    3.998130] handle_interruption: 40ab689c
[    4.002510] gdb_regs_to_pt_regs: iaoq F 40ab689c B 40ab68a0
[    4.008351] gdb_regs_to_pt_regs: iaoq F 40ab689c B 40ab68a0
[    4.013923] kgdbts: BP mismatch 40ab689c expected 40ab6898

And is expecting the old address?!

I'm using the recovery counter of the CPU, and i'm not sure whether i'm missing some detail of the Recovery counter, or some detail of kgdb tests.

If i single step with kdb in normal mode, it looks fine.

Can anyone give me a helping hand with this? I'm attaching the current (unfinished) version of the patch i'm using.

Another thing is that for software breakpoints we would need to modify kernel text. Currently it's EXEC only (which is good) but that doesn't work with kgdb for obvious reasons. Would it be ok to set it to RWX when KGDB is enabled? I'm not feeling comfortable messing with the TLB right now. Maybe later when i know a bit more of the linux parisc implementation ;-)

Thanks
Sven

commit 12f66c180e5b15a8ce02c5053484541fe46cf62a

Author: Sven Schnelle <[email protected]>
Date:   Fri Mar 22 11:23:18 2019 +0100

parisc: add KGDB support

arch/parisc/Kconfig +1 -0
index c8e621296092..a80c19c7fc0e 100644
@@ -54,6 +54,7 @@ config PARISC
 	select CPU_NO_EFFICIENT_FFS
 	select NEED_DMA_MAP_STATE
 	select NEED_SG_DMA_LENGTH
+	select HAVE_ARCH_KGDB
 
 	help
 	  The PA-RISC microprocessor is designed by Hewlett-Packard and used
arch/parisc/include/asm/kgdb.h new file +100 -0

100 lines not on this page · raw message

arch/parisc/kernel/Makefile +1 -0
index 8e5f1ab65c68..b1a69e3c91cd 100644
@@ -32,3 +32,4 @@ obj-$(CONFIG_64BIT)	+= perf.o perf_asm.o $(obj64-y)
 obj-$(CONFIG_PARISC_CPU_TOPOLOGY)	+= topology.o
 obj-$(CONFIG_FUNCTION_TRACER)		+= ftrace.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o
+obj-$(CONFIG_KGDB)			+= kgdb.o
arch/parisc/kernel/kgdb.c new file +242 -0

242 lines not on this page · raw message

arch/parisc/kernel/traps.c +14 -0
index 7e1ccafadf57..ac0c4360d76a 100644
@@ -42,6 +42,7 @@
 #include <asm/unwind.h>
 #include <asm/tlbflush.h>
 #include <asm/cacheflush.h>
+#include <linux/kgdb.h>
 
 #include "../math-emu/math-emu.h"	/* for handle_fpe() */
 
@@ -293,6 +294,14 @@ static void handle_break(struct pt_regs *regs)
 			(tt == BUG_TRAP_TYPE_NONE) ? 9 : 0);
 	}
 
+#ifdef CONFIG_KGDB
+	if (unlikely(iir == PARISC_KGDB_COMPILED_BREAK_INSN) ||
+		unlikely(iir == PARISC_KGDB_BREAK_INSN)) {
+			kgdb_handle_exception(9, SIGTRAP, 0, regs);
+			return;
+	}
+#endif
+
 	if (unlikely(iir != GDB_BREAK_INSN))
 		parisc_printk_ratelimited(0, regs,
 			KERN_DEBUG "break %d,%d: pid=%d command='%s'\n",
@@ -518,6 +527,11 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
 	case  3:
 		/* Recovery counter trap */
 		regs->gr[0] &= ~PSW_R;
+		if (kgdb_single_step) {
+			kgdb_handle_exception(3, SIGTRAP, 0, regs);
+			return;
+		}
+
 		if (user_space(regs))
 			handle_gdb_break(regs, TRAP_TRACE);
 		/* else this must be the start of a syscall - just let it run */
arch/parisc/mm/init.c +8 -0
index d0b166256f1a..39dbf0a31f8b 100644
@@ -459,14 +459,22 @@ static void __init map_pages(unsigned long start_vaddr,
 				if (force)
 					pte =  __mk_pte(address, pgprot);
 				else if (parisc_text_address(vaddr)) {
+#ifdef CONFIG_KGDB
+					pte = __mk_pte(address, PAGE_KERNEL_RWX);
+#else
 					pte = __mk_pte(address, PAGE_KERNEL_EXEC);
+#endif
 					if (address >= ro_start && address < kernel_end)
 						pte = pte_mkhuge(pte);
 				}
 				else
 #if defined(CONFIG_PARISC_PAGE_SIZE_4KB)
 				if (address >= ro_start && address < ro_end) {
+#ifdef CONFIG_KGDB
+					pte = __mk_pte(address, PAGE_KERNEL_RWX);
+#else
 					pte = __mk_pte(address, PAGE_KERNEL_EXEC);
+#endif
 					pte = pte_mkhuge(pte);
 				} else
 #endif

----- End forwarded message -----

maintainer
#1 lore raw

Hi Sven,

Quoted 4 lines · Sven Schnelle

Another thing is that for software breakpoints we would need to modify kernel text. Currently it's EXEC only (which is good) but that doesn't work with kgdb for obvious reasons. Would it be ok to set it to RWX when KGDB is enabled?

Sure, but you could use the function set_kernel_text_rw()...

Helge