diff --git a/migration/ram.c b/migration/ram.c index 42bb82f8ba..23819cda16 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -185,6 +185,8 @@ struct RAMState { uint64_t xbzrle_overflows; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; + /* protects modification of the bitmap */ + QemuMutex bitmap_mutex; }; typedef struct RAMState RAMState; @@ -230,8 +232,6 @@ static ram_addr_t ram_save_remaining(void) return ram_state.migration_dirty_pages; } -static QemuMutex migration_bitmap_mutex; - /* used by the search for pages to send */ struct PageSearchStatus { /* Current block being searched */ @@ -653,13 +653,13 @@ static void migration_bitmap_sync(RAMState *rs) trace_migration_bitmap_sync_start(); memory_global_dirty_log_sync(); - qemu_mutex_lock(&migration_bitmap_mutex); + qemu_mutex_lock(&rs->bitmap_mutex); rcu_read_lock(); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { migration_bitmap_sync_range(rs, block->offset, block->used_length); } rcu_read_unlock(); - qemu_mutex_unlock(&migration_bitmap_mutex); + qemu_mutex_unlock(&rs->bitmap_mutex); trace_migration_bitmap_sync_end(rs->num_dirty_pages_period); @@ -1526,6 +1526,7 @@ static void ram_state_reset(RAMState *rs) void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) { RAMState *rs = &ram_state; + /* called in qemu main thread, so there is * no writing race against this migration_bitmap */ @@ -1539,7 +1540,7 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) * it is safe to migration if migration_bitmap is cleared bit * at the same time. */ - qemu_mutex_lock(&migration_bitmap_mutex); + qemu_mutex_lock(&rs->bitmap_mutex); bitmap_copy(bitmap->bmap, old_bitmap->bmap, old); bitmap_set(bitmap->bmap, old, new - old); @@ -1550,7 +1551,7 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) bitmap->unsentmap = NULL; atomic_rcu_set(&migration_bitmap_rcu, bitmap); - qemu_mutex_unlock(&migration_bitmap_mutex); + qemu_mutex_unlock(&rs->bitmap_mutex); rs->migration_dirty_pages += new - old; call_rcu(old_bitmap, migration_bitmap_free, rcu); } @@ -1982,7 +1983,7 @@ static int ram_state_init(RAMState *rs) int64_t ram_bitmap_pages; /* Size of bitmap in pages, including gaps */ memset(rs, 0, sizeof(*rs)); - qemu_mutex_init(&migration_bitmap_mutex); + qemu_mutex_init(&rs->bitmap_mutex); if (migrate_use_xbzrle()) { XBZRLE_cache_lock();