|
|
0a122b |
From ccff61f6316a815aa4a538799e089dec7ce754c5 Mon Sep 17 00:00:00 2001
|
|
|
0a122b |
From: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
|
|
|
0a122b |
Date: Thu, 27 Feb 2014 14:53:37 +0100
|
|
|
0a122b |
Subject: [PATCH 3/6] Fix two XBZRLE corruption issues
|
|
|
0a122b |
|
|
|
0a122b |
RH-Author: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
|
|
|
0a122b |
Message-id: <1393512817-21040-1-git-send-email-dgilbert@redhat.com>
|
|
|
0a122b |
Patchwork-id: 57921
|
|
|
0a122b |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 1/1] Fix two XBZRLE corruption issues
|
|
|
0a122b |
Bugzilla: 1063417
|
|
|
0a122b |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
0a122b |
RH-Acked-by: Juan Quintela <quintela@redhat.com>
|
|
|
0a122b |
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
|
|
|
0a122b |
|
|
|
0a122b |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
0a122b |
|
|
|
0a122b |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1063417
|
|
|
0a122b |
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=7115209
|
|
|
0a122b |
Upstream: 6d3cb1f970ee85361618f7ff02869180394e012d
|
|
|
0a122b |
|
|
|
0a122b |
Push zero'd pages into the XBZRLE cache
|
|
|
0a122b |
A page that was cached by XBZRLE, zero'd and then XBZRLE'd again
|
|
|
0a122b |
was being compared against a stale cache value
|
|
|
0a122b |
|
|
|
0a122b |
Don't use 'qemu_put_buffer_async' to put pages from the XBZRLE cache
|
|
|
0a122b |
Since the cache might change before the data hits the wire
|
|
|
0a122b |
|
|
|
0a122b |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
0a122b |
Signed-off-by: Juan Quintela <quintela@redhat.com>
|
|
|
0a122b |
(cherry picked from commit 6d3cb1f970ee85361618f7ff02869180394e012d)
|
|
|
0a122b |
---
|
|
|
0a122b |
arch_init.c | 64 ++++++++++++++++++++++++++++++++----------
|
|
|
0a122b |
include/migration/page_cache.h | 2 +-
|
|
|
0a122b |
page_cache.c | 2 +-
|
|
|
0a122b |
3 files changed, 51 insertions(+), 17 deletions(-)
|
|
|
0a122b |
|
|
|
0a122b |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
0a122b |
---
|
|
|
0a122b |
arch_init.c | 64 ++++++++++++++++++++++++++++++---------
|
|
|
0a122b |
include/migration/page_cache.h | 2 +-
|
|
|
0a122b |
page_cache.c | 2 +-
|
|
|
0a122b |
3 files changed, 51 insertions(+), 17 deletions(-)
|
|
|
0a122b |
|
|
|
0a122b |
diff --git a/arch_init.c b/arch_init.c
|
|
|
0a122b |
index 31bf690..f5d521a 100644
|
|
|
0a122b |
--- a/arch_init.c
|
|
|
0a122b |
+++ b/arch_init.c
|
|
|
0a122b |
@@ -122,7 +122,6 @@ static void check_guest_throttling(void);
|
|
|
0a122b |
#define RAM_SAVE_FLAG_XBZRLE 0x40
|
|
|
0a122b |
/* 0x80 is reserved in migration.h start with 0x100 next */
|
|
|
0a122b |
|
|
|
0a122b |
-
|
|
|
0a122b |
static struct defconfig_file {
|
|
|
0a122b |
const char *filename;
|
|
|
0a122b |
/* Indicates it is an user config file (disabled by -no-user-config) */
|
|
|
0a122b |
@@ -133,6 +132,7 @@ static struct defconfig_file {
|
|
|
0a122b |
{ NULL }, /* end of list */
|
|
|
0a122b |
};
|
|
|
0a122b |
|
|
|
0a122b |
+static const uint8_t ZERO_TARGET_PAGE[TARGET_PAGE_SIZE];
|
|
|
0a122b |
|
|
|
0a122b |
int qemu_read_default_config_files(bool userconfig)
|
|
|
0a122b |
{
|
|
|
0a122b |
@@ -273,6 +273,34 @@ static size_t save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
|
|
|
0a122b |
return size;
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
+/* This is the last block that we have visited serching for dirty pages
|
|
|
0a122b |
+ */
|
|
|
0a122b |
+static RAMBlock *last_seen_block;
|
|
|
0a122b |
+/* This is the last block from where we have sent data */
|
|
|
0a122b |
+static RAMBlock *last_sent_block;
|
|
|
0a122b |
+static ram_addr_t last_offset;
|
|
|
0a122b |
+static unsigned long *migration_bitmap;
|
|
|
0a122b |
+static uint64_t migration_dirty_pages;
|
|
|
0a122b |
+static uint32_t last_version;
|
|
|
0a122b |
+static bool ram_bulk_stage;
|
|
|
0a122b |
+
|
|
|
0a122b |
+/* Update the xbzrle cache to reflect a page that's been sent as all 0.
|
|
|
0a122b |
+ * The important thing is that a stale (not-yet-0'd) page be replaced
|
|
|
0a122b |
+ * by the new data.
|
|
|
0a122b |
+ * As a bonus, if the page wasn't in the cache it gets added so that
|
|
|
0a122b |
+ * when a small write is made into the 0'd page it gets XBZRLE sent
|
|
|
0a122b |
+ */
|
|
|
0a122b |
+static void xbzrle_cache_zero_page(ram_addr_t current_addr)
|
|
|
0a122b |
+{
|
|
|
0a122b |
+ if (ram_bulk_stage || !migrate_use_xbzrle()) {
|
|
|
0a122b |
+ return;
|
|
|
0a122b |
+ }
|
|
|
0a122b |
+
|
|
|
0a122b |
+ /* We don't care if this fails to allocate a new cache page
|
|
|
0a122b |
+ * as long as it updated an old one */
|
|
|
0a122b |
+ cache_insert(XBZRLE.cache, current_addr, ZERO_TARGET_PAGE);
|
|
|
0a122b |
+}
|
|
|
0a122b |
+
|
|
|
0a122b |
#define ENCODING_FLAG_XBZRLE 0x1
|
|
|
0a122b |
|
|
|
0a122b |
static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
|
|
|
0a122b |
@@ -329,18 +357,6 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
|
|
|
0a122b |
return bytes_sent;
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
-
|
|
|
0a122b |
-/* This is the last block that we have visited serching for dirty pages
|
|
|
0a122b |
- */
|
|
|
0a122b |
-static RAMBlock *last_seen_block;
|
|
|
0a122b |
-/* This is the last block from where we have sent data */
|
|
|
0a122b |
-static RAMBlock *last_sent_block;
|
|
|
0a122b |
-static ram_addr_t last_offset;
|
|
|
0a122b |
-static unsigned long *migration_bitmap;
|
|
|
0a122b |
-static uint64_t migration_dirty_pages;
|
|
|
0a122b |
-static uint32_t last_version;
|
|
|
0a122b |
-static bool ram_bulk_stage;
|
|
|
0a122b |
-
|
|
|
0a122b |
static inline
|
|
|
0a122b |
ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr,
|
|
|
0a122b |
ram_addr_t start)
|
|
|
0a122b |
@@ -512,6 +528,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
|
|
|
0a122b |
} else {
|
|
|
0a122b |
int ret;
|
|
|
0a122b |
uint8_t *p;
|
|
|
0a122b |
+ bool send_async = true;
|
|
|
0a122b |
int cont = (block == last_sent_block) ?
|
|
|
0a122b |
RAM_SAVE_FLAG_CONTINUE : 0;
|
|
|
0a122b |
|
|
|
0a122b |
@@ -522,6 +539,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
|
|
|
0a122b |
ret = ram_control_save_page(f, block->offset,
|
|
|
0a122b |
offset, TARGET_PAGE_SIZE, &bytes_sent);
|
|
|
0a122b |
|
|
|
0a122b |
+ current_addr = block->offset + offset;
|
|
|
0a122b |
if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
|
|
|
0a122b |
if (ret != RAM_SAVE_CONTROL_DELAYED) {
|
|
|
0a122b |
if (bytes_sent > 0) {
|
|
|
0a122b |
@@ -536,19 +554,35 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
|
|
|
0a122b |
RAM_SAVE_FLAG_COMPRESS);
|
|
|
0a122b |
qemu_put_byte(f, 0);
|
|
|
0a122b |
bytes_sent++;
|
|
|
0a122b |
+ /* Must let xbzrle know, otherwise a previous (now 0'd) cached
|
|
|
0a122b |
+ * page would be stale
|
|
|
0a122b |
+ */
|
|
|
0a122b |
+ xbzrle_cache_zero_page(current_addr);
|
|
|
0a122b |
} else if (!ram_bulk_stage && migrate_use_xbzrle()) {
|
|
|
0a122b |
- current_addr = block->offset + offset;
|
|
|
0a122b |
bytes_sent = save_xbzrle_page(f, p, current_addr, block,
|
|
|
0a122b |
offset, cont, last_stage);
|
|
|
0a122b |
if (!last_stage) {
|
|
|
0a122b |
+ /* We must send exactly what's in the xbzrle cache
|
|
|
0a122b |
+ * even if the page wasn't xbzrle compressed, so that
|
|
|
0a122b |
+ * it's right next time.
|
|
|
0a122b |
+ */
|
|
|
0a122b |
p = get_cached_data(XBZRLE.cache, current_addr);
|
|
|
0a122b |
+
|
|
|
0a122b |
+ /* Can't send this cached data async, since the cache page
|
|
|
0a122b |
+ * might get updated before it gets to the wire
|
|
|
0a122b |
+ */
|
|
|
0a122b |
+ send_async = false;
|
|
|
0a122b |
}
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
/* XBZRLE overflow or normal page */
|
|
|
0a122b |
if (bytes_sent == -1) {
|
|
|
0a122b |
bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
|
|
|
0a122b |
- qemu_put_buffer_async(f, p, TARGET_PAGE_SIZE);
|
|
|
0a122b |
+ if (send_async) {
|
|
|
0a122b |
+ qemu_put_buffer_async(f, p, TARGET_PAGE_SIZE);
|
|
|
0a122b |
+ } else {
|
|
|
0a122b |
+ qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
|
|
|
0a122b |
+ }
|
|
|
0a122b |
bytes_sent += TARGET_PAGE_SIZE;
|
|
|
0a122b |
acct_info.norm_pages++;
|
|
|
0a122b |
}
|
|
|
0a122b |
diff --git a/include/migration/page_cache.h b/include/migration/page_cache.h
|
|
|
0a122b |
index d156f0d..2d5ce2d 100644
|
|
|
0a122b |
--- a/include/migration/page_cache.h
|
|
|
0a122b |
+++ b/include/migration/page_cache.h
|
|
|
0a122b |
@@ -66,7 +66,7 @@ uint8_t *get_cached_data(const PageCache *cache, uint64_t addr);
|
|
|
0a122b |
* @addr: page address
|
|
|
0a122b |
* @pdata: pointer to the page
|
|
|
0a122b |
*/
|
|
|
0a122b |
-int cache_insert(PageCache *cache, uint64_t addr, uint8_t *pdata);
|
|
|
0a122b |
+int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata);
|
|
|
0a122b |
|
|
|
0a122b |
/**
|
|
|
0a122b |
* cache_resize: resize the page cache. In case of size reduction the extra
|
|
|
0a122b |
diff --git a/page_cache.c b/page_cache.c
|
|
|
0a122b |
index 250772d..5a763f9 100644
|
|
|
0a122b |
--- a/page_cache.c
|
|
|
0a122b |
+++ b/page_cache.c
|
|
|
0a122b |
@@ -151,7 +151,7 @@ uint8_t *get_cached_data(const PageCache *cache, uint64_t addr)
|
|
|
0a122b |
return cache_get_by_addr(cache, addr)->it_data;
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
-int cache_insert(PageCache *cache, uint64_t addr, uint8_t *pdata)
|
|
|
0a122b |
+int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata)
|
|
|
0a122b |
{
|
|
|
0a122b |
|
|
|
0a122b |
CacheItem *it = NULL;
|
|
|
0a122b |
--
|
|
|
0a122b |
1.7.1
|
|
|
0a122b |
|