Skip to contentSkip to conversation

Xen, introducing dirty log for migration.

PATCH Superseded Anthony PERARD 3 participants 21 messages Sep 27, 2012 – Oct 2, 2012

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Xen, introducing dirty log for migration.

Hi,

This patch set will fix live migration under Xen. For this I introduce a new QMP command to switch global-dirty log and few calls (in exec.c and memory.c) to xen set_dirty function.

Change since v3:
- Coding style of patch 2
- Reword last patch comment

Change since v2:
- renamed set_dirty_helper to invalidate_and_set_dirty.
- in the last patch, set vram as dirty if the xen call fails, instead of only during migration.

Change v1-v2:
- New patch to set dirty if not, in exec.c => only one place to add the xen call in exec.c

Thanks for your reviews,

Anthony PERARD (5):
QMP, Introduce xen-set-global-dirty-log command.
xen: Introduce xen_modified_memory.
exec: Introduce helper to set dirty flags. exec, memory: Call to xen_modified_memory.
xen: Set the vram dirty when an error occur.

 exec.c           | 53 ++++++++++++++++++-----------------------------------
 hw/xen.h         |  1 +
 memory.c         |  2 ++
 qapi-schema.json | 13 +++++++++++++
 qmp-commands.hx  | 24 ++++++++++++++++++++++++
 xen-all.c        | 39 ++++++++++++++++++++++++++++++++++++++-
 xen-stub.c       |  9 +++++++++
 7 files changed, 105 insertions(+), 36 deletions(-)
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH v4 1/5 QMP, Introduce xen-set-global-dirty-log command.

This command is used during a migration of a guest under Xen. It calls memory_global_dirty_log_start or memory_global_dirty_log_stop according to the argument pass to the command.

---
 qapi-schema.json | 13 +++++++++++++
 qmp-commands.hx  | 24 ++++++++++++++++++++++++
 xen-all.c        | 15 +++++++++++++++
 xen-stub.c       |  5 +++++
 4 files changed, 57 insertions(+)
qapi-schema.json +13 -0
index 14e4419..696f45a 100644
@@ -1956,6 +1956,19 @@
 { 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} }
 
 ##
+# @xen-set-global-dirty-log
+#
+# Enable or disable the global dirty log mode.
+#
+# @enable: true to enable, false to disable.
+#
+# Returns: nothing
+#
+# Since: 1.2
+##
+{ 'command': 'xen-set-global-dirty-log', 'data': { 'enable': 'bool' } }
+
+##
 # @device_del:
 #
 # Remove a device from a guest
