kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] kvm: x86: fix a race condition result to lost INIT
  2017-07-30 16:24 [PATCH] kvm: x86: fix a race condition result to lost INIT Peng Hao
@ 2017-07-30  9:44 ` Wanpeng Li
  0 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2017-07-30  9:44 UTC (permalink / raw)
  To: Peng Hao
  Cc: Paolo Bonzini, Radim Krcmar, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, the arch/x86 maintainers, kvm, linux-kernel

2017-07-31 0:24 GMT+08:00 Peng Hao <peng.hao2@zte.com.cn>:
> when SMP VM start, AP may lost INIT because of receiving INIT between
> kvm_vcpu_ioctl_x86_get/set_vcpu_events.
>
>    vcpu 0                             vcpu 1
>                                kvm_vcpu_ioctl_x86_get_vcpu_events
>                                        events->smi.latched_init=0
>  send INIT to vcpu1
>    set vcpu1's pending_events
>                                kvm_vcpu_ioctl_x86_set_vcpu_events
>                                     events->smi.latched_init == 0
>                                       clear INIT in pending_events
> I don't think it need set/clear kernel state according to userspace's
> info.
>
> Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
> ---
>  arch/x86/kvm/x86.c | 6 ------
>  1 file changed, 6 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 6c7266f..393a7b7 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3157,12 +3157,6 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>                         vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
>                 else
>                         vcpu->arch.hflags &= ~HF_SMM_INSIDE_NMI_MASK;
> -               if (lapic_in_kernel(vcpu)) {
> -                       if (events->smi.latched_init)
> -                               set_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);

This is not correct, you will lose the INIT after live migration. I
just send out another patch to fix it. Thanks for the report.

Regards,
Wanpeng Li

> -                       else
> -                               clear_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
> -               }
>         }
>
>         kvm_make_request(KVM_REQ_EVENT, vcpu);
> --
> 1.8.3.1
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH]  kvm: x86: fix a race condition result to lost INIT
@ 2017-07-30 16:24 Peng Hao
  2017-07-30  9:44 ` Wanpeng Li
  0 siblings, 1 reply; 5+ messages in thread
From: Peng Hao @ 2017-07-30 16:24 UTC (permalink / raw)
  To: pbonzini, rkrcmar, tglx, mingo, hpa; +Cc: x86, kvm, linux-kernel, Peng Hao

when SMP VM start, AP may lost INIT because of receiving INIT between
kvm_vcpu_ioctl_x86_get/set_vcpu_events.

   vcpu 0                             vcpu 1
                               kvm_vcpu_ioctl_x86_get_vcpu_events
                                       events->smi.latched_init=0
 send INIT to vcpu1
   set vcpu1's pending_events
                               kvm_vcpu_ioctl_x86_set_vcpu_events
                                    events->smi.latched_init == 0
                                      clear INIT in pending_events
I don't think it need set/clear kernel state according to userspace's
info.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
 arch/x86/kvm/x86.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6c7266f..393a7b7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3157,12 +3157,6 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
 			vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
 		else
 			vcpu->arch.hflags &= ~HF_SMM_INSIDE_NMI_MASK;
-		if (lapic_in_kernel(vcpu)) {
-			if (events->smi.latched_init)
-				set_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
-			else
-				clear_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
-		}
 	}
 
 	kvm_make_request(KVM_REQ_EVENT, vcpu);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm: x86: fix a race condition result to lost INIT
       [not found] <201707301933188534718@zte.com.cn>
  2017-07-30 11:53 ` Wanpeng Li
@ 2017-07-30 22:25 ` Wanpeng Li
  1 sibling, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2017-07-30 22:25 UTC (permalink / raw)
  To: Peng Hao
  Cc: Paolo Bonzini, Radim Krcmar, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, the arch/x86 maintainers, kvm, linux-kernel

