@@ -189,15 +189,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
189189 return 0 ;
190190}
191191
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 )
194194{
195195 struct kvm_hypervisor_cpuid cpuid = {};
196196 struct kvm_cpuid_entry2 * entry ;
197197 u32 base ;
198198
199199 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 );
201201
202202 if (entry ) {
203203 u32 signature [3 ];
@@ -217,22 +217,29 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcp
217217 return cpuid ;
218218}
219219
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 )
222222{
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+ }
227226
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 ,
229231 KVM_CPUID_INDEX_NOT_SIGNIFICANT );
230232}
231233
232234static struct kvm_cpuid_entry2 * kvm_find_kvm_cpuid_features (struct kvm_vcpu * vcpu )
233235{
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 );
236243}
237244
238245void 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
266273 int nent )
267274{
268275 struct kvm_cpuid_entry2 * best ;
276+ struct kvm_hypervisor_cpuid kvm_cpuid ;
269277
270278 best = cpuid_entry2_find (entries , nent , 1 , KVM_CPUID_INDEX_NOT_SIGNIFICANT );
271279 if (best ) {
@@ -292,10 +300,12 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_e
292300 cpuid_entry_has (best , X86_FEATURE_XSAVEC )))
293301 best -> ebx = xstate_required_size (vcpu -> arch .xcr0 , true);
294302
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+ }
299309
300310 if (!kvm_check_has_quirk (vcpu -> kvm , KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT )) {
301311 best = cpuid_entry2_find (entries , nent , 0x1 , KVM_CPUID_INDEX_NOT_SIGNIFICANT );
0 commit comments