From: Avi Kivity Subject: [PATCH 3/3] KVM: Move mmu reload out of line Date: Thu, 17 May 2012 15:43:05 +0300 Message-ID: <1337258585-16392-4-git-send-email-avi@redhat.com> References: <1337258585-16392-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:7684 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964794Ab2EQMnN (ORCPT ); Thu, 17 May 2012 08:43:13 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4HChDbi025582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 17 May 2012 08:43:13 -0400 In-Reply-To: <1337258585-16392-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Currently we check that the mmu root exits before every entry. Use the existing KVM_REQ_MMU_RELOAD mechanism instead, by making it really reload the mmu, and by adding the request to mmu initialization code. Signed-off-by: Avi Kivity --- arch/x86/kvm/mmu.c | 2 ++ arch/x86/kvm/x86.c | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 72102e0..7b73b4b 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2723,6 +2723,7 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu) kvm_mmu_commit_zap_page(vcpu->kvm, &invalid_list); spin_unlock(&vcpu->kvm->mmu_lock); vcpu->arch.mmu.root_hpa = INVALID_PAGE; + kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu); } static int mmu_check_root(struct kvm_vcpu *vcpu, gfn_t root_gfn) @@ -3470,6 +3471,7 @@ static int init_kvm_nested_mmu(struct kvm_vcpu *vcpu) static int init_kvm_mmu(struct kvm_vcpu *vcpu) { + kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu); if (mmu_is_nested(vcpu)) return init_kvm_nested_mmu(vcpu); else if (tdp_enabled) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c0209eb..946933a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5240,8 +5240,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) if (vcpu->requests) { reqs = xchg(&vcpu->requests, 0UL); - if (test_bit(KVM_REQ_MMU_RELOAD, &reqs)) + if (test_bit(KVM_REQ_MMU_RELOAD, &reqs)) { kvm_mmu_unload(vcpu); + r = kvm_mmu_reload(vcpu); + if (unlikely(r)) { + kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu); + goto out; + } + } if (test_bit(KVM_REQ_MIGRATE_TIMER, &reqs)) __kvm_migrate_timers(vcpu); if (test_bit(KVM_REQ_CLOCK_UPDATE, &reqs)) { @@ -5299,12 +5305,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) } } - r = kvm_mmu_reload(vcpu); - if (unlikely(r)) { - kvm_x86_ops->cancel_injection(vcpu); - goto out; - } - preempt_disable(); kvm_x86_ops->prepare_guest_switch(vcpu); -- 1.7.10.1