summaryrefslogtreecommitdiff
path: root/accel/kvm/kvm-all.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel/kvm/kvm-all.c')
-rw-r--r--accel/kvm/kvm-all.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 90c88b517d..f290f487a5 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -197,26 +197,20 @@ static hwaddr kvm_align_section(MemoryRegionSection *section,
hwaddr *start)
{
hwaddr size = int128_get64(section->size);
- hwaddr delta;
-
- *start = section->offset_within_address_space;
+ hwaddr delta, aligned;
/* kvm works in page size chunks, but the function may be called
with sub-page size and unaligned start address. Pad the start
address to next and truncate size to previous page boundary. */
- delta = qemu_real_host_page_size - (*start & ~qemu_real_host_page_mask);
- delta &= ~qemu_real_host_page_mask;
- *start += delta;
+ aligned = ROUND_UP(section->offset_within_address_space,
+ qemu_real_host_page_size);
+ delta = aligned - section->offset_within_address_space;
+ *start = aligned;
if (delta > size) {
return 0;
}
- size -= delta;
- size &= qemu_real_host_page_mask;
- if (*start & ~qemu_real_host_page_mask) {
- return 0;
- }
- return size;
+ return (size - delta) & qemu_real_host_page_mask;
}
int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
@@ -394,8 +388,8 @@ static int kvm_section_update_flags(KVMMemoryListener *kml,
mem = kvm_lookup_matching_slot(kml, start_addr, size);
if (!mem) {
- fprintf(stderr, "%s: error finding slot\n", __func__);
- abort();
+ /* We don't have a slot if we want to trap every access. */
+ return 0;
}
return kvm_slot_update_flags(kml, mem, section->mr);
@@ -470,8 +464,8 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
if (size) {
mem = kvm_lookup_matching_slot(kml, start_addr, size);
if (!mem) {
- fprintf(stderr, "%s: error finding slot\n", __func__);
- abort();
+ /* We don't have a slot if we want to trap every access. */
+ return 0;
}
/* XXX bad kernel interface alert
@@ -717,11 +711,12 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
return;
}
+ /* use aligned delta to align the ram address */
ram = memory_region_get_ram_ptr(mr) + section->offset_within_region +
- (section->offset_within_address_space - start_addr);
+ (start_addr - section->offset_within_address_space);
- mem = kvm_lookup_matching_slot(kml, start_addr, size);
if (!add) {
+ mem = kvm_lookup_matching_slot(kml, start_addr, size);
if (!mem) {
return;
}
@@ -733,19 +728,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
mem->memory_size = 0;
err = kvm_set_user_memory_region(kml, mem);
if (err) {
- fprintf(stderr, "%s: error unregistering overlapping slot: %s\n",
+ fprintf(stderr, "%s: error unregistering slot: %s\n",
__func__, strerror(-err));
abort();
}
return;
}
- if (mem) {
- /* update the slot */
- kvm_slot_update_flags(kml, mem, mr);
- return;
- }
-
/* register the new slot */
mem = kvm_alloc_slot(kml);
mem->memory_size = size;