summaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2010-01-28 12:37:56 +0100
committerMarcelo Tosatti <mtosatti@redhat.com>2010-03-01 12:36:08 -0300
commit8f0b1ab6fb045a1324d9435ba00c2940783b0041 (patch)
tree34db9f9080cea014150249da16348ed3e3e01fc3 /virt
parentc45b4fd416f5497b6b38dd70acc0e5b01399e5c9 (diff)
KVM: Introduce kvm_host_page_size
This patch introduces a generic function to find out the host page size for a given gfn. This function is needed by the kvm iommu code. This patch also simplifies the x86 host_mapping_level function. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2b0974a1483..0a360c26cc3 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -45,6 +45,7 @@
#include <linux/spinlock.h>
#include <linux/compat.h>
#include <linux/srcu.h>
+#include <linux/hugetlb.h>
#include <asm/processor.h>
#include <asm/io.h>
@@ -867,6 +868,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(&current->mm->mmap_sem);
+ vma = find_vma(current->mm, addr);
+ if (!vma)
+ goto out;
+
+ size = vma_kernel_pagesize(vma);
+
+out:
+ up_read(&current->mm->mmap_sem);
+
+ return size;
+}
+
int memslot_id(struct kvm *kvm, gfn_t gfn)
{
int i;