-
Notifications
You must be signed in to change notification settings - Fork 152
Serialize guest trace data using flatbuffers #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aaa356b to
bc699db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. BTW what happens if guest is build with tracing feature, but host is not?
src/hyperlight_common/src/flatbuffer_wrappers/guest_trace_data.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the guest tracing system to use FlatBuffers for serialization instead of the heapless crate with fixed-size arrays. This allows for dynamic allocation and removes the constraints of pre-allocated buffer sizes.
Key changes:
- Replaced
heaplessdependency withVec-based collections for dynamic allocation - Introduced FlatBuffers schema (
guest_trace_data.fbs) for trace data serialization - Changed from passing raw memory pointers to passing serialized data buffers between guest and host
- Simplified event tracking by using a stream-based model (open/close events) instead of maintaining mutable span state
Reviewed Changes
Copilot reviewed 15 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/schema/guest_trace_data.fbs |
New FlatBuffers schema defining guest trace data structures |
src/schema/all.fbs |
Added include for new guest trace data schema |
src/hyperlight_common/src/flatbuffer_wrappers/guest_trace_data.rs |
New module implementing serialization/deserialization for guest trace data |
src/hyperlight_common/src/flatbuffer_wrappers/mod.rs |
Added guest_trace_data module export |
src/hyperlight_common/src/flatbuffers/mod.rs |
Added exports for new FlatBuffers-generated types |
src/hyperlight_common/src/flatbuffers/hyperlight/generated/*.rs |
Auto-generated FlatBuffers code for trace data structures |
src/hyperlight_guest_tracing/src/lib.rs |
Removed heapless-based type definitions (Spans, Events, TraceLevel, etc.) |
src/hyperlight_guest_tracing/src/state.rs |
Refactored to use Vec instead of heapless, changed to event-stream model |
src/hyperlight_guest_tracing/src/visitor.rs |
Simplified field visitor to use String/Vec instead of heapless types |
src/hyperlight_guest_tracing/Cargo.toml |
Removed heapless dependency |
src/hyperlight_host/src/sandbox/trace/context.rs |
Updated to deserialize FlatBuffers and process event stream |
src/hyperlight_host/src/hypervisor/*.rs |
Changed memory manager reference from immutable to mutable |
src/hyperlight_guest/src/exit.rs |
Updated to pass serialized data pointer/length instead of raw struct pointers |
Justfile |
Added test commands for new trace_guest feature |
Cargo.lock & guest Cargo.lock files |
Removed heapless and its transitive dependencies |
The host crashes with: Because of https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_host/src/sandbox/outb.rs#L155 I think it is ok to fail because unless the host expects this from the guest, it shall fail. |
- The files have been generated using the `flatbuffers` v25.9.23 that correctly generate `unsafe` code as opposed to previous versions Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
bc699db to
ab93d7d
Compare
This is part of #964.
Description
This PR changes the way the guest reports the guest tracing data to the host from simply providing a pointer to the data in the guest to serializing it and providing a pointer to the serialized data in the guest.
The host side can the interpret that pointer as an offset in the shared memory, retrieve a copy of that buffer in the host, deserialize it and then parse the trace events to emit corresponding tracing spans/events on the host.
To do that, the following steps were necessary:
These wrappers make use of the flatbuffers code to provide
TryFromandFromimplementations for the types used on the guest and hostGuestEventtype that is an enum with the following variants:OpenSpan- is created when a span is opened and stores all the corresponding info for that span including the TSC read on the guestCloseSpan- is created when a span is closed and stores the TSC of when that happenedLogEvent- is created when a log is encounteredGuestEventdefined above. When the guest data vector reaches the capacity, the data is serialized and the pointer and length of that buffer are written in the registers of the CPU right before calling theoutinstruction that yields control to the hostSpecial notes
I would advise special consideration to the following areas: