Page MenuHomeFreeBSD

D42135.diff
No OneTemporary

D42135.diff

diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c
--- a/sys/amd64/amd64/fpu.c
+++ b/sys/amd64/amd64/fpu.c
@@ -142,9 +142,6 @@
"memory");
}
-#define start_emulating() load_cr0(rcr0() | CR0_TS)
-#define stop_emulating() clts()
-
CTASSERT(sizeof(struct savefpu) == 512);
CTASSERT(sizeof(struct xstate_hdr) == 64);
CTASSERT(sizeof(struct savefpu_ymm) == 832);
@@ -263,7 +260,7 @@
u_long cr0;
cr0 = rcr0();
- stop_emulating();
+ fpu_enable();
fpusave(addr);
load_cr0(cr0);
}
@@ -274,7 +271,7 @@
u_long cr0;
cr0 = rcr0();
- stop_emulating();
+ fpu_enable();
fninit();
if (use_xsave)
load_xcr(XCR0, xsave_mask);
@@ -393,13 +390,13 @@
* It is too early for critical_enter() to work on AP.
*/
saveintr = intr_disable();
- stop_emulating();
+ fpu_enable();
fninit();
control = __INITIAL_FPUCW__;
fldcw(control);
mxcsr = __INITIAL_MXCSR__;
ldmxcsr(mxcsr);
- start_emulating();
+ fpu_disable();
intr_restore(saveintr);
TSEXIT();
}
@@ -430,7 +427,7 @@
cpu_thread_alloc(&thread0);
saveintr = intr_disable();
- stop_emulating();
+ fpu_enable();
fpusave_fxsave(fpu_initialstate);
if (fpu_initialstate->sv_env.en_mxcsr_mask)
@@ -473,7 +470,7 @@
}
}
- start_emulating();
+ fpu_disable();
intr_restore(saveintr);
}
/* EFIRT needs this to be initialized before we can enter our EFI environment */
@@ -488,9 +485,9 @@
critical_enter();
if (curthread == PCPU_GET(fpcurthread)) {
- stop_emulating();
+ fpu_enable();
fpusave(curpcb->pcb_save);
- start_emulating();
+ fpu_disable();
PCPU_SET(fpcurthread, NULL);
}
critical_exit();
@@ -741,7 +738,7 @@
*/
PCPU_SET(fpcurthread, td);
- stop_emulating();
+ fpu_enable();
fpu_clean_state();
pcb = td->td_pcb;
@@ -803,7 +800,7 @@
* regardless of the eager/lazy FPU context switch
* mode.
*/
- stop_emulating();
+ fpu_enable();
} else {
if (__predict_false(PCPU_GET(fpcurthread) != NULL)) {
panic(
@@ -823,7 +820,7 @@
if ((td->td_pflags & TDP_KTHREAD) != 0 || !PCB_USER_FPU(td->td_pcb)) {
PCPU_SET(fpcurthread, NULL);
- start_emulating();
+ fpu_disable();
} else if (PCPU_GET(fpcurthread) != td) {
restore_fpu_curthread(td);
}
@@ -839,7 +836,7 @@
CRITICAL_ASSERT(td);
PCPU_SET(fpcurthread, NULL);
clear_pcb_flags(td->td_pcb, PCB_FPUINITDONE);
- start_emulating();
+ fpu_disable();
}
/*
@@ -1139,7 +1136,7 @@
if ((flags & FPU_KERN_NOCTX) != 0) {
critical_enter();
- stop_emulating();
+ fpu_enable();
if (curthread == PCPU_GET(fpcurthread)) {
fpusave(curpcb->pcb_save);
PCPU_SET(fpcurthread, NULL);
@@ -1190,7 +1187,7 @@
CRITICAL_ASSERT(td);
clear_pcb_flags(pcb, PCB_FPUNOSAVE | PCB_FPUINITDONE);
- start_emulating();
+ fpu_disable();
} else {
KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) != 0,
("leaving not inuse ctx"));
diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -256,9 +256,6 @@
DEFINE_VMMOPS_IFUNC(int, restore_tsc, (void *vcpui, uint64_t now))
#endif
-#define fpu_start_emulating() load_cr0(rcr0() | CR0_TS)
-#define fpu_stop_emulating() clts()
-
SDT_PROVIDER_DEFINE(vmm);
static MALLOC_DEFINE(M_VM, "vm", "vm");
@@ -1291,7 +1288,7 @@
fpuexit(curthread);
/* restore guest FPU state */
- fpu_stop_emulating();
+ fpu_enable();
fpurestore(vcpu->guestfpu);
/* restore guest XCR0 if XSAVE is enabled in the host */
@@ -1299,10 +1296,10 @@
load_xcr(0, vcpu->guest_xcr0);
/*
- * The FPU is now "dirty" with the guest's state so turn on emulation
- * to trap any access to the FPU by the host.
+ * The FPU is now "dirty" with the guest's state so disable
+ * the FPU to trap any access by the host.
*/
- fpu_start_emulating();
+ fpu_disable();
}
static void
@@ -1319,9 +1316,9 @@
}
/* save guest FPU state */
- fpu_stop_emulating();
+ fpu_enable();
fpusave(vcpu->guestfpu);
- fpu_start_emulating();
+ fpu_disable();
}
static VMM_STAT(VCPU_IDLE_TICKS, "number of ticks vcpu was idle");
diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c
--- a/sys/i386/i386/npx.c
+++ b/sys/i386/i386/npx.c
@@ -123,9 +123,6 @@
"memory");
}
-#define start_emulating() load_cr0(rcr0() | CR0_TS)
-#define stop_emulating() clts()
-
#define GET_FPU_CW(thread) \
(cpu_fxsr ? \
(thread)->td_pcb->pcb_save->sv_xmm.sv_env.en_cw : \
@@ -224,7 +221,7 @@
/*
* Don't trap while we're probing.
*/
- stop_emulating();
+ fpu_enable();
/*
* Finish resetting the coprocessor, if any. If there is an error
@@ -413,7 +410,7 @@
* It is too early for critical_enter() to work on AP.
*/
saveintr = intr_disable();
- stop_emulating();
+ fpu_enable();
if (cpu_fxsr)
fninit();
else
@@ -424,7 +421,7 @@
mxcsr = __INITIAL_MXCSR__;
ldmxcsr(mxcsr);
}
- start_emulating();
+ fpu_disable();
intr_restore(saveintr);
}
@@ -458,7 +455,7 @@
}
saveintr = intr_disable();
- stop_emulating();
+ fpu_enable();
if (cpu_fxsr)
fpusave_fxsave(npx_initialstate);
@@ -515,7 +512,7 @@
}
}
- start_emulating();
+ fpu_disable();
intr_restore(saveintr);
}
SYSINIT(npxinitstate, SI_SUB_CPU, SI_ORDER_ANY, npxinitstate, NULL);
@@ -529,9 +526,9 @@
critical_enter();
if (curthread == PCPU_GET(fpcurthread)) {
- stop_emulating();
+ fpu_enable();
fpusave(curpcb->pcb_save);
- start_emulating();
+ fpu_disable();
PCPU_SET(fpcurthread, NULL);
}
critical_exit();
@@ -810,7 +807,7 @@
*/
PCPU_SET(fpcurthread, td);
- stop_emulating();
+ fpu_enable();
if (cpu_fxsr)
fpu_clean_state();
@@ -863,7 +860,7 @@
* regardless of the eager/lazy FPU context switch
* mode.
*/
- stop_emulating();
+ fpu_enable();
} else {
if (__predict_false(PCPU_GET(fpcurthread) != NULL)) {
printf(
@@ -891,7 +888,7 @@
npxsave(union savefpu *addr)
{
- stop_emulating();
+ fpu_enable();
fpusave(addr);
}
@@ -902,7 +899,7 @@
if (lazy_fpu_switch || (td->td_pflags & TDP_KTHREAD) != 0 ||
!PCB_USER_FPU(pcb)) {
- start_emulating();
+ fpu_disable();
PCPU_SET(fpcurthread, NULL);
} else if (PCPU_GET(fpcurthread) != td) {
restore_npx_curthread(td, pcb);
@@ -925,7 +922,7 @@
return;
}
cr0 = rcr0();
- stop_emulating();
+ fpu_enable();
fpusave(addr);
load_cr0(cr0);
}
@@ -940,7 +937,7 @@
cr0 = rcr0();
npxinit(false);
- stop_emulating();
+ fpu_enable();
fpurstor(addr);
load_cr0(cr0);
}
@@ -962,7 +959,7 @@
CRITICAL_ASSERT(td);
PCPU_SET(fpcurthread, NULL);
td->td_pcb->pcb_flags &= ~PCB_NPXINITDONE;
- start_emulating();
+ fpu_disable();
}
/*
@@ -1397,7 +1394,7 @@
if ((flags & FPU_KERN_NOCTX) != 0) {
critical_enter();
- stop_emulating();
+ fpu_enable();
if (curthread == PCPU_GET(fpcurthread)) {
fpusave(curpcb->pcb_save);
PCPU_SET(fpcurthread, NULL);
@@ -1448,7 +1445,7 @@
CRITICAL_ASSERT(td);
pcb->pcb_flags &= ~(PCB_NPXNOSAVE | PCB_NPXINITDONE);
- start_emulating();
+ fpu_disable();
} else {
KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) != 0,
("leaving not inuse ctx"));
diff --git a/sys/x86/include/fpu.h b/sys/x86/include/fpu.h
--- a/sys/x86/include/fpu.h
+++ b/sys/x86/include/fpu.h
@@ -213,4 +213,13 @@
*/
#define X86_XSTATE_XCR0_OFFSET 464
+#ifdef _KERNEL
+/*
+ * CR0_MP and CR0_EM are always set. Use CR0_TS to force traps when
+ * FPU access is disabled.
+ */
+#define fpu_enable() clts()
+#define fpu_disable() load_cr0(rcr0() | CR0_TS)
+#endif
+
#endif /* !_X86_FPU_H_ */

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 28, 12:20 AM (13 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17823533
Default Alt Text
D42135.diff (7 KB)

Event Timeline