From nobody Thu May 2 05:58:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495695542228224.8541688716258; Wed, 24 May 2017 23:59:02 -0700 (PDT) Received: from localhost ([::1]:58526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDmjb-0000hl-7D for importer@patchew.org; Thu, 25 May 2017 02:58:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDmin-0000Qi-HG for qemu-devel@nongnu.org; Thu, 25 May 2017 02:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDmik-0006IU-H1 for qemu-devel@nongnu.org; Thu, 25 May 2017 02:58:09 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3884) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dDmik-0006I5-6P for qemu-devel@nongnu.org; Thu, 25 May 2017 02:58:06 -0400 Received: from 172.30.72.55 (EHLO dggeml406-hub.china.huawei.com) ([172.30.72.55]) by dggrg03-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AOG56005; Thu, 25 May 2017 14:57:57 +0800 (CST) Received: from localhost (10.177.21.2) by dggeml406-hub.china.huawei.com (10.3.17.50) with Microsoft SMTP Server id 14.3.301.0; Thu, 25 May 2017 14:57:48 +0800 From: Zhuangyanying To: , , Date: Thu, 25 May 2017 14:56:43 +0800 Message-ID: <1495695403-8252-1-git-send-email-ann.zhuangyanying@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.177.21.2] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.59268075.00EB, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 4aeb5e1e6c783b27ac12403a86dd9dcb X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.189 Subject: [Qemu-devel] [PATCH v2] KVM: x86: Fix nmi injection failure when vcpu got blocked X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: oscar.zhangbo@huawei.com, arei.gonglei@huawei.com, ZhuangYanying , qemu-devel@nongnu.org, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: ZhuangYanying 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 --- 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_vcp= u *vcpu) if (vcpu->arch.pv.pv_unhalted) return true; =20 - 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; =20 if (kvm_test_request(KVM_REQ_SMI, vcpu)) --=20 1.8.3.1