mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-21 15:31:15 +00:00
hypervisor: Introduce VM state to Vm hypervisor trait
We may need to store hypervisor speciific data to the VM. This support is needed for Microsoft hyperv implementations. This patch introduces two new definitions to Vm trait and implements for KVM. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
parent
8962e25268
commit
77e901a602
@ -8,20 +8,20 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
|
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
|
||||||
use std::result;
|
|
||||||
use std::sync::Arc;
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
use vm_memory::Address;
|
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub use crate::aarch64::{check_required_kvm_extensions, VcpuInit, VcpuKvmState as CpuState};
|
pub use crate::aarch64::{check_required_kvm_extensions, VcpuInit, VcpuKvmState as CpuState};
|
||||||
use crate::cpu;
|
use crate::cpu;
|
||||||
use crate::device;
|
use crate::device;
|
||||||
use crate::hypervisor;
|
use crate::hypervisor;
|
||||||
use crate::vm;
|
use crate::vm;
|
||||||
|
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
|
use std::result;
|
||||||
|
use std::sync::Arc;
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
use vm_memory::Address;
|
||||||
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
// x86_64 dependencies
|
// x86_64 dependencies
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub mod x86_64;
|
pub mod x86_64;
|
||||||
@ -66,12 +66,16 @@ pub use {
|
|||||||
kvm_bindings::kvm_vcpu_events as VcpuEvents, kvm_ioctls::DeviceFd, kvm_ioctls::IoEventAddress,
|
kvm_bindings::kvm_vcpu_events as VcpuEvents, kvm_ioctls::DeviceFd, kvm_ioctls::IoEventAddress,
|
||||||
kvm_ioctls::VcpuExit,
|
kvm_ioctls::VcpuExit,
|
||||||
};
|
};
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
|
pub struct KvmVmState {}
|
||||||
|
|
||||||
|
use KvmVmState as VmState;
|
||||||
/// Wrapper over KVM VM ioctls.
|
/// Wrapper over KVM VM ioctls.
|
||||||
pub struct KvmVm {
|
pub struct KvmVm {
|
||||||
fd: Arc<VmFd>,
|
fd: Arc<VmFd>,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
msrs: MsrEntries,
|
msrs: MsrEntries,
|
||||||
|
state: KvmVmState,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a `Vec<T>` with a size in bytes at least as large as `size_in_bytes`.
|
// Returns a `Vec<T>` with a size in bytes at least as large as `size_in_bytes`.
|
||||||
@ -314,6 +318,18 @@ impl vm::Vm for KvmVm {
|
|||||||
self.create_device(&mut vfio_dev)
|
self.create_device(&mut vfio_dev)
|
||||||
.map_err(|e| vm::HypervisorVmError::CreatePassthroughDevice(e.into()))
|
.map_err(|e| vm::HypervisorVmError::CreatePassthroughDevice(e.into()))
|
||||||
}
|
}
|
||||||
|
///
|
||||||
|
/// Get the Vm state. Return VM specific data
|
||||||
|
///
|
||||||
|
fn state(&self) -> vm::Result<VmState> {
|
||||||
|
Ok(self.state)
|
||||||
|
}
|
||||||
|
///
|
||||||
|
/// Set the VM state
|
||||||
|
///
|
||||||
|
fn set_state(&self, _state: &VmState) -> vm::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Wrapper over KVM system ioctls.
|
/// Wrapper over KVM system ioctls.
|
||||||
pub struct KvmHypervisor {
|
pub struct KvmHypervisor {
|
||||||
@ -381,12 +397,19 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
|||||||
msr_entries[pos].index = *index;
|
msr_entries[pos].index = *index;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Arc::new(KvmVm { fd: vm_fd, msrs }))
|
Ok(Arc::new(KvmVm {
|
||||||
|
fd: vm_fd,
|
||||||
|
msrs,
|
||||||
|
state: VmState {},
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||||
{
|
{
|
||||||
Ok(Arc::new(KvmVm { fd: vm_fd }))
|
Ok(Arc::new(KvmVm {
|
||||||
|
fd: vm_fd,
|
||||||
|
state: VmState {},
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ pub use kvm::*;
|
|||||||
pub use vm::{DataMatch, HypervisorVmError, Vm};
|
pub use vm::{DataMatch, HypervisorVmError, Vm};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub fn new() -> std::result::Result<Arc<dyn Hypervisor>, HypervisorError> {
|
pub fn new() -> std::result::Result<Arc<dyn Hypervisor>, HypervisorError> {
|
||||||
#[cfg(feature = "kvm")]
|
#[cfg(feature = "kvm")]
|
||||||
let hv = kvm::KvmHypervisor::new()?;
|
let hv = kvm::KvmHypervisor::new()?;
|
||||||
|
@ -14,6 +14,7 @@ use crate::cpu::Vcpu;
|
|||||||
use crate::device::Device;
|
use crate::device::Device;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use crate::ClockData;
|
use crate::ClockData;
|
||||||
|
use crate::KvmVmState as VmState;
|
||||||
use crate::{CreateDevice, IoEventAddress, IrqRoutingEntry, MemoryRegion};
|
use crate::{CreateDevice, IoEventAddress, IrqRoutingEntry, MemoryRegion};
|
||||||
use kvm_ioctls::Cap;
|
use kvm_ioctls::Cap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -179,4 +180,8 @@ pub trait Vm: Send + Sync {
|
|||||||
fn check_extension(&self, c: Cap) -> bool;
|
fn check_extension(&self, c: Cap) -> bool;
|
||||||
/// Create a device that is used for passthrough
|
/// Create a device that is used for passthrough
|
||||||
fn create_passthrough_device(&self) -> Result<Arc<dyn Device>>;
|
fn create_passthrough_device(&self) -> Result<Arc<dyn Device>>;
|
||||||
|
/// Get the Vm state. Return VM specific data
|
||||||
|
fn state(&self) -> Result<VmState>;
|
||||||
|
/// Set the VM state
|
||||||
|
fn set_state(&self, state: &VmState) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user