@@ -279,6 +279,9 @@ static void intercept_x2apic_msrs(uint8_t *msr_bitmap_arg, uint32_t mode)
279
279
}
280
280
}
281
281
282
+ /**
283
+ * @pre vcpu != NULL
284
+ */
282
285
static void init_msr_area (struct acrn_vcpu * vcpu )
283
286
{
284
287
vcpu -> arch .msr_area .guest [MSR_AREA_TSC_AUX ].msr_index = MSR_IA32_TSC_AUX ;
@@ -287,47 +290,49 @@ static void init_msr_area(struct acrn_vcpu *vcpu)
287
290
vcpu -> arch .msr_area .host [MSR_AREA_TSC_AUX ].value = vcpu -> pcpu_id ;
288
291
}
289
292
293
+ /**
294
+ * @pre vcpu != NULL
295
+ */
290
296
void init_msr_emulation (struct acrn_vcpu * vcpu )
291
297
{
298
+ uint8_t * msr_bitmap = vcpu -> arch .msr_bitmap ;
292
299
uint32_t msr , i ;
293
- uint8_t * msr_bitmap ;
294
300
uint64_t value64 ;
295
301
296
- if (is_vcpu_bsp (vcpu )) {
297
- msr_bitmap = vcpu -> vm -> arch_vm .msr_bitmap ;
298
-
299
- for (i = 0U ; i < NUM_GUEST_MSRS ; i ++ ) {
300
- enable_msr_interception (msr_bitmap , emulated_guest_msrs [i ], INTERCEPT_READ_WRITE );
301
- }
302
-
303
- for (i = 0U ; i < NUM_MTRR_MSRS ; i ++ ) {
304
- enable_msr_interception (msr_bitmap , mtrr_msrs [i ], INTERCEPT_READ_WRITE );
305
- }
302
+ for (i = 0U ; i < NUM_GUEST_MSRS ; i ++ ) {
303
+ enable_msr_interception (msr_bitmap , emulated_guest_msrs [i ], INTERCEPT_READ_WRITE );
304
+ }
306
305
307
- intercept_x2apic_msrs (msr_bitmap , INTERCEPT_READ_WRITE );
306
+ for (i = 0U ; i < NUM_MTRR_MSRS ; i ++ ) {
307
+ enable_msr_interception (msr_bitmap , mtrr_msrs [i ], INTERCEPT_READ_WRITE );
308
+ }
308
309
309
- for (i = 0U ; i < NUM_UNSUPPORTED_MSRS ; i ++ ) {
310
- enable_msr_interception (msr_bitmap , unsupported_msrs [i ], INTERCEPT_READ_WRITE );
311
- }
310
+ intercept_x2apic_msrs (msr_bitmap , INTERCEPT_READ_WRITE );
312
311
313
- /* RDT-A disabled: CPUID.07H.EBX[12], CPUID.10H */
314
- for (msr = MSR_IA32_L3_MASK_0 ; msr < MSR_IA32_BNDCFGS ; msr ++ ) {
315
- enable_msr_interception (msr_bitmap , msr , INTERCEPT_READ_WRITE );
316
- }
312
+ for (i = 0U ; i < NUM_UNSUPPORTED_MSRS ; i ++ ) {
313
+ enable_msr_interception (msr_bitmap , unsupported_msrs [i ], INTERCEPT_READ_WRITE );
314
+ }
317
315
318
- /* don't need to intercept rdmsr for these MSRs */
319
- enable_msr_interception (msr_bitmap , MSR_IA32_TIME_STAMP_COUNTER , INTERCEPT_WRITE );
316
+ /* RDT-A disabled: CPUID.07H.EBX[12], CPUID.10H */
317
+ for (msr = MSR_IA32_L3_MASK_0 ; msr < MSR_IA32_BNDCFGS ; msr ++ ) {
318
+ enable_msr_interception (msr_bitmap , msr , INTERCEPT_READ_WRITE );
320
319
}
321
320
321
+ /* don't need to intercept rdmsr for these MSRs */
322
+ enable_msr_interception (msr_bitmap , MSR_IA32_TIME_STAMP_COUNTER , INTERCEPT_WRITE );
323
+
322
324
/* Setup MSR bitmap - Intel SDM Vol3 24.6.9 */
323
- value64 = hva2hpa (vcpu -> vm -> arch_vm .msr_bitmap );
325
+ value64 = hva2hpa (vcpu -> arch .msr_bitmap );
324
326
exec_vmwrite64 (VMX_MSR_BITMAP_FULL , value64 );
325
327
pr_dbg ("VMX_MSR_BITMAP: 0x%016llx " , value64 );
326
328
327
329
/* Initialize the MSR save/store area */
328
330
init_msr_area (vcpu );
329
331
}
330
332
333
+ /**
334
+ * @pre vcpu != NULL
335
+ */
331
336
int32_t rdmsr_vmexit_handler (struct acrn_vcpu * vcpu )
332
337
{
333
338
int32_t err = 0 ;
@@ -436,6 +441,10 @@ int32_t rdmsr_vmexit_handler(struct acrn_vcpu *vcpu)
436
441
* TSC, the logical processor also adds (or subtracts) value X from
437
442
* the IA32_TSC_ADJUST MSR.
438
443
*/
444
+
445
+ /**
446
+ * @pre vcpu != NULL
447
+ */
439
448
static void set_guest_tsc (struct acrn_vcpu * vcpu , uint64_t guest_tsc )
440
449
{
441
450
uint64_t tsc_delta , tsc_offset_delta , tsc_adjust ;
@@ -458,6 +467,10 @@ static void set_guest_tsc(struct acrn_vcpu *vcpu, uint64_t guest_tsc)
458
467
* MSR adds (or subtracts) value X from that MSR, the logical
459
468
* processor also adds (or subtracts) value X from the TSC."
460
469
*/
470
+
471
+ /**
472
+ * @pre vcpu != NULL
473
+ */
461
474
static void set_guest_tsc_adjust (struct acrn_vcpu * vcpu , uint64_t tsc_adjust )
462
475
{
463
476
uint64_t tsc_offset , tsc_adjust_delta ;
@@ -473,6 +486,9 @@ static void set_guest_tsc_adjust(struct acrn_vcpu *vcpu, uint64_t tsc_adjust)
473
486
vcpu_set_guest_msr (vcpu , MSR_IA32_TSC_ADJUST , tsc_adjust );
474
487
}
475
488
489
+ /**
490
+ * @pre vcpu != NULL
491
+ */
476
492
static void set_guest_ia32_misc_enalbe (struct acrn_vcpu * vcpu , uint64_t v )
477
493
{
478
494
uint32_t eax , ebx = 0U , ecx = 0U , edx = 0U ;
@@ -520,6 +536,9 @@ static void set_guest_ia32_misc_enalbe(struct acrn_vcpu *vcpu, uint64_t v)
520
536
}
521
537
}
522
538
539
+ /**
540
+ * @pre vcpu != NULL
541
+ */
523
542
int32_t wrmsr_vmexit_handler (struct acrn_vcpu * vcpu )
524
543
{
525
544
int32_t err = 0 ;
@@ -630,11 +649,14 @@ int32_t wrmsr_vmexit_handler(struct acrn_vcpu *vcpu)
630
649
return err ;
631
650
}
632
651
633
- void update_msr_bitmap_x2apic_apicv (const struct acrn_vcpu * vcpu )
652
+ /**
653
+ * @pre vcpu != NULL
654
+ */
655
+ void update_msr_bitmap_x2apic_apicv (struct acrn_vcpu * vcpu )
634
656
{
635
657
uint8_t * msr_bitmap ;
636
658
637
- msr_bitmap = vcpu -> vm -> arch_vm .msr_bitmap ;
659
+ msr_bitmap = vcpu -> arch .msr_bitmap ;
638
660
/*
639
661
* For platforms that do not support register virtualization
640
662
* all x2APIC MSRs need to intercepted. So no need to update
@@ -666,9 +688,13 @@ void update_msr_bitmap_x2apic_apicv(const struct acrn_vcpu *vcpu)
666
688
* - XAPICID/LDR: Read to XAPICID/LDR need to be trapped to guarantee guest always see right vlapic_id.
667
689
* - ICR: Write to ICR need to be trapped to avoid milicious IPI.
668
690
*/
669
- void update_msr_bitmap_x2apic_passthru (const struct acrn_vcpu * vcpu )
691
+
692
+ /**
693
+ * @pre vcpu != NULL
694
+ */
695
+ void update_msr_bitmap_x2apic_passthru (struct acrn_vcpu * vcpu )
670
696
{
671
- uint8_t * msr_bitmap = vcpu -> vm -> arch_vm .msr_bitmap ;
697
+ uint8_t * msr_bitmap = vcpu -> arch .msr_bitmap ;
672
698
673
699
intercept_x2apic_msrs (msr_bitmap , INTERCEPT_DISABLE );
674
700
enable_msr_interception (msr_bitmap , MSR_IA32_EXT_XAPICID , INTERCEPT_READ );
0 commit comments