@@ -205,8 +205,10 @@ static inline void cpu_to_be32wu(uint32_t *p, uint32_t v)
#ifdef HOST_WORDS_BIGENDIAN
#define cpu_to_32wu cpu_to_be32wu
+#define leul_to_cpu(v) le ## HOST_LONG_BITS ## _to_cpu(v)
#else
#define cpu_to_32wu cpu_to_le32wu
+#define leul_to_cpu(v) (v)
#endif
#undef le_bswap
@@ -282,11 +282,6 @@ static int kvm_set_migration_log(int enable)
return 0;
}
-static int test_le_bit(unsigned long nr, unsigned char *addr)
-{
- return (addr[nr >> 3] >> (nr & 7)) & 1;
-}
-
/**
* kvm_physical_sync_dirty_bitmap - Grab dirty bitmap from kernel space
* This function updates qemu's dirty bitmap using cpu_physical_memory_set_dirty().
@@ -299,9 +294,9 @@ static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
target_phys_addr_t end_addr)
{
KVMState *s = kvm_state;
- unsigned long size, allocated_size = 0;
- target_phys_addr_t phys_addr;
- ram_addr_t addr;
+ unsigned long size, page_number, addr, addr1, *bitmap,
+ allocated_size = 0;
+ unsigned int i, len;
KVMDirtyLog d;
KVMSlot *mem;
int ret = 0;
@@ -313,7 +308,8 @@ static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
break;
}
- size = ((mem->memory_size >> TARGET_PAGE_BITS) + 7) / 8;
+ size = ((mem->memory_size >> TARGET_PAGE_BITS) + HOST_LONG_BITS - 1) /
+ HOST_LONG_BITS * HOST_LONG_SIZE;
if (!d.dirty_bitmap) {
d.dirty_bitmap = qemu_malloc(size);
} else if (size > allocated_size) {
@@ -330,17 +326,18 @@ static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
break;
}
- for (phys_addr = mem->start_addr, addr = mem->phys_offset;
- phys_addr < mem->start_addr + mem->memory_size;
- phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {
- unsigned char *bitmap = (unsigned char *)d.dirty_bitmap;
- unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS;
-
- if (test_le_bit(nr, bitmap)) {
- cpu_physical_memory_set_dirty(addr);
+ bitmap = (unsigned long *)d.dirty_bitmap;
+ len = size / HOST_LONG_SIZE;
+ for (i = 0; i < len; i++) {
+ if (bitmap[i] != 0) {
+ page_number = i * HOST_LONG_BITS;
+ addr1 = page_number * TARGET_PAGE_SIZE;
+ addr = mem->phys_offset + addr1;
+ cpu_physical_memory_set_dirty_range(addr,
+ leul_to_cpu(bitmap[i]));
}
}
- start_addr = phys_addr;
+ start_addr = mem->start_addr + mem->memory_size;
}
qemu_free(d.dirty_bitmap);