aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNadav Amit <namit@vmware.com>2020-07-10 11:33:20 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2020-07-10 16:46:34 -0400
commiteb2db85dd01f6840e3157e3e9ca20f2c98e0e09d (patch)
treec93c89fa159654abad6a4a7ede5ad0d967bfd2e8
parent950f6bcc79112c8ab748d0f25a89d9cfdebc0813 (diff)
downloadkvm-unit-tests-master.tar.gz
x86: Allow to limit maximum RAM addressHEADmaster
While there is a feature to limit RAM memory, we should also be able to limit the maximum RAM address. Specifically, svm can only work when the maximum RAM address is lower than 4G, as it does not map the rest of the memory into the NPT. Allow to do so using the firmware, when in fact the expected use-case is to provide this infomation on bare-metal using the MEMLIMIT parameter in initrd. Signed-off-by: Nadav Amit <namit@vmware.com> Message-Id: <20200710183320.27266-5-namit@vmware.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--lib/x86/fwcfg.c4
-rw-r--r--lib/x86/fwcfg.h1
-rw-r--r--lib/x86/setup.c7
3 files changed, 12 insertions, 0 deletions
diff --git a/lib/x86/fwcfg.c b/lib/x86/fwcfg.c
index 06ef62c..c2aaf5a 100644
--- a/lib/x86/fwcfg.c
+++ b/lib/x86/fwcfg.c
@@ -28,6 +28,10 @@ static void read_cfg_override(void)
if ((str = getenv("TEST_DEVICE")))
no_test_device = !atol(str);
+ if ((str = getenv("MEMLIMIT")))
+ fw_override[FW_CFG_MAX_RAM] = atol(str) * 1024 * 1024;
+
+
fw_override_done = true;
}
diff --git a/lib/x86/fwcfg.h b/lib/x86/fwcfg.h
index 2f17461..64d4c6e 100644
--- a/lib/x86/fwcfg.h
+++ b/lib/x86/fwcfg.h
@@ -21,6 +21,7 @@
#define FW_CFG_BOOT_MENU 0x0e
#define FW_CFG_MAX_CPUS 0x0f
#define FW_CFG_MAX_ENTRY 0x10
+#define FW_CFG_MAX_RAM 0x11
#define FW_CFG_WRITE_CHANNEL 0x4000
#define FW_CFG_ARCH_LOCAL 0x8000
diff --git a/lib/x86/setup.c b/lib/x86/setup.c
index b5941cd..7befe09 100644
--- a/lib/x86/setup.c
+++ b/lib/x86/setup.c
@@ -66,6 +66,9 @@ void find_highmem(void)
u64 upper_end = bootinfo->mem_upper * 1024ull;
u64 best_start = (uintptr_t) &edata;
u64 best_end = upper_end;
+ u64 max_end = fwcfg_get_u64(FW_CFG_MAX_RAM);
+ if (max_end == 0)
+ max_end = -1ull;
bool found = false;
uintptr_t mmap = bootinfo->mmap_addr;
@@ -79,8 +82,12 @@ void find_highmem(void)
continue;
if (mem->length < best_end - best_start)
continue;
+ if (mem->base_addr >= max_end)
+ continue;
best_start = mem->base_addr;
best_end = mem->base_addr + mem->length;
+ if (best_end > max_end)
+ best_end = max_end;
found = true;
}