qmp-commands.hx +24 -0
index 6e21ddb..662b7cf 100644
@@ -493,6 +493,30 @@ Example:
 EQMP
 
     {
+        .name       = "xen-set-global-dirty-log",
+        .args_type  = "enable:b",
+        .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,
+    },
+
+SQMP
+xen-set-global-dirty-log
+-------
+
+Enable or disable the global dirty log mode.
+
+Arguments:
+
+- "enable": Enable it or disable it.
+
+Example:
+
+-> { "execute": "xen-set-global-dirty-log",
+     "arguments": { "enable": true } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "migrate",
         .args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
         .mhandler.cmd_new = qmp_marshal_input_migrate,
xen-all.c +15 -0
index f76b051..f75ae9f 100644
@@ -14,6 +14,7 @@
 #include "hw/pc.h"
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
+#include "qmp-commands.h"
 
 #include "range.h"
 #include "xen-mapcache.h"
@@ -36,6 +37,7 @@
 
 static MemoryRegion ram_memory, ram_640k, ram_lo, ram_hi;
 static MemoryRegion *framebuffer;
+static bool xen_in_migration;
 
 /* Compatibility with older version */
 #if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a
@@ -552,10 +554,14 @@ static void xen_log_sync(MemoryListener *listener, MemoryRegionSection *section)
 
 static void xen_log_global_start(MemoryListener *listener)
 {
+    if (xen_enabled()) {
+        xen_in_migration = true;
+    }
 }
 
 static void xen_log_global_stop(MemoryListener *listener)
 {
+    xen_in_migration = false;
 }
 
 static void xen_eventfd_add(MemoryListener *listener,
@@ -588,6 +594,15 @@ static MemoryListener xen_memory_listener = {
     .priority = 10,
 };
 
+void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
+{
+    if (enable) {
+        memory_global_dirty_log_start();
+    } else {
+        memory_global_dirty_log_stop();
+    }
+}
+
 /* VCPU Operations, MMIO, IO ring ... */
 
 static void xen_reset_vcpu(void *opaque)
xen-stub.c +5 -0
index 8ff2b79..5e66ba8 100644
@@ -11,6 +11,7 @@
 #include "qemu-common.h"
 #include "hw/xen.h"
 #include "memory.h"
+#include "qmp-commands.h"
 
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
@@ -54,3 +55,7 @@ int xen_init(void)
 void xen_register_framebuffer(MemoryRegion *mr)
 {
 }
+
+void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
+{
+}
Signature · 1 line
Anthony PERARD
#2 lore raw

PATCH v4 1/5 QMP, Introduce xen-set-global-dirty-log command.

In reply to Anthony PERARD

This command is used during a migration of a guest under Xen. It calls memory_global_dirty_log_start or memory_global_dirty_log_stop according to the argument pass to the command.

---
 qapi-schema.json | 13 +++++++++++++
 qmp-commands.hx  | 24 ++++++++++++++++++++++++
 xen-all.c        | 15 +++++++++++++++
 xen-stub.c       |  5 +++++
 4 files changed, 57 insertions(+)
qapi-schema.json +13 -0
index 14e4419..696f45a 100644
@@ -1956,6 +1956,19 @@
 { 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} }
 
 ##
+# @xen-set-global-dirty-log
+#
+# Enable or disable the global dirty log mode.
+#
+# @enable: true to enable, false to disable.
+#
+# Returns: nothing
+#
+# Since: 1.2
+##
+{ 'command': 'xen-set-global-dirty-log', 'data': { 'enable': 'bool' } }
+
+##
 # @device_del:
 #
 # Remove a device from a guest
qmp-commands.hx +24 -0
index 6e21ddb..662b7cf 100644
@@ -493,6 +493,30 @@ Example:
 EQMP
 
     {
+        .name       = "xen-set-global-dirty-log",
+        .args_type  = "enable:b",
+        .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,
+    },
+
+SQMP
+xen-set-global-dirty-log
+-------
+
+Enable or disable the global dirty log mode.
+
+Arguments:
+
+- "enable": Enable it or disable it.
+
+Example:
+
+-> { "execute": "xen-set-global-dirty-log",
+     "arguments": { "enable": true } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "migrate",
         .args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
         .mhandler.cmd_new = qmp_marshal_input_migrate,
xen-all.c +15 -0
index f76b051..f75ae9f 100644
@@ -14,6 +14,7 @@
 #include "hw/pc.h"
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
+#include "qmp-commands.h"
 
 #include "range.h"
 #include "xen-mapcache.h"
@@ -36,6 +37,7 @@
 
 static MemoryRegion ram_memory, ram_640k, ram_lo, ram_hi;
 static MemoryRegion *framebuffer;
+static bool xen_in_migration;
 
 /* Compatibility with older version */
 #if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a
@@ -552,10 +554,14 @@ static void xen_log_sync(MemoryListener *listener, MemoryRegionSection *section)
 
 static void xen_log_global_start(MemoryListener *listener)
 {
+    if (xen_enabled()) {
+        xen_in_migration = true;
+    }
 }
 
 static void xen_log_global_stop(MemoryListener *listener)
 {
+    xen_in_migration = false;
 }
 
 static void xen_eventfd_add(MemoryListener *listener,
@@ -588,6 +594,15 @@ static MemoryListener xen_memory_listener = {
     .priority = 10,
 };
 
+void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
+{
+    if (enable) {
+        memory_global_dirty_log_start();
+    } else {
+        memory_global_dirty_log_stop();
+    }
+}
+
 /* VCPU Operations, MMIO, IO ring ... */
 
 static void xen_reset_vcpu(void *opaque)
xen-stub.c +5 -0
index 8ff2b79..5e66ba8 100644
@@ -11,6 +11,7 @@
 #include "qemu-common.h"
 #include "hw/xen.h"
 #include "memory.h"
+#include "qmp-commands.h"
 
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
@@ -54,3 +55,7 @@ int xen_init(void)
 void xen_register_framebuffer(MemoryRegion *mr)
 {
 }
+
+void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
+{
+}
Signature · 1 line
Anthony PERARD
#3 lore raw

PATCH v4 2/5 xen: Introduce xen_modified_memory.

In reply to Anthony PERARD

This function is to be used during live migration. Every write access to the guest memory should call this funcion so the Xen tools knows which pages are dirty.

---
 hw/xen.h   |  1 +
 xen-all.c  | 21 +++++++++++++++++++++
 xen-stub.c |  4 ++++
 3 files changed, 26 insertions(+)
hw/xen.h +1 -0
index e5926b7..d14e92d 100644
@@ -48,6 +48,7 @@ void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 struct MemoryRegion;
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr);
+void xen_modified_memory(ram_addr_t start, ram_addr_t length);
 #endif
 
 struct MemoryRegion;
xen-all.c +21 -0
index f75ae9f..b11542c 100644
@@ -1228,3 +1228,24 @@ void xen_shutdown_fatal_error(const char *fmt, ...)
     /* destroy the domain */
     qemu_system_shutdown_request();
 }
+
+void xen_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+    if (unlikely(xen_in_migration)) {
+        int rc;
+        ram_addr_t start_pfn, nb_pages;
+
+        if (length == 0) {
+            length = TARGET_PAGE_SIZE;
+        }
+        start_pfn = start >> TARGET_PAGE_BITS;
+        nb_pages = ((start + length + TARGET_PAGE_SIZE - 1) >> TARGET_PAGE_BITS)
+            - start_pfn;
+        rc = xc_hvm_modified_memory(xen_xc, xen_domid, start_pfn, nb_pages);
+        if (rc) {
+            fprintf(stderr,
+                    "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s\n",
+                    __func__, start, nb_pages, rc, strerror(-rc));
+        }
+    }
+}
xen-stub.c +4 -0
index 5e66ba8..9214392 100644
@@ -59,3 +59,7 @@ void xen_register_framebuffer(MemoryRegion *mr)
 void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
 {
 }
