From patchwork Wed Mar 3 19:12:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 83438 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 o23JFYZm008766 for ; Wed, 3 Mar 2010 19:15:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756176Ab0CCTOG (ORCPT ); Wed, 3 Mar 2010 14:14:06 -0500 Received: from va3ehsobe001.messaging.microsoft.com ([216.32.180.11]:42018 "EHLO VA3EHSOBE001.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756172Ab0CCTOB (ORCPT ); Wed, 3 Mar 2010 14:14:01 -0500 Received: from mail39-va3-R.bigfish.com (10.7.14.245) by VA3EHSOBE001.bigfish.com (10.7.40.21) with Microsoft SMTP Server id 8.1.340.0; Wed, 3 Mar 2010 19:14:00 +0000 Received: from mail39-va3 (localhost [127.0.0.1]) by mail39-va3-R.bigfish.com (Postfix) with ESMTP id 793E13F808D; Wed, 3 Mar 2010 19:13:59 +0000 (UTC) X-SpamScore: 3 X-BigFish: VPS3(zz936eMab9bhab78ozz1202hzzz32i2a8h87h6bh62h) X-Spam-TCS-SCL: 1:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail39-va3 (localhost.localdomain [127.0.0.1]) by mail39-va3 (MessageSwitch) id 1267643633978552_11364; Wed, 3 Mar 2010 19:13:53 +0000 (UTC) Received: from VA3EHSMHS011.bigfish.com (unknown [10.7.14.249]) by mail39-va3.bigfish.com (Postfix) with ESMTP id 5A760A08067; Wed, 3 Mar 2010 19:13:02 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by VA3EHSMHS011.bigfish.com (10.7.99.21) with Microsoft SMTP Server (TLS) id 14.0.482.39; Wed, 3 Mar 2010 19:12:57 +0000 Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with SMTP id o23JGHax003855; Wed, 3 Mar 2010 13:16:20 -0600 X-WSS-ID: 0KYQ01B-02-H5E-02 X-M-MSG: Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2DA7EC8638; Wed, 3 Mar 2010 13:12:46 -0600 (CST) Received: from sausexmb1.amd.com ([163.181.3.156]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 3 Mar 2010 13:12:51 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 3 Mar 2010 13:12:51 -0600 Received: from lemmy.osrc.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 3 Mar 2010 20:12:42 +0100 Received: by lemmy.osrc.amd.com (Postfix, from userid 41430) id BF923C9B4F; Wed, 3 Mar 2010 20:12:42 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: Alexander Graf , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 11/18] KVM: MMU: Add infrastructure for two-level page walker Date: Wed, 3 Mar 2010 20:12:14 +0100 Message-ID: <1267643541-451-12-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1267643541-451-1-git-send-email-joerg.roedel@amd.com> References: <1267643541-451-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 03 Mar 2010 19:12:42.0735 (UTC) FILETIME=[7FD497F0:01CABB05] MIME-Version: 1.0 X-Reverse-DNS: ausb3extmailp02.amd.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]); Wed, 03 Mar 2010 19:15:35 +0000 (UTC) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c0b5576..76c8b5f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -250,6 +250,7 @@ struct kvm_mmu { void (*free)(struct kvm_vcpu *vcpu); gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access, u32 *error); + gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 *error); void (*prefetch_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page); int (*sync_page)(struct kvm_vcpu *vcpu, diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 647353d..ec3830c 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2149,6 +2149,11 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu) spin_unlock(&vcpu->kvm->mmu_lock); } +static gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 *error) +{ + return gpa; +} + static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access, u32 *error) { @@ -2399,6 +2404,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu) context->new_cr3 = nonpaging_new_cr3; context->page_fault = tdp_page_fault; context->free = nonpaging_free; + context->translate_gpa = translate_gpa; context->prefetch_page = nonpaging_prefetch_page; context->sync_page = nonpaging_sync_page; context->invlpg = nonpaging_invlpg; @@ -2443,6 +2449,7 @@ int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context) else r = paging32_init_context(vcpu, context); + vcpu->arch.mmu.translate_gpa = translate_gpa; vcpu->arch.mmu.base_role.glevels = vcpu->arch.mmu.root_level; vcpu->arch.mmu.tdp_enabled = false; diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 6c55a31..a72d5ea 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -122,6 +122,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, unsigned index, pt_access, pte_access; gpa_t pte_gpa; int rsvd_fault = 0; + u32 error; trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, fetch_fault); @@ -150,6 +151,15 @@ walk: table_gfn = gpte_to_gfn(pte); pte_gpa = gfn_to_gpa(table_gfn); pte_gpa += index * sizeof(pt_element_t); + + pte_gpa = mmu->translate_gpa(vcpu, pte_gpa, &error); + if (pte_gpa == UNMAPPED_GVA) { + walker->error_code = error; + return 0; + } + /* pte_gpa might have changed - recalculate table_gfn */ + table_gfn = gpa_to_gfn(pte_gpa); + walker->table_gfn[walker->level - 1] = table_gfn; walker->pte_gpa[walker->level - 1] = pte_gpa; @@ -209,6 +219,15 @@ walk: is_cpuid_PSE36()) walker->gfn += pse36_gfn_delta(pte); + /* Do the final translation */ + pte_gpa = gfn_to_gpa(walker->gfn); + pte_gpa = mmu->translate_gpa(vcpu, pte_gpa, &error); + if (pte_gpa == UNMAPPED_GVA) { + walker->error_code = error; + return 0; + } + walker->gfn = gpa_to_gfn(pte_gpa); + break; } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index a3fd0f9..ef2e81a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -503,6 +503,11 @@ static inline gpa_t gfn_to_gpa(gfn_t gfn) return (gpa_t)gfn << PAGE_SHIFT; } +static inline gfn_t gpa_to_gfn(gpa_t gpa) +{ + return (gfn_t)gpa >> PAGE_SHIFT; +} + static inline hpa_t pfn_to_hpa(pfn_t pfn) { return (hpa_t)pfn << PAGE_SHIFT;