Skip to content

Commit 2e9f228

Browse files
committed
[trace-host] handle a TraceBatch from the guest
- Parse the spans and events coming from the guest and create corresponding spans and events from the host that mimics a single call from host Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent e0338cc commit 2e9f228

File tree

7 files changed

+387
-13
lines changed

7 files changed

+387
-13
lines changed

Cargo.lock

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hyperlight_host/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ page_size = "0.6.0"
3535
termcolor = "1.2.0"
3636
bitflags = "2.9.3"
3737
log = "0.4.27"
38+
opentelemetry = { version = "0.30.0", optional = true }
3839
tracing = { version = "0.1.41", features = ["log"] }
3940
tracing-log = "0.2.0"
4041
tracing-core = "0.1.34"
42+
tracing-opentelemetry = { version = "0.31.0", optional = true }
4143
hyperlight-common = { workspace = true, default-features = true, features = [ "std" ] }
4244
hyperlight-guest-tracing = { workspace = true, default-features = true, optional = true }
4345
vmm-sys-util = "0.15.0"
@@ -98,7 +100,7 @@ tracing = "0.1.41"
98100
tracing-subscriber = {version = "0.3.19", features = ["std", "env-filter"]}
99101
tracing-opentelemetry = "0.31.0"
100102
opentelemetry = "0.30.0"
101-
opentelemetry-otlp = { version = "0.30.0", default-features = false, features = ["http-proto", "reqwest-blocking-client"] }
103+
opentelemetry-otlp = { version = "0.30.0", default-features = false, features = ["http-proto", "reqwest-blocking-client", "grpc-tonic"] }
102104
opentelemetry-semantic-conventions = "0.30"
103105
opentelemetry_sdk = { version = "0.30.0", features = ["rt-tokio"] }
104106
tokio = { version = "1.47.1", features = ["full"] }
@@ -132,7 +134,7 @@ executable_heap = []
132134
print_debug = []
133135
# Dumps the VM state to a file on unexpected errors or crashes. The path of the file will be printed on stdout and logged.
134136
crashdump = ["dep:chrono"]
135-
trace_guest = ["hyperlight-common/trace_guest", "hyperlight-guest-tracing/trace"]
137+
trace_guest = ["dep:opentelemetry", "dep:tracing-opentelemetry", "dep:hyperlight-guest-tracing", "hyperlight-common/trace_guest"]
136138
mem_profile = [ "trace_guest", "dep:framehop", "dep:fallible-iterator", "hyperlight-common/mem_profile" ]
137139
kvm = ["dep:kvm-bindings", "dep:kvm-ioctls"]
138140
# This feature is deprecated in favor of mshv3

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ pub(crate) struct HypervLinuxDriver {
320320
gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
321321
#[cfg(crashdump)]
322322
rt_cfg: SandboxRuntimeConfig,
323-
#[allow(dead_code)]
324323
#[cfg(feature = "trace_guest")]
325324
trace_info: TraceInfo,
326325
}
@@ -775,6 +774,9 @@ impl Hypervisor for HypervLinuxDriver {
775774
{
776775
Err(mshv_ioctls::MshvError::from(libc::EINTR))
777776
} else {
777+
#[cfg(feature = "trace_guest")]
778+
self.trace_info.setup_guest_trace();
779+
778780
// Note: if a `InterruptHandle::kill()` called while this thread is **here**
779781
// Then the vcpu will run, but we will keep sending signals to this thread
780782
// to interrupt it until `running` is set to false. The `vcpu_fd::run()` call will
@@ -923,6 +925,21 @@ impl Hypervisor for HypervLinuxDriver {
923925
}
924926
},
925927
};
928+
929+
// If trace is enabled, process the trace batch
930+
#[cfg(feature = "trace_guest")]
931+
match result {
932+
HyperlightExit::Halt()
933+
| HyperlightExit::IoOut(_, _, _, _)
934+
| HyperlightExit::Mmio(_) => {
935+
// If the result is not a halt, io out, mmio or debug exit, we need to process the trace batch
936+
let regs = self.read_regs()?;
937+
let _ = self
938+
.trace_info
939+
.handle_trace_batch(&regs, self.mem_mgr.as_mut().unwrap());
940+
}
941+
_ => {}
942+
}
926943
Ok(result)
927944
}
928945

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ pub(crate) struct HypervWindowsDriver {
293293
#[cfg(crashdump)]
294294
rt_cfg: SandboxRuntimeConfig,
295295
#[cfg(feature = "trace_guest")]
296-
#[allow(dead_code)]
297296
trace_info: TraceInfo,
298297
}
299298
/* This does not automatically impl Send because the host
@@ -761,6 +760,9 @@ impl Hypervisor for HypervWindowsDriver {
761760
Reserved: Default::default(),
762761
}
763762
} else {
763+
#[cfg(feature = "trace_guest")]
764+
self.trace_info.setup_guest_trace();
765+
764766
self.processor.run()?
765767
};
766768
self.interrupt_handle
@@ -875,6 +877,20 @@ impl Hypervisor for HypervWindowsDriver {
875877
}
876878
};
877879

880+
// If trace is enabled, process the trace batch
881+
#[cfg(feature = "trace_guest")]
882+
match result {
883+
HyperlightExit::Halt()
884+
| HyperlightExit::IoOut(_, _, _, _)
885+
| HyperlightExit::Mmio(_) => {
886+
// If the result is not a halt, io out, mmio or debug exit, we need to process the trace batch
887+
let regs = self.read_regs()?;
888+
let _ = self
889+
.trace_info
890+
.handle_trace_batch(&regs, self.mem_mgr.as_mut().unwrap());
891+
}
892+
_ => {}
893+
}
878894
Ok(result)
879895
}
880896

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ pub(crate) struct KVMDriver {
306306
#[cfg(crashdump)]
307307
rt_cfg: SandboxRuntimeConfig,
308308
#[cfg(feature = "trace_guest")]
309-
#[allow(dead_code)]
310309
trace_info: TraceInfo,
311310
}
312311

@@ -693,6 +692,9 @@ impl Hypervisor for KVMDriver {
693692
{
694693
Err(kvm_ioctls::Error::new(libc::EINTR))
695694
} else {
695+
#[cfg(feature = "trace_guest")]
696+
self.trace_info.setup_guest_trace();
697+
696698
// Note: if a `InterruptHandle::kill()` called while this thread is **here**
697699
// Then the vcpu will run, but we will keep sending signals to this thread
698700
// to interrupt it until `running` is set to false. The `vcpu_fd::run()` call will
@@ -809,6 +811,21 @@ impl Hypervisor for KVMDriver {
809811
HyperlightExit::Unknown(err_msg)
810812
}
811813
};
814+
815+
// If trace is enabled, process the trace batch
816+
#[cfg(feature = "trace_guest")]
817+
match result {
818+
HyperlightExit::Halt()
819+
| HyperlightExit::IoOut(_, _, _, _)
820+
| HyperlightExit::Mmio(_) => {
821+
// If the result is not a halt, io out, mmio or debug exit, we need to process the trace batch
822+
let regs = self.read_regs()?;
823+
let _ = self
824+
.trace_info
825+
.handle_trace_batch(&regs, self.mem_mgr.as_mut().unwrap());
826+
}
827+
_ => {}
828+
}
812829
Ok(result)
813830
}
814831

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ pub(crate) trait Hypervisor: Debug + Send {
233233
fn check_stack_guard(&self) -> Result<bool>;
234234

235235
/// Read a register for trace/unwind purposes
236-
#[allow(dead_code)]
237236
#[cfg(feature = "trace_guest")]
238237
fn read_regs(&self) -> Result<arch::X86_64Regs>;
239238

0 commit comments

Comments
 (0)