Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
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
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6938,6 +6938,7 @@ dependencies = [
"open_enum",
"pal_event",
"parking_lot",
"test_with_tracing",
"thiserror 2.0.16",
"tracelimit",
"tracing",
Expand Down Expand Up @@ -10867,6 +10868,7 @@ dependencies = [
"task_control",
"tempfile",
"test_with_tracing",
"thiserror 2.0.16",
"tracelimit",
"tracing",
"unicycle",
Expand Down
68 changes: 68 additions & 0 deletions Guide/src/dev_guide/tests/vmm.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,74 @@ engineers' local machines and in CI. Put these special words in your test to opt
- `heavy` - if your test is heavier than the typical vmm_test. E.g., your test explicitly requests 16 virtual processors.
- `very_heavy` if your test is heavier than a `heavy` test. E.g., your test explicitly requests 32 virtual processors.

### Native AF_VSOCK workloads with vsock_perf

The opt-in `vsock_perf_pci` and `vsock_perf_mmio` tests run the upstream
Linux `vsock_perf` utility directly inside an x64 Linux guest. Guest traffic
uses AF_VSOCK, with native Unix-relay peers on the host: there is no guest
NIC, TCP bridge, host Python process, or modified benchmark implementation.
This tests the userspace vsock backend, not kernel `vhost-vsock`.

Set `PETRI_VSOCK_PERF_BIN` to a **statically linked Linux x86_64 executable**
to enable the tests. The binary is copied into the guest by Pipette.
For example, build the unmodified utility from Linux v6.18.33 with a Linux
C compiler, development headers, `make`, and `curl`:

```bash
revision=83657f4189612e5cbcabc3058acd36c0bd120729
source_url="https://raw.githubusercontent.com/gregkh/linux/$revision/tools/testing/vsock"
mkdir -p target/vsock-perf-tool
for source in vsock_perf.c msg_zerocopy_common.c msg_zerocopy_common.h Makefile; do
curl --fail --location "$source_url/$source" -o "target/vsock-perf-tool/$source"
done
make -C target/vsock-perf-tool vsock_perf CC=cc LDFLAGS=-static
file target/vsock-perf-tool/vsock_perf
export PETRI_VSOCK_PERF_BIN="$(realpath target/vsock-perf-tool/vsock_perf)"
cargo xflowey vmm-tests-run --filter 'test(vsock_perf_)'
```

The source files and executable stay in the local build directory; they are
not vendored into OpenVMM. The utility has no version flag, so retain the
source revision when comparing results.

For Windows/WHP execution from WSL, also propagate the executable path:

```bash
. build_support/setup_windows_cross.sh
export WSLENV="${WSLENV:+$WSLENV:}PETRI_VSOCK_PERF_BIN/p:PETRI_VSOCK_PERF_MIB"
cargo xflowey vmm-tests-run --target windows-x64 \
--dir /mnt/c/path/to/vsock-perf-results \
--filter 'test(vsock_perf_)'
```

Each bus completes four transfers: guest TX and RX through ordinary
pause/resume, then fresh TX and RX connections after deliberately interrupting
each direction with in-place save/reset/restore. Both completed endpoints
must report **exactly 1 GiB** by default. `PETRI_VSOCK_PERF_MIB` accepts
16–4096; use 64 for a smoke run. The two interrupted transfers have a larger
budget and must end with connection failure, not successful completion.
The guest boot identity and RAM marker must survive, and fresh transfers
reuse the same service ports. Unset `PETRI_VSOCK_PERF_BIN` to disable these
VM tests.

The receiver uses the utility's standard 1 MiB read buffer and 256 KiB socket
buffer options so a final read can drain queued data when readability and
hangup are reported together. No sender headroom or drain-delay assumption
is used to relax byte-count validation.

Results include raw utility stdout/stderr and `vsock-perf-summary.json`
with both endpoint counts, utility throughput, host elapsed time, and restore
outcomes. Host elapsed time includes the deliberate pauses. The utility has
its own timing scope; for example, its sender rate measures time in `send()`
calls rather than host wall time. This is a functional load test with relay
overhead, not an isolated raw-vsock performance result.
`vsock_perf` does not provide end-to-end checksums; these counts do not
establish cryptographic payload integrity. The artifact-free
`vsock_perf_report_validation` test checks malformed, missing, duplicate,
non-finite, and incorrect-byte-count reports without booting a VM.
`vsock_perf_peer_validation` checks the native peer's payload validation,
byte counting, and stream shutdown using local Unix sockets.

### "unstable" tests

If a test is not yet reliable enough to gate PRs, mark it `unstable`. Every
Expand Down
11 changes: 9 additions & 2 deletions Guide/src/reference/openvmm/management/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,14 @@ describes the source definitions.
unless the option is supplied. For example, use
`--virtio-rtc bus=pcie:rp0` to attach it to the named PCIe port `rp0`.
* `--virtio-vsock-path <PATH>`: Add a virtio-vsock device using the OpenVMM
hybrid Unix socket relay.
hybrid Unix socket relay. This backend supports save/restore through the
PCI and MMIO transports on Windows and Linux hosts. Restore resets old
guest connections; applications must reconnect. Live host sockets and
device-side buffered data are not restored. Ordinary pause/resume preserves
connection state, although external peers may time out during a pause.
A fresh VM restore needs a usable relay endpoint and the same guest CID;
release the source endpoint before reusing its path. This does not change
the file-backed snapshot workflow's requirement to leave the source paused.
* `--virtio-vsock-bus <mmio|pci|pcie[:PORT]>`: Select the bus for a
virtio-vsock device created by `--virtio-vsock-path` or
`--virtio-vsock-vhost-cid`. When omitted, OpenVMM selects the bus
Expand All @@ -306,7 +313,7 @@ describes the source definitions.
`/dev/vhost-vsock`, the `vhost_vsock` kernel module, and shared file-backed
guest RAM (the default memory backing). It uses identity-mapped DMA and
does not support a non-identity virtual IOMMU. It conflicts with
`--virtio-vsock-path`.
`--virtio-vsock-path`. This kernel backend does not support save/restore.
* `--vhost-user <SOCKET_PATH>,type=<TYPE>[,tag=<NAME>][,num_queues=<N>][,queue_size=<N>][,pcie_port=<PORT>]`: Attach a
vhost-user device backed by an external process over a Unix socket (Linux
only). The backend process must already be listening on `SOCKET_PATH`.
Expand Down
5 changes: 5 additions & 0 deletions Guide/src/reference/openvmm/management/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ as not provided, so the ID isn't checked. The restored snapshot's
ID is returned in `RestoreVMResponse.snapshot_id`. Set `resume` to start the
restored VM immediately; otherwise it is created paused.

PCIe userspace virtio-vsock supports these operations, but restoration resets
existing streams; applications must reconnect. Supply the same guest CID and
make the Unix relay endpoint available before restoring. Live host streams and
device-side buffered data are not restored.

## Virtio-console file output

`VmService` can write a virtio-console stream directly to a host file. Set the
Expand Down
21 changes: 21 additions & 0 deletions Guide/src/user_guide/openvmm/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ OpenVMM snapshots:
| virtio-pmem | Virtio (PCI/MMIO) | Yes |
| virtio-rng | Virtio (PCI/MMIO) | Yes |
| virtio-rtc | Virtio (PCI/MMIO) | Yes |
| virtio-vsock (userspace relay) | Virtio (PCI/MMIO) | Yes; applications reconnect after restore |
| virtio-vsock (kernel vhost) | Virtio (PCI/MMIO) | **No** |
| NVMe | PCI | **No** |
| VGA | PCI | **No** (`todo!()`) |
| GDMA (MANA network) | PCI | **No** (`todo!()`) |
Expand All @@ -189,6 +191,25 @@ OpenVMM snapshots:
| VMBus serial (host) | VMBus | **No** |
| Vmbfs | VMBus | **No** |

```admonish note title="Virtio-vsock connections"
After an actual restore, the userspace vsock device sends
`VIRTIO_VSOCK_EVENT_TRANSPORT_RESET` on its event queue. A conforming guest
driver closes established connections but keeps listening sockets usable;
applications must reconnect. The guest CID must still match the saved
configuration. Ordinary pause/resume, including saving without restoring,
does not send this event.

This requires a guest driver that handles and replenishes event-queue buffers.
Host sockets and buffered stream data are not preserved. Individual connection
errors still use targeted reset packets rather than resetting the transport.
```

```admonish warning title="Virtio queue progress"
When a snapshot includes progress for an active virtio queue, its cursors must
be valid for the negotiated ring layout and queue size. Invalid progress is
rejected during restore rather than being discovered when queues restart.
```

```admonish tip
If you are unsure whether your VM configuration supports snapshots, try
issuing `save-snapshot` to a scratch directory. The save will fail
Expand Down
8 changes: 8 additions & 0 deletions petri/pipette/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! VMM-test artifact pipeline rather than launched by a developer on the host.
//! `--transport tcp|vsock` selects the connection transport, and Windows builds
//! additionally accept `--service`.
//! `vsock-listener PORT` runs a persistent echo listener for reset tests.

// UNSAFETY: init.rs requires unsafe for libc calls (fork, mount, reboot, waitpid)
// on Linux; shutdown.rs requires unsafe for the Windows shutdown API.
Expand All @@ -31,6 +32,8 @@ mod mount;
mod shutdown;
#[cfg(any(target_os = "linux", windows))]
mod trace;
#[cfg(target_os = "linux")]
mod vsock_listener;
#[cfg(windows)]
mod winsvc;

Expand Down Expand Up @@ -90,6 +93,11 @@ fn main() -> anyhow::Result<()> {
init::init_as_pid1()?;
}

#[cfg(target_os = "linux")]
if std::env::args().nth(1).as_deref() == Some("vsock-listener") {
return vsock_listener::run(std::env::args().skip(2));
}

let args = parse_args()?;

#[cfg(windows)]
Expand Down
45 changes: 45 additions & 0 deletions petri/pipette/src/vsock_listener.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Persistent guest listener used to test virtio-vsock transport resets.

use anyhow::Context;
use std::io::Read;
use std::io::Write;
use vmsocket::VmAddress;
use vmsocket::VmListener;

pub fn run(mut args: impl Iterator<Item = String>) -> anyhow::Result<()> {
let port: u32 = args
.next()
.context("missing vsock listener port")?
.parse()?;
anyhow::ensure!(port != 0 && port != u32::MAX, "invalid vsock listener port");
anyhow::ensure!(args.next().is_none(), "unexpected vsock listener argument");
let listener = VmListener::bind(VmAddress::vsock_any(port))?;
println!("listening {}", std::process::id());
std::io::stdout().flush()?;
let mut connections = 0;
loop {
let (mut stream, _) = listener.accept()?;
connections += 1;
println!("accepted {connections}");
std::io::stdout().flush()?;
let mut buffer = [0; 4096];
loop {
match stream.read(&mut buffer) {
Ok(0) => {
println!("eof {connections}");
break;
}
Ok(size) => stream.write_all(&buffer[..size])?,
Err(err) if err.kind() == std::io::ErrorKind::ConnectionReset => {
println!("reset {connections}");
break;
}
Err(err) => return Err(err).context("reading vsock listener connection"),
}
}
std::io::stdout().flush()?;
}
}
2 changes: 1 addition & 1 deletion petri/src/vm/openvmm/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ impl PetriVmConfigOpenVmm {
output_dir: log_source.output_dir().to_owned(),
openvmm_path: openvmm_path.clone(),
vtl2_vsock_path,
_vsock_path: vsock_path,
vsock_path,
properties: properties.clone(),
#[cfg(windows)]
_switch_ports: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion petri/src/vm/openvmm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ struct PetriVmResourcesOpenVmm {

// TempPaths that cannot be dropped until the end.
vtl2_vsock_path: Option<TempPath>,
_vsock_path: TempPath,
vsock_path: TempPath,

// properties needed at runtime
properties: PetriVmProperties,
Expand Down
15 changes: 15 additions & 0 deletions petri/src/vm/openvmm/modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use openvmm_defs::config::PcieMmioRangeConfig;
use openvmm_defs::config::PciePortConfig;
use openvmm_defs::config::PcieRootComplexConfig;
use openvmm_defs::config::PcieSwitchConfig;
use openvmm_defs::config::VirtioBus;
use openvmm_defs::config::VpciDeviceConfig;
use openvmm_defs::config::Vtl2BaseAddressType;
use vm_resource::IntoResource;
Expand All @@ -42,6 +43,20 @@ impl PetriVmConfigOpenVmm {
self
}

/// Attach the userspace virtio-vsock device via MMIO instead of PCIe.
///
/// Requires [`crate::PetriVmBuilder::with_virtio_vsock`] to be enabled.
pub fn with_virtio_vsock_mmio(mut self) -> Self {
let index = self
.private_virtio_devices
.iter()
.position(|(_, resource)| resource.id() == "virtio-vsock")
.expect("enable userspace virtio-vsock before selecting MMIO");
let (_, device) = self.private_virtio_devices.remove(index);
self.config.virtio_devices.push((VirtioBus::Mmio, device));
self
}

/// Enable the VTL0 alias map.
// TODO: Remove once #912 is fixed.
pub fn with_vtl0_alias_map(mut self) -> Self {
Expand Down
27 changes: 27 additions & 0 deletions petri/src/vm/openvmm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ impl PetriVmOpenVmm {
}
}

/// Get the userspace VTL0 vsock relay base path.
///
/// Guest connections to port `P` use a host Unix listener at `<base>_P`.
pub fn vtl0_vsock_path(&self) -> anyhow::Result<&Path> {
#[cfg(target_os = "linux")]
anyhow::ensure!(
self.inner
.resources
.properties
.vhost_vsock_guest_cid
.is_none(),
"kernel vhost-vsock does not use a Unix relay"
);
Ok(&self.inner.resources.vsock_path)
}

/// Get the path to the VTL 2 vsock socket, if the VM is configured with OpenHCL.
pub fn vtl2_vsock_path(&self) -> anyhow::Result<&Path> {
self.inner
Expand Down Expand Up @@ -379,6 +395,10 @@ impl PetriVmOpenVmm {
/// survives a save/restore round-trip.
pub async fn verify_save_restore(&mut self) -> anyhow::Result<()>
);
petri_vm_fn!(
/// Perform one save/reset/restore pulse, failing if reset is unsupported.
pub async fn pulse_save_restore(&mut self) -> anyhow::Result<()>
);
petri_vm_fn!(pub(crate) async fn launch_linux_direct_pipette(&mut self) -> anyhow::Result<()>);

/// Wrap the provided future in a race with the worker process's halt
Expand Down Expand Up @@ -838,6 +858,13 @@ impl PetriVmInner {
Ok(())
}

async fn pulse_save_restore(&self) -> anyhow::Result<()> {
self.worker
.pulse_save_restore()
.await
.context("save/restore pulse failed")
}

async fn verify_save_restore(&self) -> anyhow::Result<()> {
for i in 0..2 {
let result = self.worker.pulse_save_restore().await;
Expand Down
8 changes: 6 additions & 2 deletions petri/src/vm/openvmm/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,25 @@ impl PetriVmConfigOpenVmm {
// TODO: PCAT needs vga device support
// TODO: arm64 is broken?
// TODO: VPCI and some PCIe endpoints (NVMe/GDMA) don't support
// TODO: virtio vsock and console don't support save/restore yet
// TODO: kernel vhost-vsock and virtio console don't support save/restore yet
// TODO: 9p shares don't support save/restore yet
// TODO: nested virt doesn't support save/restore yet
let has_unsupported_pcie_save_restore_device = config
.pcie_devices
.iter()
.any(|device| matches!(device.resource.id(), "nvme" | "gdma"));
#[cfg(target_os = "linux")]
let has_kernel_vsock = resources.properties.vhost_vsock_guest_cid.is_some();
#[cfg(not(target_os = "linux"))]
let has_kernel_vsock = false;
let supports_save_restore = !skip_save_restore
&& !resources.properties.is_openhcl
&& !resources.properties.is_isolated
&& !resources.properties.is_pcat
&& !matches!(arch, MachineArch::Aarch64)
&& !resources.properties.using_vpci
&& !has_unsupported_pcie_save_restore_device
&& !resources.properties.use_virtio_vsock
&& !has_kernel_vsock
&& !resources.properties.use_virtio_console
&& !has_guest_shares
&& !config.hypervisor.nested_virt;
Expand Down
4 changes: 4 additions & 0 deletions vm/devices/pci/pci_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ thiserror.workspace = true
tracelimit.workspace = true
tracing.workspace = true
zerocopy.workspace = true

[dev-dependencies]
test_with_tracing.workspace = true

[lints]
workspace = true
Loading
Loading