diff options
author | Marc Zyngier <maz@kernel.org> | 2021-08-22 16:25:26 +0100 |
---|---|---|
committer | Will Deacon <will@kernel.org> | 2021-08-31 15:46:57 +0100 |
commit | bdb86d0c0c9585b6750d1992f7f19f46f82e8da8 (patch) | |
tree | 50ff8153207f60e00574372396f1d52f6efaeab3 | |
parent | 066b5c06c4e37c72ec096e69923ae3fda11b796a (diff) | |
download | kvmtool-bdb86d0c0c9585b6750d1992f7f19f46f82e8da8.tar.gz |
kvmtool: arm64: Configure VM with the minimal required IPA space
There is some value in keeping the IPA space small, as it reduces
the size of the stage-2 page tables.
Let's compute the required space at VM creation time, and inform
the kernel of our requirements.
Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Oliver Upton <oupton@google.com>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Link: https://lore.kernel.org/r/20210822152526.1291918-4-maz@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r-- | arm/aarch64/kvm.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index d03a27f2..4e66a22e 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -3,6 +3,7 @@ #include <asm/image.h> #include <linux/byteorder.h> +#include <kvm/util.h> /* * Return the TEXT_OFFSET value that the guest kernel expects. Note @@ -59,5 +60,22 @@ int kvm__arch_get_ipa_limit(struct kvm *kvm) int kvm__get_vm_type(struct kvm *kvm) { - return KVM_VM_TYPE_ARM_IPA_SIZE(kvm__arch_get_ipa_limit(kvm)); + unsigned int ipa_bits, max_ipa_bits; + unsigned long max_ipa; + + /* If we're running on an old kernel, use 0 as the VM type */ + max_ipa_bits = kvm__arch_get_ipa_limit(kvm); + if (!max_ipa_bits) + return 0; + + /* Otherwise, compute the minimal required IPA size */ + max_ipa = ARM_MEMORY_AREA + kvm->cfg.ram_size - 1; + ipa_bits = max(32, fls_long(max_ipa)); + pr_debug("max_ipa %lx ipa_bits %d max_ipa_bits %d", + max_ipa, ipa_bits, max_ipa_bits); + + if (ipa_bits > max_ipa_bits) + die("Memory too large for this system (needs %d bits, %d available)", ipa_bits, max_ipa_bits); + + return KVM_VM_TYPE_ARM_IPA_SIZE(ipa_bits); } |