Skip to content

Commit 136d605

Browse files
committed
KVM: x86: Remove all direct usage of cpuid_entry2_find()
Convert all use of cpuid_entry2_find() to kvm_find_cpuid_entry{,index}() now that cpuid_entry2_find() operates on the vCPU state, i.e. now that there is no need to use cpuid_entry2_find() directly in order to pass in non-vCPU state. To help prevent unwanted usage of cpuid_entry2_find(), #undef KVM_CPUID_INDEX_NOT_SIGNIFICANT, i.e. force KVM to use kvm_find_cpuid_entry(). No functional change intended. Reviewed-by: Maxim Levitsky <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 8b30cb3 commit 136d605

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
156156
}
157157
EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
158158

159+
/*
160+
* cpuid_entry2_find() and KVM_CPUID_INDEX_NOT_SIGNIFICANT should never be used
161+
* directly outside of kvm_find_cpuid_entry() and kvm_find_cpuid_entry_index().
162+
*/
163+
#undef KVM_CPUID_INDEX_NOT_SIGNIFICANT
164+
159165
static int kvm_check_cpuid(struct kvm_vcpu *vcpu)
160166
{
161167
struct kvm_cpuid_entry2 *best;
@@ -165,8 +171,7 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu)
165171
* The existing code assumes virtual address is 48-bit or 57-bit in the
166172
* canonical address checks; exit if it is ever changed.
167173
*/
168-
best = cpuid_entry2_find(vcpu, 0x80000008,
169-
KVM_CPUID_INDEX_NOT_SIGNIFICANT);
174+
best = kvm_find_cpuid_entry(vcpu, 0x80000008);
170175
if (best) {
171176
int vaddr_bits = (best->eax & 0xff00) >> 8;
172177

@@ -178,7 +183,7 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu)
178183
* Exposing dynamic xfeatures to the guest requires additional
179184
* enabling in the FPU, e.g. to expand the guest XSAVE state size.
180185
*/
181-
best = cpuid_entry2_find(vcpu, 0xd, 0);
186+
best = kvm_find_cpuid_entry_index(vcpu, 0xd, 0);
182187
if (!best)
183188
return 0;
184189

@@ -232,7 +237,7 @@ static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcp
232237
u32 base;
233238

234239
for_each_possible_hypervisor_cpuid_base(base) {
235-
entry = cpuid_entry2_find(vcpu, base, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
240+
entry = kvm_find_cpuid_entry(vcpu, base);
236241

237242
if (entry) {
238243
u32 signature[3];
@@ -279,7 +284,7 @@ static u64 cpuid_get_supported_xcr0(struct kvm_vcpu *vcpu)
279284
{
280285
struct kvm_cpuid_entry2 *best;
281286

282-
best = cpuid_entry2_find(vcpu, 0xd, 0);
287+
best = kvm_find_cpuid_entry_index(vcpu, 0xd, 0);
283288
if (!best)
284289
return 0;
285290

@@ -290,7 +295,7 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
290295
{
291296
struct kvm_cpuid_entry2 *best;
292297

293-
best = cpuid_entry2_find(vcpu, 1, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
298+
best = kvm_find_cpuid_entry(vcpu, 1);
294299
if (best) {
295300
/* Update OSXSAVE bit */
296301
if (boot_cpu_has(X86_FEATURE_XSAVE))
@@ -301,22 +306,22 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
301306
vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE);
302307
}
303308

304-
best = cpuid_entry2_find(vcpu, 7, 0);
309+
best = kvm_find_cpuid_entry_index(vcpu, 7, 0);
305310
if (best && boot_cpu_has(X86_FEATURE_PKU) && best->function == 0x7)
306311
cpuid_entry_change(best, X86_FEATURE_OSPKE,
307312
kvm_is_cr4_bit_set(vcpu, X86_CR4_PKE));
308313

309-
best = cpuid_entry2_find(vcpu, 0xD, 0);
314+
best = kvm_find_cpuid_entry_index(vcpu, 0xD, 0);
310315
if (best)
311316
best->ebx = xstate_required_size(vcpu->arch.xcr0, false);
312317

313-
best = cpuid_entry2_find(vcpu, 0xD, 1);
318+
best = kvm_find_cpuid_entry_index(vcpu, 0xD, 1);
314319
if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
315320
cpuid_entry_has(best, X86_FEATURE_XSAVEC)))
316321
best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
317322

318323
if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) {
319-
best = cpuid_entry2_find(vcpu, 0x1, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
324+
best = kvm_find_cpuid_entry(vcpu, 0x1);
320325
if (best)
321326
cpuid_entry_change(best, X86_FEATURE_MWAIT,
322327
vcpu->arch.ia32_misc_enable_msr &
@@ -330,8 +335,7 @@ static bool kvm_cpuid_has_hyperv(struct kvm_vcpu *vcpu)
330335
#ifdef CONFIG_KVM_HYPERV
331336
struct kvm_cpuid_entry2 *entry;
332337

333-
entry = cpuid_entry2_find(vcpu, HYPERV_CPUID_INTERFACE,
334-
KVM_CPUID_INDEX_NOT_SIGNIFICANT);
338+
entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_INTERFACE);
335339
return entry && entry->eax == HYPERV_CPUID_SIGNATURE_EAX;
336340
#else
337341
return false;

0 commit comments

Comments
 (0)