Skip to content

Commit

Permalink
KVM: Disable large pages on misaligned memory slots
Browse files Browse the repository at this point in the history
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.

Cc: [email protected]
Signed-off-by: Avi Kivity <[email protected]>
  • Loading branch information
avikivity committed Jun 10, 2009
1 parent a0861c0 commit ac04527
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,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;
Expand Down Expand Up @@ -1177,6 +1177,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 */
Expand Down

0 comments on commit ac04527

Please sign in to comment.