Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reset for net device #4389

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/vmm/src/devices/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<EventFd>)> {
None
/// Optionally deactivates this device.
fn reset(&mut self) -> Result<(), ResetError> {
Err(ResetError::NotImplemented)
Comment on lines +178 to +179
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I had in mind honestly. I assume the initial idea of giving back the EventFds was to "ensure" through the type system that they can't be used, but that is a very dubious choice, IMHO.

}
}

Expand Down
10 changes: 7 additions & 3 deletions src/vmm/src/devices/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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,
Expand Down