KVM: Fix kvm_clear_dirty_log_protect off-by-(minus-)one
authorPeter Xu <peterx@redhat.com>
Wed, 8 May 2019 09:15:46 +0000 (17:15 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 May 2019 11:43:28 +0000 (13:43 +0200)
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: 2a31b9db153530df4aa02dac8c32837bf5f47019
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virt/kvm/kvm_main.c

index ad39c57de82d8cd4a6ba3b1c3e884c5d9f3f0b63..7883e0ad07fe8c8709e32957a615d127a3ca8334 100644 (file)
@@ -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];