From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kenji Kaneshige Subject: Re: [PATCH] kernel/kvm: fix improper nmi emulation Date: Wed, 12 Oct 2011 16:01:25 +0900 Message-ID: <4E953B45.4040209@jp.fujitsu.com> References: <20110913093835.GB4265@localhost.localdomain> <20110914093441.e2bb305c.kamezawa.hiroyu@jp.fujitsu.com> <4E705BC3.5000508@cn.fujitsu.com> <20110915164704.9cacd407.kamezawa.hiroyu@jp.fujitsu.com> <4E71B28F.7030201@cn.fujitsu.com> <4E72F3BA.2000603@jp.fujitsu.com> <4E73200A.7040908@jp.fujitsu.com> <4E76C6AA.9080403@cn.fujitsu.com> <4E7B04DC.1030407@cn.fujitsu.com> <4E7B4B8F.507@siemens.com> <4E7C51E4.2000503@cn.fujitsu.com> <4E7F3585.40108@redhat.com> <4E7F635E.6080009@web.de> <4E8035F9.9080908@redhat.com> <4E928B4E.2080207@cn.fujitsu.com> <4E92C86D.9000701@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Cc: Lai Jiangshan , Jan Kiszka , KAMEZAWA Hiroyuki , "kvm@vger.kernel.org" , "qemu-devel@nongnu.org" , seabios@seabios.org To: Avi Kivity Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:47630 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751686Ab1JLHCu (ORCPT ); Wed, 12 Oct 2011 03:02:50 -0400 Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id A31FA3EE0BB for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 8A0F545DE58 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 5884345DE5A for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 48693E08007 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from ml13.s.css.fujitsu.com (ml13.s.css.fujitsu.com [10.240.81.133]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 02B5BE08004 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) In-Reply-To: <4E92C86D.9000701@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: (2011/10/10 19:26), Avi Kivity wrote: > On 10/10/2011 08:06 AM, Lai Jiangshan wrote: >> From: Kenji Kaneshige >> >> Currently, NMI interrupt is blindly sent to all the vCPUs when NMI >> button event happens. This doesn't properly emulate real hardware on >> which NMI button event triggers LINT1. Because of this, NMI is sent to >> the processor even when LINT1 is maskied in LVT. For example, this >> causes the problem that kdump initiated by NMI sometimes doesn't work >> on KVM, because kdump assumes NMI is masked on CPUs other than CPU0. >> >> With this patch, KVM_NMI ioctl is handled as follows. >> >> - When in-kernel irqchip is enabled, KVM_NMI ioctl is handled as a >> request of triggering LINT1 on the processor. LINT1 is emulated in >> in-kernel irqchip. >> >> - When in-kernel irqchip is disabled, KVM_NMI ioctl is handled as a >> request of injecting NMI to the processor. This assumes LINT1 is >> already emulated in userland. > > Please add a KVM_NMI section to Documentation/virtual/kvm/api.txt. > >> >> -static int kvm_vcpu_ioctl_nmi(struct kvm_vcpu *vcpu) >> -{ >> - kvm_inject_nmi(vcpu); >> - >> - return 0; >> -} >> - >> static int vcpu_ioctl_tpr_access_reporting(struct kvm_vcpu *vcpu, >> struct kvm_tpr_access_ctl *tac) >> { >> @@ -3038,9 +3031,10 @@ long kvm_arch_vcpu_ioctl(struct file *fi >> break; >> } >> case KVM_NMI: { >> - r = kvm_vcpu_ioctl_nmi(vcpu); >> - if (r) >> - goto out; >> + if (irqchip_in_kernel(vcpu->kvm)) >> + kvm_apic_lint1_deliver(vcpu); >> + else >> + kvm_inject_nmi(vcpu); >> r = 0; >> break; >> } > > Why did you drop kvm_vcpu_ioctl_nmi()? > > Please add (and document) a KVM_CAP flag that lets userspace know the new behaviour is supported. > Sorry for the delayed responding. I don't understand why new KVM_CAP flag is needed. I think the old behavior was clearly a bug, and new behavior is not a new capability. Furthermore, the kvm patch and the qemu patch in this patchset can be applied independently. If only the kvm patch is applied, NMI bug in kernel irq is fixed and qemu NMI behavior is not changed. If the only the qemu patch is applied, qemu NMI bug is fixed and the NMI behavior in kernel irq is not changed. Regards, Kenji Kaneshige From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:37764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDsq9-0007un-7X for qemu-devel@nongnu.org; Wed, 12 Oct 2011 03:02:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDsq7-0002C3-Or for qemu-devel@nongnu.org; Wed, 12 Oct 2011 03:02:57 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:34943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDsq7-0001zH-6M for qemu-devel@nongnu.org; Wed, 12 Oct 2011 03:02:55 -0400 Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 88D6E3EE0B6 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 7279345DE56 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 5280345DE59 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 447AEE08006 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Received: from ml13.s.css.fujitsu.com (ml13.s.css.fujitsu.com [10.240.81.133]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 01718E08003 for ; Wed, 12 Oct 2011 16:02:48 +0900 (JST) Message-ID: <4E953B45.4040209@jp.fujitsu.com> Date: Wed, 12 Oct 2011 16:01:25 +0900 From: Kenji Kaneshige MIME-Version: 1.0 References: <20110913093835.GB4265@localhost.localdomain> <20110914093441.e2bb305c.kamezawa.hiroyu@jp.fujitsu.com> <4E705BC3.5000508@cn.fujitsu.com> <20110915164704.9cacd407.kamezawa.hiroyu@jp.fujitsu.com> <4E71B28F.7030201@cn.fujitsu.com> <4E72F3BA.2000603@jp.fujitsu.com> <4E73200A.7040908@jp.fujitsu.com> <4E76C6AA.9080403@cn.fujitsu.com> <4E7B04DC.1030407@cn.fujitsu.com> <4E7B4B8F.507@siemens.com> <4E7C51E4.2000503@cn.fujitsu.com> <4E7F3585.40108@redhat.com> <4E7F635E.6080009@web.de> <4E8035F9.9080908@redhat.com> <4E928B4E.2080207@cn.fujitsu.com> <4E92C86D.9000701@redhat.com> In-Reply-To: <4E92C86D.9000701@redhat.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] kernel/kvm: fix improper nmi emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Lai Jiangshan , "kvm@vger.kernel.org" , seabios@seabios.org, "qemu-devel@nongnu.org" , Jan Kiszka , KAMEZAWA Hiroyuki (2011/10/10 19:26), Avi Kivity wrote: > On 10/10/2011 08:06 AM, Lai Jiangshan wrote: >> From: Kenji Kaneshige >> >> Currently, NMI interrupt is blindly sent to all the vCPUs when NMI >> button event happens. This doesn't properly emulate real hardware on >> which NMI button event triggers LINT1. Because of this, NMI is sent to >> the processor even when LINT1 is maskied in LVT. For example, this >> causes the problem that kdump initiated by NMI sometimes doesn't work >> on KVM, because kdump assumes NMI is masked on CPUs other than CPU0. >> >> With this patch, KVM_NMI ioctl is handled as follows. >> >> - When in-kernel irqchip is enabled, KVM_NMI ioctl is handled as a >> request of triggering LINT1 on the processor. LINT1 is emulated in >> in-kernel irqchip. >> >> - When in-kernel irqchip is disabled, KVM_NMI ioctl is handled as a >> request of injecting NMI to the processor. This assumes LINT1 is >> already emulated in userland. > > Please add a KVM_NMI section to Documentation/virtual/kvm/api.txt. > >> >> -static int kvm_vcpu_ioctl_nmi(struct kvm_vcpu *vcpu) >> -{ >> - kvm_inject_nmi(vcpu); >> - >> - return 0; >> -} >> - >> static int vcpu_ioctl_tpr_access_reporting(struct kvm_vcpu *vcpu, >> struct kvm_tpr_access_ctl *tac) >> { >> @@ -3038,9 +3031,10 @@ long kvm_arch_vcpu_ioctl(struct file *fi >> break; >> } >> case KVM_NMI: { >> - r = kvm_vcpu_ioctl_nmi(vcpu); >> - if (r) >> - goto out; >> + if (irqchip_in_kernel(vcpu->kvm)) >> + kvm_apic_lint1_deliver(vcpu); >> + else >> + kvm_inject_nmi(vcpu); >> r = 0; >> break; >> } > > Why did you drop kvm_vcpu_ioctl_nmi()? > > Please add (and document) a KVM_CAP flag that lets userspace know the new behaviour is supported. > Sorry for the delayed responding. I don't understand why new KVM_CAP flag is needed. I think the old behavior was clearly a bug, and new behavior is not a new capability. Furthermore, the kvm patch and the qemu patch in this patchset can be applied independently. If only the kvm patch is applied, NMI bug in kernel irq is fixed and qemu NMI behavior is not changed. If the only the qemu patch is applied, qemu NMI bug is fixed and the NMI behavior in kernel irq is not changed. Regards, Kenji Kaneshige