KVM: SVM: Make sure KERNEL_GS_BASE is valid when loading gs_index
authorJoerg Roedel <joerg.roedel@amd.com>
Fri, 14 Jan 2011 15:45:01 +0000 (16:45 +0100)
committerAvi Kivity <avi@redhat.com>
Wed, 9 Feb 2011 16:31:36 +0000 (18:31 +0200)
The gs_index loading code uses the swapgs instruction to
switch to the user gs_base temporarily. This is unsave in an
lightweight exit-path in KVM on AMD because the
KERNEL_GS_BASE MSR is switches lazily. An NMI happening in
the critical path of load_gs_index may use the wrong GS_BASE
value then leading to unpredictable behavior, e.g. a
triple-fault.

This patch fixes the issue by making sure that load_gs_index
is called only with a valid KERNEL_GS_BASE value loaded in
KVM.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/svm.c

index 25bd1bc5aad2b92a49e4a93b3a8d7e28db9ad511..54ce246a383ee0fa029d444b99b8faca2d6c3702 100644 (file)
@@ -1150,8 +1150,8 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
        kvm_load_ldt(svm->host.ldt);
 #ifdef CONFIG_X86_64
        loadsegment(fs, svm->host.fs);
-       load_gs_index(svm->host.gs);
        wrmsrl(MSR_KERNEL_GS_BASE, current->thread.gs);
+       load_gs_index(svm->host.gs);
 #else
        loadsegment(gs, svm->host.gs);
 #endif