Skip to content

Commit 2c9d705

Browse files
authored
[vsock] better handle Lifecycle (#1104)
This PR extends the VsockPoller event loop so that it complies with the Lifecycle trait within propolis. The virtio device now requests a pause to the event-loop by sending a VsockEvent::Pause via port_send(3C). When the event loop receives this event it finishes processing any tasks and then waits on a mpsc channel. This channel is responsible for processing follow up events driven by the virtio device lifecycle such as resume, reset, and halt. The reset event takes care of cleaning up all state internal to VsockPoller in addition to removing the cached descriptor chain in VsockVq. It's important we drop this cached descriptor as using it across device resets would cause propolis to scribble data into a random location in guest memory depending on where the GuestAddr points. Finally with this work in place it should make solving #1065 trivial.
1 parent fe47987 commit 2c9d705

4 files changed

Lines changed: 429 additions & 34 deletions

File tree

lib/propolis/src/hw/virtio/vsock.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ impl VsockVq {
151151

152152
Some(packet)
153153
}
154+
155+
/// Drop any cached descriptor chain.
156+
///
157+
/// This MUST be called when reseting the virtio-socket device so
158+
/// that we don't use stale `GuestAddr`s across device resets.
159+
#[cfg(target_os = "illumos")]
160+
pub(crate) fn clear_rx_chain(&mut self) {
161+
self.rx_chain = None;
162+
}
154163
}
155164

156165
pub struct PciVirtioSock {
@@ -253,8 +262,19 @@ impl Lifecycle for PciVirtioSock {
253262
fn type_name(&self) -> &'static str {
254263
"pci-virtio-socket"
255264
}
265+
fn pause(&self) {
266+
let _ = self.backend.pause();
267+
self.backend.wait_stopped();
268+
}
256269
fn reset(&self) {
257270
self.virtio_state.reset(self);
271+
self.backend.reset();
272+
}
273+
fn resume(&self) {
274+
self.backend.resume();
275+
}
276+
fn halt(&self) {
277+
self.backend.halt();
258278
}
259279
fn migrate(&'_ self) -> Migrator<'_> {
260280
// TODO (MTZ):

0 commit comments

Comments
 (0)