Skip to content

Commit

Permalink
kvm: Fix dirty tracking with large kernel page size
Browse files Browse the repository at this point in the history
If the kernel page size is larger than TARGET_PAGE_SIZE, which
happens for example on ppc64 with kernels compiled for 64K pages,
the dirty tracking doesn't work.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Avi Kivity <avi@redhat.com>
  • Loading branch information
dgibson authored and avikivity committed May 10, 2012
1 parent 8f473dd commit 3145fcb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kvm-all.c
Expand Up @@ -348,6 +348,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
unsigned long page_number, c;
target_phys_addr_t addr, addr1;
unsigned int len = ((section->size / TARGET_PAGE_SIZE) + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;

/*
* bitmap-traveling is faster than memory-traveling (for addr...)
Expand All @@ -359,10 +360,11 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
do {
j = ffsl(c) - 1;
c &= ~(1ul << j);
page_number = i * HOST_LONG_BITS + j;
page_number = (i * HOST_LONG_BITS + j) * hpratio;
addr1 = page_number * TARGET_PAGE_SIZE;
addr = section->offset_within_region + addr1;
memory_region_set_dirty(section->mr, addr, TARGET_PAGE_SIZE);
memory_region_set_dirty(section->mr, addr,
TARGET_PAGE_SIZE * hpratio);
} while (c != 0);
}
}
Expand Down Expand Up @@ -980,6 +982,14 @@ int kvm_init(void)

s = g_malloc0(sizeof(KVMState));

/*
* On systems where the kernel can support different base page
* sizes, host page size may be different from TARGET_PAGE_SIZE,
* even with KVM. TARGET_PAGE_SIZE is assumed to be the minimum
* page size for the system though.
*/
assert(TARGET_PAGE_SIZE <= getpagesize());

#ifdef KVM_CAP_SET_GUEST_DEBUG
QTAILQ_INIT(&s->kvm_sw_breakpoints);
#endif
Expand Down

0 comments on commit 3145fcb

Please sign in to comment.