From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: [PATCH] KVM: VMX: Fix clts Date: Sun, 24 Jan 2010 12:17:23 +0200 Message-ID: <1264328243-21604-1-git-send-email-avi@redhat.com> Cc: kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:10653 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752837Ab0AXKRZ (ORCPT ); Sun, 24 Jan 2010 05:17:25 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0OAHOjo022733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 24 Jan 2010 05:17:25 -0500 Sender: kvm-owner@vger.kernel.org List-ID: 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. Signed-off-by: Avi Kivity --- arch/x86/kvm/vmx.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 9f56110..d27ff6a 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -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; -- 1.6.5.3