Module Name:    src
Committed By:   maxv
Date:           Tue Jun 19 09:25:13 UTC 2018

Modified Files:
        src/sys/arch/x86/x86: fpu.c

Log Message:
When using EagerFPU, create the fpu state in execve at IPL_HIGH.

A preemption could occur in the middle, and we don't want that to happen,
because the context switch would use the partially-constructed fpu state.

The procedure becomes:

        splhigh
        unbusy the current cpu's fpu
        create a new fpu state in memory
        install the state on the current cpu's fpu
        splx

Disabling preemption also ensures that x86_fpu_eager doesn't change in
the middle.

In LazyFPU mode we drop IPL_HIGH right away.

Add more KASSERTs.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.38 src/sys/arch/x86/x86/fpu.c:1.39
--- src/sys/arch/x86/x86/fpu.c:1.38	Mon Jun 18 20:20:27 2018
+++ src/sys/arch/x86/x86/fpu.c	Tue Jun 19 09:25:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.38 2018/06/18 20:20:27 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.39 2018/06/19 09:25:13 maxv 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.38 2018/06/18 20:20:27 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.39 2018/06/19 09:25:13 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -624,10 +624,22 @@ fpu_save_area_clear(struct lwp *l, unsig
 {
 	union savefpu *fpu_save;
 	struct pcb *pcb;
+	int s;
 
-	fpusave_lwp(l, false);
+	KASSERT(l == curlwp);
+	KASSERT((l->l_flag & LW_SYSTEM) == 0);
 	fpu_save = process_fpframe(l);
 	pcb = lwp_getpcb(l);
+
+	s = splhigh();
+	if (x86_fpu_eager) {
+		KASSERT(pcb->pcb_fpcpu == NULL ||
+		    pcb->pcb_fpcpu == curcpu());
+		fpusave_cpu(false);
+	} else {
+		splx(s);
+		fpusave_lwp(l, false);
+	}
 	KASSERT(pcb->pcb_fpcpu == NULL);
 
 	if (i386_use_fxsave) {
@@ -650,13 +662,9 @@ fpu_save_area_clear(struct lwp *l, unsig
 	}
 	pcb->pcb_fpu_dflt_cw = x87_cw;
 
-	/*
-	 * If using eager-switch, install the FPU state on the current
-	 * CPU.
-	 */
 	if (x86_fpu_eager) {
-		KASSERT(l == curlwp);
-		fpu_eagerswitch(NULL, l);
+		fpu_eagerrestore(l);
+		splx(s);
 	}
 }
 

Reply via email to