]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
KVM: introduce gfn_to_hva()
authorIzik Eidus <izike@qumranet.com>
Sun, 11 Nov 2007 20:05:04 +0000 (22:05 +0200)
committerAvi Kivity <avi@qumranet.com>
Wed, 30 Jan 2008 15:53:01 +0000 (17:53 +0200)
Convert a guest frame number to the corresponding host virtual address.

Signed-off-by: Izik Eidus <izike@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm_main.c

index dfb65e2f87eeb0667e30a798816c696ea8acd3de..04544aecf22f2564a320d9e51093eb6a728b0e65 100644 (file)
@@ -559,28 +559,37 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
 }
 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
 
+static unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn)
+{
+       struct kvm_memory_slot *slot;
+
+       gfn = unalias_gfn(kvm, gfn);
+       slot = __gfn_to_memslot(kvm, gfn);
+       if (!slot)
+               return bad_hva();
+       return (slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE);
+}
+
 /*
  * Requires current->mm->mmap_sem to be held
  */
 static struct page *__gfn_to_page(struct kvm *kvm, gfn_t gfn)
 {
-       struct kvm_memory_slot *slot;
        struct page *page[1];
+       unsigned long addr;
        int npages;
 
        might_sleep();
 
-       gfn = unalias_gfn(kvm, gfn);
-       slot = __gfn_to_memslot(kvm, gfn);
-       if (!slot) {
+       addr = gfn_to_hva(kvm, gfn);
+       if (kvm_is_error_hva(addr)) {
                get_page(bad_page);
                return bad_page;
        }
 
-       npages = get_user_pages(current, current->mm,
-                               slot->userspace_addr
-                               + (gfn - slot->base_gfn) * PAGE_SIZE, 1,
-                               1, 1, page, NULL);
+       npages = get_user_pages(current, current->mm, addr, 1, 1, 1, page,
+                               NULL);
+
        if (npages != 1) {
                get_page(bad_page);
                return bad_page;