Commit 6d9658df authored by Ingo Molnar's avatar Ingo Molnar Committed by Avi Kivity

KVM: always reload segment selectors

failed VM entry on VMX might still change %fs or %gs, thus make sure
that KVM always reloads the segment selectors. This is crutial on both
x86 and x86_64: x86 has __KERNEL_PDA in %fs on which things like
'current' depends and x86_64 has 0 there and needs MSR_GS_BASE to work.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 6af11b9e
...@@ -1888,6 +1888,27 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) ...@@ -1888,6 +1888,27 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
[cr2]"i"(offsetof(struct kvm_vcpu, cr2)) [cr2]"i"(offsetof(struct kvm_vcpu, cr2))
: "cc", "memory" ); : "cc", "memory" );
/*
* Reload segment selectors ASAP. (it's needed for a functional
* kernel: x86 relies on having __KERNEL_PDA in %fs and x86_64
* relies on having 0 in %gs for the CPU PDA to work.)
*/
if (fs_gs_ldt_reload_needed) {
load_ldt(ldt_sel);
load_fs(fs_sel);
/*
* If we have to reload gs, we must take care to
* preserve our gs base.
*/
local_irq_disable();
load_gs(gs_sel);
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, vmcs_readl(HOST_GS_BASE));
#endif
local_irq_enable();
reload_tss();
}
++kvm_stat.exits; ++kvm_stat.exits;
save_msrs(vcpu->guest_msrs, NR_BAD_MSRS); save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
...@@ -1905,22 +1926,6 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) ...@@ -1905,22 +1926,6 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR); kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR);
r = 0; r = 0;
} else { } else {
if (fs_gs_ldt_reload_needed) {
load_ldt(ldt_sel);
load_fs(fs_sel);
/*
* If we have to reload gs, we must take care to
* preserve our gs base.
*/
local_irq_disable();
load_gs(gs_sel);
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, vmcs_readl(HOST_GS_BASE));
#endif
local_irq_enable();
reload_tss();
}
/* /*
* Profile KVM exit RIPs: * Profile KVM exit RIPs:
*/ */
......
Markdown is supported
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