[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/14] exec: fix access to ram_list.dirty_memory when
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 14/14] exec: fix access to ram_list.dirty_memory when sync dirty bitmap |
Date: |
Wed, 28 Jun 2017 13:31:06 +0200 |
From: Haozhong Zhang <address@hidden>
In cpu_physical_memory_sync_dirty_bitmap(rb, start, ...), the 2nd
argument 'start' is relative to the start of the ramblock 'rb'. When
it's used to access the dirty memory bitmap of ram_list (i.e.
ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]->blocks[]), an offset to
the start of all RAM (i.e. rb->offset) should be added to it, which has
however been missed since c/s 6b6712efcc. For a ramblock of host memory
backend whose offset is not zero, cpu_physical_memory_sync_dirty_bitmap()
synchronizes the incorrect part of the dirty memory bitmap of ram_list
to the per ramblock dirty bitmap. As a result, a guest with host
memory backend may crash after migration.
Fix it by adding the offset of ramblock when accessing the dirty memory
bitmap of ram_list in cpu_physical_memory_sync_dirty_bitmap().
Reported-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Haozhong Zhang <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Tested-by: Juan Quintela <address@hidden>
Tested-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
include/exec/ram_addr.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 73d1bea..c04f4f6 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -386,8 +386,9 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
int k;
int nr = BITS_TO_LONGS(length >> TARGET_PAGE_BITS);
unsigned long * const *src;
- unsigned long idx = (page * BITS_PER_LONG) / DIRTY_MEMORY_BLOCK_SIZE;
- unsigned long offset = BIT_WORD((page * BITS_PER_LONG) %
+ unsigned long word = BIT_WORD((start + rb->offset) >>
TARGET_PAGE_BITS);
+ unsigned long idx = (word * BITS_PER_LONG) / DIRTY_MEMORY_BLOCK_SIZE;
+ unsigned long offset = BIT_WORD((word * BITS_PER_LONG) %
DIRTY_MEMORY_BLOCK_SIZE);
rcu_read_lock();
@@ -414,9 +415,11 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock
*rb,
rcu_read_unlock();
} else {
+ ram_addr_t offset = rb->offset;
+
for (addr = 0; addr < length; addr += TARGET_PAGE_SIZE) {
if (cpu_physical_memory_test_and_clear_dirty(
- start + addr,
+ start + addr + offset,
TARGET_PAGE_SIZE,
DIRTY_MEMORY_MIGRATION)) {
*real_dirty_pages += 1;
--
2.9.4
- [Qemu-devel] [PULL 02/14] accel: introduce AccelClass.global_props, (continued)
- [Qemu-devel] [PULL 02/14] accel: introduce AccelClass.global_props, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 04/14] migration: let MigrationState be a qdev, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 07/14] migration: move skip_configuration out, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 05/14] migration: move global_state.optional out, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 08/14] migration: move skip_section_footers, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 09/14] migration: merge enforce_config_section somewhat, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 06/14] migration: move only_migratable to MigrationState, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 11/14] migration: add comment for TYPE_MIGRATE, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 10/14] migration: hmp: dump globals, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 13/14] migration: add "return-path" capability, Juan Quintela, 2017/06/28
- [Qemu-devel] [PULL 14/14] exec: fix access to ram_list.dirty_memory when sync dirty bitmap,
Juan Quintela <=
- [Qemu-devel] [PULL 12/14] vmstate: error hint for failed equal checks, Juan Quintela, 2017/06/28
- Re: [Qemu-devel] [PULL 00/14] Migration pull request for 20170628, Peter Maydell, 2017/06/29