From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, Li Zhijian <lizhijian@cn.fujitsu.com>
Subject: [Qemu-devel] [PULL 27/27] migration: extend migration_bitmap
Date: Thu, 2 Jul 2015 18:10:15 +0200 [thread overview]
Message-ID: <1435853415-23545-28-git-send-email-quintela@redhat.com> (raw)
In-Reply-To: <1435853415-23545-1-git-send-email-quintela@redhat.com>
From: Li Zhijian <lizhijian@cn.fujitsu.com>
Prevously, if we hotplug a device(e.g. device_add e1000) during
migration is processing in source side, qemu will add a new ram
block but migration_bitmap is not extended.
In this case, migration_bitmap will overflow and lead qemu abort
unexpectedly.
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
exec.c | 5 +++++
include/exec/exec-all.h | 3 +++
migration/ram.c | 28 ++++++++++++++++++++++++++++
3 files changed, 36 insertions(+)
diff --git a/exec.c b/exec.c
index f7883d2..1702544 100644
--- a/exec.c
+++ b/exec.c
@@ -1401,6 +1401,11 @@ static ram_addr_t ram_block_add(RAMBlock *new_block, Error **errp)
}
}
+ new_ram_size = MAX(old_ram_size,
+ (new_block->offset + new_block->max_length) >> TARGET_PAGE_BITS);
+ if (new_ram_size > old_ram_size) {
+ migration_bitmap_extend(old_ram_size, new_ram_size);
+ }
/* Keep the list sorted from biggest to smallest block. Unlike QTAILQ,
* QLIST (which has an RCU-friendly variant) does not have insertion at
* tail, so save the last element in last_block.
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 2573e8c..91ffa99 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -385,4 +385,7 @@ static inline bool cpu_can_do_io(CPUState *cpu)
return cpu->can_do_io != 0;
}
+#if !defined(CONFIG_USER_ONLY)
+void migration_bitmap_extend(ram_addr_t old, ram_addr_t new);
+#endif
#endif
diff --git a/migration/ram.c b/migration/ram.c
index 9c0bcfe..c696814 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -222,6 +222,7 @@ static RAMBlock *last_seen_block;
static RAMBlock *last_sent_block;
static ram_addr_t last_offset;
static unsigned long *migration_bitmap;
+static QemuMutex migration_bitmap_mutex;
static uint64_t migration_dirty_pages;
static uint32_t last_version;
static bool ram_bulk_stage;
@@ -569,11 +570,13 @@ static void migration_bitmap_sync(void)
trace_migration_bitmap_sync_start();
address_space_sync_dirty_bitmap(&address_space_memory);
+ qemu_mutex_lock(&migration_bitmap_mutex);
rcu_read_lock();
QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
migration_bitmap_sync_range(block->mr->ram_addr, block->used_length);
}
rcu_read_unlock();
+ qemu_mutex_unlock(&migration_bitmap_mutex);
trace_migration_bitmap_sync_end(migration_dirty_pages
- num_dirty_pages_init);
@@ -1062,6 +1065,30 @@ static void reset_ram_globals(void)
#define MAX_WAIT 50 /* ms, half buffered_file limit */
+void migration_bitmap_extend(ram_addr_t old, ram_addr_t new)
+{
+ /* called in qemu main thread, so there is
+ * no writing race against this migration_bitmap
+ */
+ if (migration_bitmap) {
+ unsigned long *old_bitmap = migration_bitmap, *bitmap;
+ bitmap = bitmap_new(new);
+
+ /* prevent migration_bitmap content from being set bit
+ * by migration_bitmap_sync_range() at the same time.
+ * it is safe to migration if migration_bitmap is cleared bit
+ * at the same time.
+ */
+ qemu_mutex_lock(&migration_bitmap_mutex);
+ bitmap_copy(bitmap, old_bitmap, old);
+ bitmap_set(bitmap, old, new - old);
+ atomic_rcu_set(&migration_bitmap, bitmap);
+ qemu_mutex_unlock(&migration_bitmap_mutex);
+ migration_dirty_pages += new - old;
+ synchronize_rcu();
+ g_free(old_bitmap);
+ }
+}
/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has
* long-running RCU critical section. When rcu-reclaims in the code
@@ -1078,6 +1105,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
dirty_rate_high_cnt = 0;
bitmap_sync_count = 0;
migration_bitmap_sync_init();
+ qemu_mutex_init(&migration_bitmap_mutex);
if (migrate_use_xbzrle()) {
XBZRLE_cache_lock();
--
2.4.3
next prev parent reply other threads:[~2015-07-02 16:11 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-02 16:09 [Qemu-devel] [PULL v2 00/27] Migration pull request Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 01/27] rdma: fix memory leak Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 02/27] Only try and read a VMDescription if it should be there Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 03/27] rdma typos Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 04/27] Store block name in local blocks structure Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 05/27] Translate offsets to destination address space Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 06/27] Rework ram_control_load_hook to hook during block load Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 07/27] Allow rdma_delete_block to work without the hash Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 08/27] Rework ram block hash Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 09/27] Sort destination RAMBlocks to be the same as the source Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 10/27] Sanity check RDMA remote data Juan Quintela
2015-07-02 16:09 ` [Qemu-devel] [PULL 11/27] Fail more cleanly in mismatched RAM cases Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 12/27] Fix older machine type compatibility on power with section footers Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 13/27] runstate: Add runstate store Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 14/27] runstate: migration allows more transitions now Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 15/27] migration: create new section to store global state Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 16/27] global_state: Make section optional Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 17/27] vmstate: Create optional sections Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 18/27] migration: Add configuration section Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 19/27] migration: Use cmpxchg correctly Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 20/27] migration: ensure we start in NONE state Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 21/27] migration: Use always helper to set state Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 22/27] migration: No need to call trace_migrate_set_state() Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 23/27] migration: create migration event Juan Quintela
2015-07-03 2:30 ` Wen Congyang
2015-07-02 16:10 ` [Qemu-devel] [PULL 24/27] migration: Add migration events on target side Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 25/27] check_section_footers: Check the correct section_id Juan Quintela
2015-07-02 16:10 ` [Qemu-devel] [PULL 26/27] migration: protect migration_bitmap Juan Quintela
2015-07-02 16:10 ` Juan Quintela [this message]
2015-07-02 17:31 ` [Qemu-devel] [PULL v2 00/27] Migration pull request Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435853415-23545-28-git-send-email-quintela@redhat.com \
--to=quintela@redhat.com \
--cc=amit.shah@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).