KVM: x86: fix maintenance of guest/host xcr0 state
authorMarcelo Tosatti <mtosatti@redhat.com>
Tue, 16 Apr 2013 02:30:13 +0000 (23:30 -0300)
committerGleb Natapov <gleb@redhat.com>
Wed, 8 May 2013 09:47:43 +0000 (12:47 +0300)
commit42bdf991f4cad9678ee2b98c5c2e9299a3f986ef
treeb0b91769efbecf318e968477cb1b7cc68d0defbd
parent5af43c24ca59a448c9312dd4a4a51d27ec3b9a73
KVM: x86: fix maintenance of guest/host xcr0 state

Emulation of xcr0 writes zero guest_xcr0_loaded variable so that
subsequent VM-entry reloads CPU's xcr0 with guests xcr0 value.

However, this is incorrect because guest_xcr0_loaded variable is
read to decide whether to reload hosts xcr0.

In case the vcpu thread is scheduled out after the guest_xcr0_loaded = 0
assignment, and scheduler decides to preload FPU:

switch_to
{
  __switch_to
    __math_state_restore
      restore_fpu_checking
        fpu_restore_checking
          if (use_xsave())
              fpu_xrstor_checking
xrstor64 with CPU's xcr0 == guests xcr0

Fix by properly restoring hosts xcr0 during emulation of xcr0 writes.

Analyzed-by: Ulrich Obergfell <uobergfe@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
arch/x86/kvm/x86.c