Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LuvFn-0000Ix-SO for qemu-devel@nongnu.org; Fri, 17 Apr 2009 17:05:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LuvFn-0000I9-4F for qemu-devel@nongnu.org; Fri, 17 Apr 2009 17:05:43 -0400 Received: from [199.232.76.173] (port=57272 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LuvFm-0000Hs-T8 for qemu-devel@nongnu.org; Fri, 17 Apr 2009 17:05:42 -0400 Received: from savannah.gnu.org ([199.232.41.3]:45693 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LuvFm-00018e-FU for qemu-devel@nongnu.org; Fri, 17 Apr 2009 17:05:42 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LuvFl-0008Aj-Qz for qemu-devel@nongnu.org; Fri, 17 Apr 2009 21:05:41 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LuvFl-0008Af-KR for qemu-devel@nongnu.org; Fri, 17 Apr 2009 21:05:41 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Fri, 17 Apr 2009 21:05:41 +0000 Subject: [Qemu-devel] [7170] kvm: Fix cpuid initialization (Jan Kiszka) 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@nongnu.org Revision: 7170 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7170 Author: aliguori Date: 2009-04-17 21:05:41 +0000 (Fri, 17 Apr 2009) Log Message: ----------- kvm: Fix cpuid initialization (Jan Kiszka) 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 Signed-off-by: Anthony Liguori Modified Paths: -------------- branches/stable_0_10/target-i386/kvm.c Modified: branches/stable_0_10/target-i386/kvm.c =================================================================== --- branches/stable_0_10/target-i386/kvm.c 2009-04-17 21:01:11 UTC (rev 7169) +++ branches/stable_0_10/target-i386/kvm.c 2009-04-17 21:05:41 UTC (rev 7170) @@ -40,12 +40,11 @@ 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; cpuid_i = 0; - cpu_x86_cpuid(env, 0, 0, &eax, &ebx, &ecx, &edx); - limit = eax; + cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused); for (i = 0; i <= limit; i++) { struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++]; @@ -55,26 +54,17 @@ /* Keep reading function 2 till all the input is received */ int times; - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); - times = eax & 0xff; - c->function = i; - c->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC; - c->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT; - c->eax = eax; - c->ebx = ebx; - c->ecx = ecx; - c->edx = edx; + c->flags = 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 = c->eax & 0xff; for (j = 1; j < times; ++j) { - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); + c = &cpuid_data.entries[cpuid_i++]; c->function = i; - c->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC; - c->eax = eax; - c->ebx = ebx; - c->ecx = ecx; - c->edx = edx; - c = &cpuid_data.entries[++cpuid_i]; + c->flags = KVM_CPUID_FLAG_STATEFUL_FUNC; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); } break; } @@ -82,46 +72,36 @@ case 0xb: case 0xd: for (j = 0; ; j++) { - cpu_x86_cpuid(env, i, j, &eax, &ebx, &ecx, &edx); c->function = i; c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX; c->index = j; - c->eax = eax; - c->ebx = ebx; - c->ecx = ecx; - c->edx = edx; - c = &cpuid_data.entries[++cpuid_i]; + cpu_x86_cpuid(env, i, j, &c->eax, &c->ebx, &c->ecx, &c->edx); - if (i == 4 && eax == 0) + if (i == 4 && c->eax == 0) break; - if (i == 0xb && !(ecx & 0xff00)) + if (i == 0xb && !(c->ecx & 0xff00)) break; - if (i == 0xd && eax == 0) + if (i == 0xd && c->eax == 0) break; + + c = &cpuid_data.entries[cpuid_i++]; } break; default: - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); c->function = i; - c->eax = eax; - c->ebx = ebx; - c->ecx = ecx; - c->edx = edx; + c->flags = 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 = eax; + cpu_x86_cpuid(env, 0x80000000, 0, &limit, &unused, &unused, &unused); for (i = 0x80000000; i <= limit; i++) { struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++]; - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); c->function = i; - c->eax = eax; - c->ebx = ebx; - c->ecx = ecx; - c->edx = edx; + c->flags = 0; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); } cpuid_data.cpuid.nent = cpuid_i;