From patchwork Thu Jan 28 11:37:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 75577 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 o0SBf0Wj008791 for ; Thu, 28 Jan 2010 11:41:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754899Ab0A1Lij (ORCPT ); Thu, 28 Jan 2010 06:38:39 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754716Ab0A1Lig (ORCPT ); Thu, 28 Jan 2010 06:38:36 -0500 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.15]:52076 "EHLO VA3EHSOBE006.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754767Ab0A1Lie (ORCPT ); Thu, 28 Jan 2010 06:38:34 -0500 Received: from mail162-va3-R.bigfish.com (10.7.14.250) by VA3EHSOBE006.bigfish.com (10.7.40.26) with Microsoft SMTP Server id 8.1.240.5; Thu, 28 Jan 2010 11:38:32 +0000 Received: from mail162-va3 (localhost [127.0.0.1]) by mail162-va3-R.bigfish.com (Postfix) with ESMTP id 9BD57B08A76; Thu, 28 Jan 2010 11:38:32 +0000 (UTC) X-SpamScore: 3 X-BigFish: VPS3(zzab9bh936eMab78ozz1202hzzz32i6bh87h62h) X-Spam-TCS-SCL: 1:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail162-va3 (localhost.localdomain [127.0.0.1]) by mail162-va3 (MessageSwitch) id 1264678710875880_14206; Thu, 28 Jan 2010 11:38:30 +0000 (UTC) Received: from VA3EHSMHS036.bigfish.com (unknown [10.7.14.244]) by mail162-va3.bigfish.com (Postfix) with ESMTP id C6ABA5781BC; Thu, 28 Jan 2010 11:38:30 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by VA3EHSMHS036.bigfish.com (10.7.99.46) with Microsoft SMTP Server (TLS) id 14.0.482.39; Thu, 28 Jan 2010 11:38:30 +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 ESMTP id o0SBdp5L014269; Thu, 28 Jan 2010 05:39:54 -0600 X-WSS-ID: 0KWYGBY-01-FXS-02 X-M-MSG: Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 24D931028640; Thu, 28 Jan 2010 05:38:22 -0600 (CST) Received: from sausexmb4.amd.com ([163.181.3.15]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 28 Jan 2010 05:38:25 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb4.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 28 Jan 2010 05:38:24 -0600 Received: from lemmy.osrc.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 28 Jan 2010 12:38:20 +0100 Received: by lemmy.osrc.amd.com (Postfix, from userid 41430) id A52F8C9B5A; Thu, 28 Jan 2010 12:38:20 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti , David Woodhouse CC: kvm@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 05/11] kvm: Introduce kvm_host_page_size Date: Thu, 28 Jan 2010 12:37:56 +0100 Message-ID: <1264678682-30655-6-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1264678682-30655-1-git-send-email-joerg.roedel@amd.com> References: <1264678682-30655-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 28 Jan 2010 11:38:20.0945 (UTC) FILETIME=[647E1010:01CAA00E] 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]); Thu, 28 Jan 2010 11:41:00 +0000 (UTC) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index ff2b2e8..226fa8e 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -467,24 +467,10 @@ static int has_wrprotected_page(struct kvm *kvm, static int host_mapping_level(struct kvm *kvm, gfn_t gfn) { - unsigned long page_size = PAGE_SIZE; - struct vm_area_struct *vma; - unsigned long addr; + unsigned long page_size; int i, ret = 0; - addr = gfn_to_hva(kvm, gfn); - if (kvm_is_error_hva(addr)) - return PT_PAGE_TABLE_LEVEL; - - down_read(¤t->mm->mmap_sem); - vma = find_vma(current->mm, addr); - if (!vma) - goto out; - - page_size = vma_kernel_pagesize(vma); - -out: - up_read(¤t->mm->mmap_sem); + page_size = kvm_host_page_size(kvm, gfn); for (i = PT_PAGE_TABLE_LEVEL; i < (PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES); ++i) { diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index dfde04b..a946abc 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -300,6 +300,7 @@ int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len); struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn); +unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn); void mark_page_dirty(struct kvm *kvm, gfn_t gfn); void kvm_vcpu_block(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 7c5c873..87a4a77 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -884,6 +885,30 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) } EXPORT_SYMBOL_GPL(kvm_is_visible_gfn); +unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn) +{ + struct vm_area_struct *vma; + unsigned long addr, size; + + size = PAGE_SIZE; + + addr = gfn_to_hva(kvm, gfn); + if (kvm_is_error_hva(addr)) + return PAGE_SIZE; + + down_read(¤t->mm->mmap_sem); + vma = find_vma(current->mm, addr); + if (!vma) + goto out; + + size = vma_kernel_pagesize(vma); + +out: + up_read(¤t->mm->mmap_sem); + + return size; +} + int memslot_id(struct kvm *kvm, gfn_t gfn) { int i;