KVM: VMX: Fix clts
PATCH 1/1 KVM: VMX: Fix clts
The simplistic clts implementation has a couple of flaws:
- kvm_read_cr0_bits() is temporarily unsynchronized when vcpu->arch.cr0 changes
- if the fpu is active, we need to clear GUEST_CR0.TS, not just CR_READ_SHADOW.TS, so that we don't send the guest an unexpected #NM.
Fix by replacing custom logic with a call to vmx_set_cr0(), which does the right thing, albeit less efficiently.
--- arch/x86/kvm/vmx.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx.c +1 -2
@@ -3007,8 +3007,7 @@ static int handle_cr(struct kvm_vcpu *vcpu) };break ;case 2 :/* clts */ - vcpu->arch.cr0 &= ~X86_CR0_TS ; -vmcs_writel (CR0_READ_SHADOW ,kvm_read_cr0 (vcpu)); +vmx_set_cr0 (vcpu,kvm_read_cr0_bits (vcpu, ~X86_CR0_TS ));trace_kvm_cr_write (0 ,kvm_read_cr0 (vcpu));skip_emulated_instruction (vcpu);return 1 ;
Signature · 1 line
1.6.5.3
Marcelo Tosatti
AppliedQuoted 9 lines · Avi Kivity
The simplistic clts implementation has a couple of flaws:
-kvm_read_cr0_bits()is temporarily unsynchronized whenvcpu->arch.cr0changes
- if the fpu is active, we need to clear GUEST_CR0.TS, not just CR_READ_SHADOW.TS, so that we don't send the guest an unexpected #NM.Fix by replacing custom logic with a call to
vmx_set_cr0(), which does the right thing, albeit less efficiently.Signed-off-by Avi Kivity <[email protected]>
Applied, thanks.