2017-07-30 19:33 GMT+08:00  <peng.hao2@zte.com.cn>:
>
>
>
>
>>2017-07-30 18:42 GMT+08:00  <peng.hao2@zte.com.cn>:
>
>>>> 2017-07-31 0:24 GMT+08:00 Peng Hao <peng.hao2@zte.com.cn>:
>>>
>>>> > when SMP VM start, AP may lost INIT because of receiving INIT between
>>>> > kvm_vcpu_ioctl_x86_get/set_vcpu_events.
>>>> >
>>>> >    vcpu 0                             vcpu 1
>>>> >                                kvm_vcpu_ioctl_x86_get_vcpu_events
>>>> >                                        events->smi.latched_init=0
>>>> >  send INIT to vcpu1
>>>> >    set vcpu1's pending_events
>>>> >                                kvm_vcpu_ioctl_x86_set_vcpu_events
>>>> >                                     events->smi.latched_init == 0
>>>> >                                       clear INIT in pending_events
>>>> > I don't think it need set/clear kernel state according to userspace's
>>>> > info.
>>>> >
>>>> > Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
>>>> > ---
>>>> >  arch/x86/kvm/x86.c | 6 ------
>>>> >  1 file changed, 6 deletions(-)
>>>> >
>>>> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>>> > index 6c7266f..393a7b7 100644
>>>> > --- a/arch/x86/kvm/x86.c
>>>> > +++ b/arch/x86/kvm/x86.c
>>>> > @@ -3157,12 +3157,6 @@ static int
>>>> > kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>>>> >                         vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
>>>> >                 else
>>>> >                         vcpu->arch.hflags &= ~HF_SMM_INSIDE_NMI_MASK;
>>>> > -               if (lapic_in_kernel(vcpu)) {
>>>> > -                       if (events->smi.latched_init)
>>>> > -                               set_bit(KVM_APIC_INIT,
>>>> > &vcpu->arch.apic->pending_events);
>>>
>>>> This is not correct, you will lose the INIT after live migration. I
>>>> just send out another patch to fix it. Thanks for the report.
>>>
>>> yes, you're right. I should modify on qemu not kernel.
>
>>There is a patch here to fix it in kvm, https://lkml.org/lkml/2017/7/30/72
>
>>>
>
> I was affected by sipi, kernel never report  valid sipi to user space,
>
> we don't care whether sipi is lost  after migration. Why?

Please refer to Paolo's suggestion,
https://www.mail-archive.com/qemu-devel@nongnu.org/msg464882.html

Regards,
Wanpeng Li

>
>>>> > -                       else
>>>> > -                               clear_bit(KVM_APIC_INIT,
>>>> > &vcpu->arch.apic->pending_events);
>>>> > -               }
>>>> >         }
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm: x86: fix a race condition result to lost INIT
       [not found] <201707301933188534718@zte.com.cn>
@ 2017-07-30 11:53 ` Wanpeng Li
  2017-07-30 22:25 ` Wanpeng Li
  1 sibling, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2017-07-30 11:53 UTC (permalink / raw)
  To: Peng Hao
  Cc: Paolo Bonzini, Radim Krcmar, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, the arch/x86 maintainers, kvm, linux-kernel

2017-07-30 19:33 GMT+08:00  <peng.hao2@zte.com.cn>:
>
>
>
>
>>2017-07-30 18:42 GMT+08:00  <peng.hao2@zte.com.cn>:
>
>>>> 2017-07-31 0:24 GMT+08:00 Peng Hao <peng.hao2@zte.com.cn>:
>>>
>>>> > when SMP VM start, AP may lost INIT because of receiving INIT between
>>>> > kvm_vcpu_ioctl_x86_get/set_vcpu_events.
>>>> >
>>>> >    vcpu 0                             vcpu 1
>>>> >                                kvm_vcpu_ioctl_x86_get_vcpu_events
>>>> >                                        events->smi.latched_init=0
>>>> >  send INIT to vcpu1
>>>> >    set vcpu1's pending_events
>>>> >                                kvm_vcpu_ioctl_x86_set_vcpu_events
>>>> >                                     events->smi.latched_init == 0
>>>> >                                       clear INIT in pending_events
>>>> > I don't think it need set/clear kernel state according to userspace's
>>>> > info.
>>>> >
>>>> > Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
>>>> > ---
>>>> >  arch/x86/kvm/x86.c | 6 ------
>>>> >  1 file changed, 6 deletions(-)
>>>> >
>>>> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>>> > index 6c7266f..393a7b7 100644
>>>> > --- a/arch/x86/kvm/x86.c
>>>> > +++ b/arch/x86/kvm/x86.c
>>>> > @@ -3157,12 +3157,6 @@ static int
>>>> > kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>>>> >                         vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
>>>> >                 else
>>>> >                         vcpu->arch.hflags &= ~HF_SMM_INSIDE_NMI_MASK;
>>>> > -               if (lapic_in_kernel(vcpu)) {
>>>> > -                       if (events->smi.latched_init)
>>>> > -                               set_bit(KVM_APIC_INIT,
>>>> > &vcpu->arch.apic->pending_events);
>>>
>>>> This is not correct, you will lose the INIT after live migration. I
>>>> just send out another patch to fix it. Thanks for the report.
>>>
>>> yes, you're right. I should modify on qemu not kernel.
>
>>There is a patch here to fix it in kvm, https://lkml.org/lkml/2017/7/30/72
>
>>>
>
> I was affected by sipi, kernel never report  valid sipi to user space,

How you afftected by SIPI? In addition, you reported the lost of INIT.
Is it observed by your workload or by code review?

Regards,
Wanpeng Li

>
> we don't care whether sipi is lost  after migration. Why?
>
>>>> > -                       else
>>>> > -                               clear_bit(KVM_APIC_INIT,
>>>> > &vcpu->arch.apic->pending_events);
>>>> > -               }
>>>> >         }
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm: x86: fix a race condition result to lost INIT
       [not found] <201707301842292744538@zte.com.cn>
@ 2017-07-30 11:09 ` Wanpeng Li
  0 siblings, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2017-07-30 11:09 UTC (permalink / raw)
  To: Peng Hao
  Cc: Paolo Bonzini, Radim Krcmar, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, the arch/x86 maintainers, kvm, linux-kernel

2017-07-30 18:42 GMT+08:00  <peng.hao2@zte.com.cn>:
>> 2017-07-31 0:24 GMT+08:00 Peng Hao <peng.hao2@zte.com.cn>:
>
>> > when SMP VM start, AP may lost INIT because of receiving INIT between
>> > kvm_vcpu_ioctl_x86_get/set_vcpu_events.
>> >
>> >    vcpu 0                             vcpu 1
>> >                                kvm_vcpu_ioctl_x86_get_vcpu_events
>> >                                        events->smi.latched_init=0
>> >  send INIT to vcpu1
>> >    set vcpu1's pending_events
>> >                                kvm_vcpu_ioctl_x86_set_vcpu_events
>> >                                     events->smi.latched_init == 0
>> >                                       clear INIT in pending_events
>> > I don't think it need set/clear kernel state according to userspace's
>> > info.
>> >
>> > Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
>> > ---
>> >  arch/x86/kvm/x86.c | 6 ------
>> >  1 file changed, 6 deletions(-)
>> >
>> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> > index 6c7266f..393a7b7 100644
>> > --- a/arch/x86/kvm/x86.c
>> > +++ b/arch/x86/kvm/x86.c
>> > @@ -3157,12 +3157,6 @@ static int
>> > kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>> >                         vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
>> >                 else
>> >                         vcpu->arch.hflags &= ~HF_SMM_INSIDE_NMI_MASK;
>> > -               if (lapic_in_kernel(vcpu)) {
>> > -                       if (events->smi.latched_init)
>> > -                               set_bit(KVM_APIC_INIT,
>> > &vcpu->arch.apic->pending_events);
>
>> This is not correct, you will lose the INIT after live migration. I
>> just send out another patch to fix it. Thanks for the report.
>
> yes, you're right. I should modify on qemu not kernel.

There is a patch here to fix it in kvm, https://lkml.org/lkml/2017/7/30/72

Regards,
Wanpeng Li

>
>> > -                       else
>> > -                               clear_bit(KVM_APIC_INIT,
>> > &vcpu->arch.apic->pending_events);
>> > -               }
>> >         }
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-07-30 22:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-30 16:24 [PATCH] kvm: x86: fix a race condition result to lost INIT Peng Hao
2017-07-30  9:44 ` Wanpeng Li
     [not found] <201707301933188534718@zte.com.cn>
2017-07-30 11:53 ` Wanpeng Li
2017-07-30 22:25 ` Wanpeng Li
     [not found] <201707301842292744538@zte.com.cn>
2017-07-30 11:09 ` Wanpeng Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).