+
+void xen_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+}
Signature · 1 line
Anthony PERARD
Acked-by on v4 2/5
#4 lore raw

Re: [PATCH V4 2/5] xen: Introduce xen_modified_memory.

Quoted 5 lines · Anthony PERARD

This function is to be used during live migration. Every write access to the guest memory should call this funcion so the Xen tools knows which pages are dirty.

Quoted 61 lines
 hw/xen.h   |  1 +
 xen-all.c  | 21 +++++++++++++++++++++
 xen-stub.c |  4 ++++
 3 files changed, 26 insertions(+)
hw/xen.h +1 -0
index e5926b7..d14e92d 100644
@@ -48,6 +48,7 @@ void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 struct MemoryRegion;
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr);
+void xen_modified_memory(ram_addr_t start, ram_addr_t length);
 #endif
 
 struct MemoryRegion;
xen-all.c +21 -0
index f75ae9f..b11542c 100644
@@ -1228,3 +1228,24 @@ void xen_shutdown_fatal_error(const char *fmt, ...)
     /* destroy the domain */
     qemu_system_shutdown_request();
 }
+
+void xen_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+    if (unlikely(xen_in_migration)) {
+        int rc;
+        ram_addr_t start_pfn, nb_pages;
+
+        if (length == 0) {
+            length = TARGET_PAGE_SIZE;
+        }
+        start_pfn = start >> TARGET_PAGE_BITS;
+        nb_pages = ((start + length + TARGET_PAGE_SIZE - 1) >> TARGET_PAGE_BITS)
+            - start_pfn;
+        rc = xc_hvm_modified_memory(xen_xc, xen_domid, start_pfn, nb_pages);
+        if (rc) {
+            fprintf(stderr,
+                    "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s\n",
+                    __func__, start, nb_pages, rc, strerror(-rc));
+        }
+    }
+}
xen-stub.c +4 -0
index 5e66ba8..9214392 100644
@@ -59,3 +59,7 @@ void xen_register_framebuffer(MemoryRegion *mr)
 void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
 {
 }
