From patchwork Sat Apr 17 08:50:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 93288 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 o3H8oYRO032380 for ; Sat, 17 Apr 2010 08:50:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754738Ab0DQIuK (ORCPT ); Sat, 17 Apr 2010 04:50:10 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:55344 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752729Ab0DQIuI (ORCPT ); Sat, 17 Apr 2010 04:50:08 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 19F36170044; Sat, 17 Apr 2010 16:50:06 +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 o3H8mTqO032276; Sat, 17 Apr 2010 16:48:29 +0800 Received: from [10.167.141.204] (unknown [10.167.141.204]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 03230DC2A3; Sat, 17 Apr 2010 16:53:01 +0800 (CST) Message-ID: <4BC97645.8050009@cn.fujitsu.com> Date: Sat, 17 Apr 2010 16:50:13 +0800 From: Lai Jiangshan User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Avi Kivity , Marcelo Tosatti , LKML , kvm@vger.kernel.org Subject: [PATCH] kvm x86 mmu: simplify kvm_mmu_unlink_parents() 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]); Sat, 17 Apr 2010 08:50:34 +0000 (UTC) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 90f666e..71faa04 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1453,22 +1453,33 @@ static void kvm_mmu_reset_last_pte_updated(struct kvm *kvm) static void kvm_mmu_unlink_parents(struct kvm *kvm, struct kvm_mmu_page *sp) { - u64 *parent_pte; + if (!sp->multimapped) { + if (!sp->parent_pte) + return; - while (sp->multimapped || sp->parent_pte) { - if (!sp->multimapped) - parent_pte = sp->parent_pte; - else { - struct kvm_pte_chain *chain; + __set_spte(sp->parent_pte, shadow_trap_nonpresent_pte); + sp->parent_pte = NULL; + return; + } - chain = container_of(sp->parent_ptes.first, - struct kvm_pte_chain, link); - parent_pte = chain->parent_ptes[0]; + while (!hlist_empty(&sp->parent_ptes)) { + struct kvm_pte_chain *chain; + u64 *parent_pte; + int i; + + chain = hlist_entry(sp->parent_ptes.first, + struct kvm_pte_chain, link); + for (i = 0; i < NR_PTE_CHAIN_ENTRIES; ++i) { + parent_pte = chain->parent_ptes[i]; + if (!parent_pte) + break; + __set_spte(parent_pte, shadow_trap_nonpresent_pte); } - BUG_ON(!parent_pte); - kvm_mmu_put_page(sp, parent_pte); - __set_spte(parent_pte, shadow_trap_nonpresent_pte); + hlist_del(&chain->link); + mmu_free_pte_chain(chain); } + sp->multimapped = 0; + sp->parent_pte = NULL; } static int mmu_zap_unsync_children(struct kvm *kvm,