From beb4f86b82044b57bdecb2427f240cfe583073cd Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 14 Jul 2022 13:52:52 +0000 Subject: [PATCH] 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 --- hypervisor/src/kvm/mod.rs | 22 ---------------------- hypervisor/src/lib.rs | 4 ++-- hypervisor/src/mshv/mod.rs | 30 ------------------------------ hypervisor/src/vm.rs | 8 -------- vmm/src/vm.rs | 15 ++------------- 5 files changed, 4 insertions(+), 75 deletions(-) diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index a90b82017..f7663dfe0 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -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 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, #[cfg(target_arch = "x86_64")] msrs: MsrEntries, - state: KvmVmState, dirty_log_slots: Arc>>, } @@ -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 { - 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())), })) } diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index a30b5d3cf..fc27237e5 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -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, diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index dcbeb724c..93c5e2bb9 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -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 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>, // Mshv State vm_ops: Option>, } @@ -871,16 +861,10 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> { pub struct MshvVm { fd: Arc, msrs: MsrEntries, - // Hypervisor State - hv_state: Arc>, vm_ops: Option>, dirty_log_slots: Arc>>, } -fn hv_state_init() -> Arc> { - 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 { - 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<()> { diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index 2c3a33c6b..783344415 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -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>; - /// Get the Vm state. Return VM specific data - fn state(&self) -> Result; - /// 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 diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 3b9f4a93a..a28323d55 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -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> { + 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, - pub state: Option, #[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, })