+
+void xen_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+}
Signature · 1 line
Anthony PERARD
Acked-by on v4 2/5
#5 lore raw

Re: [Qemu-devel] [PATCH V4 2/5] xen: Introduce xen_modified_memory.

In reply to Anthony PERARD
Quoted 5 lines · Anthony PERARD

This function is to be used during live migration. Every write access to the guest memory should call this funcion so the Xen tools knows which pages are dirty.

Quoted 61 lines
 hw/xen.h   |  1 +
 xen-all.c  | 21 +++++++++++++++++++++
 xen-stub.c |  4 ++++
 3 files changed, 26 insertions(+)
hw/xen.h +1 -0
index e5926b7..d14e92d 100644
@@ -48,6 +48,7 @@ void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 struct MemoryRegion;
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr);
+void xen_modified_memory(ram_addr_t start, ram_addr_t length);
 #endif
 
 struct MemoryRegion;
xen-all.c +21 -0
index f75ae9f..b11542c 100644
@@ -1228,3 +1228,24 @@ void xen_shutdown_fatal_error(const char *fmt, ...)
     /* destroy the domain */
     qemu_system_shutdown_request();
 }
+
+void xen_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+    if (unlikely(xen_in_migration)) {
+        int rc;
+        ram_addr_t start_pfn, nb_pages;
+
+        if (length == 0) {
+            length = TARGET_PAGE_SIZE;
+        }
+        start_pfn = start >> TARGET_PAGE_BITS;
+        nb_pages = ((start + length + TARGET_PAGE_SIZE - 1) >> TARGET_PAGE_BITS)
+            - start_pfn;
+        rc = xc_hvm_modified_memory(xen_xc, xen_domid, start_pfn, nb_pages);
+        if (rc) {
+            fprintf(stderr,
+                    "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s\n",
+                    __func__, start, nb_pages, rc, strerror(-rc));
+        }
+    }
+}
xen-stub.c +4 -0
index 5e66ba8..9214392 100644
@@ -59,3 +59,7 @@ void xen_register_framebuffer(MemoryRegion *mr)
 void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
 {
 }
+
+void xen_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+}
Signature · 1 line
Anthony PERARD
#6 lore raw

PATCH v4 3/5 exec: Introduce helper to set dirty flags.

In reply to Anthony PERARD

This new helper/hook is used in the next patch to add an extra call in a single place.

---
 exec.c | 52 +++++++++++++++++-----------------------------------
 1 file changed, 17 insertions(+), 35 deletions(-)
exec.c +17 -35
index bb6aa4a..366684c 100644
@@ -3417,6 +3417,18 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
 }
 
 #else
+
+static void invalidate_and_set_dirty(target_phys_addr_t addr,
+                                     target_phys_addr_t length)
+{
+    if (!cpu_physical_memory_is_dirty(addr)) {
+        /* invalidate code */
+        tb_invalidate_phys_page_range(addr, addr + length, 0);
+        /* set dirty bit */
+        cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
+    }
+}
+
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                             int len, int is_write)
 {
@@ -3462,13 +3474,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                 /* RAM case */
                 ptr = qemu_get_ram_ptr(addr1);
                 memcpy(ptr, buf, l);
-                if (!cpu_physical_memory_is_dirty(addr1)) {
-                    /* invalidate code */
-                    tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                    /* set dirty bit */
-                    cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
-                }
+                invalidate_and_set_dirty(addr1, l);
                 qemu_put_ram_ptr(ptr);
             }
         } else {
@@ -3534,13 +3540,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
             /* ROM/RAM case */
             ptr = qemu_get_ram_ptr(addr1);
             memcpy(ptr, buf, l);
-            if (!cpu_physical_memory_is_dirty(addr1)) {
-                /* invalidate code */
-                tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                /* set dirty bit */
-                cpu_physical_memory_set_dirty_flags(
-                    addr1, (0xff & ~CODE_DIRTY_FLAG));
-            }
+            invalidate_and_set_dirty(addr1, l);
             qemu_put_ram_ptr(ptr);
         }
         len -= l;
