diff --git a/src/utils/Cargo.toml b/src/utils/Cargo.toml index 2c742443acf..ea030dc453c 100644 --- a/src/utils/Cargo.toml +++ b/src/utils/Cargo.toml @@ -10,7 +10,7 @@ derive_more = { version = "0.99.17", default-features = false, features = ["from libc = "0.2.117" serde = { version = "1.0.136", features = ["derive"] } thiserror = "1.0.32" -versionize = "0.1.6" +versionize = "0.1.10" versionize_derive = "0.1.3" vmm-sys-util = "0.11.0" diff --git a/src/vmm/src/lib.rs b/src/vmm/src/lib.rs index cc054c89861..9b19a09abcc 100644 --- a/src/vmm/src/lib.rs +++ b/src/vmm/src/lib.rs @@ -64,8 +64,9 @@ use crate::device_manager::mmio::MMIODeviceManager; use crate::memory_snapshot::SnapshotMemory; use crate::persist::{MicrovmState, MicrovmStateError, VmInfo}; use crate::vmm_config::instance_info::{InstanceInfo, VmState}; -use crate::vstate::vcpu::{Vcpu, VcpuEvent, VcpuHandle, VcpuResponse, VcpuState}; -use crate::vstate::vm::Vm; +use crate::vstate::vcpu::VcpuState; +pub use crate::vstate::vcpu::{Vcpu, VcpuEvent, VcpuHandle, VcpuResponse, VcpuConfig}; +pub use crate::vstate::vm::Vm; /// Shorthand type for the EventManager flavour used by Firecracker. pub type EventManager = BaseEventManager>>; diff --git a/src/vmm/src/vstate/vcpu/mod.rs b/src/vmm/src/vstate/vcpu/mod.rs index ae835719acf..65ecfadce4f 100644 --- a/src/vmm/src/vstate/vcpu/mod.rs +++ b/src/vmm/src/vstate/vcpu/mod.rs @@ -94,21 +94,21 @@ impl fmt::Display for StartThreadedError { /// A wrapper around creating and using a vcpu. pub struct Vcpu { - // Offers kvm-arch specific functionality. + /// Access to kvm-arch specific functionality. pub kvm_vcpu: KvmVcpu, - // File descriptor for vcpu to trigger exit event on vmm. + /// File descriptor for vcpu to trigger exit event on vmm. exit_evt: EventFd, - // The receiving end of events channel owned by the vcpu side. + /// The receiving end of events channel owned by the vcpu side. event_receiver: Receiver, - // The transmitting end of the events channel which will be given to the handler. + /// The transmitting end of the events channel which will be given to the handler. event_sender: Option>, - // The receiving end of the responses channel which will be given to the handler. + /// The receiving end of the responses channel which will be given to the handler. response_receiver: Option>, - // The transmitting end of the responses channel owned by the vcpu side. + /// The transmitting end of the responses channel owned by the vcpu side. response_sender: Sender, - // Exit reason used to test run_emulation function. + /// Exit reason used to test run_emulation function. #[cfg(test)] test_vcpu_exit_reason: Mutex, errno::Error>>>, } @@ -434,6 +434,9 @@ impl Vcpu { } #[cfg(not(test))] + /// Calls `KVM_RUN` with this [`Vcpu`]'s underlying file descriptor. + /// + /// Blocks until a `VM_EXIT` is received, in which case this function returns a [`VcpuExit`] containing the reason. pub fn emulate(&self) -> std::result::Result { self.kvm_vcpu.fd.run() } @@ -584,6 +587,21 @@ pub enum VcpuResponse { SavedState(Box), } +impl fmt::Debug for VcpuResponse { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use crate::VcpuResponse::*; + match self { + Paused => write!(f, "VcpuResponse::Paused"), + Resumed => write!(f, "VcpuResponse::Resumed"), + Exited(code) => write!(f, "VcpuResponse::Exited({:?})", code), + RestoredState => write!(f, "VcpuResponse::RestoredState"), + SavedState(_) => write!(f, "VcpuResponse::SavedState"), + Error(ref err) => write!(f, "VcpuResponse::Error({:?})", err), + NotAllowed(ref reason) => write!(f, "VcpuResponse::NotAllowed({})", reason), + } + } +} + /// Wrapper over Vcpu that hides the underlying interactions with the Vcpu thread. pub struct VcpuHandle { event_sender: Sender, @@ -604,6 +622,12 @@ impl fmt::Display for VcpuSendEventError { } impl VcpuHandle { + /// Creates a new [`VcpuHandle`]. + /// + /// # Arguments + /// + `event_sender`: [`Sender`] to communicate [`VcpuEvent`] to control the vcpu. + /// + `response_received`: [`Received`] from which the vcpu's responses can be read. + /// + `vcpu_thread`: A [`JoinHandle`] for the vcpu thread. pub fn new( event_sender: Sender, response_receiver: Receiver, @@ -634,6 +658,7 @@ impl VcpuHandle { Ok(()) } + /// Returns a reference to the [`Received`] from which the vcpu's responses can be read. pub fn response_receiver(&self) -> &Receiver { &self.response_receiver } @@ -838,21 +863,6 @@ mod tests { } } - impl fmt::Debug for VcpuResponse { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use crate::VcpuResponse::*; - match self { - Paused => write!(f, "VcpuResponse::Paused"), - Resumed => write!(f, "VcpuResponse::Resumed"), - Exited(code) => write!(f, "VcpuResponse::Exited({:?})", code), - RestoredState => write!(f, "VcpuResponse::RestoredState"), - SavedState(_) => write!(f, "VcpuResponse::SavedState"), - Error(ref err) => write!(f, "VcpuResponse::Error({:?})", err), - NotAllowed(ref reason) => write!(f, "VcpuResponse::NotAllowed({})", reason), - } - } - } - // Auxiliary function being used throughout the tests. #[allow(unused_mut)] pub(crate) fn setup_vcpu(mem_size: usize) -> (Vm, Vcpu, GuestMemoryMmap) { diff --git a/tests/host_tools/uffd/Cargo.lock b/tests/host_tools/uffd/Cargo.lock index 7a51cbafe6c..8cf066a9b0c 100644 --- a/tests/host_tools/uffd/Cargo.lock +++ b/tests/host_tools/uffd/Cargo.lock @@ -362,9 +362,9 @@ dependencies = [ [[package]] name = "versionize" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6e2495726cf917e7ba7ec8bf0f0fceab543dd38d0a4195ed6bef331e38a290f" +checksum = "dca4b7062e7e6d685901e815c35f9671e059de97c1c0905eeff8592f3fff442f" dependencies = [ "bincode", "crc64",