From patchwork Tue Apr 27 10:38:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 95375 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 o3RAiKZu020876 for ; Tue, 27 Apr 2010 10:44:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755126Ab0D0Kmp (ORCPT ); Tue, 27 Apr 2010 06:42:45 -0400 Received: from tx2ehsobe004.messaging.microsoft.com ([65.55.88.14]:20551 "EHLO TX2EHSOBE008.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754586Ab0D0Kix (ORCPT ); Tue, 27 Apr 2010 06:38:53 -0400 Received: from mail184-tx2-R.bigfish.com (10.9.14.243) by TX2EHSOBE008.bigfish.com (10.9.40.28) with Microsoft SMTP Server id 8.1.340.0; Tue, 27 Apr 2010 10:38:52 +0000 Received: from mail184-tx2 (localhost.localdomain [127.0.0.1]) by mail184-tx2-R.bigfish.com (Postfix) with ESMTP id 8176216C03A4; Tue, 27 Apr 2010 10:38:52 +0000 (UTC) X-SpamScore: 17 X-BigFish: VPS17(zzab9bhb0c3ihzz1202hzz6ff19hz32i2a8h87h61h) X-Spam-TCS-SCL: 0:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail184-tx2 (localhost.localdomain [127.0.0.1]) by mail184-tx2 (MessageSwitch) id 127236473296483_11476; Tue, 27 Apr 2010 10:38:52 +0000 (UTC) Received: from TX2EHSMHS049.bigfish.com (unknown [10.9.14.254]) by mail184-tx2.bigfish.com (Postfix) with ESMTP id 0AB641940052; Tue, 27 Apr 2010 10:38:52 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by TX2EHSMHS049.bigfish.com (10.9.99.149) with Microsoft SMTP Server (TLS) id 14.0.482.44; Tue, 27 Apr 2010 10:38:51 +0000 Received: from ausb3twp01.amd.com (ausb3twp01.amd.com [163.181.250.37]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with SMTP id o3RAdC69012764; Tue, 27 Apr 2010 05:39:16 -0500 X-WSS-ID: 0L1J6WN-01-32T-02 X-M-MSG: Received: from sausexhtp02.amd.com (sausexhtp02.amd.com [163.181.3.152]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2F6651028562; Tue, 27 Apr 2010 05:38:46 -0500 (CDT) Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.2.234.1; Tue, 27 Apr 2010 05:38:49 -0500 Received: from storexmb1.amd.com (10.1.1.14) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.2.234.1; Tue, 27 Apr 2010 03:38:48 -0700 Received: from sausexmb1.amd.com ([163.181.3.156]) by storexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 27 Apr 2010 06:38:48 -0400 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 27 Apr 2010 05:38:45 -0500 Received: from lemmy.osrc.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 27 Apr 2010 12:38:35 +0200 Received: by lemmy.osrc.amd.com (Postfix, from userid 41430) id EB9BFC9C3B; Tue, 27 Apr 2010 12:38:35 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 14/22] KVM: MMU: Make walk_addr_generic capable for two-level walking Date: Tue, 27 Apr 2010 12:38:24 +0200 Message-ID: <1272364712-17425-15-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1272364712-17425-1-git-send-email-joerg.roedel@amd.com> References: <1272364712-17425-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 27 Apr 2010 10:38:35.0980 (UTC) FILETIME=[CA7390C0:01CAE5F5] 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]); Tue, 27 Apr 2010 10:44:32 +0000 (UTC) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 7819a6f..8b27026 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -121,8 +121,9 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, gfn_t table_gfn; unsigned index, pt_access, pte_access; gpa_t pte_gpa; + int offset; int rsvd_fault = 0; - u32 error; + u32 error = 0; trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, fetch_fault); @@ -149,13 +150,16 @@ walk: index = PT_INDEX(addr, walker->level); table_gfn = gpte_to_gfn(pte); - pte_gpa = gfn_to_gpa(table_gfn); - pte_gpa += index * sizeof(pt_element_t); + offset = index * sizeof(pt_element_t); + pte_gpa = gfn_to_gpa(table_gfn) + offset; 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))) - goto not_present; + if (kvm_read_guest_page_tdp(vcpu, mmu, table_gfn, &pte, offset, + sizeof(pte), &error)) { + walker->error_code = error; + return 0; + } trace_kvm_mmu_paging_element(pte, walker->level); @@ -200,15 +204,25 @@ walk: is_large_pte(pte) && mmu->root_level == PT64_ROOT_LEVEL)) { int lvl = walker->level; + gpa_t real_gpa; + gfn_t gfn; - walker->gfn = gpte_to_gfn_lvl(pte, lvl); - walker->gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) - >> PAGE_SHIFT; + gfn = gpte_to_gfn_lvl(pte, lvl); + gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) >> PAGE_SHIFT; if (PTTYPE == 32 && walker->level == PT_DIRECTORY_LEVEL && is_cpuid_PSE36()) - walker->gfn += pse36_gfn_delta(pte); + gfn += pse36_gfn_delta(pte); + + real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(gfn), + &error); + if (real_gpa == UNMAPPED_GVA) { + walker->error_code = error; + return 0; + } + + walker->gfn = real_gpa >> PAGE_SHIFT; break; } @@ -237,7 +251,7 @@ walk: return 1; not_present: - walker->error_code = 0; + walker->error_code = error; goto err; access_error: