From patchwork Wed Jun 10 15:27:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 29312 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5AFVXGZ010914 for ; Wed, 10 Jun 2009 15:31:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759894AbZFJPba (ORCPT ); Wed, 10 Jun 2009 11:31:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759860AbZFJPb3 (ORCPT ); Wed, 10 Jun 2009 11:31:29 -0400 Received: from mx2.redhat.com ([66.187.237.31]:56493 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752172AbZFJPb0 (ORCPT ); Wed, 10 Jun 2009 11:31:26 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5AFVTWo018616 for ; Wed, 10 Jun 2009 11:31:29 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5AFVR9X021558; Wed, 10 Jun 2009 11:31:28 -0400 Received: from amt.cnet (vpn-10-153.str.redhat.com [10.32.10.153]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5AFVPik019114; Wed, 10 Jun 2009 11:31:26 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 1E0D7550003; Wed, 10 Jun 2009 12:30:39 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n5AFUb6Y011122; Wed, 10 Jun 2009 12:30:37 -0300 Message-Id: <20090610152747.430811400@localhost.localdomain> References: <20090610152702.666650177@localhost.localdomain> User-Agent: quilt/0.46-1 Date: Wed, 10 Jun 2009 12:27:03 -0300 From: Marcelo Tosatti To: avi@redhat.com Cc: kvm@vger.kernel.org, Marcelo Tosatti Subject: [patch 1/6] KVM: MMU: introduce is_last_spte helper Content-Disposition: inline; filename=last-spte X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hiding some of the last largepage / level interaction (which is useful for gbpages and for zero based levels). Also merge the PT_PAGE_TABLE_LEVEL clearing loop in unlink_children. Signed-off-by: Marcelo Tosatti Index: kvm/arch/x86/kvm/mmu.c =================================================================== --- kvm.orig/arch/x86/kvm/mmu.c +++ kvm/arch/x86/kvm/mmu.c @@ -250,6 +250,15 @@ static int is_rmap_spte(u64 pte) return is_shadow_present_pte(pte); } +static int is_last_spte(u64 pte, int level) +{ + if (level == PT_PAGE_TABLE_LEVEL) + return 1; + if (level == PT_DIRECTORY_LEVEL && is_large_pte(pte)) + return 1; + return 0; +} + static pfn_t spte_to_pfn(u64 pte) { return (pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT; @@ -1293,25 +1302,17 @@ static void kvm_mmu_page_unlink_children pt = sp->spt; - if (sp->role.level == PT_PAGE_TABLE_LEVEL) { - for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { - if (is_shadow_present_pte(pt[i])) - rmap_remove(kvm, &pt[i]); - pt[i] = shadow_trap_nonpresent_pte; - } - return; - } - for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { ent = pt[i]; if (is_shadow_present_pte(ent)) { - if (!is_large_pte(ent)) { + if (!is_last_spte(ent, sp->role.level)) { ent &= PT64_BASE_ADDR_MASK; mmu_page_remove_parent_pte(page_header(ent), &pt[i]); } else { - --kvm->stat.lpages; + if (is_large_pte(ent)) + --kvm->stat.lpages; rmap_remove(kvm, &pt[i]); } } @@ -2357,8 +2358,7 @@ static void mmu_pte_write_zap_pte(struct pte = *spte; if (is_shadow_present_pte(pte)) { - if (sp->role.level == PT_PAGE_TABLE_LEVEL || - is_large_pte(pte)) + if (is_last_spte(pte, sp->role.level)) rmap_remove(vcpu->kvm, spte); else { child = page_header(pte & PT64_BASE_ADDR_MASK);