Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/dep_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
env:
CARGO_TERM_COLOR: always
RUST_LOG: debug
run: just test-rust-tracing ${{ matrix.config }} ${{ matrix.hypervisor == 'mshv2' && 'mshv2' || ''}}
run: just test-rust-tracing ${{ matrix.config }} ${{ matrix.hypervisor == 'mshv' && 'mshv2' || ''}}

- name: Download benchmarks from "latest"
run: just bench-download ${{ runner.os }} ${{ matrix.hypervisor }} ${{ matrix.cpu}} dev-latest # compare to prerelease
Expand Down
12 changes: 8 additions & 4 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ test-rust-tracing target=default-target features="":
just build-rust-guests {{ target }} trace_guest
just move-rust-guests {{ target }}
# Run hello-world example with tracing enabled to get the trace output
# Capture the trace file path and print use it afterwards to run cargo run -p trace_dump
cargo run --profile={{ if target == "debug" { "dev" } else { target } }} --example hello-world --features {{ if features =="" {'trace_guest'} else { "trace_guest," + features } }} \
| sed -n 's/.*Creating trace file at: \(.*\)/\1/p' \
| xargs -I {} cargo run -p trace_dump ./{{ simpleguest_source }}/{{ target }}/simpleguest {} list_frames
TRACE_OUTPUT="$(cargo run --profile={{ if target == "debug" { "dev" } else { target } }} --example hello-world --features {{ if features =="" {"trace_guest"} else { "trace_guest," + features } }})" && \
TRACE_FILE="$(echo "$TRACE_OUTPUT" | grep -oE 'Creating trace file at: [^ ]+' | awk -F': ' '{print $2}')" && \
echo "$TRACE_OUTPUT" && \
if [ -z "$TRACE_FILE" ]; then \
echo "Error: Could not extract trace file path from output." >&2 ; \
exit 1 ; \
fi && \
cargo run -p trace_dump ./{{ simpleguest_source }}/{{ target }}/simpleguest "$TRACE_FILE" list_frames

# Rebuild the tracing guests without the tracing feature
# This is to ensure that the tracing feature does not affect the other tests
Expand Down
27 changes: 10 additions & 17 deletions src/hyperlight_host/src/hypervisor/hyperv_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,24 +609,11 @@ impl Hypervisor for HypervLinuxDriver {
};
self.vcpu_fd.set_regs(&regs)?;

// Extract mem_mgr to avoid borrowing conflicts
let mem_mgr = self
.mem_mgr
.take()
.ok_or_else(|| new_error!("mem_mgr should be initialized"))?;

let result = VirtualCPU::run(
VirtualCPU::run(
self.as_mut_hypervisor(),
&mem_mgr,
#[cfg(gdb)]
dbg_mem_access_fn,
);

// Put mem_mgr back
self.mem_mgr = Some(mem_mgr);
result?;

Ok(())
)
}

#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
Expand Down Expand Up @@ -664,7 +651,6 @@ impl Hypervisor for HypervLinuxDriver {
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
mem_mgr: &MemMgrWrapper<HostSharedMemory>,
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
) -> Result<()> {
// Reset general purpose registers, then set RIP and RSP
Expand All @@ -688,7 +674,6 @@ impl Hypervisor for HypervLinuxDriver {
// run
VirtualCPU::run(
self.as_mut_hypervisor(),
mem_mgr,
#[cfg(gdb)]
dbg_mem_access_fn,
)?;
Expand Down Expand Up @@ -1162,6 +1147,14 @@ impl Hypervisor for HypervLinuxDriver {
Ok(())
}

fn check_stack_guard(&self) -> Result<bool> {
if let Some(mgr) = self.mem_mgr.as_ref() {
mgr.check_stack_guard()
} else {
Err(new_error!("Memory manager is not initialized"))
}
}

#[cfg(feature = "trace_guest")]
fn read_trace_reg(&self, reg: TraceRegister) -> Result<u64> {
let mut assoc = [hv_register_assoc {
Expand Down
27 changes: 10 additions & 17 deletions src/hyperlight_host/src/hypervisor/hyperv_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,24 +623,11 @@ impl Hypervisor for HypervWindowsDriver {
};
self.processor.set_general_purpose_registers(&regs)?;

// Extract mem_mgr to avoid borrowing conflicts
let mem_mgr = self
.mem_mgr
.take()
.ok_or_else(|| new_error!("mem_mgr should be initialized"))?;

let result = VirtualCPU::run(
VirtualCPU::run(
self.as_mut_hypervisor(),
&mem_mgr,
#[cfg(gdb)]
dbg_mem_access_hdl,
);

// Put mem_mgr back
self.mem_mgr = Some(mem_mgr);
result?;

Ok(())
)
}

#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
Expand All @@ -662,7 +649,6 @@ impl Hypervisor for HypervWindowsDriver {
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
mem_mgr: &MemMgrWrapper<HostSharedMemory>,
#[cfg(gdb)] dbg_mem_access_hdl: DbgMemAccessHandlerWrapper,
) -> Result<()> {
// Reset general purpose registers, then set RIP and RSP
Expand All @@ -684,7 +670,6 @@ impl Hypervisor for HypervWindowsDriver {

VirtualCPU::run(
self.as_mut_hypervisor(),
mem_mgr,
#[cfg(gdb)]
dbg_mem_access_hdl,
)?;
Expand Down Expand Up @@ -1094,6 +1079,14 @@ impl Hypervisor for HypervWindowsDriver {
Ok(())
}

fn check_stack_guard(&self) -> Result<bool> {
if let Some(mgr) = self.mem_mgr.as_ref() {
mgr.check_stack_guard()
} else {
Err(new_error!("Memory manager is not initialized"))
}
}

#[cfg(feature = "trace_guest")]
fn read_trace_reg(&self, reg: TraceRegister) -> Result<u64> {
let regs = self.processor.get_regs()?;
Expand Down
27 changes: 10 additions & 17 deletions src/hyperlight_host/src/hypervisor/kvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,24 +492,11 @@ impl Hypervisor for KVMDriver {
};
self.vcpu_fd.set_regs(&regs)?;

// Extract mem_mgr to avoid borrowing conflicts
let mem_mgr = self
.mem_mgr
.take()
.ok_or_else(|| new_error!("mem_mgr should be initialized"))?;

let result = VirtualCPU::run(
VirtualCPU::run(
self.as_mut_hypervisor(),
&mem_mgr,
#[cfg(gdb)]
dbg_mem_access_fn,
);

// Put mem_mgr back
self.mem_mgr = Some(mem_mgr);
result?;

Ok(())
)
}

#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
Expand Down Expand Up @@ -555,7 +542,6 @@ impl Hypervisor for KVMDriver {
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
mem_mgr: &MemMgrWrapper<HostSharedMemory>,
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
) -> Result<()> {
// Reset general purpose registers, then set RIP and RSP
Expand All @@ -578,7 +564,6 @@ impl Hypervisor for KVMDriver {
// run
VirtualCPU::run(
self.as_mut_hypervisor(),
mem_mgr,
#[cfg(gdb)]
dbg_mem_access_fn,
)?;
Expand Down Expand Up @@ -1012,6 +997,14 @@ impl Hypervisor for KVMDriver {
Ok(())
}

fn check_stack_guard(&self) -> Result<bool> {
if let Some(mgr) = self.mem_mgr.as_ref() {
mgr.check_stack_guard()
} else {
Err(new_error!("Memory manager is not initialized"))
}
}

#[cfg(feature = "trace_guest")]
fn read_trace_reg(&self, reg: TraceRegister) -> Result<u64> {
let regs = self.vcpu_fd.get_regs()?;
Expand Down
7 changes: 4 additions & 3 deletions src/hyperlight_host/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ pub(crate) trait Hypervisor: Debug + Send {
fn dispatch_call_from_host(
&mut self,
dispatch_func_addr: RawPtr,
mem_mgr: &MemMgrWrapper<HostSharedMemory>,
#[cfg(gdb)] dbg_mem_access_fn: DbgMemAccessHandlerWrapper,
) -> Result<()>;

Expand Down Expand Up @@ -269,6 +268,9 @@ pub(crate) trait Hypervisor: Debug + Send {
unimplemented!()
}

/// Check stack guard to see if the stack is still valid
fn check_stack_guard(&self) -> Result<bool>;

/// Read a register for trace/unwind purposes
#[cfg(feature = "trace_guest")]
fn read_trace_reg(&self, reg: TraceRegister) -> Result<u64>;
Expand All @@ -289,7 +291,6 @@ impl VirtualCPU {
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
pub(crate) fn run(
hv: &mut dyn Hypervisor,
mem_mgr: &MemMgrWrapper<HostSharedMemory>,
#[cfg(gdb)] dbg_mem_access_fn: Arc<Mutex<dyn DbgMemAccessHandlerCaller>>,
) -> Result<()> {
loop {
Expand All @@ -311,7 +312,7 @@ impl VirtualCPU {
#[cfg(crashdump)]
crashdump::generate_crashdump(hv)?;

handle_mem_access(mem_mgr)?;
handle_mem_access(hv)?;

log_then_return!("MMIO access address {:#x}", addr);
}
Expand Down
1 change: 0 additions & 1 deletion src/hyperlight_host/src/sandbox/initialized_multi_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ impl MultiUseSandbox {

self.vm.dispatch_call_from_host(
self.dispatch_ptr.clone(),
&self.mem_mgr,
#[cfg(gdb)]
self.dbg_mem_access_fn.clone(),
)?;
Expand Down
7 changes: 5 additions & 2 deletions src/hyperlight_host/src/sandbox/mem_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ use std::sync::{Arc, Mutex};

use tracing::{Span, instrument};

#[cfg(gdb)]
use super::mem_mgr::MemMgrWrapper;
use crate::error::HyperlightError::StackOverflow;
use crate::hypervisor::Hypervisor;
#[cfg(gdb)]
use crate::hypervisor::handlers::{DbgMemAccessHandlerCaller, DbgMemAccessHandlerWrapper};
#[cfg(gdb)]
use crate::mem::shared_mem::HostSharedMemory;
use crate::{Result, log_then_return};

#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
pub(crate) fn handle_mem_access(wrapper: &MemMgrWrapper<HostSharedMemory>) -> Result<()> {
if !wrapper.check_stack_guard()? {
pub(crate) fn handle_mem_access(hv: &dyn Hypervisor) -> Result<()> {
if !hv.check_stack_guard()? {
log_then_return!(StackOverflow());
}

Expand Down
8 changes: 4 additions & 4 deletions src/tests/rust_guests/witguest/Cargo.lock

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

Loading