[Bug 225321] dtrace/powerpc64: System crash

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Wed Feb 21 19:41:12 UTC 2018


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225321

--- Comment #5 from Breno Leitao <breno.leitao at gmail.com> ---
Looking further, it and the stack is properly set, i.e, the tmpstk is set at
the correct place, and the patch above, although not crashing, is far to be
correct.

This is my new discovery:

1) The tmpstk is being used by powerpc_init().
2) Powerpc_init calls kdb_enter(), which calls breakpoint().
3) Breakpoint goes to "dbtrap" label, which reset the stack to tmpstk,
overwriting it since the beginning.
4) when dbtrap/breakpoint exits, the stack is a mess, causing this problem.

To prove that, I created a stack just for the trap, and this seems to fix the
problem.

diff --git a/sys/powerpc/aim/locore64.S b/sys/powerpc/aim/locore64.S
index f283ba6489b..3dd1ca4092d 100644
--- a/sys/powerpc/aim/locore64.S
+++ b/sys/powerpc/aim/locore64.S
@@ -58,9 +58,13 @@ GLOBAL(__endkernel)
 #define        TMPSTKSZ        16384           /* 16K temporary stack */
 GLOBAL(tmpstk)
        .space  TMPSTKSZ
-
 TOC_ENTRY(tmpstk)

+#define TRAPSTKSZ      4096
+GLOBAL(trapstk)
+       .space  TRAPSTKSZ
+TOC_ENTRY(trapstk)
+
 /*
  * Entry point for bootloaders that do not fully implement ELF and start
  * at the beginning of the image (kexec, notably). In its own section so
diff --git a/sys/powerpc/aim/trap_subr64.S b/sys/powerpc/aim/trap_subr64.S
index 7ef41d90ffe..ffae46fa3f6 100644
--- a/sys/powerpc/aim/trap_subr64.S
+++ b/sys/powerpc/aim/trap_subr64.S
@@ -805,9 +805,9 @@ dbtrap:
        andi.   %r1,%r1,0xff00
        mtsprg3 %r1

-       ld      %r1,TRAP_TOCBASE(0)             /* get new SP */
-       ld      %r1,TOC_REF(tmpstk)(%r1)
-       addi    %r1,%r1,(TMPSTKSZ-48)
+       GET_TOCBASE(%r1)
+       ld      %r1,TOC_REF(trapstk)(%r1)
+       addi    %r1,%r1,(TRAPSTKSZ-48)

        FRAME_SETUP(PC_DBSAVE)
 /* Call C trap code: */

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-ppc mailing list