diff --git a/Cargo.lock b/Cargo.lock index cc6797fe4ab..f50ab6c1964 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10963,6 +10963,7 @@ name = "virtiofs" version = "0.0.0" dependencies = [ "anyhow", + "chipset_device", "event-listener", "fuse", "futures", diff --git a/Guide/src/user_guide/openvmm/snapshots.md b/Guide/src/user_guide/openvmm/snapshots.md index 6d4faf3c527..5658c3b839f 100644 --- a/Guide/src/user_guide/openvmm/snapshots.md +++ b/Guide/src/user_guide/openvmm/snapshots.md @@ -211,7 +211,10 @@ completion. OpenVMM stops at that exact post-write boundary, completes the deferred write while the vCPU is stopped, and then releases device input before resuming the vCPU. Until then, the guest's virtio-fs requests wait on their virtqueues, so -repair must not wait for a virtio-fs reply. The acknowledgement is bounded by +repair must not wait for a virtio-fs reply. Resetting a device does not release +its input either: a device that the guest resets and starts again before the +acknowledgement stays gated until OpenVMM releases device input. The +acknowledgement is bounded by `--restore-gate-timeout-ms` (60000 milliseconds by default). A control-console host can connect while input is gated, but OpenVMM reads its authentication only after the release, so its `--microvm-control-auth-timeout-ms` deadline diff --git a/vm/devices/virtio/virtio/src/device.rs b/vm/devices/virtio/virtio/src/device.rs index fe684411e54..af13408f7fd 100644 --- a/vm/devices/virtio/virtio/src/device.rs +++ b/vm/devices/virtio/virtio/src/device.rs @@ -120,13 +120,23 @@ pub trait VirtioDevice: InspectMut + Send { /// Reset device-internal state to initial values. /// - /// Called after all queues have been stopped on guest-initiated reset. + /// Called after all queues have been stopped, on a guest-initiated reset + /// and on a reset of the VM. The reset keeps the host-input gate that + /// [`quiesce_input`](Self::quiesce_input) closed: only + /// [`resume_input`](Self::resume_input) opens it, so a guest that resets + /// the device while the VMM holds its input gets none until the VMM + /// releases it. + /// /// Default: no-op. fn reset(&mut self) -> impl Future + Send { async {} } /// Stops accepting new host input while preserving device and queue state. + /// + /// The gate holds, across queue restarts and resets, until + /// [`resume_input`](Self::resume_input). Queues that start while it is + /// closed start gated. fn quiesce_input(&mut self) -> impl Future> + Send { async { Ok(()) } } diff --git a/vm/devices/virtio/virtio_console/src/saved_state.rs b/vm/devices/virtio/virtio_console/src/saved_state.rs index f07952a7e33..f7c907bcec6 100644 --- a/vm/devices/virtio/virtio_console/src/saved_state.rs +++ b/vm/devices/virtio/virtio_console/src/saved_state.rs @@ -44,14 +44,14 @@ pub(crate) const MAX_SAVED_STATE_BYTES: usize = 512 * 1024; pub(crate) const SAVED_STATE_VERSION: u32 = 1; impl VirtioConsoleDevice { - /// Resets the private state that persists across queue restarts. + /// Resets the private state that persists across queue restarts. The + /// host-input gate is kept: only resuming input releases it. pub(crate) fn reset_private_state(&mut self) { self.config = VirtioConsoleConfig::default(); let (worker, mut state) = self.worker.get_mut(); let state = state.as_mut().unwrap(); state.partial_transmit = 0; state.staged_rx.clear(); - state.input_gated = false; state.mem = GuestMemory::empty(); if let ConsoleWorkerMode::Broker(mode) = &mut worker.mode { mode.reset_for_device(); diff --git a/vm/devices/virtio/virtio_console/src/tests.rs b/vm/devices/virtio/virtio_console/src/tests.rs index 0178c4583ce..742c788845b 100644 --- a/vm/devices/virtio/virtio_console/src/tests.rs +++ b/vm/devices/virtio/virtio_console/src/tests.rs @@ -11,6 +11,7 @@ mod broker; mod direct; mod harness; mod saved_state; +mod transport; use crate::VirtioConsoleDevice; use futures::AsyncRead; diff --git a/vm/devices/virtio/virtio_console/src/tests/broker.rs b/vm/devices/virtio/virtio_console/src/tests/broker.rs index 95d6f033a90..32b51b4282c 100644 --- a/vm/devices/virtio/virtio_console/src/tests/broker.rs +++ b/vm/devices/virtio/virtio_console/src/tests/broker.rs @@ -301,6 +301,39 @@ async fn broker_quiesce_stops_new_host_input(driver: DefaultDriver) { ); } +/// A guest that resets the control console while host input is gated, and +/// then starts it again, receives no host input, the host's attachment among +/// it, until the gate is released. +#[async_test] +async fn broker_guest_reset_keeps_host_input_gated(driver: DefaultDriver) { + let mut harness = TestHarness::new_broker(&driver, BROKER_INSTANCE, BROKER_CAPABILITY); + harness.enable().await; + harness.device.quiesce_input().await.unwrap(); + + // The guest's reset, as the transport makes it when the guest writes 0 + // to the device status. It detaches a host that the broker attached. + harness.disable().await; + harness.reset_rings(); + harness.enable().await; + harness.handle.reconnect(); + + let host_attach = encode(&Record::bootstrap( + RecordType::HostAttach, + BROKER_CAPABILITY.to_vec(), + )); + harness.handle.inject_rx_data(&host_attach); + for _ in 0..20 { + yield_now().await; + } + assert_eq!(harness.handle.pending_rx_len(), host_attach.len()); + assert!(harness.handle.tx_data().is_empty()); + + harness.device.resume_input().await.unwrap(); + yield_until(|| harness.handle.tx_data().len() >= control_session_protocol::HEADER_LEN).await; + let wait = decode(&harness.handle.take_tx_data()); + assert_eq!(wait.record_type, RecordType::Wait); +} + #[async_test] async fn broker_host_lifecycle_error_does_not_stop_guest_worker(driver: DefaultDriver) { let mut harness = TestHarness::new_broker(&driver, BROKER_INSTANCE, BROKER_CAPABILITY); diff --git a/vm/devices/virtio/virtio_console/src/tests/direct.rs b/vm/devices/virtio/virtio_console/src/tests/direct.rs index cb5e48b5c4a..701773a3343 100644 --- a/vm/devices/virtio/virtio_console/src/tests/direct.rs +++ b/vm/devices/virtio/virtio_console/src/tests/direct.rs @@ -39,6 +39,38 @@ async fn input_gate_cancels_rx_but_keeps_tx_running(driver: DefaultDriver) { assert_eq!(received, b"gated-input"); } +/// A guest that resets the console while host input is gated, as a snapshot +/// boundary or a gated restore gates it, and then starts it again receives no +/// host input until the gate is released. +#[async_test] +async fn guest_reset_keeps_host_input_gated(driver: DefaultDriver) { + let mut harness = TestHarness::new(&driver); + harness.enable().await; + harness.device.quiesce_input().await.unwrap(); + + // The guest's reset, as the transport makes it when the guest writes 0 + // to the device status. + harness.disable().await; + harness.reset_rings(); + harness.enable().await; + + harness.handle.inject_rx_data(b"gated-input"); + let gpa = harness.post_rx_buffer_and_signal(0, 64); + // The worker runs: it forwards the guest's output. + harness.post_tx_and_signal(0, b"tx-while-gated"); + assert_eq!(harness.wait_for_tx_used().await, (0, 0)); + for _ in 0..10 { + yield_now().await; + } + assert_eq!(harness.handle.pending_rx_len(), b"gated-input".len()); + + harness.device.resume_input().await.unwrap(); + let (_, used_len) = harness.wait_for_rx_used().await; + let mut received = vec![0; used_len as usize]; + harness.mem.read_at(gpa, &mut received).unwrap(); + assert_eq!(received, b"gated-input"); +} + #[async_test] async fn read_error_drives_disconnect_before_reconnect(driver: DefaultDriver) { let mut harness = TestHarness::new_with_policy(&driver, VirtioConsoleDisconnectPolicy::Discard); diff --git a/vm/devices/virtio/virtio_console/src/tests/transport.rs b/vm/devices/virtio/virtio_console/src/tests/transport.rs new file mode 100644 index 00000000000..bb3d3854347 --- /dev/null +++ b/vm/devices/virtio/virtio_console/src/tests/transport.rs @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +//! Tests that drive the console through the virtio-mmio transport, as a +//! guest's driver does. + +use super::DATA_BASE; +use super::QUEUE_SIZE; +use super::RX_AVAIL_ADDR; +use super::RX_DESC_ADDR; +use super::RX_USED_ADDR; +use super::TX_AVAIL_ADDR; +use super::TX_DESC_ADDR; +use super::TX_USED_ADDR; +use super::TestHarness; +use super::harness::yield_now; +use chipset_device::io::IoResult; +use chipset_device::mmio::MmioIntercept; +use chipset_device::poll_device::PollDevice; +use guestmem::GuestMemory; +use pal_async::DefaultDriver; +use pal_async::async_test; +use pal_async::timer::PolledTimer; +use std::task::Context; +use std::task::Poll; +use std::task::Waker; +use std::time::Duration; +use test_with_tracing::test; +use virtio::spec::queue::DescriptorFlags; +use virtio::test_helpers::init_avail_ring; +use virtio::test_helpers::init_used_ring; +use virtio::test_helpers::make_available; +use virtio::test_helpers::read_used; +use virtio::test_helpers::write_descriptor; +use virtio::transport::VirtioMmioDevice; +use vmcore::device_state::ChangeDeviceState; +use vmcore::line_interrupt::LineInterrupt; + +// The virtio-mmio registers that a guest's driver writes (virtio 1.2, section +// 4.2.2). +const DRIVER_FEATURES: u64 = 0x20; +const DRIVER_FEATURES_SEL: u64 = 0x24; +const QUEUE_SEL: u64 = 0x30; +const QUEUE_NUM: u64 = 0x38; +const QUEUE_READY: u64 = 0x44; +const QUEUE_NOTIFY: u64 = 0x50; +const STATUS: u64 = 0x70; +const QUEUE_DESC_LOW: u64 = 0x80; +const QUEUE_DRIVER_LOW: u64 = 0x90; +const QUEUE_DEVICE_LOW: u64 = 0xa0; + +// The device status bits (virtio 1.2, section 2.1). +const ACKNOWLEDGE: u32 = 1; +const DRIVER: u32 = 2; +const DRIVER_OK: u32 = 4; +const FEATURES_OK: u32 = 8; + +/// The console behind the virtio-mmio transport, and the guest memory of its +/// rings, which lie where the harness puts them. +struct MmioConsole { + transport: VirtioMmioDevice, + mem: GuestMemory, +} + +impl MmioConsole { + /// Writes `value` to the transport register at `offset`, as a vCPU does, + /// and waits for the write to complete, polling the transport as the + /// chipset does. + async fn write(&mut self, offset: u64, value: u32) { + let mut token = match self.transport.mmio_write(offset, &value.to_le_bytes()) { + IoResult::Ok => return, + IoResult::Defer(token) => token, + IoResult::Err(error) => panic!("register write failed: {error:?}"), + }; + for _ in 0..1000 { + let mut cx = Context::from_waker(Waker::noop()); + self.transport.poll_device(&mut cx); + if let Poll::Ready(result) = token.poll_write(&mut cx) { + result.unwrap(); + return; + } + yield_now().await; + } + panic!("register write did not complete"); + } + + /// Initializes the device as a guest's driver does, up to DRIVER_OK, with + /// empty rings. + async fn initialize(&mut self) { + for (avail, used) in [(RX_AVAIL_ADDR, RX_USED_ADDR), (TX_AVAIL_ADDR, TX_USED_ADDR)] { + init_avail_ring(&self.mem, avail); + init_used_ring(&self.mem, used); + } + self.write(STATUS, ACKNOWLEDGE).await; + self.write(STATUS, ACKNOWLEDGE | DRIVER).await; + // VIRTIO_F_VERSION_1, bit 0 of the second feature bank. + self.write(DRIVER_FEATURES_SEL, 1).await; + self.write(DRIVER_FEATURES, 1).await; + self.write(STATUS, ACKNOWLEDGE | DRIVER | FEATURES_OK).await; + for (queue, desc, avail, used) in [ + (0, RX_DESC_ADDR, RX_AVAIL_ADDR, RX_USED_ADDR), + (1, TX_DESC_ADDR, TX_AVAIL_ADDR, TX_USED_ADDR), + ] { + self.write(QUEUE_SEL, queue).await; + self.write(QUEUE_NUM, QUEUE_SIZE.into()).await; + self.write(QUEUE_DESC_LOW, desc.try_into().unwrap()).await; + self.write(QUEUE_DRIVER_LOW, avail.try_into().unwrap()) + .await; + self.write(QUEUE_DEVICE_LOW, used.try_into().unwrap()).await; + self.write(QUEUE_READY, 1).await; + } + self.write(STATUS, ACKNOWLEDGE | DRIVER | FEATURES_OK | DRIVER_OK) + .await; + } + + /// Makes a receive buffer of `len` bytes at the start of the data area + /// available in descriptor 0, and notifies the receive queue. + async fn post_rx_buffer(&mut self, len: u32) { + write_descriptor( + &self.mem, + RX_DESC_ADDR, + 0, + DATA_BASE, + len, + DescriptorFlags::new().with_write(true), + 0, + ); + let mut avail_idx = 0; + make_available(&self.mem, RX_AVAIL_ADDR, QUEUE_SIZE, 0, &mut avail_idx); + self.write(QUEUE_NOTIFY, 0).await; + } +} + +/// A guest that writes 0 to the status of the running console while host +/// input is gated resets the device, and its driver then starts it again: the +/// console receives no host input until the gate is released. +#[async_test] +async fn guest_status_reset_keeps_host_input_gated(driver: DefaultDriver) { + let harness = TestHarness::new(&driver); + let handle = harness.handle; + let mut console = MmioConsole { + transport: VirtioMmioDevice::new( + Box::new(harness.device), + &driver, + harness.mem.clone(), + LineInterrupt::detached(), + None, + 0, + 0x1000, + ) + .unwrap(), + mem: harness.mem, + }; + console.initialize().await; + ChangeDeviceState::quiesce_input(&mut console.transport) + .await + .unwrap(); + + console.write(STATUS, 0).await; + console.initialize().await; + handle.inject_rx_data(b"gated-input"); + console.post_rx_buffer(64).await; + let mut timer = PolledTimer::new(&driver); + timer.sleep(Duration::from_millis(100)).await; + let mut used_idx = 0; + assert_eq!( + read_used(&console.mem, RX_USED_ADDR, QUEUE_SIZE, &mut used_idx), + None + ); + assert_eq!(handle.pending_rx_len(), b"gated-input".len()); + + ChangeDeviceState::resume_input(&mut console.transport) + .await + .unwrap(); + let mut used = None; + for _ in 0..500 { + used = read_used(&console.mem, RX_USED_ADDR, QUEUE_SIZE, &mut used_idx); + if used.is_some() { + break; + } + timer.sleep(Duration::from_millis(10)).await; + } + assert_eq!(used, Some((0, b"gated-input".len() as u32))); + let mut received = [0; b"gated-input".len()]; + console.mem.read_at(DATA_BASE, &mut received).unwrap(); + assert_eq!(&received, b"gated-input"); +} diff --git a/vm/devices/virtio/virtio_net/src/quiesce.rs b/vm/devices/virtio/virtio_net/src/quiesce.rs index ccec542718f..d7356a4fe27 100644 --- a/vm/devices/virtio/virtio_net/src/quiesce.rs +++ b/vm/devices/virtio/virtio_net/src/quiesce.rs @@ -5,11 +5,12 @@ //! //! Quiescing input stops the coordinator and the workers, lets each endpoint //! queue finish the work it already accepted while it stops admitting new host -//! RX, drains the resulting completions, and restarts the workers. The -//! coordinator latches the input gate and re-establishes it whenever it -//! restarts the endpoint queues; resuming input releases it. Only devices built -//! with [`NicBuilder::save_restore`](crate::NicBuilder::save_restore) support -//! input quiesce. +//! RX, drains the resulting completions, and restarts the workers. The device +//! latches the input gate, which a reset of the device keeps, and its +//! coordinator re-establishes the gate whenever it starts or restarts the +//! endpoint queues; resuming input releases it. Only devices built with +//! [`NicBuilder::save_restore`](crate::NicBuilder::save_restore) support input +//! quiesce. use crate::Coordinator; use crate::Device; diff --git a/vm/devices/virtio/virtio_net/src/saved_state.rs b/vm/devices/virtio/virtio_net/src/saved_state.rs index 6f967f2104c..186c1ec080e 100644 --- a/vm/devices/virtio/virtio_net/src/saved_state.rs +++ b/vm/devices/virtio/virtio_net/src/saved_state.rs @@ -52,12 +52,11 @@ pub(crate) struct Lifecycle { impl Lifecycle { /// Clears the queue-pair state on device reset. The endpoint generation is - /// kept. + /// kept, and so is the input gate, which only resuming input releases. pub(crate) fn reset(&mut self) { self.stop_error = None; self.stopped_feature_banks = None; self.stopped_queue_count = 0; - self.input_quiesced = false; } } diff --git a/vm/devices/virtio/virtio_net/src/tests/quiesce.rs b/vm/devices/virtio/virtio_net/src/tests/quiesce.rs index 363bd022046..a2d37cfdbf6 100644 --- a/vm/devices/virtio/virtio_net/src/tests/quiesce.rs +++ b/vm/devices/virtio/virtio_net/src/tests/quiesce.rs @@ -2,7 +2,8 @@ // Licensed under the MIT License. //! Input quiesce tests: a quiesce requested before the queues start is latched, -//! and quiesce drains the TX work that the endpoint already accepted. +//! the guest's reset of the device keeps it, and quiesce drains the TX work +//! that the endpoint already accepted. use super::TestHarness; use net_backend::TxId; @@ -22,6 +23,26 @@ async fn input_quiesce_latches_before_queue_start(driver: DefaultDriver) { harness.device.resume_input().await.unwrap(); } +/// A guest that resets the device while input is quiesced, as a snapshot +/// boundary or a gated restore quiesces it, and starts its queues again gets +/// endpoint queues that are quiesced too, until input resumes. +#[async_test] +async fn input_quiesce_survives_guest_reset(driver: DefaultDriver) { + let mut harness = TestHarness::new_save_restore(&driver); + let mut handle = harness.enable_and_get_handle().await; + harness.device.quiesce_input().await.unwrap(); + handle.wait_for_quiesce().await; + + // The guest's reset, as the transport makes it when the guest writes 0 + // to the device status. + harness.disable().await; + harness.reset_rings(); + let mut handle = harness.enable_and_get_handle().await; + handle.wait_for_quiesce().await; + + harness.device.resume_input().await.unwrap(); +} + #[async_test] async fn snapshot_drains_accepted_pending_tx_exactly_once(driver: DefaultDriver) { let mut harness = TestHarness::new_save_restore(&driver); diff --git a/vm/devices/virtio/virtiofs/Cargo.toml b/vm/devices/virtio/virtiofs/Cargo.toml index dbd9776a9d6..8fc3ca16d5d 100644 --- a/vm/devices/virtio/virtiofs/Cargo.toml +++ b/vm/devices/virtio/virtiofs/Cargo.toml @@ -46,6 +46,7 @@ windows-sys = { workspace = true, features = [ workspace = true [dev-dependencies] +chipset_device.workspace = true pal_async.workspace = true pal_event.workspace = true tempfile.workspace = true diff --git a/vm/devices/virtio/virtiofs/src/integration_tests.rs b/vm/devices/virtio/virtiofs/src/integration_tests.rs index b7110f6398b..c74967a91e5 100644 --- a/vm/devices/virtio/virtiofs/src/integration_tests.rs +++ b/vm/devices/virtio/virtiofs/src/integration_tests.rs @@ -375,6 +375,16 @@ impl TestHarness { fn tmpdir_path(&self) -> &std::path::Path { self._tmpdir.path() } + + /// Resets the guest's ring and the harness's indices for another start + /// of the device, as a guest's driver does after it resets the device. + fn reset_ring(&mut self) { + init_avail_ring(&self.mem, AVAIL_ADDR); + init_used_ring(&self.mem, USED_ADDR); + self.avail_idx = 0; + self.used_idx = 0; + self.next_data_offset = DATA_BASE; + } } // --- Tests --- @@ -427,6 +437,29 @@ async fn microvm_queue_stopped_while_input_is_quiesced_keeps_its_requests(driver harness.wait_for_init(unique, resp_gpa).await; } +/// A guest that resets the microVM device while host input is quiesced, as a +/// snapshot boundary or a gated restore quiesces it, and then starts its queue +/// again leaves its requests on the virtqueue until input resumes. +#[async_test] +async fn microvm_guest_reset_keeps_input_quiesced(driver: DefaultDriver) { + let mut harness = TestHarness::new_microvm(&driver); + harness.enable().await; + harness.fuse_init(0).await; + harness.device.quiesce_input().await.unwrap(); + + // The guest's reset, as the transport makes it when the guest writes 0 + // to the device status. + harness.device.stop_queue(0).await.unwrap(); + harness.device.reset().await; + harness.reset_ring(); + harness.enable().await; + let (unique, resp_gpa) = harness.post_fuse_init(0); + harness.assert_no_request_completes().await; + + harness.device.resume_input().await.unwrap(); + harness.wait_for_init(unique, resp_gpa).await; +} + /// GETATTR on the root inode returns a directory after INIT. #[async_test] async fn getattr_root_returns_directory(driver: DefaultDriver) { diff --git a/vm/devices/virtio/virtiofs/src/microvm/device.rs b/vm/devices/virtio/virtiofs/src/microvm/device.rs index f0349dc4b14..786d28346f4 100644 --- a/vm/devices/virtio/virtiofs/src/microvm/device.rs +++ b/vm/devices/virtio/virtiofs/src/microvm/device.rs @@ -160,7 +160,7 @@ pub(crate) fn validate_queue_features( } pub(crate) fn reset(device: &mut VirtioFsDevice) { - device.admission.resume(); + // Request admission stays as it is: only resuming input reopens it. device.save_error = None; } @@ -296,6 +296,8 @@ mod tests { use super::*; use crate::profile::MICROVM_ATTACHMENT_ID; use crate::profile::microvm_root_identity; + use chipset_device::io::IoResult; + use chipset_device::mmio::MmioIntercept; use guestmem::GuestMemory; use pal_async::DefaultDriver; use pal_async::async_test; @@ -643,4 +645,69 @@ mod tests { .unwrap(); assert!(invalid_destination.restore(restored).await.is_err()); } + + /// Returns the microVM HostFs device of the host directory `root` behind + /// the virtio-mmio transport, which is not DRIVER_OK. + fn microvm_transport(driver: &DefaultDriver, root: &Path) -> VirtioMmioDevice { + let driver_source = VmTaskDriverSource::new(SingleDriverBackend::new(driver.clone())); + let device = VirtioFsDevice::new_microvm_hostfs( + &driver_source, + MICROVM_ATTACHMENT_ID.to_owned(), + microvm_root_identity(root).unwrap(), + false, + Vec::new(), + Vec::new(), + Vec::new(), + MicroVmOwnerMode::Vmm, + root, + None, + ) + .unwrap(); + VirtioMmioDevice::new( + Box::new(device), + driver, + GuestMemory::empty(), + LineInterrupt::detached(), + None, + 0, + 0x1000, + ) + .unwrap() + } + + /// A guest that writes 0 to the status of the device while host input is + /// quiesced, as a vCPU can between a snapshot boundary's input gate and + /// the vCPU stop, resets the device but leaves its input quiesced, so the + /// capture's save succeeds. + #[async_test] + async fn guest_status_reset_keeps_input_quiesced_for_save(driver: DefaultDriver) { + let root = tempfile::tempdir().unwrap(); + let mut transport = microvm_transport(&driver, root.path()); + transport.quiesce_input().await.unwrap(); + + // The status register of the virtio-mmio transport (virtio 1.2, + // section 4.2.2). + assert!(matches!( + transport.mmio_write(0x70, &0u32.to_le_bytes()), + IoResult::Ok + )); + transport.stop().await; + transport.save().await.unwrap(); + } + + /// A reset of the VM while host input is quiesced, as during a gated + /// restore, leaves its input quiesced too: only resuming input releases + /// the gate. + #[async_test] + async fn vm_reset_keeps_input_quiesced_for_save(driver: DefaultDriver) { + let root = tempfile::tempdir().unwrap(); + let mut transport = microvm_transport(&driver, root.path()); + transport.quiesce_input().await.unwrap(); + transport.stop().await; + transport.reset().await; + + transport.start(); + transport.stop().await; + transport.save().await.unwrap(); + } } diff --git a/vm/vmcore/src/device_state.rs b/vm/vmcore/src/device_state.rs index bbdbfd55f16..c80fd6f0671 100644 --- a/vm/vmcore/src/device_state.rs +++ b/vm/vmcore/src/device_state.rs @@ -85,6 +85,10 @@ pub trait ChangeDeviceState { /// Stops accepting new host input before a snapshot vCPU boundary. /// + /// The gate holds until [`Self::resume_input`]. Neither the guest's reset + /// of the device nor [`Self::reset`] releases it, so the device's input + /// stays gated for as long as its caller holds the gate. + /// /// The vCPUs may run while the gate changes: the snapshot boundary gates /// host input before it stops them, and resumes a gate that failed before /// any of them stops. So a gate change has two parts. The caller makes @@ -130,6 +134,8 @@ pub trait ChangeDeviceState { /// Resets the device state to its initial state, for a fresh boot. /// + /// A host-input gate that [`Self::quiesce_input`] closed stays closed. + /// /// Callers must ensure that the device is in a stopped state before calling /// this method. fn reset(&mut self) -> impl Send + Future;