Skip to content

Commit 984758b

Browse files
committed
Fix
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 9abab7a commit 984758b

File tree

5 files changed

+23
-37
lines changed

5 files changed

+23
-37
lines changed

.github/workflows/dep_rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
just test-rust ${{ matrix.config }} inprocess,seccomp,${{ matrix.hypervisor == 'mshv' && 'mshv' || 'kvm' }}
134134
135135
# make sure certain cargo features compile
136-
cargo check -p hyperlight-host --features dump_on_crash
136+
cargo check -p hyperlight-host --features crashdump
137137
138138
# without any driver (shouldn't compile)
139139
just test-rust-feature-compilation-fail ${{ matrix.config }}

docs/debugging-hyperlight.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ cargo test --package hyperlight-host --test integration_test --features print_de
3939

4040
## Dumping the memory configuration, virtual processor register state and memory contents on a crash or unexpected VM Exit
4141

42-
To dump the details of the memory configuration, the virtual processors register state and the contents of the VM memory set the feature `dump_on_crash` and run a debug build. This will result in a dump file being created in the temporary directory. The name and location of the dump file will be printed to the console and logged as an error message.
42+
To dump the details of the memory configuration, the virtual processors register state and the contents of the VM memory set the feature `crashdump` and run a debug build. This will result in a dump file being created in the temporary directory. The name and location of the dump file will be printed to the console and logged as an error message.
4343

4444
There are no tools at this time to analyze the dump file, but it can be useful for debugging.

src/hyperlight_host/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ function_call_metrics = []
118118
executable_heap = []
119119
# This feature enables printing of debug information to stdout in debug builds
120120
print_debug = []
121-
# This feature enables dunping of the VMs details to a file when an unexpected or error exit occurs in a VM in debug mode
122-
# the name of the file is output to stdout and logged.
123-
crashdump = ["dep:tempfile"]
121+
crashdump = ["dep:tempfile"] # Dumps the VM state to a file on unexpected errors or crashes. The path of the file will be printed on stdout and logged. This feature can only be used in debug builds.
124122
kvm = ["dep:kvm-bindings", "dep:kvm-ioctls"]
125123
mshv = ["dep:mshv-bindings", "dep:mshv-ioctls"]
126124
inprocess = []

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -508,18 +508,6 @@ impl Hypervisor for HypervWindowsDriver {
508508
"HyperV Memory Access Details :\n GPA: {:#?}\n Access Info :{:#?}\n {:#?} ",
509509
gpa, access_info, &self
510510
);
511-
#[cfg(all(debug_assertions, feature = "dump_on_crash"))]
512-
{
513-
if let Err(e) = unsafe {
514-
self.write_dump_file(
515-
self.mem_regions.clone(),
516-
self.source_address.add(PAGE_SIZE_USIZE) as *const u8,
517-
self.size,
518-
)
519-
} {
520-
println!("Error dumping memory: {}", e);
521-
}
522-
}
523511

524512
match self.get_memory_access_violation(gpa as usize, &self.mem_regions, access_info)
525513
{
@@ -539,18 +527,6 @@ impl Hypervisor for HypervWindowsDriver {
539527
"HyperV Unexpected Exit Details :#nReason {:#?}\n {:#?}",
540528
exit_context.ExitReason, &self
541529
);
542-
#[cfg(all(debug_assertions, feature = "dump_on_crash"))]
543-
{
544-
if let Err(e) = unsafe {
545-
self.write_dump_file(
546-
self.mem_regions.clone(),
547-
self.source_address.add(PAGE_SIZE_USIZE) as *const u8,
548-
self.size,
549-
)
550-
} {
551-
println!("Error dumping memory: {}", e);
552-
}
553-
}
554530
match self.get_exit_details(exit_context.ExitReason) {
555531
Ok(error) => HyperlightExit::Unknown(error),
556532
Err(e) => HyperlightExit::Unknown(format!("Error getting exit details: {}", e)),

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ impl VirtualCPU {
204204
mem_access_fn: Arc<Mutex<dyn MemAccessHandlerCaller>>,
205205
) -> Result<()> {
206206
loop {
207-
match hv.run()? {
208-
HyperlightExit::Halt() => {
207+
match hv.run() {
208+
Ok(HyperlightExit::Halt()) => {
209209
break;
210210
}
211-
HyperlightExit::IoOut(port, data, rip, instruction_length) => {
211+
Ok(HyperlightExit::IoOut(port, data, rip, instruction_length)) => {
212212
hv.handle_io(port, data, rip, instruction_length, outb_handle_fn.clone())?
213213
}
214-
HyperlightExit::Mmio(addr) => {
214+
Ok(HyperlightExit::Mmio(addr)) => {
215215
#[cfg(crashdump)]
216216
crashdump::crashdump_to_tempfile(hv)?;
217217

@@ -223,7 +223,10 @@ impl VirtualCPU {
223223

224224
log_then_return!("MMIO access address {:#x}", addr);
225225
}
226-
HyperlightExit::AccessViolation(addr, tried, region_permission) => {
226+
Ok(HyperlightExit::AccessViolation(addr, tried, region_permission)) => {
227+
#[cfg(crashdump)]
228+
crashdump::crashdump_to_tempfile(hv)?;
229+
227230
if region_permission.intersects(MemoryRegionFlags::STACK_GUARD) {
228231
return Err(HyperlightError::StackOverflow());
229232
}
@@ -233,7 +236,7 @@ impl VirtualCPU {
233236
region_permission
234237
));
235238
}
236-
HyperlightExit::Cancelled() => {
239+
Ok(HyperlightExit::Cancelled()) => {
237240
// Shutdown is returned when the host has cancelled execution
238241
// After termination, the main thread will re-initialize the VM
239242
if let Some(hvh) = hv_handler {
@@ -246,10 +249,19 @@ impl VirtualCPU {
246249
int_counter_inc!(&NumberOfCancelledGuestExecutions);
247250
log_then_return!(ExecutionCanceledByHost());
248251
}
249-
HyperlightExit::Unknown(reason) => {
252+
Ok(HyperlightExit::Unknown(reason)) => {
253+
#[cfg(crashdump)]
254+
crashdump::crashdump_to_tempfile(hv)?;
255+
250256
log_then_return!("Unexpected VM Exit {:?}", reason);
251257
}
252-
HyperlightExit::Retry() => continue,
258+
Ok(HyperlightExit::Retry()) => continue,
259+
Err(e) => {
260+
#[cfg(crashdump)]
261+
crashdump::crashdump_to_tempfile(hv)?;
262+
263+
return Err(e);
264+
}
253265
}
254266
}
255267

0 commit comments

Comments
 (0)