Skip to content

virtio: add userspace vsock save/restore - #4982

Draft
AdityaMittal1306 wants to merge 6 commits into
microsoft:mainfrom
AdityaMittal1306:feature/virtio-vsock-save-restore
Draft

AdityaMittal1306 wants to merge 6 commits into
microsoft:mainfrom
AdityaMittal1306:feature/virtio-vsock-save-restore

Conversation

@AdityaMittal1306

@AdityaMittal1306 AdityaMittal1306 commented Nov 7, 2026 •

Copy link
Copy Markdown

Summary

Add reconnect-on-restore support for the built-in userspace virtio-vsock Unix relay through PCI and MMIO.

  • Add asynchronous per-device state hooks and an optional opaque payload through the shared transport/device-owner task.
  • Save the guest CID, pending event acknowledgment, and targeted reset identifiers for runtime errors or unconfirmed handshakes, not live host sockets or buffered stream data. Actual restore replaces host runtime and publishes VIRTIO_VSOCK_EVENT_TRANSPORT_RESET so applications reconnect.
  • Preserve connection runtime across ordinary pause/save/resume. Gate outbound RX until the guest replenishes event buffers after processing the transport reset; TX and host writes can continue. Keep bounded, targeted RSTs for individual errors and unconfirmed handshakes.
  • Keep reset publication cancellation-aware; fail the worker and reject saves on queue publication or notification failures.
  • Restore MSI-X delivery/routes and pending interrupts, and preserve upstream's explicit backend teardown acknowledgement.
  • Add device/transport regressions, four VMM scenarios, and user-facing CLI/API/snapshot documentation.

Rebase and API integration

Rebased commit: 5d2a62b4521428d59f4c6b40f9f12c95936cb9cc.
Base: 42d4fe619dd3f14ef3ddefca3bb432dc4c524596, including the SaveVM/RestoreVM APIs merged in #4553.

The Windows writable RAM-file flush fix is now supplied by #4553, so its duplicate controller hunk was dropped from this feature commit. This PR uses the existing public APIs; it does not extend their schema.

Latest transport-reset validation

Follow-up commit: f52d93c2ad1ac07992c2cd13dbc18dc70b28e5d2.

The exact 15-file event-only commit tree was validated in an isolated checkout without the local bulk/iperf changes:

  • Package check, all-target clippy, and rustdoc passed for virtio, virtio_vsock, petri, pipette, and vmm_tests.
  • 254 scoped Linux unit tests passed, with one existing skip.
  • All four default Windows/WHP vsock VM scenarios passed: PCIe/MMIO in-place restore, CLI fresh-process file snapshots, and ttrpc restoration.
  • The PCIe/MMIO tests verify accepted streams survive ordinary pause/save/resume, then receive ECONNRESET on actual restore; the same guest listener accepts new connections after each of three restores without rebinding.
  • Complete repository formatting passed last; the resulting tree exactly matched the committed selection.

The ten new event/cursor regressions also passed ten repetitions on both Windows and Linux during development. Normal targeted RSTs are retained, including the case where a RESPONSE is already in guest RAM but has not yet been consumed.

The separate bulk/iperf test implementation remains local and is not included in this follow-up.

Earlier implementation validation

All VM executions below used a Windows host with WHP and Linux guests. WSL was the cross-build environment, not the VM's hypervisor backend.

  • All-target checks, clippy, and rustdoc passed for the five modified Rust packages: pci_core, virtio, virtio_vsock, petri, and vmm_tests. Repository formatting passed last.
  • 298 unit/regression tests passed across four binaries; two existing Windows skips remain.
  • All 17 focused save/restore, lifecycle, completion, cancellation-boundary, and MSI-X regressions passed 10 repetitions.
  • Native Windows manual PCIe and MMIO tests passed same-stream pause/resume, in-place save/reset/restore with reconnect, and fresh-process file-backed snapshot restore. Guest boot identity, process identity, and an in-memory marker survived.
  • All four focused scenarios passed via cargo xflowey vmm-tests-run: PCI pulse, MMIO pulse, CLI fresh-process snapshot for both transports, and ttrpc PCIe fresh-process snapshot. All four passed 10 repetitions (40 executions), and passed again from the finalized commit.
  • The native executable was rebuilt and reports openvmm 0.5.0+g5d2a62b45 without a dirty suffix.

The ttrpc case verifies CID 42, same-stream PauseVM/ResumeVM, rejected saves preserving the source connection, returned snapshot ID matching the manifest, a paused source with ResumeVM blocked, teardown disconnect, wrong-ID rejection, restoration in a different OpenVMM process, paused restoration followed by ResumeVM, preserved guest boot ID/RAM marker, and successful reconnection/data exchange.

A short Windows output directory was required for cross-run temporary Unix-socket paths to fit SUN_LEN. Test assertions were not weakened for that environment issue.

