From: Peter Xu Date: Wed, 8 May 2019 09:15:46 +0000 (+0800) Subject: KVM: Fix kvm_clear_dirty_log_protect off-by-(minus-)one X-Git-Tag: v5.4-rc1~940^2~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53eac7a8f8cf3d7dc5ecac1946f31442f5eee5f3;p=platform%2Fkernel%2Flinux-rpi.git KVM: Fix kvm_clear_dirty_log_protect off-by-(minus-)one 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 Fixes: 2a31b9db153530df4aa02dac8c32837bf5f47019 Signed-off-by: Paolo Bonzini --- diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ad39c57..7883e0a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -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];