KVM: Correct ordering of ldt reload wrt fs/gs reload

If fs or gs refer to the ldt, they must be reloaded after the ldt. Reorder
the code to that effect.

Userspace code that uses the ldt with kvm is nonexistent, so this doesn't fix
a user-visible bug.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

authored by Avi Kivity and committed by Marcelo Tosatti 0a77fe4c 59365d13

+3 -3
+1 -1
arch/x86/kvm/svm.c
··· 3395 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip; 3396 3397 load_host_msrs(vcpu); 3398 loadsegment(fs, fs_selector); 3399 #ifdef CONFIG_X86_64 3400 load_gs_index(gs_selector); ··· 3403 #else 3404 loadsegment(gs, gs_selector); 3405 #endif 3406 - kvm_load_ldt(ldt_selector); 3407 3408 reload_tss(vcpu); 3409
··· 3395 vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip; 3396 3397 load_host_msrs(vcpu); 3398 + kvm_load_ldt(ldt_selector); 3399 loadsegment(fs, fs_selector); 3400 #ifdef CONFIG_X86_64 3401 load_gs_index(gs_selector); ··· 3402 #else 3403 loadsegment(gs, gs_selector); 3404 #endif 3405 3406 reload_tss(vcpu); 3407
+2 -2
arch/x86/kvm/vmx.c
··· 839 840 ++vmx->vcpu.stat.host_state_reload; 841 vmx->host_state.loaded = 0; 842 - if (vmx->host_state.fs_reload_needed) 843 - loadsegment(fs, vmx->host_state.fs_sel); 844 if (vmx->host_state.gs_ldt_reload_needed) { 845 kvm_load_ldt(vmx->host_state.ldt_sel); 846 #ifdef CONFIG_X86_64 ··· 848 loadsegment(gs, vmx->host_state.gs_sel); 849 #endif 850 } 851 reload_tss(); 852 #ifdef CONFIG_X86_64 853 if (is_long_mode(&vmx->vcpu)) {
··· 839 840 ++vmx->vcpu.stat.host_state_reload; 841 vmx->host_state.loaded = 0; 842 if (vmx->host_state.gs_ldt_reload_needed) { 843 kvm_load_ldt(vmx->host_state.ldt_sel); 844 #ifdef CONFIG_X86_64 ··· 850 loadsegment(gs, vmx->host_state.gs_sel); 851 #endif 852 } 853 + if (vmx->host_state.fs_reload_needed) 854 + loadsegment(fs, vmx->host_state.fs_sel); 855 reload_tss(); 856 #ifdef CONFIG_X86_64 857 if (is_long_mode(&vmx->vcpu)) {