From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFEpR-0004gx-Qr for qemu-devel@nongnu.org; Tue, 03 Apr 2012 21:16:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFEpO-00078i-Tu for qemu-devel@nongnu.org; Tue, 03 Apr 2012 21:16:05 -0400 Received: from ozlabs.org ([203.10.76.45]:48630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFEpO-00078U-Hk for qemu-devel@nongnu.org; Tue, 03 Apr 2012 21:16:02 -0400 From: David Gibson Date: Wed, 4 Apr 2012 11:15:54 +1000 Message-Id: <1333502154-23999-1-git-send-email-david@gibson.dropbear.id.au> Subject: [Qemu-devel] [PATCH, RESEND] kvm: Fix dirty tracking with large kernel page size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: avi@redhat.com, mtosatti@redhat.com Cc: aliguori@us.ibm.com, jan.kiszka@web.de, qemu-devel@nongnu.org, David Gibson 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. Cc: Avi Kivity Cc: Marcelo Tosatti Signed-off-by: Benjamin Herrenschmidt Signed-off-by: David Gibson --- kvm-all.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) Please apply. Changes since last post: * Added assertion and comment in kvm_init() as requested by Jan Kiszka diff --git a/kvm-all.c b/kvm-all.c index ba2cee1..1f49d0a 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -354,6 +354,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...) @@ -365,10 +366,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); } } @@ -986,6 +988,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 -- 1.7.9.1