@@ -91,8 +91,8 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted)
91
91
*/
92
92
#define KVM_CPUID_INDEX_NOT_SIGNIFICANT -1ull
93
93
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 )
96
96
{
97
97
struct kvm_cpuid_entry2 * e ;
98
98
int i ;
@@ -109,8 +109,8 @@ static inline struct kvm_cpuid_entry2 *cpuid_entry2_find(
109
109
*/
110
110
lockdep_assert_irqs_enabled ();
111
111
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 ];
114
114
115
115
if (e -> function != function )
116
116
continue ;
@@ -144,16 +144,14 @@ static inline struct kvm_cpuid_entry2 *cpuid_entry2_find(
144
144
145
145
static int kvm_check_cpuid (struct kvm_vcpu * vcpu )
146
146
{
147
- struct kvm_cpuid_entry2 * entries = vcpu -> arch .cpuid_entries ;
148
- int nent = vcpu -> arch .cpuid_nent ;
149
147
struct kvm_cpuid_entry2 * best ;
150
148
u64 xfeatures ;
151
149
152
150
/*
153
151
* The existing code assumes virtual address is 48-bit or 57-bit in the
154
152
* canonical address checks; exit if it is ever changed.
155
153
*/
156
- best = cpuid_entry2_find (entries , nent , 0x80000008 ,
154
+ best = cpuid_entry2_find (vcpu , 0x80000008 ,
157
155
KVM_CPUID_INDEX_NOT_SIGNIFICANT );
158
156
if (best ) {
159
157
int vaddr_bits = (best -> eax & 0xff00 ) >> 8 ;
@@ -166,7 +164,7 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu)
166
164
* Exposing dynamic xfeatures to the guest requires additional
167
165
* enabling in the FPU, e.g. to expand the guest XSAVE state size.
168
166
*/
169
- best = cpuid_entry2_find (entries , nent , 0xd , 0 );
167
+ best = cpuid_entry2_find (vcpu , 0xd , 0 );
170
168
if (!best )
171
169
return 0 ;
172
170
@@ -212,15 +210,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
212
210
return 0 ;
213
211
}
214
212
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 )
217
215
{
218
216
struct kvm_hypervisor_cpuid cpuid = {};
219
217
struct kvm_cpuid_entry2 * entry ;
220
218
u32 base ;
221
219
222
220
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 );
224
222
225
223
if (entry ) {
226
224
u32 signature [3 ];
@@ -240,13 +238,6 @@ static struct kvm_hypervisor_cpuid __kvm_get_hypervisor_cpuid(struct kvm_cpuid_e
240
238
return cpuid ;
241
239
}
242
240
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
-
250
241
static u32 kvm_apply_cpuid_pv_features_quirk (struct kvm_vcpu * vcpu )
251
242
{
252
243
struct kvm_hypervisor_cpuid kvm_cpuid ;
@@ -270,23 +261,22 @@ static u32 kvm_apply_cpuid_pv_features_quirk(struct kvm_vcpu *vcpu)
270
261
* Calculate guest's supported XCR0 taking into account guest CPUID data and
271
262
* KVM's supported XCR0 (comprised of host's XCR0 and KVM_SUPPORTED_XCR0).
272
263
*/
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 )
274
265
{
275
266
struct kvm_cpuid_entry2 * best ;
276
267
277
- best = cpuid_entry2_find (entries , nent , 0xd , 0 );
268
+ best = cpuid_entry2_find (vcpu , 0xd , 0 );
278
269
if (!best )
279
270
return 0 ;
280
271
281
272
return (best -> eax | ((u64 )best -> edx << 32 )) & kvm_caps .supported_xcr0 ;
282
273
}
283
274
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 )
286
276
{
287
277
struct kvm_cpuid_entry2 * best ;
288
278
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 );
290
280
if (best ) {
291
281
/* Update OSXSAVE bit */
292
282
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
297
287
vcpu -> arch .apic_base & MSR_IA32_APICBASE_ENABLE );
298
288
}
299
289
300
- best = cpuid_entry2_find (entries , nent , 7 , 0 );
290
+ best = cpuid_entry2_find (vcpu , 7 , 0 );
301
291
if (best && boot_cpu_has (X86_FEATURE_PKU ) && best -> function == 0x7 )
302
292
cpuid_entry_change (best , X86_FEATURE_OSPKE ,
303
293
kvm_is_cr4_bit_set (vcpu , X86_CR4_PKE ));
304
294
305
- best = cpuid_entry2_find (entries , nent , 0xD , 0 );
295
+ best = cpuid_entry2_find (vcpu , 0xD , 0 );
306
296
if (best )
307
297
best -> ebx = xstate_required_size (vcpu -> arch .xcr0 , false);
308
298
309
- best = cpuid_entry2_find (entries , nent , 0xD , 1 );
299
+ best = cpuid_entry2_find (vcpu , 0xD , 1 );
310
300
if (best && (cpuid_entry_has (best , X86_FEATURE_XSAVES ) ||
311
301
cpuid_entry_has (best , X86_FEATURE_XSAVEC )))
312
302
best -> ebx = xstate_required_size (vcpu -> arch .xcr0 , true);
313
303
314
304
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 );
316
306
if (best )
317
307
cpuid_entry_change (best , X86_FEATURE_MWAIT ,
318
308
vcpu -> arch .ia32_misc_enable_msr &
319
309
MSR_IA32_MISC_ENABLE_MWAIT );
320
310
}
321
311
}
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
- }
327
312
EXPORT_SYMBOL_GPL (kvm_update_cpuid_runtime );
328
313
329
314
static bool kvm_cpuid_has_hyperv (struct kvm_vcpu * vcpu )
330
315
{
331
316
#ifdef CONFIG_KVM_HYPERV
332
- struct kvm_cpuid_entry2 * entries = vcpu -> arch .cpuid_entries ;
333
- int nent = vcpu -> arch .cpuid_nent ;
334
317
struct kvm_cpuid_entry2 * entry ;
335
318
336
- entry = cpuid_entry2_find (entries , nent , HYPERV_CPUID_INTERFACE ,
319
+ entry = cpuid_entry2_find (vcpu , HYPERV_CPUID_INTERFACE ,
337
320
KVM_CPUID_INDEX_NOT_SIGNIFICANT );
338
321
return entry && entry -> eax == HYPERV_CPUID_SIGNATURE_EAX ;
339
322
#else
@@ -391,8 +374,7 @@ void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
391
374
kvm_apic_set_version (vcpu );
392
375
}
393
376
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 );
396
378
397
379
vcpu -> arch .pv_cpuid .features = kvm_apply_cpuid_pv_features_quirk (vcpu );
398
380
@@ -1777,16 +1759,14 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
1777
1759
struct kvm_cpuid_entry2 * kvm_find_cpuid_entry_index (struct kvm_vcpu * vcpu ,
1778
1760
u32 function , u32 index )
1779
1761
{
1780
- return cpuid_entry2_find (vcpu -> arch .cpuid_entries , vcpu -> arch .cpuid_nent ,
1781
- function , index );
1762
+ return cpuid_entry2_find (vcpu , function , index );
1782
1763
}
1783
1764
EXPORT_SYMBOL_GPL (kvm_find_cpuid_entry_index );
1784
1765
1785
1766
struct kvm_cpuid_entry2 * kvm_find_cpuid_entry (struct kvm_vcpu * vcpu ,
1786
1767
u32 function )
1787
1768
{
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 );
1790
1770
}
1791
1771
EXPORT_SYMBOL_GPL (kvm_find_cpuid_entry );
1792
1772
0 commit comments