@@ -189,15 +189,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
189
189
return 0 ;
190
190
}
191
191
192
- static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid (struct kvm_vcpu * vcpu ,
193
- const char * sig )
192
+ static struct kvm_hypervisor_cpuid __kvm_get_hypervisor_cpuid (struct kvm_cpuid_entry2 * entries ,
193
+ int nent , const char * sig )
194
194
{
195
195
struct kvm_hypervisor_cpuid cpuid = {};
196
196
struct kvm_cpuid_entry2 * entry ;
197
197
u32 base ;
198
198
199
199
for_each_possible_hypervisor_cpuid_base (base ) {
200
- entry = kvm_find_cpuid_entry ( vcpu , base );
200
+ entry = cpuid_entry2_find ( entries , nent , base , KVM_CPUID_INDEX_NOT_SIGNIFICANT );
201
201
202
202
if (entry ) {
203
203
u32 signature [3 ];
@@ -217,22 +217,29 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcp
217
217
return cpuid ;
218
218
}
219
219
220
- static struct kvm_cpuid_entry2 * __kvm_find_kvm_cpuid_features (struct kvm_vcpu * vcpu ,
221
- struct kvm_cpuid_entry2 * entries , int nent )
220
+ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid (struct kvm_vcpu * vcpu ,
221
+ const char * sig )
222
222
{
223
- u32 base = vcpu -> arch .kvm_cpuid .base ;
224
-
225
- if (!base )
226
- return NULL ;
223
+ return __kvm_get_hypervisor_cpuid (vcpu -> arch .cpuid_entries ,
224
+ vcpu -> arch .cpuid_nent , sig );
225
+ }
227
226
228
- return cpuid_entry2_find (entries , nent , base | KVM_CPUID_FEATURES ,
227
+ static struct kvm_cpuid_entry2 * __kvm_find_kvm_cpuid_features (struct kvm_cpuid_entry2 * entries ,
228
+ int nent , u32 kvm_cpuid_base )
229
+ {
230
+ return cpuid_entry2_find (entries , nent , kvm_cpuid_base | KVM_CPUID_FEATURES ,
229
231
KVM_CPUID_INDEX_NOT_SIGNIFICANT );
230
232
}
231
233
232
234
static struct kvm_cpuid_entry2 * kvm_find_kvm_cpuid_features (struct kvm_vcpu * vcpu )
233
235
{
234
- return __kvm_find_kvm_cpuid_features (vcpu , vcpu -> arch .cpuid_entries ,
235
- vcpu -> arch .cpuid_nent );
236
+ u32 base = vcpu -> arch .kvm_cpuid .base ;
237
+
238
+ if (!base )
239
+ return NULL ;
240
+
241
+ return __kvm_find_kvm_cpuid_features (vcpu -> arch .cpuid_entries ,
242
+ vcpu -> arch .cpuid_nent , base );
236
243
}
237
244
238
245
void kvm_update_pv_runtime (struct kvm_vcpu * vcpu )
@@ -266,6 +273,7 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_e
266
273
int nent )
267
274
{
268
275
struct kvm_cpuid_entry2 * best ;
276
+ struct kvm_hypervisor_cpuid kvm_cpuid ;
269
277
270
278
best = cpuid_entry2_find (entries , nent , 1 , KVM_CPUID_INDEX_NOT_SIGNIFICANT );
271
279
if (best ) {
@@ -292,10 +300,12 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_e
292
300
cpuid_entry_has (best , X86_FEATURE_XSAVEC )))
293
301
best -> ebx = xstate_required_size (vcpu -> arch .xcr0 , true);
294
302
295
- best = __kvm_find_kvm_cpuid_features (vcpu , entries , nent );
296
- if (kvm_hlt_in_guest (vcpu -> kvm ) && best &&
297
- (best -> eax & (1 << KVM_FEATURE_PV_UNHALT )))
298
- best -> eax &= ~(1 << KVM_FEATURE_PV_UNHALT );
303
+ kvm_cpuid = __kvm_get_hypervisor_cpuid (entries , nent , KVM_SIGNATURE );
304
+ if (kvm_cpuid .base ) {
305
+ best = __kvm_find_kvm_cpuid_features (entries , nent , kvm_cpuid .base );
306
+ if (kvm_hlt_in_guest (vcpu -> kvm ) && best )
307
+ best -> eax &= ~(1 << KVM_FEATURE_PV_UNHALT );
308
+ }
299
309
300
310
if (!kvm_check_has_quirk (vcpu -> kvm , KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT )) {
301
311
best = cpuid_entry2_find (entries , nent , 0x1 , KVM_CPUID_INDEX_NOT_SIGNIFICANT );
0 commit comments