@@ -3666,13 +3666,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
                 l = TARGET_PAGE_SIZE;
                 if (l > access_len)
                     l = access_len;
-                if (!cpu_physical_memory_is_dirty(addr1)) {
-                    /* invalidate code */
-                    tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                    /* set dirty bit */
-                    cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
-                }
+                invalidate_and_set_dirty(addr1, l);
                 addr1 += l;
                 access_len -= l;
             }
@@ -3978,13 +3972,7 @@ static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val,
             stl_p(ptr, val);
             break;
         }
-        if (!cpu_physical_memory_is_dirty(addr1)) {
-            /* invalidate code */
-            tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
-            /* set dirty bit */
-            cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
-        }
+        invalidate_and_set_dirty(addr1, 4);
     }
 }
 
@@ -4051,13 +4039,7 @@ static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val,
             stw_p(ptr, val);
             break;
         }
-        if (!cpu_physical_memory_is_dirty(addr1)) {
-            /* invalidate code */
-            tb_invalidate_phys_page_range(addr1, addr1 + 2, 0);
-            /* set dirty bit */
-            cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
-        }
+        invalidate_and_set_dirty(addr1, 2);
     }
 }
 
Signature · 1 line
Anthony PERARD
#7 lore raw

PATCH v4 3/5 exec: Introduce helper to set dirty flags.

In reply to Anthony PERARD

This new helper/hook is used in the next patch to add an extra call in a single place.

---
 exec.c | 52 +++++++++++++++++-----------------------------------
 1 file changed, 17 insertions(+), 35 deletions(-)
exec.c +17 -35
index bb6aa4a..366684c 100644
@@ -3417,6 +3417,18 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
 }
 
 #else
+
+static void invalidate_and_set_dirty(target_phys_addr_t addr,
+                                     target_phys_addr_t length)
+{
+    if (!cpu_physical_memory_is_dirty(addr)) {
+        /* invalidate code */
+        tb_invalidate_phys_page_range(addr, addr + length, 0);
+        /* set dirty bit */
+        cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
+    }
+}
+
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                             int len, int is_write)
 {
@@ -3462,13 +3474,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                 /* RAM case */
                 ptr = qemu_get_ram_ptr(addr1);
                 memcpy(ptr, buf, l);
-                if (!cpu_physical_memory_is_dirty(addr1)) {
-                    /* invalidate code */
-                    tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                    /* set dirty bit */
-                    cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
-                }
+                invalidate_and_set_dirty(addr1, l);
                 qemu_put_ram_ptr(ptr);
             }
         } else {
@@ -3534,13 +3540,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
             /* ROM/RAM case */
             ptr = qemu_get_ram_ptr(addr1);
             memcpy(ptr, buf, l);
-            if (!cpu_physical_memory_is_dirty(addr1)) {
-                /* invalidate code */
-                tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                /* set dirty bit */
-                cpu_physical_memory_set_dirty_flags(
-                    addr1, (0xff & ~CODE_DIRTY_FLAG));
-            }
+            invalidate_and_set_dirty(addr1, l);
             qemu_put_ram_ptr(ptr);
         }
         len -= l;
@@ -3666,13 +3666,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
                 l = TARGET_PAGE_SIZE;
                 if (l > access_len)
                     l = access_len;
-                if (!cpu_physical_memory_is_dirty(addr1)) {
-                    /* invalidate code */
-                    tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                    /* set dirty bit */
-                    cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
-                }
+                invalidate_and_set_dirty(addr1, l);
                 addr1 += l;
                 access_len -= l;
             }
@@ -3978,13 +3972,7 @@ static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val,
             stl_p(ptr, val);
             break;
         }
-        if (!cpu_physical_memory_is_dirty(addr1)) {
-            /* invalidate code */
-            tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
-            /* set dirty bit */
-            cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
-        }
+        invalidate_and_set_dirty(addr1, 4);
     }
 }
 
