1 From 0a77fe4c188e25917799f2356d4aa5e6d80c39a2 Mon Sep 17 00:00:00 2001
2 From: Avi Kivity <avi@redhat.com>
3 Date: Tue, 19 Oct 2010 18:48:35 +0200
4 Subject: KVM: Correct ordering of ldt reload wrt fs/gs reload
6 From: Avi Kivity <avi@redhat.com>
8 commit 0a77fe4c188e25917799f2356d4aa5e6d80c39a2 upstream.
10 If fs or gs refer to the ldt, they must be reloaded after the ldt. Reorder
11 the code to that effect.
13 Userspace code that uses the ldt with kvm is nonexistent, so this doesn't fix
16 Signed-off-by: Avi Kivity <avi@redhat.com>
17 Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
21 arch/x86/kvm/svm.c | 2 +-
22 arch/x86/kvm/vmx.c | 4 ++--
23 2 files changed, 3 insertions(+), 3 deletions(-)
25 --- a/arch/x86/kvm/svm.c
26 +++ b/arch/x86/kvm/svm.c
27 @@ -3281,6 +3281,7 @@ static void svm_vcpu_run(struct kvm_vcpu
28 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip;
31 + kvm_load_ldt(ldt_selector);
32 loadsegment(fs, fs_selector);
34 load_gs_index(gs_selector);
35 @@ -3288,7 +3289,6 @@ static void svm_vcpu_run(struct kvm_vcpu
37 loadsegment(gs, gs_selector);
39 - kvm_load_ldt(ldt_selector);
43 --- a/arch/x86/kvm/vmx.c
44 +++ b/arch/x86/kvm/vmx.c
45 @@ -846,8 +846,6 @@ static void __vmx_load_host_state(struct
47 ++vmx->vcpu.stat.host_state_reload;
48 vmx->host_state.loaded = 0;
49 - if (vmx->host_state.fs_reload_needed)
50 - loadsegment(fs, vmx->host_state.fs_sel);
51 if (vmx->host_state.gs_ldt_reload_needed) {
52 kvm_load_ldt(vmx->host_state.ldt_sel);
54 @@ -857,6 +855,8 @@ static void __vmx_load_host_state(struct
55 loadsegment(gs, vmx->host_state.gs_sel);
58 + if (vmx->host_state.fs_reload_needed)
59 + loadsegment(fs, vmx->host_state.fs_sel);
62 if (is_long_mode(&vmx->vcpu)) {