[PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-26 Thread Jes . Sorensen
From: Jes Sorensen Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, which can cause an EXIT with invalid state, resulting in the guest dieing. Credit to Gleb for figuring out why it was failing and how to fix it. Signed-off-by: Jes Sorensen Signed-off-by: Gleb Natapov --- arch/x8

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: > From: Jes Sorensen > > Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, > which can cause an EXIT with invalid state, resulting in the > guest dieing. Very interesting. Reality obviously doesn't bother about the statement of the v

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jes Sorensen
On 08/27/10 10:27, Jan Kiszka wrote: > Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: >> From: Jes Sorensen >> >> Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, >> which can cause an EXIT with invalid state, resulting in the >> guest dieing. > > Very interesting. Reality obviou

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Jes Sorensen wrote: > On 08/27/10 10:27, Jan Kiszka wrote: >> Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: >>> From: Jes Sorensen >>> >>> Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, >>> which can cause an EXIT with invalid state, resulting in the >>> guest dieing. >> Very i

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/26/2010 11:06 PM, jes.soren...@redhat.com wrote: From: Jes Sorensen Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, which can cause an EXIT with invalid state, resulting in the guest dieing. Credit to Gleb for figuring out why it was failing and how to fix it. Signed-off-by

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jes Sorensen
On 08/27/10 11:21, Avi Kivity wrote: >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index cf56462..8e95371 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -2888,6 +2888,8 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu) >> kvm_rip_write(vcpu, vmx->rmod

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 11:27 AM, Jan Kiszka wrote: Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: From: Jes Sorensen Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, which can cause an EXIT with invalid state, resulting in the guest dieing. Very interesting. Reality obviously doesn't

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 11:39 AM, Jan Kiszka wrote: AMD does not differentiate between MOV-SS and STI interrupt shadows. But AMD has its own NMI problems as it does not allow to trap after IRET-from-NMI and requires magic dances which are partly broken in KVM. I'm leaning towards NMI window emulation vi

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 12:41 PM, Jes Sorensen wrote: On 08/27/10 11:21, Avi Kivity wrote: diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index cf56462..8e95371 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2888,6 +2888,8 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jes Sorensen
On 08/27/10 11:47, Avi Kivity wrote: > On 08/27/2010 12:41 PM, Jes Sorensen wrote: >> Ok, try v2 that I just posted - and forgot to add v2 in the Subject line >> to - sorry. >> > > Well, in light of Jan's comment re sti; hlt being clobbered by this, we > should think about requesting an interrupt

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 12:56 PM, Jes Sorensen wrote: Well, in light of Jan's comment re sti; hlt being clobbered by this, we should think about requesting an interrupt window instead... Ok, I heading onto thin ice here :) How does one do that, just a call to kvm_x86_ops->enable_nmi_window(vcpu)

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jes Sorensen
On 08/27/10 11:59, Avi Kivity wrote: > On 08/27/2010 12:56 PM, Jes Sorensen wrote: >> >>> Well, in light of Jan's comment re sti; hlt being clobbered by this, we >>> should think about requesting an interrupt window instead... >>> >> Ok, I heading onto thin ice here :) >> >> How does one do that,

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Gleb Natapov
On Fri, Aug 27, 2010 at 10:27:37AM +0200, Jan Kiszka wrote: > Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: > > From: Jes Sorensen > > > > Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, > > which can cause an EXIT with invalid state, resulting in the > > guest dieing. > > Ver

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Avi Kivity wrote: > On 08/27/2010 11:27 AM, Jan Kiszka wrote: >> Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: >>> From: Jes Sorensen >>> >>> Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, >>> which can cause an EXIT with invalid state, resulting in the >>> guest dieing. >> Ve

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Avi Kivity wrote: > On 08/27/2010 11:39 AM, Jan Kiszka wrote: >> AMD does not differentiate between MOV-SS and STI interrupt shadows. >> >> But AMD has its own NMI problems as it does not allow to trap after >> IRET-from-NMI and requires magic dances which are partly broken in KVM. >> I'm leaning

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Gleb Natapov wrote: > On Fri, Aug 27, 2010 at 10:27:37AM +0200, Jan Kiszka wrote: >> Am 26.08.2010 22:06, jes.soren...@redhat.com wrote: >>> From: Jes Sorensen >>> >>> Injecting an NMI while GUEST_INTR_STATE_STI is set may fail, >>> which can cause an EXIT with invalid state, resulting in the >>>

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Gleb Natapov
On Fri, Aug 27, 2010 at 12:44:41PM +0300, Avi Kivity wrote: > >Thinking about the implications: Independent of virtualization, this > >means that no code code can in any way rely on the STI shadow if there > >are NMIs present that could "consume" it. Because after return from > >those NMIs, interru

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Gleb Natapov wrote: > On Fri, Aug 27, 2010 at 12:44:41PM +0300, Avi Kivity wrote: >>> Thinking about the implications: Independent of virtualization, this >>> means that no code code can in any way rely on the STI shadow if there >>> are NMIs present that could "consume" it. Because after return fr

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Gleb Natapov
On Fri, Aug 27, 2010 at 01:23:06PM +0200, Jan Kiszka wrote: > Gleb Natapov wrote: > > On Fri, Aug 27, 2010 at 12:44:41PM +0300, Avi Kivity wrote: > >>> Thinking about the implications: Independent of virtualization, this > >>> means that no code code can in any way rely on the STI shadow if there >

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 02:06 PM, Jan Kiszka wrote: Wow. Maybe we should request an interrupt window instead when blocked-by-STI is active instead of clearing it. Then we are (almost) back in pre-NMI-window times when the guest happens to spin with IRQs disabled. No. We only request an interrupt w

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 02:06 PM, Jan Kiszka wrote: Avi Kivity wrote: On 08/27/2010 11:39 AM, Jan Kiszka wrote: AMD does not differentiate between MOV-SS and STI interrupt shadows. But AMD has its own NMI problems as it does not allow to trap after IRET-from-NMI and requires magic dances which are p

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Avi Kivity wrote: > On 08/27/2010 02:06 PM, Jan Kiszka wrote: >>> Wow. Maybe we should request an interrupt window instead when >>> blocked-by-STI is active instead of clearing it. >>> >> Then we are (almost) back in pre-NMI-window times when the guest happens >> to spin with IRQs disabled. > >

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Avi Kivity wrote: > On 08/27/2010 02:06 PM, Jan Kiszka wrote: >> Avi Kivity wrote: >>>On 08/27/2010 11:39 AM, Jan Kiszka wrote: AMD does not differentiate between MOV-SS and STI interrupt shadows. But AMD has its own NMI problems as it does not allow to trap after IRET-fro

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Avi Kivity
On 08/27/2010 05:13 PM, Jan Kiszka wrote: I forgot them already. What was that, exception during IRET? Exception during IRET or any instruction under the interrupt shadow will push the TF we set to step over this issue on the guest stack. We do not intercept all the possible exceptions, so w

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-27 Thread Jan Kiszka
Avi Kivity wrote: > On 08/27/2010 05:13 PM, Jan Kiszka wrote: >>> I forgot them already. What was that, exception during IRET? >> Exception during IRET or any instruction under the interrupt shadow will >> push the TF we set to step over this issue on the guest stack. We do not >> intercept all

Re: [PATCH 1/1] Disable GUEST_INTR_STATE_STI flag before injecting NMI to guest on VMX

2010-08-29 Thread Avi Kivity
On 08/27/2010 07:43 PM, Jan Kiszka wrote: Avi Kivity wrote: On 08/27/2010 05:13 PM, Jan Kiszka wrote: I forgot them already. What was that, exception during IRET? Exception during IRET or any instruction under the interrupt shadow will push the TF we set to step over this issue on the gue