Skip to content

Commit 7dfbc62

Browse files
sean-jcbonzini
authored andcommitted
KVM: nVMX: Query current VMCS when determining if MSR bitmaps are in use
Check the current VMCS controls to determine if an MSR write will be intercepted due to MSR bitmaps being disabled. In the nested VMX case, KVM will disable MSR bitmaps in vmcs02 if they're disabled in vmcs12 or if KVM can't map L1's bitmaps for whatever reason. Note, the bad behavior is relatively benign in the current code base as KVM sets all bits in vmcs02's MSR bitmap by default, clears bits if and only if L0 KVM also disables interception of an MSR, and only uses the buggy helper for MSR_IA32_SPEC_CTRL. Because KVM explicitly tests WRMSR before disabling interception of MSR_IA32_SPEC_CTRL, the flawed check will only result in KVM reading MSR_IA32_SPEC_CTRL from hardware when it isn't strictly necessary. Tag the fix for stable in case a future fix wants to use msr_write_intercepted(), in which case a buggy implementation in older kernels could prove subtly problematic. Fixes: d28b387 ("KVM/VMX: Allow direct access to MSR_IA32_SPEC_CTRL") Cc: [email protected] Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent afd67ee commit 7dfbc62

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ void vmx_update_exception_bitmap(struct kvm_vcpu *vcpu)
769769
/*
770770
* Check if MSR is intercepted for currently loaded MSR bitmap.
771771
*/
772-
static bool msr_write_intercepted(struct kvm_vcpu *vcpu, u32 msr)
772+
static bool msr_write_intercepted(struct vcpu_vmx *vmx, u32 msr)
773773
{
774774
unsigned long *msr_bitmap;
775775
int f = sizeof(unsigned long);
776776

777-
if (!cpu_has_vmx_msr_bitmap())
777+
if (!(exec_controls_get(vmx) & CPU_BASED_USE_MSR_BITMAPS))
778778
return true;
779779

780-
msr_bitmap = to_vmx(vcpu)->loaded_vmcs->msr_bitmap;
780+
msr_bitmap = vmx->loaded_vmcs->msr_bitmap;
781781

782782
if (msr <= 0x1fff) {
783783
return !!test_bit(msr, msr_bitmap + 0x800 / f);
@@ -6751,7 +6751,7 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
67516751
* If the L02 MSR bitmap does not intercept the MSR, then we need to
67526752
* save it.
67536753
*/
6754-
if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
6754+
if (unlikely(!msr_write_intercepted(vmx, MSR_IA32_SPEC_CTRL)))
67556755
vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
67566756

67576757
x86_spec_ctrl_restore_host(vmx->spec_ctrl, 0);

0 commit comments

Comments
 (0)