Skip to content

Vm trait for reducing code duplication #469

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

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2692982
Started on changing trait
ludfjig May 7, 2025
39a7d13
mshv 'working'
ludfjig May 8, 2025
a003c8a
GDB working again (TODO: entrypoint hardcoded
ludfjig May 8, 2025
4dccf79
GDB working on kvm
ludfjig May 9, 2025
d2d6046
save
ludfjig May 12, 2025
f317d7d
cleanup
ludfjig May 12, 2025
b7d2bbc
fix up crashdump
ludfjig May 12, 2025
0a536c4
Move files around
ludfjig May 12, 2025
b5bbe6d
MSHV3 done
ludfjig May 12, 2025
ec06c04
clippy
ludfjig May 12, 2025
b4767f1
Merge branch 'main' into vm_trait
ludfjig May 12, 2025
7be03b0
Merge branch 'main' into vm_trait
ludfjig May 12, 2025
e0a5254
fmt
ludfjig May 12, 2025
5f9e80f
Windows kinda working
ludfjig May 13, 2025
7e02b7e
Windows working
ludfjig May 14, 2025
ec9c0f7
Merge branch 'main' into vm_trait
ludfjig May 14, 2025
300d071
rename some things
ludfjig May 14, 2025
ad4b41c
Merge branch 'main' into vm_trait
ludfjig May 14, 2025
de1cb48
Add round trip tests
ludfjig May 14, 2025
de0acbf
Windows done
ludfjig May 15, 2025
ca0916f
Fix things
ludfjig May 15, 2025
792722e
GOGO
ludfjig May 15, 2025
3e822f3
Typos
ludfjig May 15, 2025
1156003
No fail fast
ludfjig May 15, 2025
2a6e29e
Fix stack guard
ludfjig May 15, 2025
bb654aa
Fix windows stack guard
ludfjig May 15, 2025
bbedcab
Fix some referencing of regs
ludfjig May 15, 2025
999fa37
Debug CI
ludfjig May 15, 2025
31bfc5a
Add debugging logs for testing purpose
ludfjig May 15, 2025
39f79d8
Merge branch 'main' into vm_trait
ludfjig May 15, 2025
fdffe93
Add more debugging
ludfjig May 15, 2025
a1861df
as_ptr() -> as_ref().as_ptr()
ludfjig May 15, 2025
c7efb05
More debugging println
ludfjig May 15, 2025
c2c32c6
Remove tracing from test
ludfjig May 15, 2025
b181808
Remove comments again
ludfjig May 16, 2025
4b19772
Remove half of comments
ludfjig May 16, 2025
9b0a88d
Merge branch 'main' into vm_trait
ludfjig May 16, 2025
d62f533
Remove more comments
ludfjig May 16, 2025
afd79df
Print name only
ludfjig May 16, 2025
a9a1e5d
Static + no printing
ludfjig May 16, 2025
76fa02b
Some windows cleanup
ludfjig May 18, 2025
6c4ca58
Ctrl+c in gdb works on kvm and whp
ludfjig May 18, 2025
fb4990a
simplify hw logic
ludfjig May 18, 2025
c9bf37f
Some typos and const cleanup
ludfjig May 18, 2025
32a25d2
Fix constant
ludfjig May 18, 2025
e5303e7
Test static->const again to see if it fails on windows
ludfjig May 18, 2025
7e0b1fc
back to static
ludfjig May 18, 2025
d7bc96c
Merge branch 'main' into vm_trait
ludfjig May 19, 2025
5bbc400
Undo testing changes
ludfjig May 21, 2025
b4398fb
Merge branch 'main' into vm_trait
ludfjig May 21, 2025
e5f03c2
Remove unused var
ludfjig May 21, 2025
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
10 changes: 5 additions & 5 deletions src/hyperlight_host/src/hypervisor/crashdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use std::io::Write;

use tempfile::NamedTempFile;

use super::Hypervisor;
use super::hyperlight_vm::HyperlightSandbox;
use crate::hypervisor::HyperlightVm;
use crate::{new_error, Result};

/// Dump registers + memory regions + raw memory to a tempfile
#[cfg(crashdump)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're wondering why this was removed, it's because this entire crashdump module is already gated on this

pub(crate) fn crashdump_to_tempfile(hv: &dyn Hypervisor) -> Result<()> {
pub(crate) fn crashdump_to_tempfile(vm: &HyperlightSandbox) -> Result<()> {
let mut temp_file = NamedTempFile::with_prefix("mem")?;
let hv_details = format!("{:#x?}", hv);
let hv_details = format!("{:#x?}", vm);

// write hypervisor details such as registers, info about mapped memory regions, etc.
temp_file.write_all(hv_details.as_bytes())?;
temp_file.write_all(b"================ MEMORY DUMP =================\n")?;

// write the raw memory dump for each memory region
for region in hv.get_memory_regions() {
for region in vm.get_memory_regions() {
if region.host_region.start == 0 || region.host_region.is_empty() {
continue;
}
Expand Down
19 changes: 0 additions & 19 deletions src/hyperlight_host/src/hypervisor/fpu.rs

This file was deleted.

42 changes: 18 additions & 24 deletions src/hyperlight_host/src/hypervisor/gdb/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ limitations under the License.

//! This file contains architecture specific code for the x86_64

use std::collections::HashMap;

use super::VcpuStopReason;
use crate::hypervisor::regs::CommonRegisters;
use crate::hypervisor::vm::Vm;
use crate::Result;

// Described in Table 6-1. Exceptions and Interrupts at Page 6-13 Vol. 1
// of Intel 64 and IA-32 Architectures Software Developer's Manual
/// Exception id for #DB
const DB_EX_ID: u32 = 1;
pub(crate) const DB_EX_ID: u32 = 1;
/// Exception id for #BP - triggered by the INT3 instruction
const BP_EX_ID: u32 = 3;
pub(crate) const BP_EX_ID: u32 = 3;

/// Software Breakpoint size in memory
pub(crate) const SW_BP_SIZE: usize = 1;
Expand Down Expand Up @@ -54,58 +55,51 @@ pub(crate) const DR6_HW_BP_FLAGS_MASK: u64 = 0x0F << DR6_HW_BP_FLAGS_POS;
/// NOTE: Additional checks are done for the entrypoint, stored hw_breakpoints
/// and sw_breakpoints to ensure the stop reason is valid with internal state
pub(crate) fn vcpu_stop_reason(
single_step: bool,
rip: u64,
dr6: u64,
vm: &mut dyn Vm,
entrypoint: u64,
dr6: u64,
exception: u32,
hw_breakpoints: &[u64],
sw_breakpoints: &HashMap<u64, [u8; SW_BP_SIZE]>,
) -> VcpuStopReason {
) -> Result<VcpuStopReason> {
let CommonRegisters { rip, .. } = vm.get_regs()?;
if DB_EX_ID == exception {
// If the BS flag in DR6 register is set, it means a single step
// instruction triggered the exit
// Check page 19-4 Vol. 3B of Intel 64 and IA-32
// Architectures Software Developer's Manual
if dr6 & DR6_BS_FLAG_MASK != 0 && single_step {
return VcpuStopReason::DoneStep;
if dr6 & DR6_BS_FLAG_MASK != 0 {
return Ok(VcpuStopReason::DoneStep);
}

// If any of the B0-B3 flags in DR6 register is set, it means a
// hardware breakpoint triggered the exit
// Check page 19-4 Vol. 3B of Intel 64 and IA-32
// Architectures Software Developer's Manual
if DR6_HW_BP_FLAGS_MASK & dr6 != 0 && hw_breakpoints.contains(&rip) {
if DR6_HW_BP_FLAGS_MASK & dr6 != 0 {
if rip == entrypoint {
return VcpuStopReason::EntryPointBp;
vm.remove_hw_breakpoint(entrypoint)?;
return Ok(VcpuStopReason::EntryPointBp);
}
return VcpuStopReason::HwBp;
return Ok(VcpuStopReason::HwBp);
}
}

if BP_EX_ID == exception && sw_breakpoints.contains_key(&rip) {
return VcpuStopReason::SwBp;
if BP_EX_ID == exception {
return Ok(VcpuStopReason::SwBp);
}

// Log an error and provide internal debugging info
log::error!(
r"The vCPU exited because of an unknown reason:
single_step: {:?}
rip: {:?}
dr6: {:?}
entrypoint: {:?}
exception: {:?}
hw_breakpoints: {:?}
sw_breakpoints: {:?}
",
single_step,
rip,
dr6,
entrypoint,
exception,
hw_breakpoints,
sw_breakpoints,
);

VcpuStopReason::Unknown
Ok(VcpuStopReason::Unknown)
}
243 changes: 0 additions & 243 deletions src/hyperlight_host/src/hypervisor/gdb/kvm_debug.rs

This file was deleted.

Loading
Loading