Scope and draft status

  • Current ttrpc VMConfig exposes vsock via PCIe, not MMIO. API coverage is therefore PCIe; MMIO is covered through the existing CLI/Petri paths.
  • Kernel vhost-vsock remains unsupported. External host streams and application state are not checkpointed.
  • Linux-host VM execution remains unverified. Linux unit tests pass; existing Windows skips remain. No KVM permissions or group memberships were changed.
  • Automated PCIe/MMIO VM cases cover guest-initiated reconnection and host-initiated accepted connections, including one guest listener preserved across three restores without rebinding. Pending and unread-response handshake cases are covered in device tests.

The PR remains a draft for team review of the reconnect/reset-priority design and remaining platform coverage. Guest images, local harness assets, logs, and the separate validation checkout are not committed.

Native vsock_perf workload validation

Commit: c7fe63258f1e3baded963dc76dcb5b6c53cfcca2.

  • Add opt-in PCIe/MMIO workloads using the unmodified upstream Linux vsock_perf executable, supplied through PETRI_VSOCK_PERF_BIN. The executable and upstream source are not vendored, and no new dependency versions are introduced.
  • Guest traffic uses native AF_VSOCK with host Unix-relay peers, without a guest NIC or TCP bridge. Each bus completes four exact 1 GiB transfers and verifies disconnect/reconnect after save/reset/restore during both TX and RX.
  • Add artifact-free peer and report/error-parser regressions, shared workload helpers, bounded lifecycle waits, and reproduction instructions in the VMM testing Guide.
  • The exact four-file commit tree was validated in an isolated checkout without the uncommitted iperf/bulk code: package check, all-target clippy, rustdoc, both default helper tests, both full-size Windows/WHP VM workloads plus helpers, and complete repository formatting passed.
  • Exact endpoint counts verified 8 GiB of completed payload, excluding four intentionally interrupted transfers. Both workloads reached clean power-off and teardown; no owned test guests remained.
  • Default opt-in behavior was checked separately: with the binary variable unset, only the two artifact-free helpers ran.

Earlier native stress runs intermittently stalled in WHP doorbell cleanup during reset or guest shutdown. They did not recur in the two post-restart full reruns or the isolated pre-commit run; this test commit does not claim a production fix for that historical issue. Linux-host VM execution remains unverified.

The separate stock-iperf3/SHA-256 bulk test implementation, its dependency wiring, and its artifact-discovery changes remain local and uncommitted.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 20:03
@github-actions github-actions Bot added Guide unsafe Related to unsafe code labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

RX and TX completion paths still swallow used-ring publication failures, allowing saves to capture orphaned descriptors that restore cannot complete; both paths need failure propagation and a non-reset regression test.

1 open issue
What changed in this PR

Adds reconnect-on-restore support for OpenVMM’s userspace virtio-vsock relay over PCI and MMIO. Ordinary pause/resume preserves streams; snapshot restoration resets saved connections so applications reconnect.

Changes:

  • Adds asynchronous device-state hooks and vsock connection metadata persistence.
  • Retains pending resets and fixes MSI-X restoration and Windows snapshot flushing.
  • Adds device, transport, and VM regressions, Petri helpers, and reconnect-policy documentation.
File Description
vmm_tests/​vmm_tests/​tests/​tests/​multiarch/​vsock.rs Adds reconnect and file-backed snapshot VM tests.
vmm_tests/​vmm_tests/​tests/​tests/​multiarch.rs Registers the vsock test module.
vm/​devices/​virtio/​virtio/​src/​transport/​task.rs Handles device save/restore commands.
vm/​devices/​virtio/​virtio/​src/​transport/​saved_state.rs Adds an optional device-state payload.
vm/​devices/​virtio/​virtio/​src/​transport/​pci.rs Awaits shared save/restore hooks.
vm/​devices/​virtio/​virtio/​src/​transport/​mmio.rs Converts save/restore to asynchronous operations.
vm/​devices/​virtio/​virtio/​src/​transport/​core.rs Routes state operations through the device task.
vm/​devices/​virtio/​virtio/​src/​tests.rs Tests completion errors and device-state transport behavior.
vm/​devices/​virtio/​virtio/​src/​device.rs Defines asynchronous device-state hooks.
vm/​devices/​virtio/​virtio/​src/​common.rs Adds fallible queue completion.
vm/​devices/​virtio/​virtio_vsock/​src/​lib.rs Implements connection persistence and reset delivery.
vm/​devices/​virtio/​virtio_vsock/​src/​integration_tests.rs Tests lifecycle, reconnect, backpressure, and validation.
vm/​devices/​virtio/​virtio_vsock/​src/​connections.rs Exposes connection keys and centralizes pending resets.
vm/​devices/​virtio/​virtio_vsock/​Cargo.toml Adds typed-error support.
vm/​devices/​pci/​pci_core/​src/​capabilities/​msix.rs Restores interrupt delivery, routes, and pending state.
vm/​devices/​pci/​pci_core/​Cargo.toml Adds tracing support for tests.
petri/​src/​vm/​openvmm/​start.rs Enables userspace vsock save/restore eligibility.
petri/​src/​vm/​openvmm/​runtime.rs Exposes a strict save/reset/restore helper.
petri/​src/​vm/​openvmm/​modify.rs Adds MMIO vsock configuration support.
openvmm/​openvmm_entry/​src/​vm_controller.rs Uses a writable handle for snapshot flushing.
Guide/​src/​reference/​openvmm/​management/​cli.md Documents reconnect semantics and backend limitations.
Cargo.lock Records added crate dependencies.

