From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LtHuk-0004X7-DM for qemu-devel@nongnu.org; Mon, 13 Apr 2009 04:53:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LtHuf-0004WU-Fc for qemu-devel@nongnu.org; Mon, 13 Apr 2009 04:53:13 -0400 Received: from [199.232.76.173] (port=44509 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LtHuf-0004WR-61 for qemu-devel@nongnu.org; Mon, 13 Apr 2009 04:53:09 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:54250) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LtHue-0008AO-5o for qemu-devel@nongnu.org; Mon, 13 Apr 2009 04:53:08 -0400 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate01.web.de (Postfix) with ESMTP id 1C6A8FFD645B for ; Mon, 13 Apr 2009 10:53:07 +0200 (CEST) Received: from [88.66.126.154] (helo=[192.168.1.123]) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1LtHuc-0003yH-00 for qemu-devel@nongnu.org; Mon, 13 Apr 2009 10:53:06 +0200 Message-ID: <49E2FD72.6000101@web.de> Date: Mon, 13 Apr 2009 10:53:06 +0200 From: Jan Kiszka MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig5B029D6F426D1244C188AA4D" Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH][STABLE] kvm: Fix cpuid initialization Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig5B029D6F426D1244C188AA4D Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable [ Looks like we need more kvm users via upstream qemu... ] Fix (more or less) spurious guest boot failures due to corrupted cpuid states. The reason was insufficient initialization of cpuid entries before passing them to the kernel. At this chance also fix improper entry pointer progression and simplify the code a bit. Signed-off-by: Jan Kiszka --- target-i386/kvm.c | 60 ++++++++++++++++++-----------------------------= ------ 1 files changed, 20 insertions(+), 40 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 4f437c2..2de8b81 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -41,12 +41,11 @@ int kvm_arch_init_vcpu(CPUState *env) struct kvm_cpuid_entry2 entries[100]; } __attribute__((packed)) cpuid_data; uint32_t limit, i, j, cpuid_i; - uint32_t eax, ebx, ecx, edx; + uint32_t unused; =20 cpuid_i =3D 0; =20 - cpu_x86_cpuid(env, 0, 0, &eax, &ebx, &ecx, &edx); - limit =3D eax; + cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused); =20 for (i =3D 0; i <=3D limit; i++) { struct kvm_cpuid_entry2 *c =3D &cpuid_data.entries[cpuid_i++]; @@ -56,26 +55,17 @@ int kvm_arch_init_vcpu(CPUState *env) /* Keep reading function 2 till all the input is received */= int times; =20 - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); - times =3D eax & 0xff; - c->function =3D i; - c->flags |=3D KVM_CPUID_FLAG_STATEFUL_FUNC; - c->flags |=3D KVM_CPUID_FLAG_STATE_READ_NEXT; - c->eax =3D eax; - c->ebx =3D ebx; - c->ecx =3D ecx; - c->edx =3D edx; + c->flags =3D KVM_CPUID_FLAG_STATEFUL_FUNC | + KVM_CPUID_FLAG_STATE_READ_NEXT; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx)= ; + times =3D c->eax & 0xff; =20 for (j =3D 1; j < times; ++j) { - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); + c =3D &cpuid_data.entries[cpuid_i++]; c->function =3D i; - c->flags |=3D KVM_CPUID_FLAG_STATEFUL_FUNC; - c->eax =3D eax; - c->ebx =3D ebx; - c->ecx =3D ecx; - c->edx =3D edx; - c =3D &cpuid_data.entries[++cpuid_i]; + c->flags =3D KVM_CPUID_FLAG_STATEFUL_FUNC; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->= edx); } break; } @@ -83,46 +73,36 @@ int kvm_arch_init_vcpu(CPUState *env) case 0xb: case 0xd: for (j =3D 0; ; j++) { - cpu_x86_cpuid(env, i, j, &eax, &ebx, &ecx, &edx); c->function =3D i; c->flags =3D KVM_CPUID_FLAG_SIGNIFCANT_INDEX; c->index =3D j; - c->eax =3D eax; - c->ebx =3D ebx; - c->ecx =3D ecx; - c->edx =3D edx; - c =3D &cpuid_data.entries[++cpuid_i]; + cpu_x86_cpuid(env, i, j, &c->eax, &c->ebx, &c->ecx, &c->= edx); =20 - if (i =3D=3D 4 && eax =3D=3D 0) + if (i =3D=3D 4 && c->eax =3D=3D 0) break; - if (i =3D=3D 0xb && !(ecx & 0xff00)) + if (i =3D=3D 0xb && !(c->ecx & 0xff00)) break; - if (i =3D=3D 0xd && eax =3D=3D 0) + if (i =3D=3D 0xd && c->eax =3D=3D 0) break; + + c =3D &cpuid_data.entries[cpuid_i++]; } break; default: - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); c->function =3D i; - c->eax =3D eax; - c->ebx =3D ebx; - c->ecx =3D ecx; - c->edx =3D edx; + c->flags =3D 0; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx)= ; break; } } - cpu_x86_cpuid(env, 0x80000000, 0, &eax, &ebx, &ecx, &edx); - limit =3D eax; + cpu_x86_cpuid(env, 0x80000000, 0, &limit, &unused, &unused, &unused)= ; =20 for (i =3D 0x80000000; i <=3D limit; i++) { struct kvm_cpuid_entry2 *c =3D &cpuid_data.entries[cpuid_i++]; =20 - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); c->function =3D i; - c->eax =3D eax; - c->ebx =3D ebx; - c->ecx =3D ecx; - c->edx =3D edx; + c->flags =3D 0; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); } =20 cpuid_data.cpuid.nent =3D cpuid_i; --------------enig5B029D6F426D1244C188AA4D 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 iEYEARECAAYFAkni/XIACgkQniDOoMHTA+n4vgCfcvmkJnHWFDRlN74UcZOQPY7i KGoAn34MEHgKQWJnsiaAbwKoYLhKpv0+ =PvTV -----END PGP SIGNATURE----- --------------enig5B029D6F426D1244C188AA4D--