Skip to content

Commit 14b51b6

Browse files
agrafmdroth
authored andcommitted
kvm: Fix memory slot page alignment logic
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: [email protected] Signed-off-by: Alexander Graf <[email protected]> (cherry picked from commit f2a6403) Signed-off-by: Michael Roth <[email protected]>
1 parent ea227e2 commit 14b51b6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kvm-all.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,10 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)
617617
unsigned delta;
618618

619619
/* kvm works in page size chunks, but the function may be called
620-
with sub-page size and unaligned start address. */
621-
delta = TARGET_PAGE_ALIGN(size) - size;
620+
with sub-page size and unaligned start address. Pad the start
621+
address to next and truncate size to previous page boundary. */
622+
delta = (TARGET_PAGE_SIZE - (start_addr & ~TARGET_PAGE_MASK));
623+
delta &= ~TARGET_PAGE_MASK;
622624
if (delta > size) {
623625
return;
624626
}

0 commit comments

Comments
 (0)