Tue Jun 7 14:53:03 2011 UTC ()
Don't call psignal() without holding proc_lock. This is the cause of
the reboot of PR port-xen/45028
Now that Xen2 is gone, handle FPU context switches the same way as
amd64. This makes all tests in /usr/tests/lib/libc/ieeefp pass.


(bouyer)
diff -r1.702 -r1.703 src/sys/arch/i386/i386/machdep.c
diff -r1.139 -r1.140 src/sys/arch/i386/isa/npx.c
diff -r1.11 -r1.12 src/sys/arch/xen/include/i386/hypercalls.h

cvs diff -r1.702 -r1.703 src/sys/arch/i386/i386/machdep.c (expand / switch to context diff)
--- src/sys/arch/i386/i386/machdep.c 2011/04/26 15:51:23 1.702
+++ src/sys/arch/i386/i386/machdep.c 2011/06/07 14:53:03 1.703
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.702 2011/04/26 15:51:23 joerg Exp $	*/
+/*	$NetBSD: machdep.c,v 1.703 2011/06/07 14:53:03 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.702 2011/04/26 15:51:23 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.703 2011/06/07 14:53:03 bouyer Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -527,7 +527,7 @@
 #ifndef XEN
 	lldt(pmap_kernel()->pm_ldt_sel);
 #else
-	HYPERVISOR_fpu_taskswitch();
+	HYPERVISOR_fpu_taskswitch(1);
 	XENPRINTF(("lwp tss sp %p ss %04x/%04x\n",
 	    (void *)pcb->pcb_esp0,
 	    GSEL(GDATA_SEL, SEL_KPL),
@@ -552,7 +552,7 @@
 	pcb = lwp_getpcb(l);
 	ci = curcpu();
 	if (ci->ci_fpused) {
-		HYPERVISOR_fpu_taskswitch();
+		HYPERVISOR_fpu_taskswitch(1);
 		ci->ci_fpused = 0;
 	}
 

cvs diff -r1.139 -r1.140 src/sys/arch/i386/isa/Attic/npx.c (expand / switch to context diff)
--- src/sys/arch/i386/isa/Attic/npx.c 2010/12/20 00:25:35 1.139
+++ src/sys/arch/i386/isa/Attic/npx.c 2011/06/07 14:53:03 1.140
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.139 2010/12/20 00:25:35 matt Exp $	*/
+/*	$NetBSD: npx.c,v 1.140 2011/06/07 14:53:03 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.139 2010/12/20 00:25:35 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.140 2011/06/07 14:53:03 bouyer Exp $");
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -159,8 +159,8 @@
 static int	npxdna(struct cpu_info *);
 
 #ifdef XEN
-#define	clts()
-#define	stts()
+#define	clts() HYPERVISOR_fpu_taskswitch(0)
+#define	stts() HYPERVISOR_fpu_taskswitch(1)
 #endif
 
 static	enum npx_type		npx_type;
@@ -190,9 +190,7 @@
 npxdna_empty(struct cpu_info *ci)
 {
 
-#ifndef XEN
 	panic("npxdna vector not initialized");
-#endif
 	return 0;
 }
 
@@ -507,7 +505,9 @@
 		 * Currently, we treat this like an asynchronous interrupt, but
 		 * this has disadvantages.
 		 */
+		mutex_enter(proc_lock);
 		psignal(l->l_proc, SIGFPE);
+		mutex_exit(proc_lock);
 	}
 
 	kpreempt_enable();

cvs diff -r1.11 -r1.12 src/sys/arch/xen/include/i386/Attic/hypercalls.h (expand / switch to context diff)
--- src/sys/arch/xen/include/i386/Attic/hypercalls.h 2011/03/30 22:57:24 1.11
+++ src/sys/arch/xen/include/i386/Attic/hypercalls.h 2011/06/07 14:53:03 1.12
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypercalls.h,v 1.11 2011/03/30 22:57:24 jym Exp $	*/
+/*	$NetBSD: hypercalls.h,v 1.12 2011/06/07 14:53:03 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -226,7 +226,6 @@
     return ret;
 }
 
-#if 0
 static __inline int
 HYPERVISOR_fpu_taskswitch(int set)
 {
@@ -238,19 +237,6 @@
 
     return ret;
 }
-#else /* 0 */
-/* Xen2 compat: always i38HYPERVISOR_fpu_taskswitch(1) */
-static __inline int
-HYPERVISOR_fpu_taskswitch(void)
-{
-    long ret;
-    long ign1;
-    _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (1)),
-	_harg("=a" (ret), "=b" (ign1)));
-
-    return ret;
-}
-#endif /* 0 */
 
 static __inline int
 HYPERVISOR_update_descriptor(uint64_t ma, uint32_t word1, uint32_t word2)