Skip to content

Commit 458151f

Browse files
ouptonbonzini
authored andcommitted
KVM: nVMX: Use kvm_set_msr to load IA32_PERF_GLOBAL_CTRL on VM-Exit
The existing implementation for loading the IA32_PERF_GLOBAL_CTRL MSR on VM-exit was incorrect, as the next call to atomic_switch_perf_msrs() could cause this value to be overwritten. Instead, call kvm_set_msr() which will allow atomic_switch_perf_msrs() to correctly set the values. Define a macro, SET_MSR_OR_WARN(), to set the MSR with kvm_set_msr() and WARN on failure. Suggested-by: Jim Mattson <[email protected]> Co-developed-by: Krish Sadhukhan <[email protected]> Signed-off-by: Krish Sadhukhan <[email protected]> Signed-off-by: Oliver Upton <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Reviewed-by: Peter Shier <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c547cb6 commit 458151f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ module_param(nested_early_check, bool, S_IRUGO);
2828
failed; \
2929
})
3030

31+
#define SET_MSR_OR_WARN(vcpu, idx, data) \
32+
({ \
33+
bool failed = kvm_set_msr(vcpu, idx, data); \
34+
if (failed) \
35+
pr_warn_ratelimited( \
36+
"%s cannot write MSR (0x%x, 0x%llx)\n", \
37+
__func__, idx, data); \
38+
failed; \
39+
})
40+
3141
/*
3242
* Hyper-V requires all of these, so mark them as supported even though
3343
* they are just treated the same as all-context.
@@ -3879,8 +3889,8 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
38793889
vcpu->arch.pat = vmcs12->host_ia32_pat;
38803890
}
38813891
if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
3882-
vmcs_write64(GUEST_IA32_PERF_GLOBAL_CTRL,
3883-
vmcs12->host_ia32_perf_global_ctrl);
3892+
SET_MSR_OR_WARN(vcpu, MSR_CORE_PERF_GLOBAL_CTRL,
3893+
vmcs12->host_ia32_perf_global_ctrl);
38843894

38853895
/* Set L1 segment info according to Intel SDM
38863896
27.5.2 Loading Host Segment and Descriptor-Table Registers */

0 commit comments

Comments
 (0)