Module Name: src
Committed By: maxv
Date: Tue Oct 31 11:37:05 UTC 2017
Modified Files:
src/sys/arch/x86/x86: fpu.c identcpu.c
Log Message:
Always use x86_fpu_save, clearer.
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/x86/fpu.c
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/x86/x86/identcpu.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.15 src/sys/arch/x86/x86/fpu.c:1.16
--- src/sys/arch/x86/x86/fpu.c:1.15 Tue Oct 31 10:35:58 2017
+++ src/sys/arch/x86/x86/fpu.c Tue Oct 31 11:37:05 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.15 2017/10/31 10:35:58 maxv Exp $ */
+/* $NetBSD: fpu.c,v 1.16 2017/10/31 11:37:05 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.15 2017/10/31 10:35:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.16 2017/10/31 11:37:05 maxv Exp $");
#include "opt_multiprocessor.h"
@@ -368,10 +368,12 @@ fpudna(struct trapframe *frame)
ci->ci_fpcurlwp = l;
pcb->pcb_fpcpu = ci;
- if (i386_use_fxsave) {
- if (x86_xsave_features != 0) {
- xrstor(&pcb->pcb_savefpu, x86_xsave_features);
- } else {
+ switch (x86_fpu_save) {
+ case FPU_SAVE_FSAVE:
+ frstor(&pcb->pcb_savefpu);
+ break;
+
+ case FPU_SAVE_FXSAVE:
/*
* AMD FPU's do not restore FIP, FDP, and FOP on
* fxrstor, leaking other process's execution history.
@@ -384,11 +386,13 @@ fpudna(struct trapframe *frame)
if (fngetsw() & 0x80)
fnclex();
fldummy();
-
fxrstor(&pcb->pcb_savefpu);
- }
- } else {
- frstor(&pcb->pcb_savefpu);
+ break;
+
+ case FPU_SAVE_XSAVE:
+ case FPU_SAVE_XSAVEOPT:
+ xrstor(&pcb->pcb_savefpu, x86_xsave_features);
+ break;
}
KASSERT(ci == curcpu());
@@ -416,13 +420,20 @@ fpusave_cpu(bool save)
if (save) {
clts();
- if (i386_use_fxsave) {
- if (x86_xsave_features != 0)
- xsave(&pcb->pcb_savefpu, x86_xsave_features);
- else
+
+ switch (x86_fpu_save) {
+ case FPU_SAVE_FSAVE:
+ fnsave(&pcb->pcb_savefpu);
+ break;
+
+ case FPU_SAVE_FXSAVE:
fxsave(&pcb->pcb_savefpu);
- } else {
- fnsave(&pcb->pcb_savefpu);
+ break;
+
+ case FPU_SAVE_XSAVE:
+ case FPU_SAVE_XSAVEOPT:
+ xsave(&pcb->pcb_savefpu, x86_xsave_features);
+ break;
}
}
Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.60 src/sys/arch/x86/x86/identcpu.c:1.61
--- src/sys/arch/x86/x86/identcpu.c:1.60 Mon Oct 9 17:49:28 2017
+++ src/sys/arch/x86/x86/identcpu.c Tue Oct 31 11:37:05 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: identcpu.c,v 1.60 2017/10/09 17:49:28 maya Exp $ */
+/* $NetBSD: identcpu.c,v 1.61 2017/10/31 11:37:05 maxv Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.60 2017/10/09 17:49:28 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.61 2017/10/31 11:37:05 maxv Exp $");
#include "opt_xen.h"
@@ -64,7 +64,7 @@ static const struct x86_cache_info amd_c
int cpu_vendor;
char cpu_brand_string[49];
-int x86_fpu_save __read_mostly = FPU_SAVE_FSAVE;
+int x86_fpu_save __read_mostly;
unsigned int x86_fpu_save_size __read_mostly = 512;
uint64_t x86_xsave_features __read_mostly = 0;
@@ -723,6 +723,8 @@ cpu_probe_fpu(struct cpu_info *ci)
{
u_int descs[4];
+ x86_fpu_save = FPU_SAVE_FSAVE;
+
#ifdef i386 /* amd64 always has fxsave, sse and sse2 */
/* If we have FXSAVE/FXRESTOR, use them. */
if ((ci->ci_feat_val[0] & CPUID_FXSR) == 0) {
@@ -750,7 +752,7 @@ cpu_probe_fpu(struct cpu_info *ci)
x86_fpu_save = FPU_SAVE_FXSAVE;
- /* See if xsave (for AVX is supported) */
+ /* See if xsave (for AVX) is supported */
if ((ci->ci_feat_val[1] & CPUID2_XSAVE) == 0)
return;
@@ -768,6 +770,7 @@ cpu_probe_fpu(struct cpu_info *ci)
#ifdef XEN
/* Don't use xsave, force fxsave with x86_xsave_features = 0. */
+ x86_fpu_save = FPU_SAVE_FXSAVE;
#else
x86_xsave_features = (uint64_t)descs[3] << 32 | descs[0];
#endif