From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REe2y-0002qO-TO for qemu-devel@nongnu.org; Fri, 14 Oct 2011 05:27:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REe2v-0002LK-0i for qemu-devel@nongnu.org; Fri, 14 Oct 2011 05:27:20 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:53700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REe2u-0002L3-DR for qemu-devel@nongnu.org; Fri, 14 Oct 2011 05:27:16 -0400 Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate03.web.de (Postfix) with ESMTP id 93A101A0D70D3 for ; Fri, 14 Oct 2011 11:22:19 +0200 (CEST) Message-ID: <4E97FF47.4000107@web.de> Date: Fri, 14 Oct 2011 11:22:15 +0200 From: Jan Kiszka 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> <4E97FACE.7030509@cn.fujitsu.com> In-Reply-To: <4E97FACE.7030509@cn.fujitsu.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig679678E697B296524F6AC5D1" Subject: Re: [Qemu-devel] [PATCH 2/2 V5] qemu-kvm: fix improper nmi emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lai Jiangshan Cc: "kvm@vger.kernel.org" , Avi Kivity , "qemu-devel@nongnu.org" , KAMEZAWA Hiroyuki , Kenji Kaneshige This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig679678E697B296524F6AC5D1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > With this patch, inject-nmi request is handled as follows. >=20 > - When in-kernel irqchip is enabled and KVM_SET_LINT1 is enabled, > inject LINT1 instead of NMI interrupt. >=20 > - otherwise when in-kernel irqchip is enabled, get the in-kernel > LAPIC states and test the APIC_LVT_MASKED, if LINT1 is unmasked, > and then delivering the NMI directly. >=20 > - otherwise, userland lapic emulates NMI button and inject NMI > if it is unmasked. >=20 > Signed-off-by: Lai Jiangshan > Reported-by: Kenji Kaneshige > --- > hw/apic.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > hw/apic.h | 1 + > monitor.c | 6 ++++- > 3 files changed, 78 insertions(+), 1 deletions(-) >=20 > diff --git a/hw/apic.c b/hw/apic.c > index 69d6ac5..91b82d0 100644 > --- a/hw/apic.c > +++ b/hw/apic.c > @@ -205,6 +205,78 @@ void apic_deliver_pic_intr(DeviceState *d, int lev= el) > } > } > =20 > +#ifdef KVM_CAP_IRQCHIP Please read all my comments. That unfortunately also applies to the rest of the patch. > +static inline uint32_t kapic_reg(struct kvm_lapic_state *kapic, int re= g_id); > + > +static void kvm_irqchip_deliver_nmi(void *p) > +{ > + APICState *s =3D p; > + struct kvm_lapic_state klapic; > + uint32_t lvt; > + > + kvm_get_lapic(s->cpu_env, &klapic); > + lvt =3D kapic_reg(&klapic, 0x32 + APIC_LVT_LINT1); > + > + if (lvt & APIC_LVT_MASKED) { > + return; > + } > + > + if (((lvt >> 8) & 7) !=3D APIC_DM_NMI) { > + return; > + } > + > + kvm_vcpu_ioctl(s->cpu_env, KVM_NMI); > +} > + > +static void __apic_deliver_nmi(APICState *s) > +{ > + if (kvm_irqchip_in_kernel()) { > + run_on_cpu(s->cpu_env, kvm_irqchip_deliver_nmi, s); > + } else { > + apic_local_deliver(s, APIC_LVT_LINT1); > + } > +} > +#else > +static void __apic_deliver_nmi(APICState *s) > +{ > + apic_local_deliver(s, APIC_LVT_LINT1); > +} > +#endif > + > +enum { > + KVM_SET_LINT1_UNKNOWN, > + KVM_SET_LINT1_ENABLED, > + KVM_SET_LINT1_DISABLED, > +}; > + > +static void kvm_set_lint1(void *p) > +{ > + CPUState *env =3D p; > + > + kvm_vcpu_ioctl(env, KVM_SET_LINT1); > +} > + > +void apic_deliver_nmi(DeviceState *d) > +{ > + APICState *s =3D DO_UPCAST(APICState, busdev.qdev, d); > + static int kernel_lint1 =3D KVM_SET_LINT1_UNKNOWN; > + > + if (kernel_lint1 =3D=3D KVM_SET_LINT1_UNKNOWN) { > + if (kvm_enabled() && kvm_irqchip_in_kernel() && > + kvm_check_extension(kvm_state, KVM_CAP_SET_LINT1)) { That CAP test belongs where the injection shall happen. Here you decide about user space vs. kernel space APIC model. Let's try it together: if kvm_enabled && kvm_irqchip_in_kernel run_on_cpu(kvm_apic_deliver_nmi) else apic_local_deliver(APIC_LVT_LINT1) with kvm_acpi_deliver_nmi like this: if !check_extention(CAP_SET_LINT1) get_kernel_apic_state if !nmi_acceptable return kvm_vcpu_ioctl(KVM_NMI) Please don't trust me blindly and re-check, but this is how the scenario looks like to me. Thanks for your patience, Jan --------------enig679678E697B296524F6AC5D1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk6X/0gACgkQitSsb3rl5xQKRQCcCUSRUAgOKounrQYwQcwQ0qv0 e9YAnjopVxSYtRR/tn1FcpQuciQYmVPV =dbar -----END PGP SIGNATURE----- --------------enig679678E697B296524F6AC5D1--