qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] KVM: x86: Fix nmi injection failure when vcpu got blocked
@ 2017-05-25  6:56 Zhuangyanying
  2017-05-25 14:17 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Zhuangyanying @ 2017-05-25  6:56 UTC (permalink / raw)
  To: pbonzini, rkrcmar, herongguang.he
  Cc: qemu-devel, arei.gonglei, oscar.zhangbo, kvm, 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 KVM_REQ_NMI request plus with nmi_queued in
vm_vcpu_has_events().

Signed-off-by: Zhuang Yanying <ann.zhuangyanying@huawei.com>
---
 arch/x86/kvm/x86.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 02363e3..2d15708 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8394,7 +8394,9 @@ 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) ||
+	    atomic_read(&vcpu->arch.nmi_queued)) &&
+	    kvm_x86_ops->nmi_allowed(vcpu))
 		return true;
 
 	if (kvm_test_request(KVM_REQ_SMI, vcpu))
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PATCH v2] KVM: x86: Fix nmi injection failure when vcpu got blocked
  2017-05-25  6:56 [Qemu-devel] [PATCH v2] KVM: x86: Fix nmi injection failure when vcpu got blocked Zhuangyanying
@ 2017-05-25 14:17 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2017-05-25 14:17 UTC (permalink / raw)
  To: Zhuangyanying, rkrcmar, herongguang.he
  Cc: qemu-devel, arei.gonglei, oscar.zhangbo, kvm



On 25/05/2017 08:56, Zhuangyanying wrote:
> 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 KVM_REQ_NMI request plus with nmi_queued in
> vm_vcpu_has_events().
> 
> Signed-off-by: Zhuang Yanying <ann.zhuangyanying@huawei.com>
> ---
>  arch/x86/kvm/x86.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 02363e3..2d15708 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8394,7 +8394,9 @@ 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) ||
> +	    atomic_read(&vcpu->arch.nmi_queued)) &&
> +	    kvm_x86_ops->nmi_allowed(vcpu))

It's the other way round; nmi_pending was correct in your v1.

Testing KVM_REQ_NMI replaces nmi_queued, while the bugfix tests
"vcpu->arch.nmi_pending && kvm_x86_ops->nmi_allowed(vcpu)".  The new est
has to match the existing test in inject_pending_event.

In fact, we also need to do the same change for SMIs, i.e.

	kvm_test_request(KVM_REQ_SMI, vcpu) ||
	(vcpu->arch.smi_pending && !is_smm(vcpu))

Thanks,

Paolo

>  		return true;
>  
>  	if (kvm_test_request(KVM_REQ_SMI, vcpu))
> 

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

end of thread, other threads:[~2017-05-25 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-25  6:56 [Qemu-devel] [PATCH v2] KVM: x86: Fix nmi injection failure when vcpu got blocked Zhuangyanying
2017-05-25 14:17 ` Paolo Bonzini

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).