From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kenji Kaneshige Subject: Re: [PATCH 1/1 V2] kernel/kvm: fix improper nmi emulation Date: Wed, 12 Oct 2011 16:02:11 +0900 Message-ID: <4E953B73.3040904@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> <4E947628.6020105@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Cc: KAMEZAWA Hiroyuki , "kvm@vger.kernel.org" , "qemu-devel@nongnu.org" , seabios@seabios.org To: Lai Jiangshan , Avi Kivity , Jan Kiszka Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:57392 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751368Ab1JLHD2 (ORCPT ); Wed, 12 Oct 2011 03:03:28 -0400 Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 26F2B3EE0BD for ; Wed, 12 Oct 2011 16:03:27 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 0E41F45DE6A for ; Wed, 12 Oct 2011 16:03:27 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id EA11A45DE68 for ; Wed, 12 Oct 2011 16:03:26 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id DC2B61DB803C for ; Wed, 12 Oct 2011 16:03:26 +0900 (JST) Received: from m107.s.css.fujitsu.com (m107.s.css.fujitsu.com [10.240.81.147]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9ED0C1DB8038 for ; Wed, 12 Oct 2011 16:03:26 +0900 (JST) In-Reply-To: <4E947628.6020105@cn.fujitsu.com> Sender: kvm-owner@vger.kernel.org List-ID: (2011/10/12 2:00), 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. > > (laijs) Changed from v1: > Add KVM_NMI API document > Add KVM_CAP_USER_NMI > > Signed-off-by: Kenji Kaneshige > Tested-by: Lai Jiangshan > --- > Documentation/virtual/kvm/api.txt | 20 ++++++++++++++++++++ > arch/x86/kvm/irq.h | 1 + > arch/x86/kvm/lapic.c | 7 +++++++ > arch/x86/kvm/x86.c | 12 ++++++++++++ > include/linux/kvm.h | 3 +++ > 5 files changed, 43 insertions(+), 0 deletions(-) > > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > index b0e4b9c..5c24cc3 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -1430,6 +1430,26 @@ is supported; 2 if the processor requires all virtual machines to have > an RMA, or 1 if the processor can use an RMA but doesn't require it, > because it supports the Virtual RMA (VRMA) facility. > > +4.64 KVM_NMI > + > +Capability: KVM_CAP_USER_NMI > +Architectures: x86 > +Type: vcpu ioctl > +Parameters: none > +Returns: 0 on success, -1 on error > + > +This ioctl injects NMI to the vcpu. > + > +If with capability KVM_CAP_LAPIC_NMI, 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 lapic 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 lapic. > + > 5. The kvm_run structure > > Application code obtains a pointer to the kvm_run structure by > diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h > index 53e2d08..0c96315 100644 > --- a/arch/x86/kvm/irq.h > +++ b/arch/x86/kvm/irq.h > @@ -95,6 +95,7 @@ void kvm_pic_reset(struct kvm_kpic_state *s); > void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu); > void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu); > void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu); > +void kvm_apic_lint1_deliver(struct kvm_vcpu *vcpu); > void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu); > void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu); > void __kvm_migrate_timers(struct kvm_vcpu *vcpu); > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 57dcbd4..87fe36a 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1039,6 +1039,13 @@ void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu) > kvm_apic_local_deliver(apic, APIC_LVT0); > } > > +void kvm_apic_lint1_deliver(struct kvm_vcpu *vcpu) > +{ > + struct kvm_lapic *apic = vcpu->arch.apic; > + > + kvm_apic_local_deliver(apic, APIC_LVT1); > +} > + > static struct kvm_timer_ops lapic_timer_ops = { > .is_periodic = lapic_is_periodic, > }; > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 84a28ea..6862ef7 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2729,12 +2729,24 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, > return 0; > } > > +#ifdef KVM_CAP_LAPIC_NMI > +static int kvm_vcpu_ioctl_nmi(struct kvm_vcpu *vcpu) > +{ > + if (irqchip_in_kernel(vcpu->kvm)) > + kvm_apic_lint1_deliver(vcpu); > + else > + kvm_inject_nmi(vcpu); > + > + return 0; > +} > +#else > static int kvm_vcpu_ioctl_nmi(struct kvm_vcpu *vcpu) > { > kvm_inject_nmi(vcpu); > > return 0; > } > +#endif I don't think we need to keep old kvm_vcpu_ioctl_nmi() behavior because it's clearly a bug. Regards, Kenji Kaneshige