arch, pci, vmm: Initial switch to the hypervisor crate

Start moving the vmm, arch and pci crates to being hypervisor agnostic
by using the hypervisor trait and abstractions. This is not a complete
switch and there are still some remaining KVM dependencies.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Muminul Islam
2020-06-01 19:29:54 -07:00
committed by Samuel Ortiz
parent c48d0c1a67
commit e4dee57e81
24 changed files with 294 additions and 1023 deletions

View File

@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0
//
extern crate hypervisor;
use crate::config::{HotplugMethod, MemoryConfig};
use crate::MEMORY_MANAGER_SNAPSHOT_ID;
#[cfg(feature = "acpi")]
@@ -12,8 +12,9 @@ use arch::{get_host_cpu_phys_bits, layout, RegionType};
#[cfg(target_arch = "x86_64")]
use devices::ioapic;
use devices::BusDevice;
use kvm_bindings::{kvm_userspace_memory_region, KVM_MEM_READONLY};
use kvm_ioctls::*;
use hypervisor::kvm::{kvm_userspace_memory_region, KVM_MEM_READONLY};
use std::convert::TryInto;
use std::ffi;
use std::fs::{File, OpenOptions};
@@ -56,7 +57,7 @@ pub struct MemoryManager {
next_kvm_memory_slot: u32,
start_of_device_area: GuestAddress,
end_of_device_area: GuestAddress,
pub fd: Arc<VmFd>,
pub fd: Arc<dyn hypervisor::Vm>,
hotplug_slots: Vec<HotPlugState>,
selected_slot: usize,
backing_file: Option<PathBuf>,
@@ -103,7 +104,7 @@ pub enum Error {
InvalidSize,
/// Failed to set the user memory region.
SetUserMemoryRegion(kvm_ioctls::Error),
SetUserMemoryRegion(hypervisor::HypervisorVmError),
/// Failed to EventFd.
EventFdFail(io::Error),
@@ -214,7 +215,7 @@ impl BusDevice for MemoryManager {
impl MemoryManager {
pub fn new(
fd: Arc<VmFd>,
fd: Arc<dyn hypervisor::Vm>,
config: &MemoryConfig,
ext_regions: Option<Vec<MemoryRegion>>,
prefault: bool,
@@ -381,7 +382,7 @@ impl MemoryManager {
pub fn new_from_snapshot(
snapshot: &Snapshot,
fd: Arc<VmFd>,
fd: Arc<dyn hypervisor::Vm>,
config: &MemoryConfig,
source_url: &str,
prefault: bool,
@@ -685,8 +686,8 @@ impl MemoryManager {
flags: if readonly { KVM_MEM_READONLY } else { 0 },
};
// Safe because the guest regions are guaranteed not to overlap.
unsafe { self.fd.set_user_memory_region(mem_region) }
self.fd
.set_user_memory_region(mem_region)
.map_err(Error::SetUserMemoryRegion)?;
// Mark the pages as mergeable if explicitly asked for.
@@ -738,8 +739,8 @@ impl MemoryManager {
flags: 0,
};
// Safe to remove because we know the region exist.
unsafe { self.fd.set_user_memory_region(mem_region) }
self.fd
.set_user_memory_region(mem_region)
.map_err(Error::SetUserMemoryRegion)?;
// Mark the pages as unmergeable if there were previously marked as