[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/50] kvm: factor out alignment of memory section
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 27/50] kvm: factor out alignment of memory section |
Date: |
Tue, 19 Sep 2017 14:29:16 +0200 |
From: David Hildenbrand <address@hidden>
Factor it out, so we can reuse it later.
Signed-off-by: David Hildenbrand <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
accel/kvm/kvm-all.c | 59 +++++++++++++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 20 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 985b179..e0d100b 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -190,6 +190,36 @@ static KVMSlot *kvm_lookup_matching_slot(KVMMemoryListener
*kml,
}
/*
+ * Calculate and align the start address and the size of the section.
+ * Return the size. If the size is 0, the aligned section is empty.
+ */
+static hwaddr kvm_align_section(MemoryRegionSection *section,
+ hwaddr *start)
+{
+ hwaddr size = int128_get64(section->size);
+ hwaddr delta;
+
+ *start = section->offset_within_address_space;
+
+ /* 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;
+ if (delta > size) {
+ return 0;
+ }
+ size -= delta;
+ size &= qemu_real_host_page_mask;
+ if (*start & ~qemu_real_host_page_mask) {
+ return 0;
+ }
+
+ return size;
+}
+
+/*
* Find overlapping slot with lowest start address
*/
static KVMSlot *kvm_lookup_overlapping_slot(KVMMemoryListener *kml,
@@ -700,25 +730,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
int err;
MemoryRegion *mr = section->mr;
bool writeable = !mr->readonly && !mr->rom_device;
- hwaddr start_addr = section->offset_within_address_space;
- ram_addr_t size = int128_get64(section->size);
- void *ram = NULL;
- unsigned delta;
-
- /* 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_addr &
~qemu_real_host_page_mask);
- delta &= ~qemu_real_host_page_mask;
- if (delta > size) {
- return;
- }
- start_addr += delta;
- size -= delta;
- size &= qemu_real_host_page_mask;
- if (!size || (start_addr & ~qemu_real_host_page_mask)) {
- return;
- }
+ hwaddr start_addr, size;
+ void *ram;
if (!memory_region_is_ram(mr)) {
if (writeable || !kvm_readonly_mem_allowed) {
@@ -730,7 +743,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
}
}
- ram = memory_region_get_ram_ptr(mr) + section->offset_within_region +
delta;
+ size = kvm_align_section(section, &start_addr);
+ if (!size) {
+ return;
+ }
+
+ ram = memory_region_get_ram_ptr(mr) + section->offset_within_region +
+ (section->offset_within_address_space - start_addr);
while (1) {
mem = kvm_lookup_overlapping_slot(kml, start_addr, start_addr + size);
--
1.8.3.1
- [Qemu-devel] [PULL 20/50] i386/kvm: introduce tsc_is_stable_and_known(), (continued)
- [Qemu-devel] [PULL 20/50] i386/kvm: introduce tsc_is_stable_and_known(), Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 17/50] MAINTAINERS: update mail address for NVDIMM, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 18/50] i386/kvm: use a switch statement for MSR detection, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 19/50] i386/kvm: set tsc_khz before configuring Hyper-V CPUID, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 29/50] kvm: we never have overlapping slots in kvm_set_phys_mem(), Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 30/50] kvm: kvm_log_start/stop are only called with known sections, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 28/50] kvm: use start + size for memory ranges, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 21/50] i386/kvm: advertise Hyper-V frequency MSRs, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 22/50] MAINTAINERS: update email, add missing test entry for megasas, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 24/50] scsi/esp: Rename the ESP macro to ESP_STATE, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 27/50] kvm: factor out alignment of memory section,
Paolo Bonzini <=
- [Qemu-devel] [PULL 31/50] kvm: kvm_log_sync() is only called with known memory sections, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 25/50] multiboot: validate multiboot header address values, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 32/50] test-qga: add missing qemu-ga tool dependency, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 26/50] kvm: require JOIN_MEMORY_REGIONS_WORKS, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 23/50] memory: Rename queue to mrqueue (memory region queue), Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 13/50] scsi: move non-emulation specific code to scsi/, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 33/50] hw/i386: Improve some of the warning messages, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 35/50] Convert single line fprintf(.../n) to warn_report(), Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 38/50] target/mips: Convert VM clock update prints to warn_report, Paolo Bonzini, 2017/09/19
- [Qemu-devel] [PULL 36/50] Convert multi-line fprintf() to warn_report(), Paolo Bonzini, 2017/09/19