KVM: x86: avoid unnecessary XSETBV on guest entry

"Linux Kernel Mailing List" <[email protected]> Sat, 10 Feb 2018 22:00:19 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/476b7adaa3272557168b287175b1e9e943913404
Commit:     476b7adaa3272557168b287175b1e9e943913404
Parent:     efdab992813fb2ed825745625b83c05032e9cda2
Refname:    refs/heads/master
Author:     Paolo Bonzini <[email protected]>
AuthorDate: Wed Dec 13 13:51:32 2017 +0100
Committer:  Radim Krčmář <[email protected]>
CommitDate: Tue Jan 16 16:34:13 2018 +0100

    KVM: x86: avoid unnecessary XSETBV on guest entry
    
    xsetbv can be expensive when running on nested virtualization, try to
    avoid it.
    
    Reviewed-by: Jim Mattson <[email protected]>
    Reviewed-by: Wanpeng Li <[email protected]>
    Reviewed-by: Quan Xu <[email protected]>
    Signed-off-by: Paolo Bonzini <[email protected]>
    Signed-off-by: Radim Krčmář <[email protected]>
---
 arch/x86/kvm/x86.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a3dd44bb6f1e..56d8a1e11e50 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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;
 	}
 }
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html