Skip to content

Commit 363ac11

Browse files
Andrew Jonesandreeaflorescu
authored andcommitted
Create an AArch64 specific create_vm
Not all AArch64 platforms support IPAs up to 40 bits. When KVM supports Cap::ArmVmIPASize it's better to get the IPA size from the host and use that when creating the VM, which may avoid unnecessary VM creation failures. Additionally, when 40 is selected with the value 0, which means use the default, some versions of KVM will skip a check resulting in a difficult to debug fail. We must still use 0 when KVM only supports the legacy fixed 40 bit IPA. Signed-off-by: Andrew Jones <drjones@redhat.com>
1 parent 3b75cb1 commit 363ac11

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/ioctls/system.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,36 @@ impl Kvm {
381381
/// assert!(vm.run_size() == kvm.get_vcpu_mmap_size().unwrap());
382382
/// ```
383383
///
384+
#[cfg(not(any(target_arch = "aarch64")))]
384385
pub fn create_vm(&self) -> Result<VmFd> {
385386
self.create_vm_with_type(0) // Create using default VM type
386387
}
387388

389+
/// AArch64 specific create_vm to create a VM fd using the KVM fd using the host's maximum IPA size.
390+
///
391+
/// See the arm64 section of KVM documentation for `KVM_CREATE_VM`.
392+
/// A call to this function will also initialize the size of the vcpu mmap area using the
393+
/// `KVM_GET_VCPU_MMAP_SIZE` ioctl.
394+
///
395+
/// # Example
396+
///
397+
/// ```
398+
/// # use kvm_ioctls::Kvm;
399+
/// let kvm = Kvm::new().unwrap();
400+
/// let vm = kvm.create_vm().unwrap();
401+
/// // Check that the VM mmap size is the same reported by `KVM_GET_VCPU_MMAP_SIZE`.
402+
/// assert!(vm.run_size() == kvm.get_vcpu_mmap_size().unwrap());
403+
/// ```
404+
///
405+
#[cfg(any(target_arch = "aarch64"))]
406+
pub fn create_vm(&self) -> Result<VmFd> {
407+
let mut ipa_size = 0; // Create using default VM type
408+
if self.check_extension(Cap::ArmVmIPASize) {
409+
ipa_size = self.get_host_ipa_limit();
410+
}
411+
self.create_vm_with_type(ipa_size as u64)
412+
}
413+
388414
/// AArch64 specific function to create a VM fd using the KVM fd with flexible IPA size.
389415
///
390416
/// See the arm64 section of KVM documentation for `KVM_CREATE_VM`.

0 commit comments

Comments
 (0)