]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
kvm: Fix memory slot page alignment logic
authorAlexander Graf <agraf@suse.de>
Fri, 7 Nov 2014 21:12:48 +0000 (22:12 +0100)
committerAlexander Graf <agraf@suse.de>
Thu, 20 Nov 2014 13:52:01 +0000 (14:52 +0100)
Memory slots have to be page aligned to get entered into KVM. There
is existing logic that tries to ensure that we pad memory slots that
are not page aligned to the biggest region that would still fit in the
alignment requirements.

Unfortunately, that logic is broken. It tries to calculate the start
offset based on the region size.

Fix up the logic to do the thing it was intended to do and document it
properly in the comment above it.

With this patch applied, I can successfully run an e500 guest with more
than 3GB RAM (at which point RAM starts overlapping subpage memory regions).

Cc: qemu-stable@nongnu.org
Signed-off-by: Alexander Graf <agraf@suse.de>
kvm-all.c

index 44a5e724ea726f4c177b4c7c66dc9b7b9b30dee7..596e7ce6c3e02719caf9955eb6193d41381678d1 100644 (file)
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -634,8 +634,10 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
     unsigned delta;
 
     /* kvm works in page size chunks, but the function may be called
-       with sub-page size and unaligned start address. */
-    delta = TARGET_PAGE_ALIGN(size) - size;
+       with sub-page size and unaligned start address. Pad the start
+       address to next and truncate size to previous page boundary. */
+    delta = (TARGET_PAGE_SIZE - (start_addr & ~TARGET_PAGE_MASK));
+    delta &= ~TARGET_PAGE_MASK;
     if (delta > size) {
         return;
     }