Review effort: Balanced

0
}
};
state.rx_queue.complete(queue_work, bytes);
Add async device-specific saved state to the PCI and MMIO transports. Preserve vsock runtime across pause/resume and restore old guest connections as pending resets, retaining invalidations under RX backpressure.

Rearm MSI-X delivery and pending state on restore, and use a writable RAM-file handle when flushing Windows snapshots. Add device, transport, and Petri regressions plus reconnect documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AdityaMittal1306
AdityaMittal1306 force-pushed the feature/virtio-vsock-save-restore branch from e07981d to 5d2a62b Compare November 11, 2026 08:02
Copilot AI balanced review requested due to automatic review settings November 11, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Awaiting reset delivery when RX has no buffers blocks TX and write-ready processing, stalling unrelated connections and risking deadlock; the fix needs a regression test covering a pending reset with a ready TX descriptor.

2 open issues

Review effort: Balanced

Propagate normal RX/TX completion failures and reject saves from failed workers. Keep reset delivery nonblocking while preserving RX ordering, bound the pending reset backlog, and add failure and backpressure regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 07:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Reconnect/reset ordering affects guest connection lifetimes, worker cancellation, and shared MSI-X routing, requiring human architectural review and still-pending Linux/KVM runtime and stress validation.

1 open issue
1 resolved since last review

Review effort: Balanced

Reuse queue-size and split/packed cursor validation before applying supplied
active-queue state. Preserve legacy behavior when progress is absent.

Add PCI/MMIO rejection tests and vsock regressions for queued work across
pause/resume and restore into fresh guest memory without another kick.
Document early rejection of malformed queue progress.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Reconnect/reset lifecycle ordering and shared MSI-X/irqfd restoration require domain-owner review, with Linux/KVM and buffered-ring/stress validation still pending.

1 open issue

Review effort: Balanced

Publish VIRTIO_VSOCK_EVENT_TRANSPORT_RESET after actual restore while
preserving ordinary pause/save/resume connections. Gate outbound RX until
the guest replenishes event buffers, using producer progress rather than
stale kicks, and preserve outstanding event acknowledgments across saves.

Keep targeted RSTs for runtime errors and unconfirmed handshakes, including
responses published but not yet consumed by the guest. Add shared queue
notification regressions and real-guest persistent-listener restore tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A stale reset is delivered before the response to a replacement request on a reused port pair, aborting the guest’s reconnect in a way the later response cannot recover.

2 open issues

Review effort: Balanced


state.queue_pending(pending);
Ok(())
Ok(pending)
Add opt-in PCIe and MMIO workloads using an unmodified upstream Linux
vsock_perf binary with native AF_VSOCK and Unix-relay host peers.

Require exact endpoint byte counts across pause/resume and fresh transfers
after interrupting both directions with actual save/reset/restore. Bound
lifecycle waits and verify guest identity, reconnect, and clean teardown.

Add artifact-free report/peer regressions, shared workload helpers, and
reproduction instructions. Keep iperf/bulk workloads and their dependencies
outside this commit; the benchmark executable is not vendored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Reconnect/reset ordering and shared MSI-X restoration need device-owner and architectural review, while Linux/KVM save/restore behavior remains unverified under live vsock traffic.

2 open issues

Review effort: Balanced

Build on the shared lifecycle from microsoft#4713 while retaining the current
asynchronous snapshot interfaces. Park the shared device owner for
direct metadata access and defer restored notifications until start.

Stage vsock metadata until activation, retain queues for ordinary
pause/resume, and block activation after incomplete restore. Share
vsock queue setup so startup and restore validate the same features.

Add lifecycle, staging, notification, and queue-construction regressions
and document the retained-pause and restore-activation contract.

Validate virtio and virtio_vsock on Windows and Linux with check,
all-targets clippy, rustdoc, and agent nextest (194 and 199 passed).
Run cargo xtask fmt --fix last; no additional source changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 14:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical pending-reset race can send a stale RST before a replacement connection’s RESPONSE, causing ECONNRESET; the fix must retire the reset only after successful acceptance and add ordering and real-guest reconnection coverage.

3 open issues

Review effort: Balanced


state.queue_pending(pending);
Ok(())
Ok(pending)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guide unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants