virtio: add the vhost-vsock backend for virtio-vsock#4006
virtio: add the vhost-vsock backend for virtio-vsock#4006will-j-wright wants to merge 2 commits into
Conversation
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
Pull request overview
Adds a Linux-only virtio-vsock backend that delegates the virtqueue data path to the kernel via /dev/vhost-vsock, making the guest reachable from the host’s AF_VSOCK namespace. This integrates the backend end-to-end (resource handle + resolver + CLI + docs) and extends Petri/CI to exercise it.
Changes:
- Introduce
VhostVsockDevice(Linuxvhost_vsock) implementation invirtio_vsock. - Wire the backend through
virtio_resources, resolver registration, and a newopenvmmCLI flag--virtio-vsock-vhost-cid. - Update Petri to connect to pipette over host
AF_VSOCK, add a new Petri boot test, and prepare/dev/vhost-vsockin the nextest/flowey job.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vmm_tests/vmm_tests/tests/tests/multiarch.rs | Adds a Linux boot test that uses the vhost-vsock backend and validates host-to-guest AF_VSOCK connectivity via pipette. |
| vm/devices/virtio/virtio_vsock/src/vhost.rs | New Linux vhost-vsock virtio-vsock device implementation + unit tests for CID validation, queue state encoding, and memory mapping. |
| vm/devices/virtio/virtio_vsock/src/resolver.rs | Adds a Linux-only static resolver for the new vhost-vsock handle. |
| vm/devices/virtio/virtio_vsock/src/lib.rs | Plumbs in the Linux-only vhost module and updates the crate-level unsafe rationale comment. |
| vm/devices/virtio/virtio_vsock/Cargo.toml | Adds Linux-only dependencies needed by the vhost backend (nix ioctl, pal_event, sparse_mmap). |
| vm/devices/virtio/virtio_resources/src/lib.rs | Adds VirtioVsockVhostHandle MeshPayload resource ID for selecting the vhost backend. |
| petri/src/vm/openvmm/runtime.rs | Adds AF_VSOCK-based pipette connection path when a vhost-vsock CID is configured. |
| petri/src/vm/openvmm/construct.rs | Chooses between user-mode vsock vs vhost-vsock resources and enforces shared-memory requirements when vhost-vsock is enabled. |
| petri/src/vm/mod.rs | Extends PetriVmBuilder/properties with a Linux-only vhost-vsock guest CID knob (with_vhost_vsock). |
| petri/Cargo.toml | Adds Linux-only vmsocket dependency for AF_VSOCK connections. |
| openvmm/openvmm_resources/src/lib.rs | Registers the new Linux-only virtio-vsock vhost resolver. |
| openvmm/openvmm_entry/src/lib.rs | Adds device creation from the new CLI option (--virtio-vsock-vhost-cid). |
| openvmm/openvmm_entry/src/cli_args.rs | Defines CLI flag, CID parser/validation, and tests for the new option. |
| Guide/src/reference/openvmm/management/cli.md | Documents --virtio-vsock-path and new --virtio-vsock-vhost-cid behavior/requirements. |
| flowey/flowey_lib_hvlite/src/test_nextest_vmm_tests_archive.rs | Adds an optional pre-test step to modprobe vhost_vsock and chmod /dev/vhost-vsock. |
| flowey/flowey_lib_hvlite/src/_jobs/local_build_and_run_nextest_vmm_tests.rs | Threads through the new prepare_vhost_vsock option (disabled for this local job). |
| flowey/flowey_lib_hvlite/src/_jobs/consume_and_test_nextest_vmm_tests_archive.rs | Enables vhost-vsock preparation for Linux x86_64 nextest runs (where the new test applies). |
| Cargo.lock | Records new dependency usage (notably nix and sparse_mmap). |
71e831d to
ad62631
Compare
ad62631 to
6cec5b8
Compare
chris-oo
left a comment
There was a problem hiding this comment.
i didn't look too much at vhost.rs, i need a bit more context to really review it / john perhaps has the right context
| // that requires shared, file-backed memory. | ||
| let private_incompatible = firmware.is_openhcl() || firmware.is_pcat(); | ||
| let private_incompatible = | ||
| firmware.is_openhcl() || firmware.is_pcat() || vhost_vsock_guest_cid.is_some(); |
There was a problem hiding this comment.
this needs a comment why this is private incompatible (because the kernel needs access, or why?)
There was a problem hiding this comment.
does the bail below not have enough detail?
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 18 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
vm/devices/virtio/virtio_vsock/src/vhost.rs:17
size_ofis used unqualified in this module (e.g. when building the vhost memory table and device register length), but it isn’t imported into scope anywhere in the file. This will fail to compile unless each call is qualified (e.g.std::mem::size_of). Add ause core::mem::size_of;(orstd::mem::size_of) near the other imports.
use crate::spec::VsockConfig;
use anyhow::Context as _;
use guestmem::GuestMemory;
use inspect::InspectMut;
use pal_event::Event;
6cec5b8 to
4738e22
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
vm/devices/virtio/virtio_vsock/src/vhost.rs:22
size_of::<...>()is used in this module (e.g. when building the vhost memory table), butsize_ofisn't imported, so this file won't compile on Linux. Importsize_offromstd::mem(orcore::mem).
use pal_event::Event;
use sparse_mmap::SparseMapping;
use std::os::fd::AsFd as _;
use std::os::fd::AsRawFd as _;
use std::os::fd::OwnedFd;
use std::os::fd::RawFd;
4738e22 to
8201d63
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
vm/devices/virtio/virtio_vsock/src/vhost.rs:17
- This module calls
size_of::<...>()(e.g. when building the vhost memory table), butsize_ofisn’t imported, so the file won’t compile as-is. Add an explicituse std::mem::size_of;near the other imports.
use crate::spec::VsockConfig;
use anyhow::Context as _;
use guestmem::GuestMemory;
use inspect::InspectMut;
use pal_event::Event;
| match self.memory().read_used_index(&runtime.params) { | ||
| Ok(index) => index, | ||
| Err(error) => { | ||
| tracelimit::warn_ratelimited!( | ||
| error = &*error as &dyn std::error::Error, | ||
| index, | ||
| "failed to read vhost-vsock used index" | ||
| ); | ||
| return None; | ||
| } | ||
| } |
Add the vhost-vsock backend for virtio-vsock, implemented as
VhostVsockDevice. This backend manifests asAF_VSOCKon both ends of the connection by delegating the virtqueues to the kernel with/dev/vhost-vsock, rather than the user-modeAF_UNIX/AF_VSOCKhybrid model used byVirtioVsockDevice. This exposes the guest in the host'sAF_VSOCKnamespace, allowing users on the host toconnect(AF_VSOCK, CID, port)to reach services inside guest.Also add a new petri test exercising this scenario.