aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Elisei <alexandru.elisei@arm.com>2022-06-16 14:48:21 +0100
committerWill Deacon <will@kernel.org>2022-07-01 16:08:06 +0100
commitcce5a4f6ae9b1db634245521e7967cc605e0bedc (patch)
tree9b3940c81295537378f4786cc641d1c81b16ea9c
parentabe3f28a9c0700837aca75887f0cd65c6371e2e4 (diff)
downloadkvmtool-cce5a4f6ae9b1db634245521e7967cc605e0bedc.tar.gz
arm/arm64: Fail if RAM size is too large for 32-bit guests
For 64-bit guests, kvmtool exists with an error in kvm__get_vm_type() if the memory size is larger than what KVM supports. For 32-bit guests, the RAM size is silently rounded down to ARM_LOMAP_MAX_MEMORY in kvm__arch_init(). Be consistent and exit with an error when the user has configured the wrong RAM size for 32-bit guests. Reviewed-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Reviewed-and-Tested-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20220616134828.129006-6-alexandru.elisei@arm.com Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r--arm/aarch32/kvm.c4
-rw-r--r--arm/aarch64/kvm.c5
-rw-r--r--arm/kvm.c2
3 files changed, 10 insertions, 1 deletions
diff --git a/arm/aarch32/kvm.c b/arm/aarch32/kvm.c
index ae33ac92..9d68d7a1 100644
--- a/arm/aarch32/kvm.c
+++ b/arm/aarch32/kvm.c
@@ -2,4 +2,8 @@
void kvm__arch_validate_cfg(struct kvm *kvm)
{
+ if (kvm->cfg.ram_size > ARM_LOMAP_MAX_MEMORY) {
+ die("RAM size 0x%llx exceeds maximum allowed 0x%llx",
+ kvm->cfg.ram_size, ARM_LOMAP_MAX_MEMORY);
+ }
}
diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c
index ca348f11..2134528b 100644
--- a/arm/aarch64/kvm.c
+++ b/arm/aarch64/kvm.c
@@ -39,6 +39,11 @@ int vcpu_affinity_parser(const struct option *opt, const char *arg, int unset)
void kvm__arch_validate_cfg(struct kvm *kvm)
{
+ if (kvm->cfg.arch.aarch32_guest &&
+ kvm->cfg.ram_size > ARM_LOMAP_MAX_MEMORY) {
+ die("RAM size 0x%llx exceeds maximum allowed 0x%llx",
+ kvm->cfg.ram_size, ARM_LOMAP_MAX_MEMORY);
+ }
}
/*
diff --git a/arm/kvm.c b/arm/kvm.c
index c5913000..af0feae4 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -65,7 +65,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
* If using THP, then our minimal alignment becomes 2M.
* 2M trumps 64K, so let's go with that.
*/
- kvm->ram_size = min(ram_size, (u64)ARM_MAX_MEMORY(kvm));
+ kvm->ram_size = ram_size;
kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path,
kvm->arch.ram_alloc_size);