From: Lauri Kasanen Date: Thu, 27 May 2021 15:51:39 +0000 (+0300) Subject: KVM expects full pages, and this is documented precisely nowhere. Sigh. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eedf0cdfea7c0c6b8089dd0fe3be8fd07d538a31;p=kvm-minippc.git KVM expects full pages, and this is documented precisely nowhere. Sigh. --- diff --git a/main.c b/main.c index f4e8b58..0b9263f 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,7 @@ #include #include +#define PAGE_SIZE (64 * 1024) // assumption #define MAXDUMPS 10 #define RAMSIZE (64 * 1024 * 1024) #define PROGSTART 0x20000000 @@ -333,7 +334,9 @@ int main(int argc, char **argv) { printf("Loading binary %u bytes\n", binlen); - if (posix_memalign((void **) &progmem, 64 * 1024, binlen)) + const unsigned progmemlen = (binlen + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); + + if (posix_memalign((void **) &progmem, 64 * 1024, progmemlen)) abort(); if (fread(progmem, binlen, 1, binary) != 1) @@ -370,7 +373,7 @@ int main(int argc, char **argv) { region.slot = 1; region.guest_phys_addr = PROGSTART; - region.memory_size = binlen; + region.memory_size = progmemlen; region.userspace_addr = (uint64_t) progmem; region.flags = KVM_MEM_READONLY; if (ioctl(vmfd, KVM_SET_USER_MEMORY_REGION, ®ion) == -1)