Skip to contentSkip to conversation

Early x86_64 crash

PATCH In review Jeff Dike 2 participants 4 messages Sep 29, 2005 – Oct 2, 2005 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 1/1 Early x86_64 crash

If you are running UML/x86_64 and are seeing it crash before starting init, I'd like you to do the following:
- make sure that you have CONFIG_FRAME_POINTER disabled
- enable it and see that UML boots
- apply the patch below, disable CONFIG_FRAME_POINTER again, and
see if UML still boots
- report results back to me

Jeff

arch/um/sys-x86_64/stub_segv.c +19 -6
Index: test/arch/um/sys-x86_64/stub_segv.c
===================================================================
@@ -11,6 +11,16 @@
 #include "sysdep/sigcontext.h"
 #include "sysdep/faultinfo.h"
 
+/* Copied from sys-x86_64/signal.c - Can't find an equivalent definition
+ * in the libc headers anywhere.
+ */
+struct rt_sigframe
+{
+        char *pretcode;
+        struct ucontext uc;
+        struct siginfo info;
+};
+
 void __attribute__ ((__section__ (".__syscall_stub")))
 stub_segv_handler(int sig)
 {
@@ -22,11 +32,14 @@
 
 	__asm__("movq %0, %%rax ; syscall": : "g" (__NR_getpid));
 	__asm__("movq %%rax, %%rdi ; movq %0, %%rax ; movq %1, %%rsi ;"
-		"syscall": : "g" (__NR_kill), "g" (SIGUSR1));
-	/* Two popqs to restore the stack to the state just before entering
-	 * the handler, one pops the return address, the other pops the frame
-	 * pointer.
+		"syscall": : "g" (__NR_kill), "g" (SIGUSR1) : 
+                "%rdi", "%rax", "%rsi");
+	/* sys_sigreturn expects that the stack pointer will be 8 bytes into
+	 * the signal frame.  So, we use the ucontext pointer, which we know
+	 * already, to get the signal frame pointer, and add 8 to that.
 	 */
-	__asm__("popq %%rax ; popq %%rax ; movq %0, %%rax ; syscall" : : "g"
-		(__NR_rt_sigreturn));
+        __asm__("movq %0, %%rsp": : 
+                "g" ((unsigned long) container_of(uc, struct rt_sigframe, 
+						  uc) + 8));
+	__asm__("movq %0, %%rax ; syscall" : : "g" (__NR_rt_sigreturn));
 }

-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#2 lore raw
In reply to Blaisorblade
Quoted 2 lines · Blaisorblade

I assume you've been able to reproduce this crash and see this patch fix it, right?

Yup.

Quoted 2 lines

I've attached the addon with additional clobber, and with fixed tabs (i.e. hardtabs). Not compiled it (no time to reboot right now).

Yeah, I'll fix the spacing in my copy.

Jeff

-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#3 lore raw
Quoted 10 lines · Jeff Dike
Quoted 2 lines · Blaisorblade

I assume you've been able to reproduce this crash and see this patch fix it, right?

Yup.

Quoted 2 lines

I've attached the addon with additional clobber, and with fixed tabs (i.e. hardtabs). Not compiled it (no time to reboot right now).

Yeah, I'll fix the spacing in my copy.

I'm assuming the additional clobbers are ok, and queuing the whole in -bs3.

Signature · 20 lines
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade


		
___________________________________ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.messenger.yahoo.com



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#1 lore raw
In reply to Jeff Dike
Quoted 2 lines · Jeff Dike

If you are running UML/x86_64 and are seeing it crash before starting init, I'd like you to do the following:

I assume you've been able to reproduce this crash and see this patch fix it, right?

I'm going to take it for -bs3, meanwhile, as soon as you answer on the attachment (I'd like it at least to compile).

Review line 33

Quoted 11 lines

- make sure that you have CONFIG_FRAME_POINTER disabled
- enable it and see that UML boots
- apply the patch below, disable CONFIG_FRAME_POINTER again, and
see if UML still boots
- report results back to me

Jeff

(quoted diff) +0 -0
@@ -22,11 +32,14 @@
 
 	__asm__("movq %0, %%rax ; syscall": : "g" (__NR_getpid));

Why there's no "%rax" in the register clobber list, here and at the end?

Review line 36

Quoted 7 lines
(quoted diff) +2 -4
 	__asm__("movq %%rax, %%rdi ; movq %0, %%rax ; movq %1, %%rsi ;"
-		"syscall": : "g" (__NR_kill), "g" (SIGUSR1));
-	/* Two popqs to restore the stack to the state just before entering
-	 * the handler, one pops the return address, the other pops the frame
-	 * pointer.
+		"syscall": : "g" (__NR_kill), "g" (SIGUSR1) :
+                "%rdi", "%rax", "%rsi");

Here you're correctly informing GCC that your asm uses these regs.

Review line 45

Quoted 11 lines
(quoted diff) +7 -2
+	/* sys_sigreturn expects that the stack pointer will be 8 bytes into
+	 * the signal frame.  So, we use the ucontext pointer, which we know
+	 * already, to get the signal frame pointer, and add 8 to that.
 	 */
-	__asm__("popq %%rax ; popq %%rax ; movq %0, %%rax ; syscall" : : "g"
-		(__NR_rt_sigreturn));
+        __asm__("movq %0, %%rsp": :
+                "g" ((unsigned long) container_of(uc, struct rt_sigframe,
+						  uc) + 8));
+	__asm__("movq %0, %%rax ; syscall" : : "g" (__NR_rt_sigreturn));
 }

I've attached the addon with additional clobber, and with fixed tabs (i.e. hardtabs). Not compiled it (no time to reboot right now).

Signature · 3 lines
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade
arch/um/sys-x86_64/stub_segv.c +6 -6
Index: linux-2.6.13/arch/um/sys-x86_64/stub_segv.c
===================================================================
@@ -25,20 +25,20 @@ stub_segv_handler(int sig)
 {
 	struct ucontext *uc;
 
-	__asm__("movq %%rdx, %0" : "=g" (uc) :);
+	__asm__("movq %%rdx, %0" : "=g" (uc) : );
         GET_FAULTINFO_FROM_SC(*((struct faultinfo *) UML_CONFIG_STUB_DATA),
                               &uc->uc_mcontext);
 
-	__asm__("movq %0, %%rax ; syscall": : "g" (__NR_getpid));
+	__asm__("movq %0, %%rax ; syscall": : "g" (__NR_getpid) : "%rax");
 	__asm__("movq %%rax, %%rdi ; movq %0, %%rax ; movq %1, %%rsi ;"
 		"syscall": : "g" (__NR_kill), "g" (SIGUSR1) :
-                "%rdi", "%rax", "%rsi");
+		"%rdi", "%rax", "%rsi");
 	/* sys_sigreturn expects that the stack pointer will be 8 bytes into
 	 * the signal frame.  So, we use the ucontext pointer, which we know
 	 * already, to get the signal frame pointer, and add 8 to that.
 	 */
-        __asm__("movq %0, %%rsp": :
-                "g" ((unsigned long) container_of(uc, struct rt_sigframe,
+	__asm__("movq %0, %%rsp": :
+		"g" ((unsigned long) container_of(uc, struct rt_sigframe,
 						  uc) + 8));
-	__asm__("movq %0, %%rax ; syscall" : : "g" (__NR_rt_sigreturn));
+	__asm__("movq %0, %%rax ; syscall" : : "g" (__NR_rt_sigreturn) : "%rax");
 }