Skip to content

Commit 2fe3586

Browse files
MrXinWangSebastien Boeuf
authored and
Sebastien Boeuf
committed
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>
1 parent 805cb30 commit 2fe3586

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

hypervisor/src/kvm/mod.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use crate::vm::{self, VmmOps};
2222
use crate::{arm64_core_reg_id, offset__of};
2323
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
2424
use serde_derive::{Deserialize, Serialize};
25+
#[cfg(target_arch = "aarch64")]
26+
use std::convert::TryInto;
2527
use std::os::unix::io::{AsRawFd, RawFd};
2628
use std::result;
2729
#[cfg(target_arch = "x86_64")]
@@ -558,7 +560,18 @@ impl hypervisor::Hypervisor for KvmHypervisor {
558560
/// let vm = hypervisor.create_vm().unwrap()
559561
///
560562
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
561-
self.create_vm_with_type(0) // Create with default platform type
563+
#[allow(unused_mut)]
564+
let mut vm_type: u64 = 0; // Create with default platform type
565+
566+
// When KVM supports Cap::ArmVmIPASize, it is better to get the IPA
567+
// size from the host and use that when creating the VM, which may
568+
// avoid unnecessary VM creation failures.
569+
#[cfg(target_arch = "aarch64")]
570+
if self.kvm.check_extension(Cap::ArmVmIPASize) {
571+
vm_type = self.kvm.get_host_ipa_limit().try_into().unwrap();
572+
}
573+
574+
self.create_vm_with_type(vm_type)
562575
}
563576

564577
fn check_required_extensions(&self) -> hypervisor::Result<()> {
@@ -575,6 +588,7 @@ impl hypervisor::Hypervisor for KvmHypervisor {
575588
.get_supported_cpuid(kvm_bindings::KVM_MAX_CPUID_ENTRIES)
576589
.map_err(|e| hypervisor::HypervisorError::GetCpuId(e.into()))
577590
}
591+
578592
#[cfg(target_arch = "x86_64")]
579593
///
580594
/// Retrieve the list of MSRs supported by KVM.

0 commit comments

Comments
 (0)