Commit a33609cae0d57a7574608145f553cc5279221c31
1 parent
641636d1
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 <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7167 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
20 additions
and
40 deletions
target-i386/kvm.c
... | ... | @@ -41,12 +41,11 @@ int kvm_arch_init_vcpu(CPUState *env) |
41 | 41 | struct kvm_cpuid_entry2 entries[100]; |
42 | 42 | } __attribute__((packed)) cpuid_data; |
43 | 43 | uint32_t limit, i, j, cpuid_i; |
44 | - uint32_t eax, ebx, ecx, edx; | |
44 | + uint32_t unused; | |
45 | 45 | |
46 | 46 | cpuid_i = 0; |
47 | 47 | |
48 | - cpu_x86_cpuid(env, 0, 0, &eax, &ebx, &ecx, &edx); | |
49 | - limit = eax; | |
48 | + cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused); | |
50 | 49 | |
51 | 50 | for (i = 0; i <= limit; i++) { |
52 | 51 | struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++]; |
... | ... | @@ -56,26 +55,17 @@ int kvm_arch_init_vcpu(CPUState *env) |
56 | 55 | /* Keep reading function 2 till all the input is received */ |
57 | 56 | int times; |
58 | 57 | |
59 | - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); | |
60 | - times = eax & 0xff; | |
61 | - | |
62 | 58 | c->function = i; |
63 | - c->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC; | |
64 | - c->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT; | |
65 | - c->eax = eax; | |
66 | - c->ebx = ebx; | |
67 | - c->ecx = ecx; | |
68 | - c->edx = edx; | |
59 | + c->flags = KVM_CPUID_FLAG_STATEFUL_FUNC | | |
60 | + KVM_CPUID_FLAG_STATE_READ_NEXT; | |
61 | + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); | |
62 | + times = c->eax & 0xff; | |
69 | 63 | |
70 | 64 | for (j = 1; j < times; ++j) { |
71 | - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); | |
65 | + c = &cpuid_data.entries[cpuid_i++]; | |
72 | 66 | c->function = i; |
73 | - c->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC; | |
74 | - c->eax = eax; | |
75 | - c->ebx = ebx; | |
76 | - c->ecx = ecx; | |
77 | - c->edx = edx; | |
78 | - c = &cpuid_data.entries[++cpuid_i]; | |
67 | + c->flags = KVM_CPUID_FLAG_STATEFUL_FUNC; | |
68 | + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); | |
79 | 69 | } |
80 | 70 | break; |
81 | 71 | } |
... | ... | @@ -83,46 +73,36 @@ int kvm_arch_init_vcpu(CPUState *env) |
83 | 73 | case 0xb: |
84 | 74 | case 0xd: |
85 | 75 | for (j = 0; ; j++) { |
86 | - cpu_x86_cpuid(env, i, j, &eax, &ebx, &ecx, &edx); | |
87 | 76 | c->function = i; |
88 | 77 | c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX; |
89 | 78 | c->index = j; |
90 | - c->eax = eax; | |
91 | - c->ebx = ebx; | |
92 | - c->ecx = ecx; | |
93 | - c->edx = edx; | |
94 | - c = &cpuid_data.entries[++cpuid_i]; | |
79 | + cpu_x86_cpuid(env, i, j, &c->eax, &c->ebx, &c->ecx, &c->edx); | |
95 | 80 | |
96 | - if (i == 4 && eax == 0) | |
81 | + if (i == 4 && c->eax == 0) | |
97 | 82 | break; |
98 | - if (i == 0xb && !(ecx & 0xff00)) | |
83 | + if (i == 0xb && !(c->ecx & 0xff00)) | |
99 | 84 | break; |
100 | - if (i == 0xd && eax == 0) | |
85 | + if (i == 0xd && c->eax == 0) | |
101 | 86 | break; |
87 | + | |
88 | + c = &cpuid_data.entries[cpuid_i++]; | |
102 | 89 | } |
103 | 90 | break; |
104 | 91 | default: |
105 | - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); | |
106 | 92 | c->function = i; |
107 | - c->eax = eax; | |
108 | - c->ebx = ebx; | |
109 | - c->ecx = ecx; | |
110 | - c->edx = edx; | |
93 | + c->flags = 0; | |
94 | + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); | |
111 | 95 | break; |
112 | 96 | } |
113 | 97 | } |
114 | - cpu_x86_cpuid(env, 0x80000000, 0, &eax, &ebx, &ecx, &edx); | |
115 | - limit = eax; | |
98 | + cpu_x86_cpuid(env, 0x80000000, 0, &limit, &unused, &unused, &unused); | |
116 | 99 | |
117 | 100 | for (i = 0x80000000; i <= limit; i++) { |
118 | 101 | struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++]; |
119 | 102 | |
120 | - cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx); | |
121 | 103 | c->function = i; |
122 | - c->eax = eax; | |
123 | - c->ebx = ebx; | |
124 | - c->ecx = ecx; | |
125 | - c->edx = edx; | |
104 | + c->flags = 0; | |
105 | + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); | |
126 | 106 | } |
127 | 107 | |
128 | 108 | cpuid_data.cpuid.nent = cpuid_i; | ... | ... |