Repository navigation
virtio: Notify guests of runtime config changes - #5150
Anatol Belski (weltling) wants to merge 4 commits into
Conversation
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
84cc019 to
f30d30f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The tests can miss regressions because they do not verify MSI-X interrupt delivery, and the resize assertion can be satisfied by the worker’s initial capacity snapshot rather than runtime resize handling.
2 open issues
What changed in this PR
This PR lets VirtIO devices notify guests of runtime configuration changes through the shared transport layer, including block capacity and network link-status changes.
Changes:
- Introduces a shared 8-bit generation counter with pending-change notifications.
- Connects runtime updates to PCI and MMIO interrupts and prompts guests to reread configuration after restore.
- Adds transport, disk-resize, and network link-status tests.
| File | Description |
|---|---|
vm/devices/virtio/virtio/src/transport/saved_state.rs |
Stores the generation counter as u8. |
vm/devices/virtio/virtio/src/transport/pci.rs |
Reads the shared generation counter for PCI. |
vm/devices/virtio/virtio/src/transport/mmio.rs |
Reads the shared generation counter for MMIO. |
vm/devices/virtio/virtio/src/transport/core.rs |
Handles pending notifications, reset, restore, and teardown. |
vm/devices/virtio/virtio/src/tests.rs |
Tests runtime updates, counter wrapping, and restore notifications. |
vm/devices/virtio/virtio/src/lib.rs |
Exports ConfigGeneration. |
vm/devices/virtio/virtio/src/device.rs |
Adds the optional configuration-generation handle to device traits. |
vm/devices/virtio/virtio/src/config.rs |
Implements shared generation tracking and notification state. |
vm/devices/virtio/virtio_net/src/tests.rs |
Tests link-status updates and adapts register access. |
vm/devices/virtio/virtio_net/src/lib.rs |
Publishes endpoint link-status changes. |
vm/devices/virtio/virtio_net/Cargo.toml |
Makes parking_lot a runtime dependency. |
vm/devices/virtio/virtio_blk/src/lib.rs |
Watches disk resizing and publishes updated capacity. |
vm/devices/virtio/virtio_blk/src/integration_tests.rs |
Adds a guest-visible capacity update test. |
vm/devices/virtio/virtio_blk/Cargo.toml |
Adds synchronization and resize-test dependencies. |
Cargo.lock |
Records updated block-device dependencies. |
Review effort: Balanced
f30d30f to
0e1abfb
Compare
0e1abfb to
de5286d
Compare
| pending: bool, | ||
| #[inspect(skip)] | ||
| waker: Option<Waker>, |
There was a problem hiding this comment.
Could we reuse vmcore::slim_event::SlimEvent for the notification side here? The pending flag and waker handling substantially duplicate it. The generation/update synchronization belongs in this wrapper, but it seems worth separating that from the existing event primitive.
There was a problem hiding this comment.
Switched to the SlimEvent API. The config update and the generation bump are still under the mutex.
Thanks
| pub(crate) fn poll_change(&self, waker: &Waker, ready: bool) -> bool { | ||
| let mut state = self.0.lock(); | ||
| match &mut state.waker { | ||
| Some(registered) => registered.clone_from(waker), | ||
| None => state.waker = Some(waker.clone()), | ||
| } | ||
| ready && std::mem::take(&mut state.pending) | ||
| } | ||
|
|
||
| pub(crate) fn clear_waker(&self) { | ||
| self.0.lock().waker = None; | ||
| } |
There was a problem hiding this comment.
The following comment goes away if we adopt SlimEvent, but registere.clone_from(waker) can drop the previous waker while holding the generation mutex. clear_waker() also drops it under that mutex. We should move the old waker out and drop it after releasing the lock to prevent possible deadlock.
SlimEvent's poll_wait defers destruction after unlocking.
There was a problem hiding this comment.
Rewrote as suggested, so the event is signalled outside the generation mutex. The old event is also dropped after unlocking.
Thanks
de5286d to
91d91be
Compare
91d91be to
ee56d46
Compare
Keep the generation in the width of the PCI common config field. Widen it only at the register boundary so it cannot overlap the queue selector. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
ee56d46 to
e5047cf
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The resize and link-status tests verify register updates but lack transport-backed checks that generation advances and config-change interrupts reach the guest with DRIVER_OK set.
2 open issues
1 resolved since last review
Review effort: Balanced
Let devices advance their config generation when publishing new values. Deliver pending notifications through both transports and refresh guest config after restore. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Watch backend resize events and publish the new capacity with a config generation update. Exercise a RAM disk resize in the block device test. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
e5047cf to
d67c1eb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The capacity calculation can overflow after a runtime disk resize, causing a panic or reporting zero capacity unless unrepresentable sizes are explicitly handled.
1 open issue
2 resolved since last review
Review effort: Balanced
Publish endpoint link status changes through the shared config generation handle. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
d67c1eb to
7554c20
Compare


The VirtIO config generation counter previously advanced only during feature negotiation. This change lets devices notify guests when their config changes at runtime.