qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] kvm: Fix memory slot page alignment logic
@ 2014-11-07 21:18 Alexander Graf
  2014-11-07 21:24 ` [Qemu-devel] [Qemu-ppc] " Alexander Graf
  2014-11-10 12:31 ` [Qemu-devel] " Igor Mammedov
  0 siblings, 2 replies; 9+ messages in thread
From: Alexander Graf @ 2014-11-07 21:18 UTC (permalink / raw)
  To: qemu-ppc; +Cc: pbonzini, qemu-stable, stuart.yoder, kvm, qemu-devel

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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 44a5e72..596e7ce 100644
--- 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;
     }
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-11-10 14:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 21:18 [Qemu-devel] [PATCH] kvm: Fix memory slot page alignment logic Alexander Graf
2014-11-07 21:24 ` [Qemu-devel] [Qemu-ppc] " Alexander Graf
2014-11-10 12:31 ` [Qemu-devel] " Igor Mammedov
2014-11-10 13:16   ` Alexander Graf
2014-11-10 13:54     ` Paolo Bonzini
2014-11-10 13:55     ` Peter Maydell
2014-11-10 14:48       ` Alexander Graf
2014-11-10 13:55     ` Igor Mammedov
2014-11-10 14:47       ` Alexander Graf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).