From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lai Jiangshan Subject: Re: [Qemu-devel] [PATCH 1/1 V5] kernel/kvm: introduce KVM_SET_LINT1 and fix improper nmi emulation Date: Fri, 14 Oct 2011 17:27:21 +0800 Message-ID: <4E980079.5060704@cn.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> <4E928B54.1070707@cn.fujitsu.com> <4E92958E.9000509@web.de> <4E9476E2.1070804@cn.fujitsu.com> <4E948842.4030406@web.de> <4E978827.6070008@cn.fujitsu.com> <4E97CE42.9020102@web.de> <4E97D85C.7070107@cn.fujitsu.com> <4E97DB62.9020605@web.de> <4E97FAC7.6080007@cn.fujitsu.com> <4E97 FBB9.2040909@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: "kvm@vger.kernel.org" , Avi Kivity , "qemu-devel@nongnu.org" , KAMEZAWA Hiroyuki , Kenji Kaneshige To: Jan Kiszka Return-path: Received: from cn.fujitsu.com ([222.73.24.84]:57269 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755494Ab1JNJ0F (ORCPT ); Fri, 14 Oct 2011 05:26:05 -0400 In-Reply-To: <4E97FBB9.2040909@web.de> Sender: kvm-owner@vger.kernel.org List-ID: On 10/14/2011 05:07 PM, Jan Kiszka wrote: > On 2011-10-14 11:03, Lai Jiangshan wrote: >> 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 masked 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, we introduce introduce KVM_SET_LINT1, >> and we can use KVM_SET_LINT1 to correctly emulate NMI button >> without change the old KVM_NMI behavior. >> >> Signed-off-by: Lai Jiangshan >> Reported-by: Kenji Kaneshige >> --- >> arch/x86/include/asm/kvm.h | 1 + >> arch/x86/kvm/irq.h | 1 + >> arch/x86/kvm/lapic.c | 7 +++++++ >> arch/x86/kvm/x86.c | 8 ++++++++ >> include/linux/kvm.h | 5 +++++ >> 5 files changed, 22 insertions(+), 0 deletions(-) >> diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h >> index 4d8dcbd..88d0ac3 100644 >> --- a/arch/x86/include/asm/kvm.h >> +++ b/arch/x86/include/asm/kvm.h >> @@ -24,6 +24,7 @@ >> #define __KVM_HAVE_DEBUGREGS >> #define __KVM_HAVE_XSAVE >> #define __KVM_HAVE_XCRS >> +#define __KVM_HAVE_SET_LINT1 >> >> /* Architectural interrupt line count. */ >> #define KVM_NR_INTERRUPTS 256 >> 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..fccd094 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -2077,6 +2077,7 @@ int kvm_dev_ioctl_check_extension(long ext) >> case KVM_CAP_XSAVE: >> case KVM_CAP_ASYNC_PF: >> case KVM_CAP_GET_TSC_KHZ: >> + case KVM_CAP_SET_LINT1: >> r = 1; >> break; >> case KVM_CAP_COALESCED_MMIO: >> @@ -3264,6 +3265,13 @@ long kvm_arch_vcpu_ioctl(struct file *filp, >> >> goto out; >> } >> + case KVM_SET_LINT1: { >> + r = -EINVAL; >> + if (!irqchip_in_kernel(vcpu->kvm)) >> + goto out; >> + r = 0; >> + kvm_apic_lint1_deliver(vcpu); >> + } >> default: >> r = -EINVAL; >> } >> diff --git a/include/linux/kvm.h b/include/linux/kvm.h >> index aace6b8..3a10572 100644 >> --- a/include/linux/kvm.h >> +++ b/include/linux/kvm.h >> @@ -554,6 +554,9 @@ struct kvm_ppc_pvinfo { >> #define KVM_CAP_PPC_SMT 64 >> #define KVM_CAP_PPC_RMA 65 >> #define KVM_CAP_S390_GMAP 71 >> +#ifdef __KVM_HAVE_SET_LINT1 >> +#define KVM_CAP_SET_LINT1 72 >> +#endif > > Actually, there is no need for __KVM_HAVE_SET_LINT1 and #ifdef. User > land will just do a runtime check. > > There is not bad result brought by __KVM_HAVE_SET_LINT1 and help for compile time check. Thanks, Lai From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REe29-0002An-QB for qemu-devel@nongnu.org; Fri, 14 Oct 2011 05:26:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REe24-0002GD-IT for qemu-devel@nongnu.org; Fri, 14 Oct 2011 05:26:29 -0400 Received: from [222.73.24.84] (port=62694 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REe1x-0002Cm-Gw for qemu-devel@nongnu.org; Fri, 14 Oct 2011 05:26:24 -0400 Message-ID: <4E980079.5060704@cn.fujitsu.com> Date: Fri, 14 Oct 2011 17:27:21 +0800 From: Lai Jiangshan 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> <4E928B54.1070707@cn.fujitsu.com> <4E92958E.9000509@web.de> <4E9476E2.1070804@cn.fujitsu.com> <4E948842.4030406@web.de> <4E978827.6070008@cn.fujitsu.com> <4E97CE42.9020102@web.de> <4E97D85C.7070107@cn.fujitsu.com> <4E97DB62.9020605@web.de> <4E97FAC7.6080007@cn.fujitsu.com> <4E97FBB9.2040909@web.de> In-Reply-To: <4E97FBB9.2040909@web.de> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH 1/1 V5] kernel/kvm: introduce KVM_SET_LINT1 and fix improper nmi emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Kenji Kaneshige , KAMEZAWA Hiroyuki , Avi Kivity , "kvm@vger.kernel.org" , "qemu-devel@nongnu.org" On 10/14/2011 05:07 PM, Jan Kiszka wrote: > On 2011-10-14 11:03, Lai Jiangshan wrote: >> 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 masked 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, we introduce introduce KVM_SET_LINT1, >> and we can use KVM_SET_LINT1 to correctly emulate NMI button >> without change the old KVM_NMI behavior. >> >> Signed-off-by: Lai Jiangshan >> Reported-by: Kenji Kaneshige >> --- >> arch/x86/include/asm/kvm.h | 1 + >> arch/x86/kvm/irq.h | 1 + >> arch/x86/kvm/lapic.c | 7 +++++++ >> arch/x86/kvm/x86.c | 8 ++++++++ >> include/linux/kvm.h | 5 +++++ >> 5 files changed, 22 insertions(+), 0 deletions(-) >> diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h >> index 4d8dcbd..88d0ac3 100644 >> --- a/arch/x86/include/asm/kvm.h >> +++ b/arch/x86/include/asm/kvm.h >> @@ -24,6 +24,7 @@ >> #define __KVM_HAVE_DEBUGREGS >> #define __KVM_HAVE_XSAVE >> #define __KVM_HAVE_XCRS >> +#define __KVM_HAVE_SET_LINT1 >> >> /* Architectural interrupt line count. */ >> #define KVM_NR_INTERRUPTS 256 >> 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..fccd094 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -2077,6 +2077,7 @@ int kvm_dev_ioctl_check_extension(long ext) >> case KVM_CAP_XSAVE: >> case KVM_CAP_ASYNC_PF: >> case KVM_CAP_GET_TSC_KHZ: >> + case KVM_CAP_SET_LINT1: >> r = 1; >> break; >> case KVM_CAP_COALESCED_MMIO: >> @@ -3264,6 +3265,13 @@ long kvm_arch_vcpu_ioctl(struct file *filp, >> >> goto out; >> } >> + case KVM_SET_LINT1: { >> + r = -EINVAL; >> + if (!irqchip_in_kernel(vcpu->kvm)) >> + goto out; >> + r = 0; >> + kvm_apic_lint1_deliver(vcpu); >> + } >> default: >> r = -EINVAL; >> } >> diff --git a/include/linux/kvm.h b/include/linux/kvm.h >> index aace6b8..3a10572 100644 >> --- a/include/linux/kvm.h >> +++ b/include/linux/kvm.h >> @@ -554,6 +554,9 @@ struct kvm_ppc_pvinfo { >> #define KVM_CAP_PPC_SMT 64 >> #define KVM_CAP_PPC_RMA 65 >> #define KVM_CAP_S390_GMAP 71 >> +#ifdef __KVM_HAVE_SET_LINT1 >> +#define KVM_CAP_SET_LINT1 72 >> +#endif > > Actually, there is no need for __KVM_HAVE_SET_LINT1 and #ifdef. User > land will just do a runtime check. > > There is not bad result brought by __KVM_HAVE_SET_LINT1 and help for compile time check. Thanks, Lai