@@ -4051,13 +4039,7 @@ static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val,
             stw_p(ptr, val);
             break;
         }
-        if (!cpu_physical_memory_is_dirty(addr1)) {
-            /* invalidate code */
-            tb_invalidate_phys_page_range(addr1, addr1 + 2, 0);
-            /* set dirty bit */
-            cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
-        }
+        invalidate_and_set_dirty(addr1, 2);
     }
 }
 
Signature · 1 line
Anthony PERARD
#8 lore raw

PATCH v4 4/5 exec, memory: Call to xen_modified_memory.

In reply to Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about dirtybits during migration.

---
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
exec.c +1 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void invalidate_and_set_dirty(target_phys_addr_t addr,
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +2 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 }
 
Signature · 1 line
Anthony PERARD
#9 lore raw

Re: [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

Quoted 4 lines · Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about dirtybits during migration.

If I am not mistaken, this is the last patch that needs reviewing. Avi, are you OK with it?

Quoted 39 lines
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
exec.c +1 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void invalidate_and_set_dirty(target_phys_addr_t addr,
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +2 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 }
 
Signature · 1 line
Anthony PERARD
#10 lore raw

Re: [Qemu-devel] [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

In reply to Anthony PERARD
Quoted 4 lines · Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about dirtybits during migration.

If I am not mistaken, this is the last patch that needs reviewing. Avi, are you OK with it?

Quoted 39 lines
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
exec.c +1 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void invalidate_and_set_dirty(target_phys_addr_t addr,
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +2 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 }
 
Signature · 1 line
Anthony PERARD
#11 lore raw

Re: [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

Quoted 37 lines · Stefano Stabellini
Quoted 4 lines · Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about dirtybits during migration.

If I am not mistaken, this is the last patch that needs reviewing. Avi, are you OK with it?

Quoted 26 lines
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
exec.c +1 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void invalidate_and_set_dirty(target_phys_addr_t addr,
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +1 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
Quoted 9 lines

memory.c void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr, · line 1083

Quoted 9 lines
memory.c +1 -0
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 }

I would prefer this bit pushed into cpu_physical_set_dirty_range(). Possibly the first bit too?

Signature · 1 line
error compiling committee.c: too many arguments to function
#12 lore raw

Re: [Qemu-devel] [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

In reply to Stefano Stabellini
Quoted 37 lines · Stefano Stabellini
Quoted 4 lines · Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about dirtybits during migration.

If I am not mistaken, this is the last patch that needs reviewing. Avi, are you OK with it?

Quoted 26 lines
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
exec.c +1 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void invalidate_and_set_dirty(target_phys_addr_t addr,
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +1 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
Quoted 9 lines

memory.c void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr, · line 1083

Quoted 9 lines
memory.c +1 -0
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 }

I would prefer this bit pushed into cpu_physical_set_dirty_range(). Possibly the first bit too?

Signature · 1 line
error compiling committee.c: too many arguments to function
#13 lore raw

Re: [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

Quoted 3 lines · Avi Kivity
Quoted 2 lines · Stefano Stabellini
Quoted 1 line · Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about

dirtybits

Quoted 13 lines
Quoted 13 lines
Quoted 3 lines

during migration.

If I am not mistaken, this is the last patch that needs reviewing. Avi, are you OK with it?

Quoted 4 lines
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
Quoted 5 lines
Quoted 5 lines

exec.c static void

Quoted 5 lines
exec.c +0 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void

invalidate_and_set_dirty(target_phys_addr_t addr,

Quoted 2 lines
Quoted 2 lines

exec.c static void · line 3428

Quoted 2 lines
exec.c +0 -0
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff &

~CODE_DIRTY_FLAG));

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
exec.c +1 -0
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +1 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
Quoted 3 lines
Quoted 3 lines

memory.c void memory_region_set_dirty(MemoryRegion *mr,

Quoted 3 lines
memory.c +0 -0
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr,

target_phys_addr_t addr,

Quoted 5 lines
Quoted 5 lines

memory.c void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,

Quoted 5 lines
memory.c +1 -0
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr,

size, -1);

Quoted 3 lines
Quoted 1 line

memory.c void memory_region_set_dirty(MemoryRegion *mr, · line 1083

Quoted 1 line
memory.c +0 -0
 }

I would prefer this bit pushed into cpu_physical_set_dirty_range().

Ok, I will call the function from cpu_physical_memory_set_dirty_range() instead of from memory_region_set_dirty.

Quoted 1 line

Possibly the first bit too?

But the call from invalidate_and_set_dirty, I can not remove it because it does not work. The xen function must be called without condition as xen and qemu does not maintained the same dirtymap.

Signature · 1 line
Anthony PERARD
#14 lore raw

Re: [Qemu-devel] [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

In reply to Avi Kivity
Quoted 3 lines · Avi Kivity
Quoted 2 lines · Stefano Stabellini
Quoted 1 line · Anthony PERARD

This patch add some calls to xen_modified_memory to notify Xen about

dirtybits

Quoted 13 lines
Quoted 13 lines
Quoted 3 lines

during migration.

If I am not mistaken, this is the last patch that needs reviewing. Avi, are you OK with it?

Quoted 4 lines
 exec.c   | 1 +
 memory.c | 2 ++
 2 files changed, 3 insertions(+)
Quoted 5 lines
Quoted 5 lines

exec.c static void

Quoted 5 lines
exec.c +0 -0
index 366684c..1114a09 100644
@@ -3427,6 +3427,7 @@ static void

invalidate_and_set_dirty(target_phys_addr_t addr,

Quoted 2 lines
Quoted 2 lines

exec.c static void · line 3428

Quoted 2 lines
exec.c +0 -0
         /* set dirty bit */
         cpu_physical_memory_set_dirty_flags(addr, (0xff &

~CODE_DIRTY_FLAG));

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
exec.c +1 -0
     }
+    xen_modified_memory(addr, length);
 }
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
memory.c +1 -0
index 4f3ade0..015c544 100644
@@ -19,6 +19,7 @@
 #include "bitops.h"
 #include "kvm.h"
 #include <assert.h>
+#include "hw/xen.h"
 
Quoted 3 lines
Quoted 3 lines

memory.c void memory_region_set_dirty(MemoryRegion *mr,

Quoted 3 lines
memory.c +0 -0
 #define WANT_EXEC_OBSOLETE
 #include "exec-obsolete.h"
@@ -1077,6 +1078,7 @@ void memory_region_set_dirty(MemoryRegion *mr,

target_phys_addr_t addr,

Quoted 5 lines
Quoted 5 lines

memory.c void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,

Quoted 5 lines
memory.c +1 -0
                              target_phys_addr_t size)
 {
     assert(mr->terminates);
+    xen_modified_memory(mr->ram_addr + addr, size);
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr,

size, -1);

Quoted 3 lines
Quoted 1 line

memory.c void memory_region_set_dirty(MemoryRegion *mr, · line 1083

Quoted 1 line
memory.c +0 -0
 }

I would prefer this bit pushed into cpu_physical_set_dirty_range().

Ok, I will call the function from cpu_physical_memory_set_dirty_range() instead of from memory_region_set_dirty.

Quoted 1 line

Possibly the first bit too?

But the call from invalidate_and_set_dirty, I can not remove it because it does not work. The xen function must be called without condition as xen and qemu does not maintained the same dirtymap.

Signature · 1 line
Anthony PERARD
#15 lore raw

Re: [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

Quoted 6 lines · Anthony PERARD
Quoted 2 lines

Possibly the first bit too?

But the call from invalidate_and_set_dirty, I can not remove it because it does not work. The xen function must be called without condition as xen and qemu does not maintained the same dirtymap.

Right, in fact we added invalidate_and_set_dirty() in order to stick the xen call in it, I just forgot about it. So the first bit is okay.

Signature · 1 line
error compiling committee.c: too many arguments to function
#16 lore raw

Re: [Qemu-devel] [PATCH V4 4/5] exec, memory: Call to xen_modified_memory.

In reply to Anthony PERARD
Quoted 6 lines · Anthony PERARD
Quoted 2 lines

Possibly the first bit too?

But the call from invalidate_and_set_dirty, I can not remove it because it does not work. The xen function must be called without condition as xen and qemu does not maintained the same dirtymap.

Right, in fact we added invalidate_and_set_dirty() in order to stick the xen call in it, I just forgot about it. So the first bit is okay.

Signature · 1 line
error compiling committee.c: too many arguments to function
#17 lore raw

PATCH v4 5/5 xen: Set the vram dirty when an error occur.

In reply to Anthony PERARD

If the call to xc_hvm_track_dirty_vram() fails, then we set dirtybit on all the video ram. This case happens during migration.

---
 xen-all.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen-all.c +2 -1
index b11542c..e6308be 100644
@@ -507,7 +507,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
                                  bitmap);
     if (rc < 0) {
         if (rc != -ENODATA) {
-            fprintf(stderr, "xen: track_dirty_vram failed (0x" TARGET_FMT_plx
+            memory_region_set_dirty(framebuffer, 0, size);
+            DPRINTF("xen: track_dirty_vram failed (0x" TARGET_FMT_plx
                     ", 0x" TARGET_FMT_plx "): %s\n",
                     start_addr, start_addr + size, strerror(-rc));
         }
Signature · 1 line
Anthony PERARD
#18 lore raw

PATCH v4 5/5 xen: Set the vram dirty when an error occur.

In reply to Anthony PERARD

If the call to xc_hvm_track_dirty_vram() fails, then we set dirtybit on all the video ram. This case happens during migration.

---
 xen-all.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen-all.c +2 -1
index b11542c..e6308be 100644
@@ -507,7 +507,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
                                  bitmap);
     if (rc < 0) {
         if (rc != -ENODATA) {
-            fprintf(stderr, "xen: track_dirty_vram failed (0x" TARGET_FMT_plx
+            memory_region_set_dirty(framebuffer, 0, size);
+            DPRINTF("xen: track_dirty_vram failed (0x" TARGET_FMT_plx
                     ", 0x" TARGET_FMT_plx "): %s\n",
                     start_addr, start_addr + size, strerror(-rc));
         }
Signature · 1 line
Anthony PERARD
Acked-by on v4 5/5
#19 lore raw

Re: [PATCH V4 5/5] xen: Set the vram dirty when an error occur.

Quoted 4 lines · Anthony PERARD

If the call to xc_hvm_track_dirty_vram() fails, then we set dirtybit on all the video ram. This case happens during migration.

Quoted 20 lines
 xen-all.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen-all.c +2 -1
index b11542c..e6308be 100644
@@ -507,7 +507,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
                                  bitmap);
     if (rc < 0) {
         if (rc != -ENODATA) {
-            fprintf(stderr, "xen: track_dirty_vram failed (0x" TARGET_FMT_plx
+            memory_region_set_dirty(framebuffer, 0, size);
+            DPRINTF("xen: track_dirty_vram failed (0x" TARGET_FMT_plx
                     ", 0x" TARGET_FMT_plx "): %s\n",
                     start_addr, start_addr + size, strerror(-rc));
         }
Signature · 1 line
Anthony PERARD
Acked-by on v4 5/5
#20 lore raw

Re: [Qemu-devel] [PATCH V4 5/5] xen: Set the vram dirty when an error occur.

In reply to Anthony PERARD
Quoted 4 lines · Anthony PERARD

If the call to xc_hvm_track_dirty_vram() fails, then we set dirtybit on all the video ram. This case happens during migration.

Quoted 20 lines
 xen-all.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen-all.c +2 -1
index b11542c..e6308be 100644
@@ -507,7 +507,8 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
                                  bitmap);
     if (rc < 0) {
         if (rc != -ENODATA) {
-            fprintf(stderr, "xen: track_dirty_vram failed (0x" TARGET_FMT_plx
+            memory_region_set_dirty(framebuffer, 0, size);
+            DPRINTF("xen: track_dirty_vram failed (0x" TARGET_FMT_plx
                     ", 0x" TARGET_FMT_plx "): %s\n",
                     start_addr, start_addr + size, strerror(-rc));
         }
Signature · 1 line
Anthony PERARD