Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751422AbdLNBFg (ORCPT ); Wed, 13 Dec 2017 20:05:36 -0500 Received: from mail-ot0-f193.google.com ([74.125.82.193]:42569 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbdLNBFe (ORCPT ); Wed, 13 Dec 2017 20:05:34 -0500 X-Google-Smtp-Source: ACJfBotVRHvzaW4l2/0NzhDlxWKR4dva8hm7z9b/sP2/g3/iLrKifLqneNGg8//nOmhZix0UZjvxjQYIGTwQj6rvZPc= MIME-Version: 1.0 In-Reply-To: <1513169512-28139-1-git-send-email-pbonzini@redhat.com> References: <1513169512-28139-1-git-send-email-pbonzini@redhat.com> From: Wanpeng Li Date: Thu, 14 Dec 2017 09:05:33 +0800 Message-ID: Subject: Re: [PATCH] KVM: x86: avoid unnecessary XSETBV on guest entry To: Paolo Bonzini Cc: "linux-kernel@vger.kernel.org" , kvm , Wanpeng Li Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1022 Lines: 29 2017-12-13 20:51 GMT+08:00 Paolo Bonzini : > xsetbv can be expensive when running on nested virtualization, try to > avoid it. > > Signed-off-by: Paolo Bonzini Reviewed-by: Wanpeng Li > --- > 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 0f82e2cbf64c..daa1918031df 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; > } > } > -- > 1.8.3.1 >