From 1eb8a4671fdeb982887475f5664fb1031ecd2bd4 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Wed, 9 Jun 2021 20:45:11 +0800 Subject: [PATCH] arch: aarch64: Remove hardcoded host IPA size With the ability of getting host IPA size in `hypervisor` crate, we can query the host IPA size through ioctl instead of hardcoding a maximum IPA size. Therefore this commit removes the hardcoded maximum host IPA size. Signed-off-by: Henry Wang --- arch/src/aarch64/mod.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index 08f4be21f..e57f0a471 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -19,6 +19,7 @@ use crate::GuestMemoryMmap; use crate::RegionType; use gic::GicDevice; use std::collections::HashMap; +use std::convert::TryInto; use std::ffi::CStr; use std::fmt::Debug; use std::sync::Arc; @@ -195,22 +196,17 @@ fn get_fdt_addr() -> u64 { } pub fn get_host_cpu_phys_bits() -> u8 { - // The value returned here is used to determine the physical address space size - // for a VM (IPA size). - // In recent kernel versions, the maximum IPA size supported by the host can be - // known by querying cap KVM_CAP_ARM_VM_IPA_SIZE. And the IPA size for a - // guest can be configured smaller. - // But in Cloud-Hypervisor we simply use the maximum value for the VM. - // Reference https://lwn.net/Articles/766767/. - // - // The correct way to query KVM_CAP_ARM_VM_IPA_SIZE is via rust-vmm/kvm-ioctls, - // which wraps all IOCTL's and provides easy interface to user hypervisors. - // For now the cap hasn't been supported. A separate patch will be submitted to - // rust-vmm to add it. - // So a hardcoded value is used here as a temporary solution. - // It will be replace once rust-vmm/kvm-ioctls is ready. - // - 40 + // A dummy hypervisor created only for querying the host IPA size and will + // be freed after the query. + let hv = hypervisor::new().unwrap(); + let host_cpu_phys_bits = hv.get_host_ipa_limit().try_into().unwrap(); + if host_cpu_phys_bits == 0 { + // Host kernel does not support `get_host_ipa_limit`, + // we return the default value 40 here. + 40 + } else { + host_cpu_phys_bits + } } #[cfg(test)]