From: Jan Kiszka Subject: Re: [PATCH] return default values for apic probe functions. Date: Fri, 17 Apr 2009 08:56:37 +0200 Message-ID: <49E82825.602@web.de> References: <1239945321-3903-1-git-send-email-glommer@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigFF5ED47C2AEE1ED27392DE4E" Cc: kvm@vger.kernel.org, avi@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org To: Glauber Costa Return-path: Received: from fmmailgate02.web.de ([217.72.192.227]:47023 "EHLO fmmailgate02.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755643AbZDQG5M (ORCPT ); Fri, 17 Apr 2009 02:57:12 -0400 In-Reply-To: <1239945321-3903-1-git-send-email-glommer@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFF5ED47C2AEE1ED27392DE4E Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Glauber Costa wrote: > As KVM cpus runs on threads, it is possible that > we call kvm_load_registers() from a cpu thread, while the > apic has not yet fully initialized. kvm_load_registers() is called > from ap_main_loop. >=20 > This is not a problem when we're starting the whole machine together, > but is a problem for hotplug, since we don't have the protection > of the locks that protect machine initialization. Currently, some execu= tions > of cpu hotplug on rainy sundays fail with a segfault. >=20 > Moving apic initialization to before kvm_init_vpcu proved fruitful, > as there are some dependencies involved. (kvm irqchip would fail to > initialize). >=20 > This patch provides default values to be used for tpr and apic_base, > that will be returned when the apic is not yet properly initialized. > It is aimed at kvm, where the problem exists, but it could equally be > used for qemu too, if there is agreement. >=20 > Signed-off-by: Glauber Costa > --- > qemu/hw/apic.c | 12 ++++++++++-- > 1 files changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/qemu/hw/apic.c b/qemu/hw/apic.c > index b926508..06fb9b5 100644 > --- a/qemu/hw/apic.c > +++ b/qemu/hw/apic.c > @@ -301,7 +301,12 @@ uint64_t cpu_get_apic_base(CPUState *env) > #ifdef DEBUG_APIC > printf("cpu_get_apic_base: %016" PRIx64 "\n", (uint64_t)s->apicbas= e); > #endif > - return s->apicbase; > + if (s) { > + return s->apicbase; > + } > + else { > + return 0xfee00000 | MSR_IA32_APICBASE_ENABLE; > + } > } Even on sunny days, this collides with QEMU commit #7048. :) Does Intel specify what non-existent MSRs should return, ie. is your version still correct if !s->apicbase means that there is actually no APIC? And does kvm depend on the default base? If so, I would say: provide a patch against upstream. > =20 > void cpu_set_apic_tpr(CPUX86State *env, uint8_t val) > @@ -314,7 +319,10 @@ void cpu_set_apic_tpr(CPUX86State *env, uint8_t va= l) > uint8_t cpu_get_apic_tpr(CPUX86State *env) > { > APICState *s =3D env->apic_state; > - return s->tpr >> 4; > + if (s) > + return s->tpr >> 4; > + else > + return 0; > } > =20 > /* return -1 if no bit is set */ This is already upstream. Jan --------------enigFF5ED47C2AEE1ED27392DE4E 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.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAknoKCkACgkQniDOoMHTA+kFzgCeLKyQjRDqp/fZdFk2US1swq0S RqkAn1KwWdZqRYtn5HNqfg8Ug5oiw2Wu =35TG -----END PGP SIGNATURE----- --------------enigFF5ED47C2AEE1ED27392DE4E--