Skip to contentSkip to conversation

KVM: VMX: Fix clts

PATCH Applied Avi Kivity 2 participants 2 messages Jan 24, 2010 – Jan 25, 2010

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

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
index 9f56110..d27ff6a 100644
@@ -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
#1 lore raw
Quoted 9 lines · Avi Kivity

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.

Applied, thanks.