]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
KVM: Disable large pages on misaligned memory slots
authorAvi Kivity <avi@redhat.com>
Mon, 8 Jun 2009 12:52:39 +0000 (15:52 +0300)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 2 Jul 2009 23:49:32 +0000 (16:49 -0700)
commit ac04527f7947020c5890090b2ac87af4e98d977e upstream.

If a slots guest physical address and host virtual address unequal (mod
large page size), then we would erronously try to back guest large pages
with host large pages.  Detect this misalignment and diable large page
support for the trouble slot.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
virt/kvm/kvm_main.c

index 4d0dd390aa50129a99df9c13d3643a96ff0bfd50..cf4bdc97faa49036a63df30abcb1d37d1f348e09 100644 (file)
@@ -919,7 +919,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 {
        int r;
        gfn_t base_gfn;
-       unsigned long npages;
+       unsigned long npages, ugfn;
        int largepages;
        unsigned long i;
        struct kvm_memory_slot *memslot;
@@ -1010,6 +1010,14 @@ int __kvm_set_memory_region(struct kvm *kvm,
                        new.lpage_info[0].write_count = 1;
                if ((base_gfn+npages) % KVM_PAGES_PER_HPAGE)
                        new.lpage_info[largepages-1].write_count = 1;
+               ugfn = new.userspace_addr >> PAGE_SHIFT;
+               /*
+                * If the gfn and userspace address are not aligned wrt each
+                * other, disable large page support for this slot
+                */
+               if ((base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE - 1))
+                       for (i = 0; i < largepages; ++i)
+                               new.lpage_info[i].write_count = 1;
        }
 
        /* Allocate page dirty bitmap if needed */