Module Name: src
Committed By: riastradh
Date: Thu Jun 4 19:53:55 UTC 2020
Modified Files:
src/sys/arch/x86/x86: fpu.c
Log Message:
Call clts/stts in fpu_kern_enter/leave so they work.
To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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.61 src/sys/arch/x86/x86/fpu.c:1.62
--- src/sys/arch/x86/x86/fpu.c:1.61 Fri Jan 31 08:55:38 2020
+++ src/sys/arch/x86/x86/fpu.c Thu Jun 4 19:53:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.61 2020/01/31 08:55:38 maxv Exp $ */
+/* $NetBSD: fpu.c,v 1.62 2020/06/04 19:53:55 riastradh Exp $ */
/*
* Copyright (c) 2008, 2019 The NetBSD Foundation, Inc. All
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.61 2020/01/31 08:55:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.62 2020/06/04 19:53:55 riastradh Exp $");
#include "opt_multiprocessor.h"
@@ -365,6 +365,14 @@ fpu_kern_enter(void)
} else {
fpu_save_lwp(l);
}
+
+ /*
+ * Clear CR0_TS, which fpu_save_lwp set if it saved anything --
+ * otherwise the CPU will trap if we try to use the FPU under
+ * the false impression that there has been a task switch since
+ * the last FPU usage requiring that we save the FPU state.
+ */
+ clts();
}
void
@@ -375,6 +383,13 @@ fpu_kern_leave(void)
KASSERT(ci->ci_ilevel == IPL_HIGH);
KASSERT(ci->ci_kfpu_spl != -1);
+
+ /*
+ * Set CR0_TS again so that the kernel can't accidentally use
+ * the FPU.
+ */
+ stts();
+
s = ci->ci_kfpu_spl;
ci->ci_kfpu_spl = -1;
splx(s);