hypervisor: support AArch64 get_host_ipa_limit

Not all AArch64 platforms support IPAs up to 40 bits. Since the
kvm-ioctl crate now supports `get_host_ipa_limit` for AArch64,
when creating the VM, it is better to get the IPA size from the
host and use that to create the VM.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
This commit is contained in:
Henry Wang 2021-06-09 17:42:37 +08:00 committed by Sebastien Boeuf
parent 805cb303d5
commit 2fe3586eba

View File

@ -22,6 +22,8 @@ use crate::vm::{self, VmmOps};
use crate::{arm64_core_reg_id, offset__of};
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
use serde_derive::{Deserialize, Serialize};
#[cfg(target_arch = "aarch64")]
use std::convert::TryInto;
use std::os::unix::io::{AsRawFd, RawFd};
use std::result;
#[cfg(target_arch = "x86_64")]
@ -558,7 +560,18 @@ impl hypervisor::Hypervisor for KvmHypervisor {
/// let vm = hypervisor.create_vm().unwrap()
///
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
self.create_vm_with_type(0) // Create with default platform type
#[allow(unused_mut)]
let mut vm_type: u64 = 0; // Create with default platform type
// When KVM supports Cap::ArmVmIPASize, it is better to get the IPA
// size from the host and use that when creating the VM, which may
// avoid unnecessary VM creation failures.
#[cfg(target_arch = "aarch64")]
if self.kvm.check_extension(Cap::ArmVmIPASize) {
vm_type = self.kvm.get_host_ipa_limit().try_into().unwrap();
}
self.create_vm_with_type(vm_type)
}
fn check_required_extensions(&self) -> hypervisor::Result<()> {
@ -575,6 +588,7 @@ impl hypervisor::Hypervisor for KvmHypervisor {
.get_supported_cpuid(kvm_bindings::KVM_MAX_CPUID_ENTRIES)
.map_err(|e| hypervisor::HypervisorError::GetCpuId(e.into()))
}
#[cfg(target_arch = "x86_64")]
///
/// Retrieve the list of MSRs supported by KVM.