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