Skip to content

Commit 285185f

Browse files
committed
KVM: x86: Always operate on kvm_vcpu data in cpuid_entry2_find()
Now that KVM sets vcpu->arch.cpuid_{entries,nent} before processing the incoming CPUID entries during KVM_SET_CPUID{,2}, drop the @entries and @nent params from cpuid_entry2_find() and unconditionally operate on the vCPU state. 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 a5b3271 commit 285185f

File tree

1 file changed

+21
-41
lines changed

1 file changed

+21
-41
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted)
9191
*/
9292
#define KVM_CPUID_INDEX_NOT_SIGNIFICANT -1ull
9393

94-
static inline struct kvm_cpuid_entry2 *cpuid_entry2_find(
95-
struct kvm_cpuid_entry2 *entries, int nent, u32 function, u64 index)
94+
static struct kvm_cpuid_entry2 *cpuid_entry2_find(struct kvm_vcpu *vcpu,
95+
u32 function, u64 index)
9696
{
9797
struct kvm_cpuid_entry2 *e;
9898
int i;
@@ -109,8 +109,8 @@ static inline struct kvm_cpuid_entry2 *cpuid_entry2_find(
109109
*/
110110
lockdep_assert_irqs_enabled();
111111

112-
for (i = 0; i < nent; i++) {
113-
e = &entries[i];
112+
for (i = 0; i < vcpu->arch.cpuid_nent; i++) {
113+
e = &vcpu->arch.cpuid_entries[i];
114114

115115
if (e->function != function)
116116
continue;
@@ -144,16 +144,14 @@ static inline struct kvm_cpuid_entry2 *cpuid_entry2_find(
144144

145145
static int kvm_check_cpuid(struct kvm_vcpu *vcpu)
146146
{
147-
struct kvm_cpuid_entry2 *entries = vcpu->arch.cpuid_entries;
148-
int nent = vcpu->arch.cpuid_nent;
149147
struct kvm_cpuid_entry2 *best;
150148
u64 xfeatures;
151149

152150
/*
153151
* The existing code assumes virtual address is 48-bit or 57-bit in the
154152
* canonical address checks; exit if it is ever changed.
155153
*/
156-
best = cpuid_entry2_find(entries, nent, 0x80000008,
154+
best = cpuid_entry2_find(vcpu, 0x80000008,
157155
KVM_CPUID_INDEX_NOT_SIGNIFICANT);
158156
if (best) {
159157
int vaddr_bits = (best->eax & 0xff00) >> 8;
@@ -166,7 +164,7 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu)
166164
* Exposing dynamic xfeatures to the guest requires additional
167165
* enabling in the FPU, e.g. to expand the guest XSAVE state size.
168166
*/
169-
best = cpuid_entry2_find(entries, nent, 0xd, 0);
167+
best = cpuid_entry2_find(vcpu, 0xd, 0);
170168
if (!best)
171169
return 0;
172170

@@ -212,15 +210,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
212210
return 0;
213211
}
214212

215-
static struct kvm_hypervisor_cpuid __kvm_get_hypervisor_cpuid(struct kvm_cpuid_entry2 *entries,
216-
int nent, const char *sig)
213+
static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu,
214+
const char *sig)
217215
{
218216
struct kvm_hypervisor_cpuid cpuid = {};
219217
struct kvm_cpuid_entry2 *entry;
220218
u32 base;
221219

222220
for_each_possible_hypervisor_cpuid_base(base) {
223-
entry = cpuid_entry2_find(entries, nent, base, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
221+
entry = cpuid_entry2_find(vcpu, base, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
224222

225223
if (entry) {
226224
u32 signature[3];
@@ -240,13 +238,6 @@ static struct kvm_hypervisor_cpuid __kvm_get_hypervisor_cpuid(struct kvm_cpuid_e
240238
return cpuid;
241239
}
242240

243-
static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu,
244-
const char *sig)
245-
{
246-
return __kvm_get_hypervisor_cpuid(vcpu->arch.cpuid_entries,
247-
vcpu->arch.cpuid_nent, sig);
248-
}
249-
250241
static u32 kvm_apply_cpuid_pv_features_quirk(struct kvm_vcpu *vcpu)
251242
{
252243
struct kvm_hypervisor_cpuid kvm_cpuid;
@@ -270,23 +261,22 @@ static u32 kvm_apply_cpuid_pv_features_quirk(struct kvm_vcpu *vcpu)
270261
* Calculate guest's supported XCR0 taking into account guest CPUID data and
271262
* KVM's supported XCR0 (comprised of host's XCR0 and KVM_SUPPORTED_XCR0).
272263
*/
273-
static u64 cpuid_get_supported_xcr0(struct kvm_cpuid_entry2 *entries, int nent)
264+
static u64 cpuid_get_supported_xcr0(struct kvm_vcpu *vcpu)
274265
{
275266
struct kvm_cpuid_entry2 *best;
276267

277-
best = cpuid_entry2_find(entries, nent, 0xd, 0);
268+
best = cpuid_entry2_find(vcpu, 0xd, 0);
278269
if (!best)
279270
return 0;
280271

281272
return (best->eax | ((u64)best->edx << 32)) & kvm_caps.supported_xcr0;
282273
}
283274

284-
static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *entries,
285-
int nent)
275+
void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
286276
{
287277
struct kvm_cpuid_entry2 *best;
288278

289-
best = cpuid_entry2_find(entries, nent, 1, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
279+
best = cpuid_entry2_find(vcpu, 1, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
290280
if (best) {
291281
/* Update OSXSAVE bit */
292282
if (boot_cpu_has(X86_FEATURE_XSAVE))
@@ -297,43 +287,36 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_e
297287
vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE);
298288
}
299289

300-
best = cpuid_entry2_find(entries, nent, 7, 0);
290+
best = cpuid_entry2_find(vcpu, 7, 0);
301291
if (best && boot_cpu_has(X86_FEATURE_PKU) && best->function == 0x7)
302292
cpuid_entry_change(best, X86_FEATURE_OSPKE,
303293
kvm_is_cr4_bit_set(vcpu, X86_CR4_PKE));
304294

305-
best = cpuid_entry2_find(entries, nent, 0xD, 0);
295+
best = cpuid_entry2_find(vcpu, 0xD, 0);
306296
if (best)
307297
best->ebx = xstate_required_size(vcpu->arch.xcr0, false);
308298

309-
best = cpuid_entry2_find(entries, nent, 0xD, 1);
299+
best = cpuid_entry2_find(vcpu, 0xD, 1);
310300
if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
311301
cpuid_entry_has(best, X86_FEATURE_XSAVEC)))
312302
best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
313303

314304
if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) {
315-
best = cpuid_entry2_find(entries, nent, 0x1, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
305+
best = cpuid_entry2_find(vcpu, 0x1, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
316306
if (best)
317307
cpuid_entry_change(best, X86_FEATURE_MWAIT,
318308
vcpu->arch.ia32_misc_enable_msr &
319309
MSR_IA32_MISC_ENABLE_MWAIT);
320310
}
321311
}
322-
323-
void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
324-
{
325-
__kvm_update_cpuid_runtime(vcpu, vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
326-
}
327312
EXPORT_SYMBOL_GPL(kvm_update_cpuid_runtime);
328313

329314
static bool kvm_cpuid_has_hyperv(struct kvm_vcpu *vcpu)
330315
{
331316
#ifdef CONFIG_KVM_HYPERV
332-
struct kvm_cpuid_entry2 *entries = vcpu->arch.cpuid_entries;
333-
int nent = vcpu->arch.cpuid_nent;
334317
struct kvm_cpuid_entry2 *entry;
335318

336-
entry = cpuid_entry2_find(entries, nent, HYPERV_CPUID_INTERFACE,
319+
entry = cpuid_entry2_find(vcpu, HYPERV_CPUID_INTERFACE,
337320
KVM_CPUID_INDEX_NOT_SIGNIFICANT);
338321
return entry && entry->eax == HYPERV_CPUID_SIGNATURE_EAX;
339322
#else
@@ -391,8 +374,7 @@ void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
391374
kvm_apic_set_version(vcpu);
392375
}
393376

394-
vcpu->arch.guest_supported_xcr0 =
395-
cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
377+
vcpu->arch.guest_supported_xcr0 = cpuid_get_supported_xcr0(vcpu);
396378

397379
vcpu->arch.pv_cpuid.features = kvm_apply_cpuid_pv_features_quirk(vcpu);
398380

@@ -1777,16 +1759,14 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
17771759
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry_index(struct kvm_vcpu *vcpu,
17781760
u32 function, u32 index)
17791761
{
1780-
return cpuid_entry2_find(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
1781-
function, index);
1762+
return cpuid_entry2_find(vcpu, function, index);
17821763
}
17831764
EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry_index);
17841765

17851766
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
17861767
u32 function)
17871768
{
1788-
return cpuid_entry2_find(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent,
1789-
function, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
1769+
return cpuid_entry2_find(vcpu, function, KVM_CPUID_INDEX_NOT_SIGNIFICANT);
17901770
}
17911771
EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
17921772

0 commit comments

Comments
 (0)