@@ -63,22 +63,24 @@ static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcp
63
63
return entry ;
64
64
}
65
65
66
- static inline int set_vcpuid_entry (struct acrn_vm * vm ,
66
+ static inline int32_t set_vcpuid_entry (struct acrn_vm * vm ,
67
67
const struct vcpuid_entry * entry )
68
68
{
69
69
struct vcpuid_entry * tmp ;
70
70
size_t entry_size = sizeof (struct vcpuid_entry );
71
+ int32_t ret ;
71
72
72
73
if (vm -> vcpuid_entry_nr == MAX_VM_VCPUID_ENTRIES ) {
73
74
pr_err ("%s, vcpuid entry over MAX_VM_VCPUID_ENTRIES(%u)\n" ,
74
75
__func__ , MAX_VM_VCPUID_ENTRIES );
75
- return - ENOMEM ;
76
+ ret = - ENOMEM ;
77
+ } else {
78
+ tmp = & vm -> vcpuid_entries [vm -> vcpuid_entry_nr ];
79
+ vm -> vcpuid_entry_nr ++ ;
80
+ (void )memcpy_s (tmp , entry_size , entry , entry_size );
81
+ ret = 0 ;
76
82
}
77
-
78
- tmp = & vm -> vcpuid_entries [vm -> vcpuid_entry_nr ];
79
- vm -> vcpuid_entry_nr ++ ;
80
- (void )memcpy_s (tmp , entry_size , entry , entry_size );
81
- return 0 ;
83
+ return ret ;
82
84
}
83
85
84
86
/**
@@ -320,102 +322,100 @@ void guest_cpuid(struct acrn_vcpu *vcpu,
320
322
* ecx = 0U ;
321
323
* edx = 0U ;
322
324
}
323
-
324
- return ;
325
- }
326
-
327
- /* percpu related */
328
- switch (leaf ) {
329
- case 0x01U :
330
- {
331
- cpuid (leaf , eax , ebx , ecx , edx );
332
- uint32_t apicid = vlapic_get_apicid (vcpu_vlapic (vcpu ));
333
- /* Patching initial APIC ID */
334
- * ebx &= ~APIC_ID_MASK ;
335
- * ebx |= (apicid << APIC_ID_SHIFT );
325
+ } else {
326
+ /* percpu related */
327
+ switch (leaf ) {
328
+ case 0x01U :
329
+ {
330
+ cpuid (leaf , eax , ebx , ecx , edx );
331
+ uint32_t apicid = vlapic_get_apicid (vcpu_vlapic (vcpu ));
332
+ /* Patching initial APIC ID */
333
+ * ebx &= ~APIC_ID_MASK ;
334
+ * ebx |= (apicid << APIC_ID_SHIFT );
336
335
337
336
#ifndef CONFIG_MTRR_ENABLED
338
- /* mask mtrr */
339
- * edx &= ~CPUID_EDX_MTRR ;
337
+ /* mask mtrr */
338
+ * edx &= ~CPUID_EDX_MTRR ;
340
339
#endif
341
340
342
- /* mask pcid */
343
- * ecx &= ~CPUID_ECX_PCID ;
341
+ /* mask pcid */
342
+ * ecx &= ~CPUID_ECX_PCID ;
344
343
345
- /*mask vmx to guest os */
346
- * ecx &= ~CPUID_ECX_VMX ;
344
+ /*mask vmx to guest os */
345
+ * ecx &= ~CPUID_ECX_VMX ;
347
346
348
- /*no xsave support for guest if it is not enabled on host*/
349
- if ((* ecx & CPUID_ECX_OSXSAVE ) == 0U ) {
350
- * ecx &= ~CPUID_ECX_XSAVE ;
351
- }
347
+ /*no xsave support for guest if it is not enabled on host*/
348
+ if ((* ecx & CPUID_ECX_OSXSAVE ) == 0U ) {
349
+ * ecx &= ~CPUID_ECX_XSAVE ;
350
+ }
352
351
353
- * ecx &= ~CPUID_ECX_OSXSAVE ;
354
- if ((* ecx & CPUID_ECX_XSAVE ) != 0U ) {
355
- uint64_t cr4 ;
356
- /*read guest CR4*/
357
- cr4 = exec_vmread (VMX_GUEST_CR4 );
358
- if ((cr4 & CR4_OSXSAVE ) != 0UL ) {
359
- * ecx |= CPUID_ECX_OSXSAVE ;
352
+ * ecx &= ~CPUID_ECX_OSXSAVE ;
353
+ if ((* ecx & CPUID_ECX_XSAVE ) != 0U ) {
354
+ uint64_t cr4 ;
355
+ /*read guest CR4*/
356
+ cr4 = exec_vmread (VMX_GUEST_CR4 );
357
+ if ((cr4 & CR4_OSXSAVE ) != 0UL ) {
358
+ * ecx |= CPUID_ECX_OSXSAVE ;
359
+ }
360
360
}
361
+ break ;
361
362
}
362
- break ;
363
- }
364
363
365
- case 0x0bU :
366
- /* Patching X2APIC */
364
+ case 0x0bU :
365
+ /* Patching X2APIC */
367
366
#ifdef CONFIG_PARTITION_MODE
368
- cpuid_subleaf (leaf , subleaf , eax , ebx , ecx , edx );
369
- #else
370
- if (is_vm0 (vcpu -> vm )) {
371
367
cpuid_subleaf (leaf , subleaf , eax , ebx , ecx , edx );
372
- } else {
373
- * ecx = subleaf & 0xFFU ;
374
- * edx = vlapic_get_apicid (vcpu_vlapic (vcpu ));
375
- /* No HT emulation for UOS */
376
- switch (subleaf ) {
377
- case 0U :
378
- * eax = 0U ;
379
- * ebx = 1U ;
380
- * ecx |= (1U << 8U );
381
- break ;
382
- case 1U :
383
- if (vcpu -> vm -> hw .created_vcpus == 1U ) {
368
+ #else
369
+ if (is_vm0 (vcpu -> vm )) {
370
+ cpuid_subleaf (leaf , subleaf , eax , ebx , ecx , edx );
371
+ } else {
372
+ * ecx = subleaf & 0xFFU ;
373
+ * edx = vlapic_get_apicid (vcpu_vlapic (vcpu ));
374
+ /* No HT emulation for UOS */
375
+ switch (subleaf ) {
376
+ case 0U :
384
377
* eax = 0U ;
385
- } else {
386
- * eax = (uint32_t )fls32 (vcpu -> vm -> hw .created_vcpus - 1U ) + 1U ;
378
+ * ebx = 1U ;
379
+ * ecx |= (1U << 8U );
380
+ break ;
381
+ case 1U :
382
+ if (vcpu -> vm -> hw .created_vcpus == 1U ) {
383
+ * eax = 0U ;
384
+ } else {
385
+ * eax = (uint32_t )fls32 (vcpu -> vm -> hw .created_vcpus - 1U ) + 1U ;
386
+ }
387
+ * ebx = vcpu -> vm -> hw .created_vcpus ;
388
+ * ecx |= (2U << 8U );
389
+ break ;
390
+ default :
391
+ * eax = 0U ;
392
+ * ebx = 0U ;
393
+ * ecx |= (0U << 8U );
394
+ break ;
387
395
}
388
- * ebx = vcpu -> vm -> hw . created_vcpus ;
389
- * ecx |= ( 2U << 8U );
396
+ }
397
+ #endif
390
398
break ;
391
- default :
399
+
400
+ case 0x0dU :
401
+ if (!cpu_has_cap (X86_FEATURE_OSXSAVE )) {
392
402
* eax = 0U ;
393
403
* ebx = 0U ;
394
- * ecx |= (0U << 8U );
395
- break ;
404
+ * ecx = 0U ;
405
+ * edx = 0U ;
406
+ } else {
407
+ cpuid_subleaf (leaf , subleaf , eax , ebx , ecx , edx );
396
408
}
397
- }
398
- #endif
399
- break ;
409
+ break ;
400
410
401
- case 0x0dU :
402
- if (! cpu_has_cap ( X86_FEATURE_OSXSAVE )) {
403
- * eax = 0U ;
404
- * ebx = 0U ;
405
- * ecx = 0U ;
406
- * edx = 0U ;
407
- } else {
408
- cpuid_subleaf ( leaf , subleaf , eax , ebx , ecx , edx ) ;
411
+ default :
412
+ /*
413
+ * In this switch statement, leaf shall either be 0x01U or 0x0bU
414
+ * or 0x0dU. All the other cases have been handled properly
415
+ * before this switch statement.
416
+ * Gracefully return if prior case clauses have not been met.
417
+ */
418
+ break ;
409
419
}
410
- break ;
411
-
412
- default :
413
- /*
414
- * In this switch statement, leaf shall either be 0x01U or 0x0bU
415
- * or 0x0dU. All the other cases have been handled properly
416
- * before this switch statement.
417
- * Gracefully return if prior case clauses have not been met.
418
- */
419
- break ;
420
420
}
421
421
}
0 commit comments