Module Name:    src
Committed By:   martin
Date:           Tue Jul 10 15:35:26 UTC 2018

Modified Files:
        src/sys/arch/amd64/amd64 [netbsd-8]: locore.S
        src/sys/arch/i386/i386 [netbsd-8]: locore.S
        src/sys/arch/x86/x86 [netbsd-8]: fpu.c

Log Message:
Pull up the following, requested by maxv in ticket #910:

        sys/arch/amd64/amd64/locore.S   r1.167 (patch)
        sys/arch/i386/i386/locore.S     r1.158 (patch)
        sys/arch/x86/x86/fpu.c          r1.44 (patch)

Don't switch the FPU when leaving a softint. This fixes
several problems when EagerFPU is enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.123.6.7 -r1.123.6.8 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.145.6.4 -r1.145.6.5 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.12.8.2 -r1.12.8.3 src/sys/arch/x86/x86/fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.123.6.7 src/sys/arch/amd64/amd64/locore.S:1.123.6.8
--- src/sys/arch/amd64/amd64/locore.S:1.123.6.7	Sat Jun 23 11:39:01 2018
+++ src/sys/arch/amd64/amd64/locore.S	Tue Jul 10 15:35:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.123.6.7 2018/06/23 11:39:01 martin Exp $	*/
+/*	$NetBSD: locore.S,v 1.123.6.8 2018/07/10 15:35:26 martin Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1094,20 +1094,6 @@ skip_save:
 	popq	%rdx
 #endif
 
-#ifndef XEN
-	/* RDI/RSI got clobbered. */
-	movq	%r13,%rdi
-	movq	%r12,%rsi
-
-	pushq	%rdx
-	movb	_C_LABEL(x86_fpu_eager),%dl
-	testb	%dl,%dl
-	jz	.Lno_eagerfpu
-	callq	_C_LABEL(fpu_eagerswitch)
-.Lno_eagerfpu:
-	popq	%rdx
-#endif
-
 	/* Switch to newlwp's stack. */
 	movq	L_PCB(%r12),%r14
 	movq	PCB_RSP(%r14),%rsp
@@ -1148,6 +1134,18 @@ skip_save:
 #endif
 .Lring0_switched:
 
+#ifndef XEN
+	pushq	%rdx
+	movb	_C_LABEL(x86_fpu_eager),%dl
+	testb	%dl,%dl
+	jz	.Lno_eagerfpu
+	movq	%r13,%rdi
+	movq	%r12,%rsi
+	callq	_C_LABEL(fpu_eagerswitch)
+.Lno_eagerfpu:
+	popq	%rdx
+#endif
+
 	/* Don't bother with the rest if switching to a system process. */
 	testl	$LW_SYSTEM,L_FLAG(%r12)
 	jnz	switch_return

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.145.6.4 src/sys/arch/i386/i386/locore.S:1.145.6.5
--- src/sys/arch/i386/i386/locore.S:1.145.6.4	Sat Jun 23 11:39:02 2018
+++ src/sys/arch/i386/i386/locore.S	Tue Jul 10 15:35:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.145.6.4 2018/06/23 11:39:02 martin Exp $	*/
+/*	$NetBSD: locore.S,v 1.145.6.5 2018/07/10 15:35:26 martin Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145.6.4 2018/06/23 11:39:02 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145.6.5 2018/07/10 15:35:26 martin Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -1089,19 +1089,6 @@ ENTRY(cpu_switchto)
 	movl	%ebp,PCB_EBP(%eax)
 skip_save:
 
-#ifndef XEN
-	pushl	%edx
-	movb	_C_LABEL(x86_fpu_eager),%dl
-	testb	%dl,%dl
-	jz	.Lno_eagerfpu
-	pushl	%edi
-	pushl	%esi
-	call	_C_LABEL(fpu_eagerswitch)
-	addl	$8,%esp
-.Lno_eagerfpu:
-	popl	%edx
-#endif
-
 	/* Switch to newlwp's stack. */
 	movl	L_PCB(%edi),%ebx
 	movl	PCB_EBP(%ebx),%ebp
@@ -1129,6 +1116,19 @@ skip_save:
 	movl	%eax,TSS_ESP0(%ecx)
 #endif
 
+#ifndef XEN
+	pushl	%edx
+	movb	_C_LABEL(x86_fpu_eager),%dl
+	testb	%dl,%dl
+	jz	.Lno_eagerfpu
+	pushl	%edi
+	pushl	%esi
+	call	_C_LABEL(fpu_eagerswitch)
+	addl	$8,%esp
+.Lno_eagerfpu:
+	popl	%edx
+#endif
+
 	/* Don't bother with the rest if switching to a system process. */
 	testl	$LW_SYSTEM,L_FLAG(%edi)
 	jnz	switch_return

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.12.8.2 src/sys/arch/x86/x86/fpu.c:1.12.8.3
--- src/sys/arch/x86/x86/fpu.c:1.12.8.2	Sat Jun 23 11:39:02 2018
+++ src/sys/arch/x86/x86/fpu.c	Tue Jul 10 15:35:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.12.8.2 2018/06/23 11:39:02 martin Exp $	*/
+/*	$NetBSD: fpu.c,v 1.12.8.3 2018/07/10 15:35:26 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.12.8.2 2018/06/23 11:39:02 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.12.8.3 2018/07/10 15:35:26 martin Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -306,6 +306,20 @@ fpu_eagerswitch(struct lwp *oldlwp, stru
 	int s;
 
 	s = splhigh();
+#ifdef DIAGNOSTIC
+	if (oldlwp != NULL) {
+		struct pcb *pcb = lwp_getpcb(oldlwp);
+		struct cpu_info *ci = curcpu();
+		if (pcb->pcb_fpcpu == NULL) {
+			KASSERT(ci->ci_fpcurlwp != oldlwp);
+		} else if (pcb->pcb_fpcpu == ci) {
+			KASSERT(ci->ci_fpcurlwp == oldlwp);
+		} else {
+			panic("%s: oldlwp's state installed elsewhere",
+			    __func__);
+		}
+	}
+#endif
 	fpusave_cpu(true);
 	if (!(newlwp->l_flag & LW_SYSTEM))
 		fpu_eagerrestore(newlwp);

Reply via email to