From patchwork Fri Jun 25 12:07:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 108040 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5PCBJJ6007147 for ; Fri, 25 Jun 2010 12:11:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755935Ab0FYMLK (ORCPT ); Fri, 25 Jun 2010 08:11:10 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:54906 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755829Ab0FYMLI (ORCPT ); Fri, 25 Jun 2010 08:11: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 A682017011F; Fri, 25 Jun 2010 20:10:56 +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 o5PC8Nqh011847; Fri, 25 Jun 2010 20:08:23 +0800 Received: from [10.167.141.99] (unknown [10.167.141.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 4FEC910C005; Fri, 25 Jun 2010 20:10:53 +0800 (CST) Message-ID: <4C249BF0.1010807@cn.fujitsu.com> Date: Fri, 25 Jun 2010 20:07:12 +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 v2 9/10] KVM: MMU: combine guest pte read between walk and pte prefetch References: <4C2498EC.2010006@cn.fujitsu.com> In-Reply-To: <4C2498EC.2010006@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]); Fri, 25 Jun 2010 12:11:51 +0000 (UTC) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 134f031..641c2ca 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -67,6 +67,7 @@ struct guest_walker { int level; gfn_t table_gfn[PT_MAX_FULL_LEVELS]; pt_element_t ptes[PT_MAX_FULL_LEVELS]; + pt_element_t prefetch_ptes[PTE_PREFETCH_NUM]; gpa_t pte_gpa[PT_MAX_FULL_LEVELS]; unsigned pt_access; unsigned pte_access; @@ -110,6 +111,31 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte) return access; } +static int FNAME(read_guest_pte)(struct kvm_vcpu *vcpu, + struct guest_walker *walker, + gpa_t pte_gpa, pt_element_t *pte) +{ + int index, ret; + u64 mask; + gpa_t base_gpa; + + if (walker->level > PT_PAGE_TABLE_LEVEL) + return kvm_read_guest(vcpu->kvm, pte_gpa, pte, + sizeof(*pte)); + + mask = PTE_PREFETCH_NUM * sizeof(*pte) - 1; + base_gpa = pte_gpa & ~mask; + index = (pte_gpa - base_gpa) / sizeof(*pte); + + ret = kvm_read_guest(vcpu->kvm, base_gpa, walker->prefetch_ptes, + sizeof(walker->prefetch_ptes)); + if (ret) + return ret; + + *pte = walker->prefetch_ptes[index]; + return 0; +} + /* * Fetch a guest pte for a guest virtual address */ @@ -151,7 +177,7 @@ walk: walker->table_gfn[walker->level - 1] = table_gfn; walker->pte_gpa[walker->level - 1] = pte_gpa; - if (kvm_read_guest(vcpu->kvm, pte_gpa, &pte, sizeof(pte))) + if (FNAME(read_guest_pte)(vcpu, walker, pte_gpa, &pte)) goto not_present; trace_kvm_mmu_paging_element(pte, walker->level); @@ -291,12 +317,12 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, gpte_to_gfn(gpte), pfn, true, true); } -static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, u64 *sptep) +static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, + struct guest_walker *gw, u64 *sptep) { struct kvm_mmu_page *sp; - pt_element_t gptep[PTE_PREFETCH_NUM]; - gpa_t first_pte_gpa; - int offset = 0, index, i, j, max; + pt_element_t *gptep; + int index, i, j, max; sp = page_header(__pa(sptep)); index = sptep - sp->spt; @@ -311,15 +337,7 @@ static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, u64 *sptep) i = index & ~(PTE_PREFETCH_NUM - 1); max = index | (PTE_PREFETCH_NUM - 1); - if (PTTYPE == 32) - offset = sp->role.quadrant << PT64_LEVEL_BITS; - - first_pte_gpa = gfn_to_gpa(sp->gfn) + - (offset + i) * sizeof(pt_element_t); - - if (kvm_read_guest_atomic(vcpu->kvm, first_pte_gpa, gptep, - sizeof(gptep)) < 0) - return; + gptep = gw->prefetch_ptes; for (j = 0; i < max; i++, j++) { pt_element_t gpte; @@ -395,7 +413,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, user_fault, write_fault, dirty, ptwrite, level, gw->gfn, pfn, false, true); - FNAME(pte_prefetch)(vcpu, sptep); + FNAME(pte_prefetch)(vcpu, gw, sptep); break; }