diff --git a/src/vmm/src/devices/virtio/device.rs b/src/vmm/src/devices/virtio/device.rs index 80135576e13..f2774071ca1 100644 --- a/src/vmm/src/devices/virtio/device.rs +++ b/src/vmm/src/devices/virtio/device.rs @@ -13,7 +13,7 @@ use utils::eventfd::EventFd; use super::mmio::{VIRTIO_MMIO_INT_CONFIG, VIRTIO_MMIO_INT_VRING}; use super::queue::Queue; -use super::ActivateError; +use super::{ActivateError, ResetError}; use crate::devices::virtio::AsAny; use crate::logger::{error, warn}; use crate::vstate::memory::GuestMemoryMmap; @@ -174,10 +174,9 @@ pub trait VirtioDevice: AsAny + Send { /// Checks if the resources of this device are activated. fn is_activated(&self) -> bool; - /// Optionally deactivates this device and returns ownership of the guest memory map, interrupt - /// event, and queue events. - fn reset(&mut self) -> Option<(EventFd, Vec)> { - None + /// Optionally deactivates this device. + fn reset(&mut self) -> Result<(), ResetError> { + Err(ResetError::NotImplemented) } } diff --git a/src/vmm/src/devices/virtio/mmio.rs b/src/vmm/src/devices/virtio/mmio.rs index 96bd914d984..fcb7458a904 100644 --- a/src/vmm/src/devices/virtio/mmio.rs +++ b/src/vmm/src/devices/virtio/mmio.rs @@ -201,8 +201,12 @@ impl MmioTransport { let mut device_status = self.device_status; let reset_result = self.locked_device().reset(); match reset_result { - Some((_interrupt_evt, mut _queue_evts)) => {} - None => { + Ok(_) => { + // The device MUST initialize device status to 0 upon reset. + device_status = INIT; + } + Err(e) => { + warn!("failed to reset virtio device: {:?}", e); device_status |= FAILED; } } @@ -469,7 +473,7 @@ pub(crate) mod tests { let m = single_region_mem(0x1000); let mut dummy = DummyDevice::new(); // Validate reset is no-op. - assert!(dummy.reset().is_none()); + assert!(dummy.reset().is_err()); let mut d = MmioTransport::new(m, Arc::new(Mutex::new(dummy)), false); // We just make sure here that the implementation of a mmio device behaves as we expect,