qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH, RESEND] kvm: Fix dirty tracking with large kernel page size
@ 2012-04-04  1:15 David Gibson
  2012-04-04  8:41 ` Avi Kivity
  0 siblings, 1 reply; 13+ messages in thread
From: David Gibson @ 2012-04-04  1:15 UTC (permalink / raw)
  To: avi, mtosatti; +Cc: aliguori, jan.kiszka, qemu-devel, 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 <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH, RESEND] kvm: Fix dirty tracking with large kernel page size
@ 2012-04-02  4:04 David Gibson
  2012-04-02  4:14 ` Benjamin Herrenschmidt
  2012-04-03  7:08 ` Jan Kiszka
  0 siblings, 2 replies; 13+ messages in thread
From: David Gibson @ 2012-04-02  4:04 UTC (permalink / raw)
  To: avi, mtosatti; +Cc: aliguori, David Gibson, qemu-devel, Avi Kivity

From: Ben Herrenschmidt <benh@kernel.crashing.org>

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 <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 kvm-all.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

I've sent this a number of times now, the last couple without comment.
It fixes a real bug, please apply.

diff --git a/kvm-all.c b/kvm-all.c
index ba2cee1..7e44429 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);
         }
     }
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-05-10 10:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-04  1:15 [Qemu-devel] [PATCH, RESEND] kvm: Fix dirty tracking with large kernel page size David Gibson
2012-04-04  8:41 ` Avi Kivity
2012-05-09 22:23   ` Anthony Liguori
2012-05-10  9:27     ` Avi Kivity
2012-05-10 10:49       ` Jan Kiszka
2012-05-10 10:55         ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2012-04-02  4:04 David Gibson
2012-04-02  4:14 ` Benjamin Herrenschmidt
2012-04-03  7:08 ` Jan Kiszka
2012-04-04  1:12   ` David Gibson
2012-04-04 10:58     ` Jan Kiszka
2012-04-04 14:24       ` David Gibson
2012-04-05  7:32         ` Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).