From patchwork Mon Nov 26 18:55:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/6] kvm: fix incorrect length in a loop over kvm dirty pages map Date: Mon, 26 Nov 2012 08:55:54 -0000 From: Alexander Graf X-Patchwork-Id: 202007 Message-Id: <1353956157-26879-4-git-send-email-agraf@suse.de> To: "qemu-devel@nongnu.org qemu-devel" Cc: Blue Swirl , Alexey Kardashevskiy , "qemu-ppc@nongnu.org List" , Aurelien Jarno From: Alexey Kardashevskiy QEMU allocates a map enough for 4k pages. However the system page size can be 64K (for example on POWER) and the host kernel uses only a small part of it as one big stores a dirty flag for 16 pages 4K each, the hpratio variable stores this ratio and the kvm_get_dirty_pages_log_range function handles it correctly. However kvm_get_dirty_pages_log_range still goes beyond the data provided by the host kernel which is not correct. It does not cause errors at the moment as the whole bitmap is zeroed before doing KVM ioctl. The patch reduces number of iterations over the map. Signed-off-by: Alexey Kardashevskiy Signed-off-by: Alexander Graf --- kvm-all.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 3bc3347..8e9a8d8 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -364,7 +364,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, unsigned int i, j; unsigned long page_number, c; hwaddr addr, addr1; - unsigned int len = ((section->size / TARGET_PAGE_SIZE) + HOST_LONG_BITS - 1) / HOST_LONG_BITS; + unsigned int len = ((section->size / getpagesize()) + HOST_LONG_BITS - 1) / HOST_LONG_BITS; unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE; /*