Skip to content

Commit 5a0e259

Browse files
authored
Fix StackOverflow produced by guest logging (#1067)
* Fix StackOverflow produced by guest logging Signed-off-by: Doru Blânzeanu <[email protected]> * [guest] Enable `log` feature for `tracing` crate in simpleguest - The rationale for this change is to allow hyperlight core to test this scenario and catch potential issues early, not downstream. - This makes all trace spans to be created as logs when there is no subscriber installed on the guest (when `trace_guest` not enabled) - The `log_messages` integration test verifies that the guest correctly behaves when `RUST_LOG` enables guest logs. Signed-off-by: Doru Blânzeanu <[email protected]> --------- Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 09346ac commit 5a0e259

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test-integration guest target=default-target features="":
166166
@# run execute_on_heap test with feature "executable_heap" on and off
167167
{{if os() == "windows" { "$env:" } else { "" } }}GUEST="{{guest}}"{{if os() == "windows" { ";" } else { "" } }} {{ cargo-cmd }} test --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test integration_test execute_on_heap {{ if features =="" {" --features executable_heap"} else {"--features executable_heap," + features} }} -- --ignored
168168
{{if os() == "windows" { "$env:" } else { "" } }}GUEST="{{guest}}"{{if os() == "windows" { ";" } else { "" } }} {{ cargo-cmd }} test --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test integration_test execute_on_heap {{ if features =="" {""} else {"--features " + features} }} -- --ignored
169-
169+
170170
@# run the rest of the integration tests
171171
@# skip interrupt_random_kill_stress_test and then run it explicitly so we can see the output more
172172
{{if os() == "windows" { "$env:" } else { "" } }}GUEST="{{guest}}"{{if os() == "windows" { ";" } else { "" } }} {{ cargo-cmd }} test -p hyperlight-host {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test '*' -- --skip interrupt_random_kill_stress_test

src/hyperlight_guest/src/guest_handle/io.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ impl GuestHandle {
8989
}
9090

9191
/// Pushes the given data onto the shared output data buffer.
92-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
9392
pub fn push_shared_output_data(&self, data: &[u8]) -> Result<()> {
9493
let peb_ptr = self.peb().unwrap();
9594
let output_stack_size = unsafe { (*peb_ptr).output_stack.size as usize };

src/hyperlight_host/tests/integration_test.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,19 @@ fn recursive_stack_allocate_overflow() {
727727
#[test]
728728
#[ignore]
729729
fn log_message() {
730-
// internal_dispatch_function does a log::trace! in debug mode, and we call it 6 times in `log_test_messages`
731-
let num_fixed_trace_log = if cfg!(debug_assertions) { 6 } else { 0 };
730+
// The magic numbers below represent the number of fixed log messages that are emitted as
731+
// follows:
732+
// - internal_dispatch_function does a log::trace! in debug mode
733+
// - logs from trace level tracing spans created as logs because of the tracing `log` feature
734+
// - 6 from evolve call (hyperlight_main + halt)
735+
// - 16 from guest call (internal_dispatch_function + others)
736+
// and are multiplied because we make 6 calls to `log_test_messages`
737+
// NOTE: These numbers need to be updated if log messages or spans are added/removed
738+
let num_fixed_trace_log = if cfg!(debug_assertions) {
739+
(1 + 22) * 6
740+
} else {
741+
22 * 6
742+
};
732743

733744
let tests = vec![
734745
(LevelFilter::Trace, 5 + num_fixed_trace_log),

src/tests/rust_guests/simpleguest/Cargo.lock

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

src/tests/rust_guests/simpleguest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ hyperlight-guest-bin = { path = "../../../hyperlight_guest_bin" }
99
hyperlight-common = { path = "../../../hyperlight_common", default-features = false }
1010
hyperlight-guest-tracing = { path = "../../../hyperlight_guest_tracing" }
1111
log = {version = "0.4", default-features = false }
12-
tracing = { version = "0.1.41", default-features = false, features = ["attributes"] }
12+
tracing = { version = "0.1.41", default-features = false, features = ["log", "attributes"] }
1313

1414
[features]
1515
default = []

0 commit comments

Comments
 (0)