From patchwork Sun May 30 12:37:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 103126 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4UCfwPM018024 for ; Sun, 30 May 2010 12:41:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753083Ab0E3Mlk (ORCPT ); Sun, 30 May 2010 08:41:40 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:63756 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752566Ab0E3Mlj (ORCPT ); Sun, 30 May 2010 08:41:39 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id F3AF2170044; Sun, 30 May 2010 20:41:27 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o4UCdAOL030846; Sun, 30 May 2010 20:39:10 +0800 Received: from [10.167.141.99] (unknown [10.167.141.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 3303910C0BA; Sun, 30 May 2010 20:45:09 +0800 (CST) Message-ID: <4C025C24.9010200@cn.fujitsu.com> Date: Sun, 30 May 2010 20:37:56 +0800 From: Xiao Guangrong User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , LKML , KVM list Subject: [PATCH 2/5] KVM: MMU: split the operations of kvm_mmu_zap_page() References: <4C025BDC.1020304@cn.fujitsu.com> In-Reply-To: <4C025BDC.1020304@cn.fujitsu.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 30 May 2010 12:41:58 +0000 (UTC) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 0cd0f29..e4df1cf 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -388,6 +388,7 @@ struct kvm_arch { * Hash table of struct kvm_mmu_page. */ struct list_head active_mmu_pages; + struct list_head invalid_mmu_pages; struct list_head assigned_dev_head; struct iommu_domain *iommu_domain; int iommu_flags; diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 84c705e..0c957bf 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -915,6 +915,7 @@ static int is_empty_shadow_page(u64 *spt) static void kvm_mmu_free_page(struct kvm *kvm, struct kvm_mmu_page *sp) { ASSERT(is_empty_shadow_page(sp->spt)); + hlist_del(&sp->hash_link); list_del(&sp->link); __free_page(virt_to_page(sp->spt)); if (!sp->role.direct) @@ -1560,6 +1561,46 @@ static int mmu_zap_unsync_children(struct kvm *kvm, return zapped; } +static int kvm_mmu_prepare_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp) +{ + int ret; + + trace_kvm_mmu_zap_page(sp); + ++kvm->stat.mmu_shadow_zapped; + ret = mmu_zap_unsync_children(kvm, sp); + kvm_mmu_page_unlink_children(kvm, sp); + kvm_mmu_unlink_parents(kvm, sp); + if (!sp->role.invalid && !sp->role.direct) + unaccount_shadowed(kvm, sp->gfn); + if (sp->unsync) + kvm_unlink_unsync_page(kvm, sp); + if (!sp->root_count) + /* Count self */ + ret++; + else + kvm_reload_remote_mmus(kvm); + + sp->role.invalid = 1; + list_move(&sp->link, &kvm->arch.invalid_mmu_pages); + kvm_mmu_reset_last_pte_updated(kvm); + return ret; +} + +static void kvm_mmu_commit_zap_page(struct kvm *kvm) +{ + struct kvm_mmu_page *sp, *n; + + if (list_empty(&kvm->arch.invalid_mmu_pages)) + return; + + kvm_flush_remote_tlbs(kvm); + list_for_each_entry_safe(sp, n, &kvm->arch.invalid_mmu_pages, link) { + WARN_ON(!sp->role.invalid); + if (!sp->root_count) + kvm_mmu_free_page(kvm, sp); + } +} + static int kvm_mmu_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp) { int ret; @@ -1577,7 +1618,6 @@ static int kvm_mmu_zap_page(struct kvm *kvm, struct kvm_mmu_page *sp) if (!sp->root_count) { /* Count self */ ret++; - hlist_del(&sp->hash_link); kvm_mmu_free_page(kvm, sp); } else { sp->role.invalid = 1; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5e5cd8d..225c3c4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5331,6 +5331,7 @@ struct kvm *kvm_arch_create_vm(void) } INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); + INIT_LIST_HEAD(&kvm->arch.invalid_mmu_pages); INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */