Skip to content

Refactor Vm trait #517

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
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)]
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

why did this logic change?

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

why did this if change?

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