Repository navigation
Conversation
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The cross-boundary stream protocol couples credit accounting, backpressure, guest scheduling, cancellation, and snapshot lifetimes, requiring human review and runtime validation on supported hypervisors to confirm security and teardown invariants.
No open issues 🎉
What changed in this PR
This PR adds optional byte streams to Hyperlight’s host and guest calls. Readers can cross the sandbox boundary while writers remain local, with bounded buffering and credit-based flow control over virtqueues.
Changes:
- Adds stream endpoints, wire records, reader transfers, and publication tracking.
- Integrates stream traffic with guest tasks, progress turns, cancellation, and snapshot constraints.
- Adds protocol tests, fuzzing support, CI coverage, and API documentation.
| File | Description |
|---|---|
src/tests/rust_guests/simpleguest/src/main.rs |
Adds guest functions for stream lifecycle tests. |
src/tests/rust_guests/simpleguest/Cargo.toml |
Enables guest stream support. |
src/hyperlight_host/tests/sandbox_host_tests.rs |
Tests recovery after oversized guest results. |
src/hyperlight_host/src/sandbox/snapshot/tripwires.rs |
Pins stream protocol constants. |
src/hyperlight_host/src/sandbox/snapshot/file/config.rs |
Supports stream reader types in snapshot metadata. |
src/hyperlight_host/src/sandbox/outb.rs |
Handles stream messages and transactional host replies. |
src/hyperlight_host/src/mem/virtq/mod.rs |
Exposes one-way message handling. |
src/hyperlight_host/src/mem/virtq/codec.rs |
Decodes reader transfers and validates one-way messages. |
src/hyperlight_host/src/mem/mgr.rs |
Manages stream sessions and queue traffic. |
src/hyperlight_host/src/lib.rs |
Exposes host stream endpoints. |
src/hyperlight_host/src/hypervisor/mod.rs |
Adds cancellation wakeups for stream drives. |
src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs |
Preserves pending TLB flushes after execution errors. |
src/hyperlight_host/src/hypervisor/hyperlight_vm/mod.rs |
Distinguishes cancellation before guest entry. |
src/hyperlight_host/src/hypervisor/hyperlight_vm/aarch64.rs |
Preserves pending TLB flushes after execution errors. |
src/hyperlight_host/src/error.rs |
Defines the active-stream snapshot error. |
src/hyperlight_host/Cargo.toml |
Adds the optional streams feature. |
src/hyperlight_host/benches/benchmarks.rs |
Adapts codec benchmarks to owned pending messages. |
src/hyperlight_guest/src/transport/mod.rs |
Propagates initialization validation errors. |
src/hyperlight_guest/src/transport/context.rs |
Handles stream dispatch, status, and response capacity. |
src/hyperlight_guest/src/transport/codec.rs |
Decodes readers and copies incoming stream payloads. |
src/hyperlight_guest/src/task.rs |
Adds a bounded, wake-driven guest executor. |
src/hyperlight_guest/src/task_noop.rs |
Provides task stubs without streams. |
src/hyperlight_guest/src/stream.rs |
Exposes task-backed stream production. |
src/hyperlight_guest/src/lib.rs |
Exposes stream and task modules. |
src/hyperlight_guest/Cargo.toml |
Adds the guest streams feature. |
src/hyperlight_guest_capi/src/types/return_value.rs |
Handles the unsupported stream return variant. |
src/hyperlight_guest_capi/src/types/parameter.rs |
Rejects stream parameters in the C API. |
src/hyperlight_guest_bin/src/lib.rs |
Checks transport initialization completion. |
src/hyperlight_guest_bin/src/host_comm.rs |
Constructs parameters without cloning values. |
src/hyperlight_guest_bin/src/guest_function/call.rs |
Polls tasks and completes progress turns. |
src/hyperlight_guest_bin/Cargo.toml |
Forwards the streams feature. |
src/hyperlight_common/src/virtq/producer.rs |
Adds descriptor and slot reservation support. |
src/hyperlight_common/src/virtq/pool/tests.rs |
Tests largest-free-slot reporting. |
src/hyperlight_common/src/virtq/pool/slot.rs |
Reports the largest available slot size. |
src/hyperlight_common/src/transport.rs |
Adds stream framing and pending publication ownership. |
src/hyperlight_common/src/stream/sync.rs |
Provides pipe locking and session notifications. |
src/hyperlight_common/src/stream/record.rs |
Defines and validates stream wire records. |
src/hyperlight_common/src/stream/producer.rs |
Implements producer completion and cancellation. |
src/hyperlight_common/src/stream/noop.rs |
Rejects stream operations when disabled. |
src/hyperlight_common/src/stream/mod.rs |
Defines shared stream exports and limits. |
src/hyperlight_common/src/stream/id.rs |
Defines validated stream identifiers. |
src/hyperlight_common/src/stream/error.rs |
Defines stream and protocol errors. |
src/hyperlight_common/src/stream/endpoint.rs |
Implements asynchronous reader and writer APIs. |
src/hyperlight_common/src/lib.rs |
Exposes shared stream functionality. |
src/hyperlight_common/src/func/ret_type.rs |
Supports non-cloneable stream return values. |
src/hyperlight_common/src/func/param_type.rs |
Supports non-cloneable stream parameters. |
src/hyperlight_common/src/flatbuffer_wrappers/wire.rs |
Encodes reader transfers and caps control data. |
src/hyperlight_common/src/flatbuffer_wrappers/function_types.rs |
Adds stream value types and decoding. |
src/hyperlight_common/src/flatbuffer_wrappers/function_call.rs |
Tracks reader ownership through call encoding. |
src/hyperlight_common/src/flatbuffer_wrappers/codec.rs |
Adds payload limits and transfer lifecycle tests. |
src/hyperlight_common/src/flatbuffer_wrappers/abi_tests.rs |
Pins stream value and return-type tags. |
src/hyperlight_common/Cargo.toml |
Declares the shared streams feature. |
Justfile |
Adds stream test commands to CI-equivalent recipes. |
fuzz/fuzz_targets/control_decode.rs |
Exercises decoding with stream session state. |
fuzz/Cargo.toml |
Enables streams for fuzzing. |
docs/virtio-host-guest-communication.md |
Documents stream transport and snapshot behavior. |
docs/snapshot-versioning.md |
Documents stream protocol compatibility checks. |
CHANGELOG.md |
Records stream APIs and breaking changes. |
.github/workflows/dep_build_test.yml |
Runs stream tests in CI. |
Review effort: Balanced
Benchmark ResultsMeasured commit: kvm / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
kvm / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / amd (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |
ludfjig
left a comment
There was a problem hiding this comment.
this looks good to me. https://github.com/andreiltd/hyperlight-stream-demo is very clean. Btw I assume an awaitable host-side driver is planned for later? Would this remove Sandbox::block_on? Or keep it? I am a bit fuzzy on the async details :D
Hey, yes in the HIP I proposed
The question whether The HIP also proposed |
jprendes
left a comment
There was a problem hiding this comment.
This looks relly good.
My main concern is with the blocking nature of drive.
That beind said, I would be more than happy for us to merge this as is and we can iterate on the exact mechanics of drive later.
| $macro!(bool, Bool); | ||
| $macro!(Vec<u8>, VecBytes); | ||
| $macro!(Vec<$crate::func::Bytes>, ByteChunks); | ||
| $macro!($crate::stream::StreamReader<u8>, StreamReader); |
There was a problem hiding this comment.
I was a bit surprised that the StreamReader can cross the host-guest boundary and not the writer.
@andreiltd pointed out that this is how CM does it (for good reasons), which is fair enough.
We might want to consider allowing the StreamWriter to cross the boundary in some future.
| /// Poll `work` to completion, running progress turns while it waits. | ||
| #[cfg(feature = "streams")] | ||
| #[instrument(err(Debug), skip_all, parent = Span::current())] | ||
| fn drive<F: Future>(&mut self, work: F) -> Result<F::Output> { |
There was a problem hiding this comment.
I was hoping this could be async fn drive(&mut self) -> () that drives the sandbox.
We would have to think when the sandbox wakes up.
In the past I've linked that with having some activity in the host functions, but maybe we need a different model here.
Maybe a better approach here is a shared state between the streams and the sandbox, where we can put a Notify or something similar.
Overview
streamis a one-way byte pipe with one writer and one reader.Muxstands in for the missing end. It turns pipe activity into smallrecordsand sends them over the virtqueues.Creditscap the bytes in flight to onewindow(16 KiB by default) per stream.block_onruns progress turns.tasksin a tiny executor. Each turn polls them.Local Pipe
stream::new()returns(reader, writer). They share oneArc<Pipe>with a capacity ofDEFAULT_WINDOW(16384 bytes).VecDeque<Bytes>. A chunk keeps its storage, so moving a chunk never copies it.Moving a reader to the peer
The side that sends a reader away is its origin. The origin names the stream with a
StreamId. After the move, each side has its own pipe. The Mux on each side holds the end whose handle is on the other side.On the wire, a reader inside a call is
WireValue::StreamReader(Transfer)Peer can return its reader (returning reader) in which case it will be reattached to the pipe and pipe will become local.
Records
A record is a postcard enum. The control part holds the records. The payload bytes follow in record order with no framing.
CREDIT{sid, bytes}CLOSE_READER{sid}DATA{sid, len}lenpayload bytes belong tosid.END{sid, aborted}STATUS{flags}Mux::prepare_recordsfills a batch up to the buffer size:Bytesclone of the origin pipe (peek). The bytes are copied once, into the queue buffer.Example:
The guest wrote "hello" to S1 (sid) and closed the writer. One flush made this message:
API
You can check this demo app showcasing streams: https://github.com/andreiltd/hyperlight-stream-demo