All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: X86: Fix loss of pending INIT due to race
@ 2017-08-01 23:05 Wanpeng Li
  2017-08-02  7:44 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Wanpeng Li @ 2017-08-01 23:05 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: Paolo Bonzini, Radim Krčmář, Wanpeng Li

From: Wanpeng Li <wanpeng.li@hotmail.com>

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
                                      if (events->smi.latched_init == 0)
                                        clear INIT in pending_events

This patch fixes it by just update SMM related flags if we are in SMM.

Thanks Peng Hao for the report and original commit message.

Reported-by: Peng Hao <peng.hao2@zte.com.cn>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
v1 -> v2:
 * move the stuff under if (events->smi_smm)

 arch/x86/kvm/x86.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1a4c84d..839b5dad6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3160,15 +3160,18 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
 		kvm_set_hflags(vcpu, hflags);
 
 		vcpu->arch.smi_pending = events->smi.pending;
-		if (events->smi.smm_inside_nmi)
-			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);
+
+		if (events->smi.smm) {
+			if (events->smi.smm_inside_nmi)
+				vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
 			else
-				clear_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
+				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);
+			}
 		}
 	}
 
-- 
2.7.4

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

* Re: [PATCH v2] KVM: X86: Fix loss of pending INIT due to race
  2017-08-01 23:05 [PATCH v2] KVM: X86: Fix loss of pending INIT due to race Wanpeng Li
@ 2017-08-02  7:44 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2017-08-02  7:44 UTC (permalink / raw)
  To: Wanpeng Li, linux-kernel, kvm; +Cc: Radim Krčmář, Wanpeng Li

On 02/08/2017 01:05, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
> 
> 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
>                                       if (events->smi.latched_init == 0)
>                                         clear INIT in pending_events
> 
> This patch fixes it by just update SMM related flags if we are in SMM.
> 
> Thanks Peng Hao for the report and original commit message.
> 
> Reported-by: Peng Hao <peng.hao2@zte.com.cn>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> v1 -> v2:
>  * move the stuff under if (events->smi_smm)
> 
>  arch/x86/kvm/x86.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 1a4c84d..839b5dad6 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3160,15 +3160,18 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
>  		kvm_set_hflags(vcpu, hflags);
>  
>  		vcpu->arch.smi_pending = events->smi.pending;
> -		if (events->smi.smm_inside_nmi)
> -			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);
> +
> +		if (events->smi.smm) {
> +			if (events->smi.smm_inside_nmi)
> +				vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
>  			else
> -				clear_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
> +				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);
> +			}
>  		}
>  	}
>  
> 


Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

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

end of thread, other threads:[~2017-08-02  7:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-01 23:05 [PATCH v2] KVM: X86: Fix loss of pending INIT due to race Wanpeng Li
2017-08-02  7:44 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.