mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-30 16:35:31 +00:00
hypervisor, vmm: drop VmState and code
VmState was introduced to hold hypervisor specific VM state. KVM does not need it and MSHV does not really use it yet. Just drop the code. It can be easily revived once there is a need. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
72d552e5e1
commit
beb4f86b82
@ -25,7 +25,6 @@ use crate::vm::{self, InterruptSourceConfig, VmOps};
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use crate::{arm64_core_reg_id, offset__of};
|
||||
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
@ -263,11 +262,6 @@ impl From<CpuState> for VcpuKvmState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct KvmVmState {}
|
||||
|
||||
pub use KvmVmState as VmState;
|
||||
|
||||
struct KvmDirtyLogSlot {
|
||||
slot: u32,
|
||||
guest_phys_addr: u64,
|
||||
@ -280,7 +274,6 @@ pub struct KvmVm {
|
||||
fd: Arc<VmFd>,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
msrs: MsrEntries,
|
||||
state: KvmVmState,
|
||||
dirty_log_slots: Arc<RwLock<HashMap<u32, KvmDirtyLogSlot>>>,
|
||||
}
|
||||
|
||||
@ -657,19 +650,6 @@ impl vm::Vm for KvmVm {
|
||||
self.create_device(&mut vfio_dev)
|
||||
.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(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Start logging dirty pages
|
||||
///
|
||||
@ -914,7 +894,6 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
||||
Ok(Arc::new(KvmVm {
|
||||
fd: vm_fd,
|
||||
msrs,
|
||||
state: VmState {},
|
||||
dirty_log_slots: Arc::new(RwLock::new(HashMap::new())),
|
||||
}))
|
||||
}
|
||||
@ -923,7 +902,6 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
||||
{
|
||||
Ok(Arc::new(KvmVm {
|
||||
fd: vm_fd,
|
||||
state: VmState {},
|
||||
dirty_log_slots: Arc::new(RwLock::new(HashMap::new())),
|
||||
}))
|
||||
}
|
||||
|
@ -59,12 +59,12 @@ pub use kvm::x86_64;
|
||||
pub use kvm::{aarch64, GicState};
|
||||
// Aliased types exposed from both hypervisors
|
||||
#[cfg(feature = "kvm")]
|
||||
pub use kvm::{ClockData, CreateDevice, DeviceAttr, DeviceFd, IrqRoutingEntry, VmState};
|
||||
pub use kvm::{ClockData, CreateDevice, DeviceAttr, DeviceFd, IrqRoutingEntry};
|
||||
#[cfg(all(feature = "mshv", target_arch = "x86_64"))]
|
||||
pub use mshv::x86_64;
|
||||
// Aliased types exposed from both hypervisors
|
||||
#[cfg(all(feature = "mshv", target_arch = "x86_64"))]
|
||||
pub use mshv::{CreateDevice, DeviceAttr, DeviceFd, IrqRoutingEntry, VmState};
|
||||
pub use mshv::{CreateDevice, DeviceAttr, DeviceFd, IrqRoutingEntry};
|
||||
use std::sync::Arc;
|
||||
pub use vm::{
|
||||
DataMatch, HypervisorVmError, InterruptSourceConfig, LegacyIrqSourceConfig, MsiIrqSourceConfig,
|
||||
|
@ -14,7 +14,6 @@ use crate::vec_with_array_field;
|
||||
use crate::vm::{self, InterruptSourceConfig, VmOps};
|
||||
pub use mshv_bindings::*;
|
||||
use mshv_ioctls::{set_registers_64, Mshv, NoDatamatch, VcpuFd, VmFd};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
@ -132,13 +131,6 @@ impl From<CpuState> for VcpuMshvState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)]
|
||||
pub struct HvState {
|
||||
hypercall_page: u64,
|
||||
}
|
||||
|
||||
pub use HvState as VmState;
|
||||
|
||||
struct MshvDirtyLogSlot {
|
||||
guest_pfn: u64,
|
||||
memory_size: u64,
|
||||
@ -217,7 +209,6 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
||||
Ok(Arc::new(MshvVm {
|
||||
fd: vm_fd,
|
||||
msrs,
|
||||
hv_state: hv_state_init(),
|
||||
vm_ops: None,
|
||||
dirty_log_slots: Arc::new(RwLock::new(HashMap::new())),
|
||||
}))
|
||||
@ -246,7 +237,6 @@ pub struct MshvVcpu {
|
||||
vp_index: u8,
|
||||
cpuid: CpuId,
|
||||
msrs: MsrEntries,
|
||||
hv_state: Arc<RwLock<HvState>>, // Mshv State
|
||||
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
||||
}
|
||||
|
||||
@ -871,16 +861,10 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
|
||||
pub struct MshvVm {
|
||||
fd: Arc<VmFd>,
|
||||
msrs: MsrEntries,
|
||||
// Hypervisor State
|
||||
hv_state: Arc<RwLock<HvState>>,
|
||||
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
||||
dirty_log_slots: Arc<RwLock<HashMap<u64, MshvDirtyLogSlot>>>,
|
||||
}
|
||||
|
||||
fn hv_state_init() -> Arc<RwLock<HvState>> {
|
||||
Arc::new(RwLock::new(HvState { hypercall_page: 0 }))
|
||||
}
|
||||
|
||||
///
|
||||
/// Implementation of Vm trait for Mshv
|
||||
/// Example:
|
||||
@ -954,7 +938,6 @@ impl vm::Vm for MshvVm {
|
||||
vp_index: id,
|
||||
cpuid: CpuId::new(1).unwrap(),
|
||||
msrs: self.msrs.clone(),
|
||||
hv_state: self.hv_state.clone(),
|
||||
vm_ops,
|
||||
};
|
||||
Ok(Arc::new(vcpu))
|
||||
@ -1128,19 +1111,6 @@ impl vm::Vm for MshvVm {
|
||||
.map_err(|e| vm::HypervisorVmError::SetGsiRouting(e.into()))
|
||||
}
|
||||
///
|
||||
/// Get the Vm state. Return VM specific data
|
||||
///
|
||||
fn state(&self) -> vm::Result<VmState> {
|
||||
Ok(*self.hv_state.read().unwrap())
|
||||
}
|
||||
///
|
||||
/// Set the VM state
|
||||
///
|
||||
fn set_state(&self, state: VmState) -> vm::Result<()> {
|
||||
self.hv_state.write().unwrap().hypercall_page = state.hypercall_page;
|
||||
Ok(())
|
||||
}
|
||||
///
|
||||
/// Start logging dirty pages
|
||||
///
|
||||
fn start_dirty_log(&self) -> vm::Result<()> {
|
||||
|
@ -14,10 +14,6 @@ use crate::aarch64::VcpuInit;
|
||||
use crate::arch::aarch64::gic::Vgic;
|
||||
use crate::cpu::Vcpu;
|
||||
use crate::device::Device;
|
||||
#[cfg(feature = "kvm")]
|
||||
use crate::kvm::KvmVmState as VmState;
|
||||
#[cfg(feature = "mshv")]
|
||||
use crate::mshv::HvState as VmState;
|
||||
#[cfg(feature = "tdx")]
|
||||
use crate::x86_64::CpuId;
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
@ -338,10 +334,6 @@ pub trait Vm: Send + Sync {
|
||||
fn check_extension(&self, c: Cap) -> bool;
|
||||
/// Create a device that is used for passthrough
|
||||
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<()>;
|
||||
/// Start logging dirty pages
|
||||
fn start_dirty_log(&self) -> Result<()>;
|
||||
/// Stop logging dirty pages
|
||||
|
@ -30,7 +30,7 @@ use crate::memory_manager::{
|
||||
};
|
||||
#[cfg(feature = "guest_debug")]
|
||||
use crate::migration::url_to_file;
|
||||
use crate::migration::{get_vm_snapshot, url_to_path, SNAPSHOT_CONFIG_FILE, SNAPSHOT_STATE_FILE};
|
||||
use crate::migration::{url_to_path, SNAPSHOT_CONFIG_FILE, SNAPSHOT_STATE_FILE};
|
||||
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
||||
use crate::GuestMemoryMmap;
|
||||
use crate::{
|
||||
@ -813,12 +813,6 @@ impl Vm {
|
||||
vm.enable_split_irq().unwrap();
|
||||
}
|
||||
|
||||
let vm_snapshot = get_vm_snapshot(snapshot).map_err(Error::Restore)?;
|
||||
if let Some(state) = vm_snapshot.state {
|
||||
vm.set_state(state)
|
||||
.map_err(|e| Error::Restore(MigratableError::Restore(e.into())))?;
|
||||
}
|
||||
|
||||
let memory_manager = if let Some(memory_manager_snapshot) =
|
||||
snapshot.snapshots.get(MEMORY_MANAGER_SNAPSHOT_ID)
|
||||
{
|
||||
@ -2180,6 +2174,7 @@ impl Vm {
|
||||
&mut self,
|
||||
snapshot: &Snapshot,
|
||||
) -> Result<Option<hypervisor::ClockData>> {
|
||||
use crate::migration::get_vm_snapshot;
|
||||
let vm_snapshot = get_vm_snapshot(snapshot).map_err(Error::Restore)?;
|
||||
self.saved_clock = vm_snapshot.clock;
|
||||
Ok(self.saved_clock)
|
||||
@ -2623,7 +2618,6 @@ impl Pausable for Vm {
|
||||
pub struct VmSnapshot {
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
pub clock: Option<hypervisor::ClockData>,
|
||||
pub state: Option<hypervisor::VmState>,
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
pub common_cpuid: hypervisor::x86_64::CpuId,
|
||||
}
|
||||
@ -2673,14 +2667,9 @@ impl Snapshottable for Vm {
|
||||
};
|
||||
|
||||
let mut vm_snapshot = Snapshot::new(VM_SNAPSHOT_ID);
|
||||
let vm_state = self
|
||||
.vm
|
||||
.state()
|
||||
.map_err(|e| MigratableError::Snapshot(e.into()))?;
|
||||
let vm_snapshot_data = serde_json::to_vec(&VmSnapshot {
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
clock: self.saved_clock,
|
||||
state: Some(vm_state),
|
||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||
common_cpuid,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user