From nobody Sat Apr 27 21:25:54 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 14957765779831016.9231628454627; Thu, 25 May 2017 22:29:37 -0700 (PDT) Received: from localhost ([::1]:35032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dE7oe-0005f8-OS for importer@patchew.org; Fri, 26 May 2017 01:29:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dE7nZ-00052W-KE for qemu-devel@nongnu.org; Fri, 26 May 2017 01:28:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dE7nV-0000XI-Ju for qemu-devel@nongnu.org; Fri, 26 May 2017 01:28:29 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:4001) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dE7nU-0000VW-Vf for qemu-devel@nongnu.org; Fri, 26 May 2017 01:28:25 -0400 Received: from 172.30.72.56 (EHLO DGGEML403-HUB.china.huawei.com) ([172.30.72.56]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id APF95950; Fri, 26 May 2017 13:28:14 +0800 (CST) Received: from localhost (10.177.21.2) by DGGEML403-HUB.china.huawei.com (10.3.17.33) with Microsoft SMTP Server id 14.3.301.0; Fri, 26 May 2017 13:28:06 +0800 From: Zhuangyanying To: , Date: Fri, 26 May 2017 13:16:48 +0800 Message-ID: <1495775808-10396-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.0A020206.5927BCF0.00BD, 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: 6ed092324eb2b9f56f00a55e6b316752 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.187 Subject: [Qemu-devel] [PATCH v3] 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: kvm@vger.kernel.org, oscar.zhangbo@huawei.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, herongguang.he@huawei.com, ZhuangYanying 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 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 --- 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.=20 --- 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_v= cpu *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) || + (vcpu->arch.nmi_pending && + kvm_x86_ops->nmi_allowed(vcpu))) return true; =20 - 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; =20 if (kvm_arch_interrupt_allowed(vcpu) && --=20 1.8.3.1