Commit 5104d7ff authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: VMX: Disable preemption when probing user return MSRs

Disable preemption when probing a user return MSR via RDSMR/WRMSR.  If
the MSR holds a different value per logical CPU, the WRMSR could corrupt
the host's value if KVM is preempted between the RDMSR and WRMSR, and
then rescheduled on a different CPU.

Opportunistically land the helper in common x86, SVM will use the helper
in a future commit.

Fixes: 4be53410

 ("KVM: VMX: Initialize vmx->guest_msrs[] right after allocation")
Cc: Xiaoyao Li <>
Signed-off-by: default avatarSean Christopherson <>
Message-Id: <>
Reviewed-by: default avatarJim Mattson <>
Signed-off-by: default avatarPaolo Bonzini <>
parent 2183de41
......@@ -1777,6 +1777,7 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
unsigned long icr, int op_64_bit);
void kvm_define_user_return_msr(unsigned index, u32 msr);
int kvm_probe_user_return_msr(u32 msr);
int kvm_set_user_return_msr(unsigned index, u64 val, u64 mask);
u64 kvm_scale_tsc(struct kvm_vcpu *vcpu, u64 tsc);
......@@ -6914,12 +6914,9 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
for (i = 0; i < ARRAY_SIZE(vmx_uret_msrs_list); ++i) {
u32 index = vmx_uret_msrs_list[i];
u32 data_low, data_high;
int j = vmx->nr_uret_msrs;
if (rdmsr_safe(index, &data_low, &data_high) < 0)
if (wrmsr_safe(index, data_low, data_high) < 0)
if (kvm_probe_user_return_msr(index))
vmx->guest_uret_msrs[j].slot = i;
......@@ -339,6 +339,22 @@ static void kvm_on_user_return(struct user_return_notifier *urn)
int kvm_probe_user_return_msr(u32 msr)
u64 val;
int ret;
ret = rdmsrl_safe(msr, &val);
if (ret)
goto out;
ret = wrmsrl_safe(msr, val);
return ret;
void kvm_define_user_return_msr(unsigned slot, u32 msr)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment