Skip to content

Commit

Permalink
KVM: MMU: Fix off-by-one calculating large page count
Browse files Browse the repository at this point in the history
The large page initialization code concludes there are two large pages spanned
by a slot covering 1 (small) page starting at gfn 1.  This is incorrect, and
also results in incorrect write_count initialization in some cases (base = 1,
npages = 513 for example).

Cc: [email protected]
Signed-off-by: Avi Kivity <[email protected]>
  • Loading branch information
avikivity committed Apr 22, 2009
1 parent 0910697 commit 99894a7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
int r;
gfn_t base_gfn;
unsigned long npages;
int largepages;
unsigned long i;
struct kvm_memory_slot *memslot;
struct kvm_memory_slot old, new;
Expand Down Expand Up @@ -995,11 +996,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
new.userspace_addr = 0;
}
if (npages && !new.lpage_info) {
int largepages = npages / KVM_PAGES_PER_HPAGE;
if (npages % KVM_PAGES_PER_HPAGE)
largepages++;
if (base_gfn % KVM_PAGES_PER_HPAGE)
largepages++;
largepages = 1 + (base_gfn + npages - 1) / KVM_PAGES_PER_HPAGE;
largepages -= base_gfn / KVM_PAGES_PER_HPAGE;

new.lpage_info = vmalloc(largepages * sizeof(*new.lpage_info));

Expand Down

0 comments on commit 99894a7

Please sign in to comment.