Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/hyperlight_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ workspace = true
[dependencies]
flatbuffers = { version = "25.9.23", default-features = false }
anyhow = { version = "1.0.100", default-features = false }
log = "0.4.29"
tracing = { version = "0.1.43", optional = true }
arbitrary = {version = "1.4.2", optional = true, features = ["derive"]}
spin = "0.10.0"
thiserror = { version = "2.0.16", default-features = false }
log = { version = "0.4.29", default-features = false }

[features]
default = ["tracing"]
tracing = ["dep:tracing"]
fuzzing = ["dep:arbitrary"]
trace_guest = []
mem_profile = []
std = ["thiserror/std", "log/std", "tracing/std"]
std = ["thiserror/std", "tracing/std", "log/std"]

[lib]
bench = false # see https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ limitations under the License.
*/

use anyhow::{Error, Result, bail};
use log::Level;
#[cfg(feature = "tracing")]
use tracing::{Span, instrument};

use crate::flatbuffers::hyperlight::generated::LogLevel as FbLogLevel;

// Define a minimal Level enum for conversions.
// This mirrors log::Level/tracing::Level but is no_std compatible.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Level {
Trace,
Debug,
Info,
Warn,
Error,
}

#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum LogLevel {
Expand Down Expand Up @@ -112,3 +122,16 @@ impl From<Level> for LogLevel {
}
}
}

