All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Zhuangyanying <ann.zhuangyanying@huawei.com>
Cc: pbonzini@redhat.com, herongguang.he@huawei.com,
	qemu-devel@nongnu.org, arei.gonglei@huawei.com,
	oscar.zhangbo@huawei.com, kvm@vger.kernel.org
Subject: Re: [PATCH v3] KVM: x86: Fix nmi injection failure when vcpu got blocked
Date: Tue, 30 May 2017 15:36:05 +0200	[thread overview]
Message-ID: <20170530133605.GA18926@potion> (raw)
In-Reply-To: <1495775808-10396-1-git-send-email-ann.zhuangyanying@huawei.com>

2017-05-26 13:16+0800, Zhuangyanying:
> From: ZhuangYanying <ann.zhuangyanying@huawei.com>
> 
> When spin_lock_irqsave() deadlock occurs inside the guest, vcpu threads,
> other than the lock-holding one, would enter into S state because of
> pvspinlock. Then inject NMI via libvirt API "inject-nmi", the NMI could
> not be injected into vm.
> 
> The reason is:
> 1 It sets nmi_queued to 1 when calling ioctl KVM_NMI in qemu, and sets
> cpu->kvm_vcpu_dirty to true in do_inject_external_nmi() meanwhile.
> 2 It sets nmi_queued to 0 in process_nmi(), before entering guest, because
> cpu->kvm_vcpu_dirty is true.
> 
> It's not enough just to check nmi_queued to decide whether to stay in
> vcpu_block() or not. NMI should be injected immediately at any situation.
> Add checking nmi_pending, and testing KVM_REQ_NMI replaces nmi_queued
> in vm_vcpu_has_events().
> 
> Do the same change for SMIs.
> 
> Signed-off-by: Zhuang Yanying <ann.zhuangyanying@huawei.com>
> ---
> v1->v2
>   - simplify message. The complete description is here:
>     http://www.spinics.net/lists/kvm/msg150380.html
>   - Testing KVM_REQ_NMI replaces nmi_pending.
>   - Add Testing kvm_x86_ops->nmi_allowed(vcpu).
> v2->v3
>   - Testing KVM_REQ_NMI replaces nmi_queued, not nmi_pending.
>   - Do the same change for SMIs. 
> ---
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> @@ -8394,10 +8394,13 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
>  	if (vcpu->arch.pv.pv_unhalted)
>  		return true;
>  
> -	if (atomic_read(&vcpu->arch.nmi_queued))
> +	if (kvm_test_request(KVM_REQ_NMI, vcpu) ||
> +	    (vcpu->arch.nmi_pending &&

I think the logic should be

  	if ((kvm_test_request(KVM_REQ_NMI, vcpu) || vcpu->arch.nmi_pending) &&
  			kvm_x86_ops->nmi_allowed(vcpu))

because there is no reason to resume the VCPU if we cannot inject.

> +	     kvm_x86_ops->nmi_allowed(vcpu)))
>  		return true;
>  
> -	if (kvm_test_request(KVM_REQ_SMI, vcpu))
> +	if (kvm_test_request(KVM_REQ_SMI, vcpu) ||
> +	    (vcpu->arch.smi_pending && !is_smm(vcpu)))

Ditto.

>  		return true;
>  
>  	if (kvm_arch_interrupt_allowed(vcpu) &&

We'll then be consistent with other interrupts,

Thanks.

WARNING: multiple messages have this Message-ID (diff)
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Zhuangyanying <ann.zhuangyanying@huawei.com>
Cc: pbonzini@redhat.com, herongguang.he@huawei.com,
	qemu-devel@nongnu.org, arei.gonglei@huawei.com,
	oscar.zhangbo@huawei.com, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH v3] KVM: x86: Fix nmi injection failure when vcpu got blocked
Date: Tue, 30 May 2017 15:36:05 +0200	[thread overview]
Message-ID: <20170530133605.GA18926@potion> (raw)
In-Reply-To: <1495775808-10396-1-git-send-email-ann.zhuangyanying@huawei.com>

2017-05-26 13:16+0800, Zhuangyanying:
> From: ZhuangYanying <ann.zhuangyanying@huawei.com>
> 
> When spin_lock_irqsave() deadlock occurs inside the guest, vcpu threads,
> other than the lock-holding one, would enter into S state because of
> pvspinlock. Then inject NMI via libvirt API "inject-nmi", the NMI could
> not be injected into vm.
> 
> The reason is:
> 1 It sets nmi_queued to 1 when calling ioctl KVM_NMI in qemu, and sets
> cpu->kvm_vcpu_dirty to true in do_inject_external_nmi() meanwhile.
> 2 It sets nmi_queued to 0 in process_nmi(), before entering guest, because
> cpu->kvm_vcpu_dirty is true.
> 
> It's not enough just to check nmi_queued to decide whether to stay in
> vcpu_block() or not. NMI should be injected immediately at any situation.
> Add checking nmi_pending, and testing KVM_REQ_NMI replaces nmi_queued
> in vm_vcpu_has_events().
> 
> Do the same change for SMIs.
> 
> Signed-off-by: Zhuang Yanying <ann.zhuangyanying@huawei.com>
> ---
> v1->v2
>   - simplify message. The complete description is here:
>     http://www.spinics.net/lists/kvm/msg150380.html
>   - Testing KVM_REQ_NMI replaces nmi_pending.
>   - Add Testing kvm_x86_ops->nmi_allowed(vcpu).
> v2->v3
>   - Testing KVM_REQ_NMI replaces nmi_queued, not nmi_pending.
>   - Do the same change for SMIs. 
> ---
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> @@ -8394,10 +8394,13 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
>  	if (vcpu->arch.pv.pv_unhalted)
>  		return true;
>  
> -	if (atomic_read(&vcpu->arch.nmi_queued))
> +	if (kvm_test_request(KVM_REQ_NMI, vcpu) ||
> +	    (vcpu->arch.nmi_pending &&

I think the logic should be

  	if ((kvm_test_request(KVM_REQ_NMI, vcpu) || vcpu->arch.nmi_pending) &&
  			kvm_x86_ops->nmi_allowed(vcpu))

because there is no reason to resume the VCPU if we cannot inject.

> +	     kvm_x86_ops->nmi_allowed(vcpu)))
>  		return true;
>  
> -	if (kvm_test_request(KVM_REQ_SMI, vcpu))
> +	if (kvm_test_request(KVM_REQ_SMI, vcpu) ||
> +	    (vcpu->arch.smi_pending && !is_smm(vcpu)))

Ditto.

>  		return true;
>  
>  	if (kvm_arch_interrupt_allowed(vcpu) &&

We'll then be consistent with other interrupts,

Thanks.

  reply	other threads:[~2017-05-30 13:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26  5:16 [PATCH v3] KVM: x86: Fix nmi injection failure when vcpu got blocked Zhuangyanying
2017-05-26  5:16 ` [Qemu-devel] " Zhuangyanying
2017-05-30 13:36 ` Radim Krčmář [this message]
2017-05-30 13:36   ` Radim Krčmář
2017-05-30 15:15   ` Paolo Bonzini
2017-05-30 15:15     ` [Qemu-devel] " Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170530133605.GA18926@potion \
    --to=rkrcmar@redhat.com \
    --cc=ann.zhuangyanying@huawei.com \
    --cc=arei.gonglei@huawei.com \
    --cc=herongguang.he@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=oscar.zhangbo@huawei.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.