Skip to content

Commit

Permalink
KVM: Fix kvm_clear_dirty_log_protect off-by-(minus-)one
Browse files Browse the repository at this point in the history
Just imaging the case where num_pages < BITS_PER_LONG, then the loop
will be skipped while it shouldn't.

Signed-off-by: Peter Xu <peterx@redhat.com>
Fixes: 2a31b9d
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
xzpeter authored and bonzini committed May 8, 2019
1 parent 4ddc920 commit 53eac7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,8 +1264,8 @@ int kvm_clear_dirty_log_protect(struct kvm *kvm,
return -EFAULT;

spin_lock(&kvm->mmu_lock);
for (offset = log->first_page,
i = offset / BITS_PER_LONG, n = log->num_pages / BITS_PER_LONG; n--;
for (offset = log->first_page, i = offset / BITS_PER_LONG,
n = DIV_ROUND_UP(log->num_pages, BITS_PER_LONG); n--;
i++, offset += BITS_PER_LONG) {
unsigned long mask = *dirty_bitmap_buffer++;
atomic_long_t *p = (atomic_long_t *) &dirty_bitmap[i];
Expand Down

0 comments on commit 53eac7a

Please sign in to comment.