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
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
41 changes: 31 additions & 10 deletions src/vmm/src/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::devices::virtio::net::{
gen, NetError, NetQueue, MAX_BUFFER_SIZE, NET_QUEUE_SIZES, RX_INDEX, TX_INDEX,
};
use crate::devices::virtio::queue::{DescriptorChain, Queue};
use crate::devices::virtio::{ActivateError, TYPE_NET};
use crate::devices::virtio::{ActivateError, ResetError, TYPE_NET};
use crate::devices::{report_net_event_fail, DeviceError};
use crate::dumbo::pdu::arp::ETH_IPV4_FRAME_LEN;
use crate::dumbo::pdu::ethernet::{EthernetFrame, PAYLOAD_OFFSET};
Expand Down Expand Up @@ -870,6 +870,15 @@ impl VirtioDevice for Net {
fn is_activated(&self) -> bool {
self.device_state.is_activated()
}

fn reset(&mut self) -> Result<(), ResetError> {
self.device_state = DeviceState::Inactive;
self.rx_bytes_read = 0;
self.rx_deferred_frame = false;
self.rx_frame_buf = [0u8; MAX_BUFFER_SIZE];
self.metrics = NetMetricsPerDevice::alloc(self.id.clone());
Comment on lines +875 to +879
Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely need to reset the acked_features here, too.

Also, @sudanl0 do you think it is ok to reset the metrics here? I think it's more of a philosophical question, on whether we want our metrics to reflect the fact that the device has been reset by zeroing them out. Maybe, it would make sense to add a reset counter metric as well.

Ok(())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -2015,17 +2024,29 @@ pub mod tests {
th.activate_net();
let net = th.net.lock().unwrap();

// Test queues count (TX and RX).
let queues = net.queues();
assert_eq!(queues.len(), NET_QUEUE_SIZES.len());
assert_eq!(queues[RX_INDEX].size, th.rxq.size());
assert_eq!(queues[TX_INDEX].size, th.txq.size());
let validate = |net: &Net| {
// Test queues count (TX and RX).
let queues = net.queues();
assert_eq!(queues.len(), NET_QUEUE_SIZES.len());
assert_eq!(queues[RX_INDEX].size, th.rxq.size());
assert_eq!(queues[TX_INDEX].size, th.txq.size());

// Test corresponding queues events.
assert_eq!(net.queue_events().len(), NET_QUEUE_SIZES.len());

// Test interrupts.
assert!(!&net.irq_trigger.has_pending_irq(IrqType::Vring));
};

validate(&net);

// Test corresponding queues events.
assert_eq!(net.queue_events().len(), NET_QUEUE_SIZES.len());
// Test reset.
let mut net = net;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you can just mark as mut the net device at line 2025?

assert!(net.device_state.is_activated());
net.reset().unwrap();
assert!(!net.device_state.is_activated());

// Test interrupts.
assert!(!&net.irq_trigger.has_pending_irq(IrqType::Vring));
validate(&net);
}

#[test]
Expand Down
Loading