All of lore.kernel.org
 help / color / mirror / Atom feed
* Restoring FPU exception state
@ 2016-02-17 13:08 David Vrabel
  2016-02-17 13:45 ` Jan Beulich
  0 siblings, 1 reply; 11+ messages in thread
From: David Vrabel @ 2016-02-17 13:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Kevin Tian, Paul Durrant, Feng Wu, Jan Beulich

The FPU exception state includes 4 registers:

- 64-bit FIP
- 16-bit FCS
- 64-bit FDP
- 16-bit FDS

When a CPU takes an FPU exception in long mode, all 4 registers are
fully updated.  This state can be saved with a combination of REX.W
prefixed XSAVE and FNSTENV.  This state cannot be restored with any
combination of instructions as those that restore the 64-bit FIP/FDP
clear FCS and FDS; and those that restore FCS and FDS clear the upper
32-bits of FIP and FDP [1].

This causes problems when running Microsoft's Driver Verifier in a
64-bit Windows guest (seen with Windows 7 SP1, but other versions may
also be affected).

The Driver Verifier prior to calling a driver's interrupt handler will
save the FPU state, after the handler is called it will save the state
again and do a byte-by-byte compare to verify the state has not changed.
 A 0x3D (INTERRUPT_EXCEPTION_NOT_HANDLED) BugCheck is raised if the
state does not match.

Windows uses XSAVE to save the FPU state, but it does not use a REX.W
prefixed XSAVE, and saves only the lower 32-bits of FIP/FDP and FCS/FDS.

If the VCPU is descheduled between these two checks, the contents of
FCS/FDS is lost, Windows will notice and BugCheck.

When saving a VCPUs FPU state, Xen first uses a REX.W prefixed XSAVE and
notices that FIP/FDP[64:32] is non-zero and assumes are REX.W prefixed
XRSTOR is required to restore the full 64-bits of FIP/FDP.  This clears
FCS/FDS.

On processors with FPCSDS[2] (bit 13) set in CPUID leaf 0x7, sub-leaf
0x0, do not save FCS/FDS (they always write zeros) and this problem does
not occur, because FCS/FDS never needs to be restored.

Does anyone any thoughts of a solution for processors without the FPCSDS
feature?

David

[1] Intel SDM vol 1. section 8.1.8.
[2] http://www.sandpile.org/x86/cpuid.htm#level_0000_0007h

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-02-24 10:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-17 13:08 Restoring FPU exception state David Vrabel
2016-02-17 13:45 ` Jan Beulich
2016-02-18  6:30   ` Tian, Kevin
2016-02-18  8:16     ` Jan Beulich
2016-02-18  8:41       ` Paul Durrant
2016-02-18  8:49         ` Jan Beulich
2016-02-18  8:54           ` Paul Durrant
2016-02-18  9:24             ` Jan Beulich
2016-02-18  9:30               ` Paul Durrant
2016-02-24 10:33   ` Tian, Kevin
2016-02-24 10:42     ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.