KVM: x86: avoid unnecessary XSETBV on guest entry
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 13 Dec 2017 12:51:32 +0000 (13:51 +0100)
committerRadim Krčmář <rkrcmar@redhat.com>
Tue, 16 Jan 2018 15:34:13 +0000 (16:34 +0100)
xsetbv can be expensive when running on nested virtualization, try to
avoid it.

Reviewed-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Wanpeng Li <wanpeng.li@hotmail.com>
Reviewed-by: Quan Xu <quan.xu0@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/kvm/x86.c

index a3dd44bb6f1e61b662c1a52bab7d14a3c57aa6bf..56d8a1e11e50b04d6d61cbf3ba6cf93c58755c9d 100644 (file)
@@ -702,7 +702,8 @@ static void kvm_load_guest_xcr0(struct kvm_vcpu *vcpu)
        if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE) &&
                        !vcpu->guest_xcr0_loaded) {
                /* kvm_set_xcr() also depends on this */
-               xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0);
+               if (vcpu->arch.xcr0 != host_xcr0)
+                       xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0);
                vcpu->guest_xcr0_loaded = 1;
        }
 }