// Conversion from log::Level (which guest logger uses) to LogLevel
impl From<log::Level> for LogLevel {
fn from(val: log::Level) -> LogLevel {
match val {
log::Level::Trace => LogLevel::Trace,
log::Level::Debug => LogLevel::Debug,
log::Level::Info => LogLevel::Information,
log::Level::Warn => LogLevel::Warning,
log::Level::Error => LogLevel::Error,
}
}
}
2 changes: 1 addition & 1 deletion src/hyperlight_component_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ proc-macro2 = { version = "1.0.103" }
syn = { version = "2.0.111" }
itertools = { version = "0.14.0" }
prettyplease = { version = "0.2.37" }
log = { version = "0.4" }
tracing = { version = "0.1.43" }
10 changes: 5 additions & 5 deletions src/hyperlight_component_util/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl<'a, 'b> State<'a, 'b> {
let Some(ref mut cnvs) = self.cur_needs_vars else {
return;
};
log::debug!("debug varref: recording {:?} for var {:?}", cnvs.iter(), un);
tracing::debug!("debug varref: recording {:?} for var {:?}", cnvs.iter(), un);
self.vars_needs_vars[un].extend(cnvs.iter());
}
/// Get a list of all the variables needed by a var, given its absolute
Expand All @@ -426,7 +426,7 @@ impl<'a, 'b> State<'a, 'b> {
if self.vars_needs_vars.len() < un + 1 {
return BTreeSet::new();
};
log::debug!(
tracing::debug!(
"debug varref: looking up {:?} for var {:?}",
self.vars_needs_vars[un].iter(),
un
Expand Down Expand Up @@ -559,7 +559,7 @@ impl<'a, 'b> State<'a, 'b> {
Defined::Handleable(Handleable::Var(tv)) => match tv {
Tyvar::Bound(n) => {
let bv = &self.bound_vars[self.var_offset + (*n as usize)];
log::debug!("checking an origin {:?} {:?}", bv.origin, self.origin);
tracing::debug!("checking an origin {:?} {:?}", bv.origin, self.origin);
if bv.origin.matches(self.origin.iter()) {
Some((*n, bv.bound.clone()))
} else {
Expand Down Expand Up @@ -588,7 +588,7 @@ impl<'a, 'b> State<'a, 'b> {
///
/// Precondition: all named traits/modules must exist
pub fn resolve_trait_immut(&self, absolute: bool, path: &[Ident]) -> &Trait {
log::debug!("resolving trait {:?} {:?}", absolute, path);
tracing::debug!("resolving trait {:?} {:?}", absolute, path);
let mut m = if absolute {
&*self.root_mod
} else {
Expand All @@ -611,7 +611,7 @@ impl<'a, 'b> State<'a, 'b> {
.enumerate()
.for_each(|(i, vs)| {
*vs = vs.iter().map(|v| v + n).collect();
log::debug!("updated {:?} to {:?}", i, *vs);
tracing::debug!("updated {:?} to {:?}", i, *vs);
});
for _ in 0..n {
self.vars_needs_vars.push_front(BTreeSet::new());
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_component_util/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn emit_component<'a, 'b, 'c>(
/// - functions when given a type that implements the `Guest` trait
pub fn emit_toplevel<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, n: &str, ct: &'c Component<'b>) {
s.is_impl = true;
log::debug!("\n\n=== starting guest emit ===\n");
tracing::debug!("\n\n=== starting guest emit ===\n");
let wn = split_wit_name(n);

let ns = wn.namespace_path();
Expand Down
8 changes: 4 additions & 4 deletions src/hyperlight_component_util/src/hl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub fn emit_hl_unmarshal_value(s: &mut State, id: Ident, vt: &Value) -> TokenStr
}
Value::Own(ht) => {
let vi = resolve_handleable_to_resource(s, ht);
log::debug!("resolved ht to r (1) {:?} {:?}", ht, vi);
tracing::debug!("resolved ht to r (1) {:?} {:?}", ht, vi);
if s.is_guest {
let rid = format_ident!("HostResource{}", vi);
if s.is_wasmtime_guest {
Expand Down Expand Up @@ -326,7 +326,7 @@ pub fn emit_hl_unmarshal_value(s: &mut State, id: Ident, vt: &Value) -> TokenStr
}
Value::Borrow(ht) => {
let vi = resolve_handleable_to_resource(s, ht);
log::debug!("resolved ht to r (2) {:?} {:?}", ht, vi);
tracing::debug!("resolved ht to r (2) {:?} {:?}", ht, vi);
if s.is_guest {
let rid = format_ident!("HostResource{}", vi);
if s.is_wasmtime_guest {
Expand Down Expand Up @@ -624,7 +624,7 @@ pub fn emit_hl_marshal_value(s: &mut State, id: Ident, vt: &Value) -> TokenStrea
}
Value::Own(ht) => {
let vi = resolve_handleable_to_resource(s, ht);
log::debug!("resolved ht to r (3) {:?} {:?}", ht, vi);
tracing::debug!("resolved ht to r (3) {:?} {:?}", ht, vi);
if s.is_guest {
let call = if s.is_wasmtime_guest {
quote! { () }
Expand All @@ -645,7 +645,7 @@ pub fn emit_hl_marshal_value(s: &mut State, id: Ident, vt: &Value) -> TokenStrea
}
Value::Borrow(ht) => {
let vi = resolve_handleable_to_resource(s, ht);
log::debug!("resolved ht to r (6) {:?} {:?}", ht, vi);
tracing::debug!("resolved ht to r (6) {:?} {:?}", ht, vi);
if s.is_guest {
let call = if s.is_wasmtime_guest {
quote! { () }
Expand Down
4 changes: 2 additions & 2 deletions src/hyperlight_component_util/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn emit_import_extern_decl<'a, 'b, 'c>(
ExternDesc::CoreModule(_) => panic!("core module (im/ex)ports are not supported"),
ExternDesc::Func(ft) => {
let hln = emit_fn_hl_name(s, ed.kebab_name);
log::debug!("providing host function {}", hln);
tracing::debug!("providing host function {}", hln);
let (pds, pus) = ft
.params
.iter()
Expand Down Expand Up @@ -382,7 +382,7 @@ fn emit_component<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, wn: WitName, ct: &'c Com
/// See [`emit_component`]
pub fn emit_toplevel<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, n: &str, ct: &'c Component<'b>) {
s.is_impl = true;
log::debug!("\n\n=== starting host emit ===\n");
tracing::debug!("\n\n=== starting host emit ===\n");
let wn = split_wit_name(n);
emit_component(s, wn, ct)
}
14 changes: 7 additions & 7 deletions src/hyperlight_component_util/src/rtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn try_find_local_var_id(
return Some(emit_resource_ref(s, n, path));
}
}
log::debug!("path is {:?}\n", path);
tracing::debug!("path is {:?}\n", path);
let mut path = path.iter().rev();
let name = kebab_to_type(path.next().unwrap().name());
let owner = path.next();
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn emit_var_ref_value(s: &mut State, tv: &Tyvar) -> TokenStream {
/// the bound variable being referenced
/// - `is_value`: whether this is a value (e.g. constructor) or type context.
pub fn emit_var_ref_noff(s: &mut State, n: u32, is_value: bool) -> TokenStream {
log::debug!("var_ref {:?} {:?}", &s.bound_vars[n as usize], s.origin);
tracing::debug!("var_ref {:?} {:?}", &s.bound_vars[n as usize], s.origin);
// if the variable was defined locally, try to reference it directly
let id = try_find_local_var_id(s, n);
let id = match id {
Expand Down Expand Up @@ -317,7 +317,7 @@ pub fn emit_value(s: &mut State, vt: &Value) -> TokenStream {
wrap(emit_var_ref(s, tv))
} else {
let n = crate::hl::resolve_handleable_to_resource(s, ht);
log::debug!("resolved ht to r (4) {:?} {:?}", ht, n);
tracing::debug!("resolved ht to r (4) {:?} {:?}", ht, n);
let id = format_ident!("HostResource{}", n);
wrap(quote! { #id })
}
Expand All @@ -339,7 +339,7 @@ pub fn emit_value(s: &mut State, vt: &Value) -> TokenStream {
wrap(emit_var_ref(s, tv))
} else {
let n = crate::hl::resolve_handleable_to_resource(s, ht);
log::debug!("resolved ht to r (5) {:?} {:?}", ht, n);
tracing::debug!("resolved ht to r (5) {:?} {:?}", ht, n);
let id = format_ident!("HostResource{}", n);
wrap(quote! { #id })
}
Expand Down Expand Up @@ -619,7 +619,7 @@ fn emit_extern_decl<'a, 'b, 'c>(
s: &'c mut State<'a, 'b>,
ed: &'c ExternDecl<'b>,
) -> TokenStream {
log::debug!(" emitting decl {:?}", ed.kebab_name);
tracing::debug!(" emitting decl {:?}", ed.kebab_name);
match &ed.desc {
ExternDesc::CoreModule(_) => panic!("core module (im/ex)ports are not supported"),
ExternDesc::Func(ft) => {
Expand Down Expand Up @@ -749,7 +749,7 @@ fn emit_extern_decl<'a, 'b, 'c>(
/// Emit (via mutating `s`) a Rust trait declaration corresponding to
/// this instance type
fn emit_instance<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, wn: WitName, it: &'c Instance<'b>) {
log::debug!("emitting instance {:?}", wn);
tracing::debug!("emitting instance {:?}", wn);
let mut s = s.with_cursor(wn.namespace_idents());

let name = kebab_to_type(wn.name);
Expand Down Expand Up @@ -801,7 +801,7 @@ fn emit_instance<'a, 'b, 'c>(s: &'c mut State<'a, 'b>, wn: WitName, it: &'c Inst
}

drop(sv);
log::debug!("after exports, ncur_needs_vars is {:?}", needs_vars);
tracing::debug!("after exports, ncur_needs_vars is {:?}", needs_vars);
for v in needs_vars {
let id = s.noff_var_id(v);
s.cur_trait().tvs.insert(id, (Some(v), TokenStream::new()));
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_component_util/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn read_wit_type_from_file<R, F: FnMut(String, &etypes::Component) -> R>(
let ExternDesc::Component(ct) = &export.desc else {
panic!("malformed component type container: does not contain component type");
};
log::debug!("hcm: considering component type {:?}", ct);
tracing::debug!("hcm: considering component type {:?}", ct);
cb(export.kebab_name.to_string(), ct)
}

Expand Down
1 change: 1 addition & 0 deletions src/hyperlight_guest_capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ hyperlight-common = { workspace = true, default-features = false }

flatbuffers = { version = "25.2.10", default-features = false }
log = { version = "0.4", default-features = false }
tracing = { version = "0.1.43", default-features = false }

[build-dependencies]
cbindgen = "0.29.2"
1 change: 0 additions & 1 deletion src/hyperlight_host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ blake3 = "1.8.2"
page_size = "0.6.0"
termcolor = "1.2.0"
bitflags = "2.10.0"
log = "0.4.29"
opentelemetry = { version = "0.31.0", optional = true }
tracing = { version = "0.1.43", features = ["log"] }
tracing-log = "0.2.0"
Expand Down
21 changes: 19 additions & 2 deletions src/hyperlight_host/src/hypervisor/hyperlight_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,28 @@ use std::sync::atomic::AtomicU8;
use std::sync::atomic::AtomicU64;
use std::sync::{Arc, Mutex};

use log::LevelFilter;
use tracing::level_filters::LevelFilter;
use tracing::{Span, instrument};
#[cfg(feature = "trace_guest")]
use tracing_opentelemetry::OpenTelemetrySpanExt;

// Helper function to convert LevelFilter to u64 for guest
fn level_filter_to_u64(filter: LevelFilter) -> u64 {
// Map LevelFilter to numeric values matching the guest expectations
// OFF = 5, ERROR = 4, WARN = 3, INFO = 2, DEBUG = 1, TRACE = 0
if filter >= LevelFilter::ERROR {
4
} else if filter >= LevelFilter::WARN {
3
} else if filter >= LevelFilter::INFO {
2
} else if filter >= LevelFilter::DEBUG {
1
} else {
0
}
}

#[cfg(gdb)]
use super::gdb::{DebugCommChannel, DebugMsg, DebugResponse, DebuggableVm, VcpuStopReason, arch};
use super::regs::{CommonFpu, CommonRegisters};
Expand Down Expand Up @@ -229,7 +246,7 @@ impl HyperlightVm {
self.page_size = page_size as usize;

let guest_max_log_level: u64 = match guest_max_log_level {
Some(level) => level as u64,
Some(level) => level_filter_to_u64(level),
None => get_max_log_level().into(),
};

Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/src/hypervisor/hyperv_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn is_hypervisor_present() -> bool {
match Mshv::new() {
Ok(_) => true,
Err(_) => {
log::info!("MSHV is not available on this system");
tracing::info!("MSHV is not available on this system");
false
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/hyperlight_host/src/hypervisor/kvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ pub(crate) fn is_hypervisor_present() -> bool {
match api_version {
version if version == 12 && kvm.check_extension(UserMemory) => true,
12 => {
log::info!("KVM does not have KVM_CAP_USER_MEMORY capability");
tracing::info!("KVM does not have KVM_CAP_USER_MEMORY capability");
false
}
version => {
log::info!("KVM GET_API_VERSION returned {}, expected 12", version);
tracing::info!("KVM GET_API_VERSION returned {}, expected 12", version);
false
}
}
} else {
log::info!("KVM is not available on this system");
tracing::info!("KVM is not available on this system");
false
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ impl DebuggableVm for KvmVm {
fn set_debug(&mut self, enable: bool) -> Result<()> {
use kvm_bindings::{KVM_GUESTDBG_ENABLE, KVM_GUESTDBG_USE_HW_BP, KVM_GUESTDBG_USE_SW_BP};

log::info!("Setting debug to {}", enable);
tracing::info!("Setting debug to {}", enable);
if enable {
self.debug_regs.control |=
KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_USE_SW_BP;
Expand All @@ -205,7 +205,7 @@ impl DebuggableVm for KvmVm {
fn set_single_step(&mut self, enable: bool) -> Result<()> {
use kvm_bindings::KVM_GUESTDBG_SINGLESTEP;

log::info!("Setting single step to {}", enable);
tracing::info!("Setting single step to {}", enable);
if enable {
self.debug_regs.control |= KVM_GUESTDBG_SINGLESTEP;
} else {
Expand Down
Loading
Loading