public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] KVM: x86: Fix nmi injection failure when vcpu got blocked
@ 2017-05-26  5:16 Zhuangyanying
  2017-05-30 13:36 ` Radim Krčmář
  0 siblings, 1 reply; 3+ messages in thread
From: Zhuangyanying @ 2017-05-26  5:16 UTC (permalink / raw)
  To: pbonzini, rkrcmar
  Cc: herongguang.he, 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 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. 
---
 arch/x86/kvm/x86.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 02363e3..a2cd099 100644
--- 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 &&
+	     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)))
 		return true;
 
 	if (kvm_arch_interrupt_allowed(vcpu) &&
-- 
1.8.3.1

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

end of thread, other threads:[~2017-05-30 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-26  5:16 [PATCH v3] KVM: x86: Fix nmi injection failure when vcpu got blocked Zhuangyanying
2017-05-30 13:36 ` Radim Krčmář
2017-05-30 15:15   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox