x86/fpu: improve check for XSAVE* not writing FIP/FDP fields
authorDavid Vrabel <david.vrabel@citrix.com>
Fri, 18 Mar 2016 08:49:01 +0000 (09:49 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 18 Mar 2016 08:49:01 +0000 (09:49 +0100)
commite869abd77aa32fb0a5212d34ae954e4dbcb8f7a5
treea3e07c25f7b7258facf9439a5522bf1911da7ae1
parent5e88c358d785d75e155fe8e6c8ee685a2afdcd0b
x86/fpu: improve check for XSAVE* not writing FIP/FDP fields

The hardware may not write the FIP/FDP fields with a XSAVE*
instruction.  e.g., with XSAVEOPT/XSAVES if the state hasn't changed
or on AMD CPUs when a floating point exception is not pending.  We
need to identify this case so we can correctly apply the check for
whether to save/restore FCS/FDS.

By poisoning FIP in the saved state we can check if the hardware
writes to this field.  The poison value is both: a) non-canonical; and
b) random with a vanishingly small probability of matching a value
written by the hardware (1 / (2^63) = 10^-19).

The poison value is fixed and thus knowable by a guest (or guest
userspace).  This could allow the guest to cause Xen to incorrectly
detect that the field has not been written.  But: a) this requires the
FIP register to be a full 64 bits internally which is not the case for
all current AMD and Intel CPUs; and b) this only allows the guest (or
a guest userspace process) to corrupt its own state (i.e., it cannot
affect the state of another guest or another user space process).

This results in smaller code with fewer branches and is more
understandable.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Intel confirmed that 64-bit {F,}XRSTOR sign-extend FIP from bit 47.
While leaving the description above intact, modify the code comment
accordingly.

Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/xstate.c