@@ -525,44 +525,19 @@ static int nested_vmx_check_tpr_shadow_controls(struct kvm_vcpu *vcpu,
525
525
}
526
526
527
527
/*
528
- * If a msr is allowed by L0, we should check whether it is allowed by L1.
529
- * The corresponding bit will be cleared unless both of L0 and L1 allow it.
528
+ * For x2APIC MSRs, ignore the vmcs01 bitmap. L1 can enable x2APIC without L1
529
+ * itself utilizing x2APIC. All MSRs were previously set to be intercepted,
530
+ * only the "disable intercept" case needs to be handled.
530
531
*/
531
- static void nested_vmx_disable_intercept_for_msr (unsigned long * msr_bitmap_l1 ,
532
- unsigned long * msr_bitmap_nested ,
533
- u32 msr , int type )
532
+ static void nested_vmx_disable_intercept_for_x2apic_msr (unsigned long * msr_bitmap_l1 ,
533
+ unsigned long * msr_bitmap_l0 ,
534
+ u32 msr , int type )
534
535
{
535
- int f = sizeof (unsigned long );
536
+ if (type & MSR_TYPE_R && !vmx_test_msr_bitmap_read (msr_bitmap_l1 , msr ))
537
+ vmx_clear_msr_bitmap_read (msr_bitmap_l0 , msr );
536
538
537
- /*
538
- * See Intel PRM Vol. 3, 20.6.9 (MSR-Bitmap Address). Early manuals
539
- * have the write-low and read-high bitmap offsets the wrong way round.
540
- * We can control MSRs 0x00000000-0x00001fff and 0xc0000000-0xc0001fff.
541
- */
542
- if (msr <= 0x1fff ) {
543
- if (type & MSR_TYPE_R &&
544
- !test_bit (msr , msr_bitmap_l1 + 0x000 / f ))
545
- /* read-low */
546
- __clear_bit (msr , msr_bitmap_nested + 0x000 / f );
547
-
548
- if (type & MSR_TYPE_W &&
549
- !test_bit (msr , msr_bitmap_l1 + 0x800 / f ))
550
- /* write-low */
551
- __clear_bit (msr , msr_bitmap_nested + 0x800 / f );
552
-
553
- } else if ((msr >= 0xc0000000 ) && (msr <= 0xc0001fff )) {
554
- msr &= 0x1fff ;
555
- if (type & MSR_TYPE_R &&
556
- !test_bit (msr , msr_bitmap_l1 + 0x400 / f ))
557
- /* read-high */
558
- __clear_bit (msr , msr_bitmap_nested + 0x400 / f );
559
-
560
- if (type & MSR_TYPE_W &&
561
- !test_bit (msr , msr_bitmap_l1 + 0xc00 / f ))
562
- /* write-high */
563
- __clear_bit (msr , msr_bitmap_nested + 0xc00 / f );
564
-
565
- }
539
+ if (type & MSR_TYPE_W && !vmx_test_msr_bitmap_write (msr_bitmap_l1 , msr ))
540
+ vmx_clear_msr_bitmap_write (msr_bitmap_l0 , msr );
566
541
}
567
542
568
543
static inline void enable_x2apic_msr_intercepts (unsigned long * msr_bitmap )
@@ -631,7 +606,7 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
631
606
/*
632
607
* To keep the control flow simple, pay eight 8-byte writes (sixteen
633
608
* 4-byte writes on 32-bit systems) up front to enable intercepts for
634
- * the x2APIC MSR range and selectively disable them below .
609
+ * the x2APIC MSR range and selectively toggle those relevant to L2 .
635
610
*/
636
611
enable_x2apic_msr_intercepts (msr_bitmap_l0 );
637
612
@@ -650,17 +625,17 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
650
625
}
651
626
}
652
627
653
- nested_vmx_disable_intercept_for_msr (
628
+ nested_vmx_disable_intercept_for_x2apic_msr (
654
629
msr_bitmap_l1 , msr_bitmap_l0 ,
655
630
X2APIC_MSR (APIC_TASKPRI ),
656
631
MSR_TYPE_R | MSR_TYPE_W );
657
632
658
633
if (nested_cpu_has_vid (vmcs12 )) {
659
- nested_vmx_disable_intercept_for_msr (
634
+ nested_vmx_disable_intercept_for_x2apic_msr (
660
635
msr_bitmap_l1 , msr_bitmap_l0 ,
661
636
X2APIC_MSR (APIC_EOI ),
662
637
MSR_TYPE_W );
663
- nested_vmx_disable_intercept_for_msr (
638
+ nested_vmx_disable_intercept_for_x2apic_msr (
664
639
msr_bitmap_l1 , msr_bitmap_l0 ,
665
640
X2APIC_MSR (APIC_SELF_IPI ),
666
641
MSR_TYPE_W );
0 commit comments