Skip to content

Commit 83bafef

Browse files
jsmattsonjrbonzini
authored andcommitted
kvm: nVMX: Update MSR load counts on a VMCS switch
When L0 establishes (or removes) an MSR entry in the VM-entry or VM-exit MSR load lists, the change should affect the dormant VMCS as well as the current VMCS. Moreover, the vmcs02 MSR-load addresses should be initialized. Signed-off-by: Jim Mattson <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent cf3215d commit 83bafef

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/x86/kvm/vmx.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9967,6 +9967,15 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
99679967
*/
99689968
vmx_set_constant_host_state(vmx);
99699969

9970+
/*
9971+
* Set the MSR load/store lists to match L0's settings.
9972+
*/
9973+
vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
9974+
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
9975+
vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
9976+
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
9977+
vmcs_write64(VM_ENTRY_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.guest));
9978+
99709979
/*
99719980
* HOST_RSP is normally set correctly in vmx_vcpu_run() just before
99729981
* entry, but only if the current (host) sp changed from the value
@@ -10799,6 +10808,8 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
1079910808
load_vmcs12_host_state(vcpu, vmcs12);
1080010809

1080110810
/* Update any VMCS fields that might have changed while L2 ran */
10811+
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
10812+
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.nr);
1080210813
vmcs_write64(TSC_OFFSET, vcpu->arch.tsc_offset);
1080310814
if (vmx->hv_deadline_tsc == -1)
1080410815
vmcs_clear_bits(PIN_BASED_VM_EXEC_CONTROL,

0 commit comments

Comments
 (0)