* [PATCH] KVM: VMX: Pass cr0.mp through to the guest when the fpu is active
@ 2010-01-24 14:26 Avi Kivity
2010-01-24 14:31 ` Avi Kivity
2010-01-25 13:32 ` Marcelo Tosatti
0 siblings, 2 replies; 3+ messages in thread
From: Avi Kivity @ 2010-01-24 14:26 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm
When cr0.mp is clear, the guest doesn't expect a #NM in response to
a WAIT instruction. Because we always keep cr0.mp set, it will get
a #NM, and potentially be confused.
Fix by keeping cr0.mp set only when the fpu is inactive, and passing
it through when inactive.
Reported-by: Lorenzo Martignoni <martignlo@gmail.com>
Analyzed-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
arch/x86/kvm/vmx.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index d27ff6a..9befb53 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -66,7 +66,7 @@ module_param(emulate_invalid_guest_state, bool, S_IRUGO);
#define KVM_GUEST_CR0_MASK \
(KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE)
#define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST \
- (X86_CR0_WP | X86_CR0_NE | X86_CR0_MP)
+ (X86_CR0_WP | X86_CR0_NE)
#define KVM_VM_CR0_ALWAYS_ON \
(KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE)
#define KVM_CR4_GUEST_OWNED_BITS \
@@ -796,12 +796,15 @@ static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
static void vmx_fpu_activate(struct kvm_vcpu *vcpu)
{
+ ulong cr0;
+
if (vcpu->fpu_active)
return;
vcpu->fpu_active = 1;
- vmcs_clear_bits(GUEST_CR0, X86_CR0_TS);
- if (kvm_read_cr0_bits(vcpu, X86_CR0_TS))
- vmcs_set_bits(GUEST_CR0, X86_CR0_TS);
+ cr0 = vmcs_readl(GUEST_CR0);
+ cr0 &= ~(X86_CR0_TS | X86_CR0_MP);
+ cr0 |= kvm_read_cr0_bits(vcpu, X86_CR0_TS | X86_CR0_MP);
+ vmcs_writel(GUEST_CR0, cr0);
update_exception_bitmap(vcpu);
vcpu->arch.cr0_guest_owned_bits = X86_CR0_TS;
vmcs_writel(CR0_GUEST_HOST_MASK, ~vcpu->arch.cr0_guest_owned_bits);
@@ -812,7 +815,7 @@ static void vmx_fpu_deactivate(struct kvm_vcpu *vcpu)
ulong old_ts, old_cr0;
old_ts = kvm_read_cr0_bits(vcpu, X86_CR0_TS);
- vmcs_set_bits(GUEST_CR0, X86_CR0_TS);
+ vmcs_set_bits(GUEST_CR0, X86_CR0_TS | X86_CR0_MP);
update_exception_bitmap(vcpu);
vcpu->arch.cr0_guest_owned_bits = 0;
vmcs_writel(CR0_GUEST_HOST_MASK, ~vcpu->arch.cr0_guest_owned_bits);
@@ -1765,7 +1768,7 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
ept_update_paging_mode_cr0(&hw_cr0, cr0, vcpu);
if (!vcpu->fpu_active)
- hw_cr0 |= X86_CR0_TS;
+ hw_cr0 |= X86_CR0_TS | X86_CR0_MP;
vmcs_writel(CR0_READ_SHADOW, cr0);
vmcs_writel(GUEST_CR0, hw_cr0);
--
1.6.5.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: VMX: Pass cr0.mp through to the guest when the fpu is active
2010-01-24 14:26 [PATCH] KVM: VMX: Pass cr0.mp through to the guest when the fpu is active Avi Kivity
@ 2010-01-24 14:31 ` Avi Kivity
2010-01-25 13:32 ` Marcelo Tosatti
1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2010-01-24 14:31 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm
On 01/24/2010 04:26 PM, Avi Kivity wrote:
> When cr0.mp is clear, the guest doesn't expect a #NM in response to
> a WAIT instruction. Because we always keep cr0.mp set, it will get
> a #NM, and potentially be confused.
>
> Fix by keeping cr0.mp set only when the fpu is inactive, and passing
> it through when inactive.
>
Note: since all reasonable guests set cr0.mp, and those that don't
shouldn't issue fwait, there's no need to queue this for .33 or stable.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: VMX: Pass cr0.mp through to the guest when the fpu is active
2010-01-24 14:26 [PATCH] KVM: VMX: Pass cr0.mp through to the guest when the fpu is active Avi Kivity
2010-01-24 14:31 ` Avi Kivity
@ 2010-01-25 13:32 ` Marcelo Tosatti
1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2010-01-25 13:32 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm
On Sun, Jan 24, 2010 at 04:26:40PM +0200, Avi Kivity wrote:
> When cr0.mp is clear, the guest doesn't expect a #NM in response to
> a WAIT instruction. Because we always keep cr0.mp set, it will get
> a #NM, and potentially be confused.
>
> Fix by keeping cr0.mp set only when the fpu is inactive, and passing
> it through when inactive.
>
> Reported-by: Lorenzo Martignoni <martignlo@gmail.com>
> Analyzed-by: Gleb Natapov <gleb@redhat.com>
> Signed-off-by: Avi Kivity <avi@redhat.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-25 13:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-24 14:26 [PATCH] KVM: VMX: Pass cr0.mp through to the guest when the fpu is active Avi Kivity
2010-01-24 14:31 ` Avi Kivity
2010-01-25 13:32 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox