Skip to content

Commit e36af82

Browse files
committed
Fixes issues from merge and splits trait to expose only public method (#994)
Signed-off-by: Simon Davies <[email protected]>
1 parent 144ece0 commit e36af82

File tree

5 files changed

+129
-114
lines changed

5 files changed

+129
-114
lines changed

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use super::{
7070
CR0_AM, CR0_ET, CR0_MP, CR0_NE, CR0_PE, CR0_PG, CR0_WP, CR4_OSFXSR, CR4_OSXMMEXCPT, CR4_PAE,
7171
EFER_LMA, EFER_LME, EFER_NX, EFER_SCE,
7272
};
73-
use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, VirtualCPU};
73+
use super::{HyperlightExit, Hypervisor, LinuxInterruptHandle, VirtualCPU};
7474
#[cfg(gdb)]
7575
use crate::HyperlightError;
7676
use crate::hypervisor::get_memory_access_violation;
@@ -764,11 +764,15 @@ impl Hypervisor for HypervLinuxDriver {
764764
.tid
765765
.store(unsafe { libc::pthread_self() as u64 }, Ordering::Release);
766766
// Note: if `InterruptHandle::kill()` is called while this thread is **here**
767+
// Cast to internal trait for access to internal methods
768+
let interrupt_handle_internal =
769+
self.interrupt_handle.as_ref() as &dyn super::InterruptHandleInternal;
770+
767771
// (after set_running_bit but before checking cancel_requested):
768772
// - kill() will stamp cancel_requested with the current generation
769773
// - We will check cancel_requested below and skip the VcpuFd::run() call
770774
// - This is the desired behavior - the kill takes effect immediately
771-
let generation = self.interrupt_handle.set_running_bit();
775+
let generation = interrupt_handle_internal.set_running_bit();
772776

773777
#[cfg(not(gdb))]
774778
let debug_interrupt = false;
@@ -785,8 +789,7 @@ impl Hypervisor for HypervLinuxDriver {
785789
// - kill() will stamp cancel_requested with the current generation
786790
// - We will proceed with vcpu.run(), but signals will be sent to interrupt it
787791
// - The vcpu will be interrupted and return EINTR (handled below)
788-
let exit_reason = if self
789-
.interrupt_handle
792+
let exit_reason = if interrupt_handle_internal
790793
.is_cancel_requested_for_generation(generation)
791794
|| debug_interrupt
792795
{
@@ -818,9 +821,8 @@ impl Hypervisor for HypervLinuxDriver {
818821
// - kill() continues sending signals to this thread (running bit is still set)
819822
// - The signals are harmless (no-op handler), we just need to check cancel_requested
820823
// - We load cancel_requested below to determine if this run was cancelled
821-
let cancel_requested = self
822-
.interrupt_handle
823-
.is_cancel_requested_for_generation(generation);
824+
let cancel_requested =
825+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
824826
#[cfg(gdb)]
825827
let debug_interrupt = self
826828
.interrupt_handle
@@ -832,7 +834,7 @@ impl Hypervisor for HypervLinuxDriver {
832834
// - kill() continues sending signals until running bit is cleared
833835
// - The newly stamped cancel_requested will affect the NEXT vcpu.run() call
834836
// - Signals sent now are harmless (no-op handler)
835-
self.interrupt_handle.clear_running_bit();
837+
interrupt_handle_internal.clear_running_bit();
836838
// At this point, running bit is clear so kill() will stop sending signals.
837839
// However, we may still receive delayed signals that were sent before clear_running_bit.
838840
// These stale signals are harmless because:
@@ -927,7 +929,7 @@ impl Hypervisor for HypervLinuxDriver {
927929
// - A signal meant for a different sandbox on the same thread
928930
// In these cases, we return Retry to continue execution.
929931
if cancel_requested {
930-
self.interrupt_handle.clear_cancel_requested();
932+
interrupt_handle_internal.clear_cancel_requested();
931933
HyperlightExit::Cancelled()
932934
} else {
933935
#[cfg(gdb)]
@@ -963,7 +965,7 @@ impl Hypervisor for HypervLinuxDriver {
963965
self as &mut dyn Hypervisor
964966
}
965967

966-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
968+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
967969
self.interrupt_handle.clone()
968970
}
969971

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ use super::{
5555
};
5656
use super::{HyperlightExit, Hypervisor, InterruptHandle, VirtualCPU};
5757
use crate::hypervisor::fpu::FP_CONTROL_WORD_DEFAULT;
58-
use crate::hypervisor::get_memory_access_violation;
58+
use crate::hypervisor::regs::{CommonFpu, CommonRegisters};
5959
use crate::hypervisor::wrappers::WHvGeneralRegisters;
60+
use crate::hypervisor::{
61+
InterruptHandleInternal, get_memory_access_violation, get_memory_access_violation,
62+
};
6063
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
6164
use crate::mem::ptr::{GuestPtr, RawPtr};
6265
use crate::mem::shared_mem::HostSharedMemory;
@@ -737,8 +740,12 @@ impl Hypervisor for HypervWindowsDriver {
737740

738741
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
739742
fn run(&mut self) -> Result<super::HyperlightExit> {
743+
// Cast to internal trait for access to internal methods
744+
let interrupt_handle_internal =
745+
self.interrupt_handle.as_ref() as &dyn super::InterruptHandleInternal;
746+
740747
// Get current generation and set running bit
741-
let generation = self.interrupt_handle.set_running_bit();
748+
let generation = interrupt_handle_internal.set_running_bit();
742749

743750
#[cfg(not(gdb))]
744751
let debug_interrupt = false;
@@ -749,8 +756,7 @@ impl Hypervisor for HypervWindowsDriver {
749756
.load(Ordering::Relaxed);
750757

751758
// Check if cancellation was requested for THIS generation
752-
let exit_context = if self
753-
.interrupt_handle
759+
let exit_context = if interrupt_handle_internal
754760
.is_cancel_requested_for_generation(generation)
755761
|| debug_interrupt
756762
{
@@ -773,18 +779,17 @@ impl Hypervisor for HypervWindowsDriver {
773779
};
774780

775781
// Clear running bit
776-
self.interrupt_handle.clear_running_bit();
782+
interrupt_handle_internal.clear_running_bit();
777783

778784
let is_canceled = exit_context.ExitReason == WHV_RUN_VP_EXIT_REASON(8193i32); // WHvRunVpExitReasonCanceled
779785

780786
// Check if this was a manual cancellation (vs internal Windows cancellation)
781-
let cancel_was_requested_manually = self
782-
.interrupt_handle
783-
.is_cancel_requested_for_generation(generation);
787+
let cancel_was_requested_manually =
788+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
784789

785790
// Only clear cancel_requested if we're actually processing a cancellation for this generation
786791
if is_canceled && cancel_was_requested_manually {
787-
self.interrupt_handle.clear_cancel_requested();
792+
interrupt_handle_internal.clear_cancel_requested();
788793
}
789794

790795
#[cfg(gdb)]
@@ -915,7 +920,36 @@ impl Hypervisor for HypervWindowsDriver {
915920
Ok(result)
916921
}
917922

918-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
923+
/// Get regs
924+
#[allow(dead_code)]
925+
fn regs(&self) -> Result<CommonRegisters> {
926+
self.processor.regs()
927+
}
928+
/// Set regs
929+
fn set_regs(&mut self, regs: &CommonRegisters) -> Result<()> {
930+
self.processor.set_regs(regs)
931+
}
932+
/// Get fpu regs
933+
#[allow(dead_code)]
934+
fn fpu(&self) -> Result<CommonFpu> {
935+
self.processor.fpu()
936+
}
937+
/// Set fpu regs
938+
fn set_fpu(&mut self, fpu: &CommonFpu) -> Result<()> {
939+
self.processor.set_fpu(fpu)
940+
}
941+
/// Get special regs
942+
#[allow(dead_code)]
943+
fn sregs(&self) -> Result<CommonSpecialRegisters> {
944+
self.processor.sregs()
945+
}
946+
/// Set special regs
947+
#[allow(dead_code)]
948+
fn set_sregs(&mut self, sregs: &CommonSpecialRegisters) -> Result<()> {
949+
self.processor.set_sregs(sregs)
950+
}
951+
952+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
919953
self.interrupt_handle.clone()
920954
}
921955

@@ -1204,19 +1238,22 @@ impl InterruptHandle for WindowsInterruptHandle {
12041238
// Only call WHvCancelRunVirtualProcessor if VCPU is actually running in guest mode
12051239
running && unsafe { WHvCancelRunVirtualProcessor(self.partition_handle, 0, 0).is_ok() }
12061240
}
1241+
12071242
#[cfg(gdb)]
12081243
fn kill_from_debugger(&self) -> bool {
12091244
self.debug_interrupt.store(true, Ordering::Relaxed);
12101245
let (running, _) = self.get_running_and_generation();
12111246
running && unsafe { WHvCancelRunVirtualProcessor(self.partition_handle, 0, 0).is_ok() }
12121247
}
12131248

1214-
fn get_call_active(&self) -> &AtomicBool {
1215-
&self.call_active
1249+
fn dropped(&self) -> bool {
1250+
self.dropped.load(Ordering::Relaxed)
12161251
}
1252+
}
12171253

1218-
fn get_dropped(&self) -> &AtomicBool {
1219-
&self.dropped
1254+
impl InterruptHandleInternal for WindowsInterruptHandle {
1255+
fn get_call_active(&self) -> &AtomicBool {
1256+
&self.call_active
12201257
}
12211258

12221259
fn get_running(&self) -> &AtomicU64 {

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use super::{
3737
CR0_AM, CR0_ET, CR0_MP, CR0_NE, CR0_PE, CR0_PG, CR0_WP, CR4_OSFXSR, CR4_OSXMMEXCPT, CR4_PAE,
3838
EFER_LMA, EFER_LME, EFER_NX, EFER_SCE,
3939
};
40-
use super::{HyperlightExit, Hypervisor, InterruptHandle, LinuxInterruptHandle, VirtualCPU};
40+
use super::{HyperlightExit, Hypervisor, LinuxInterruptHandle, VirtualCPU};
4141
#[cfg(gdb)]
4242
use crate::HyperlightError;
4343
use crate::hypervisor::get_memory_access_violation;
@@ -667,11 +667,15 @@ impl Hypervisor for KVMDriver {
667667
.tid
668668
.store(unsafe { libc::pthread_self() as u64 }, Ordering::Release);
669669
// Note: if `InterruptHandle::kill()` is called while this thread is **here**
670+
// Cast to internal trait for access to internal methods
671+
let interrupt_handle_internal =
672+
self.interrupt_handle.as_ref() as &dyn super::InterruptHandleInternal;
673+
670674
// (after set_running_bit but before checking cancel_requested):
671675
// - kill() will stamp cancel_requested with the current generation
672676
// - We will check cancel_requested below and skip the VcpuFd::run() call
673677
// - This is the desired behavior - the kill takes effect immediately
674-
let generation = self.interrupt_handle.set_running_bit();
678+
let generation = interrupt_handle_internal.set_running_bit();
675679

676680
#[cfg(not(gdb))]
677681
let debug_interrupt = false;
@@ -687,8 +691,7 @@ impl Hypervisor for KVMDriver {
687691
// - kill() will stamp cancel_requested with the current generation
688692
// - We will proceed with vcpu.run(), but signals will be sent to interrupt it
689693
// - The vcpu will be interrupted and return EINTR (handled below)
690-
let exit_reason = if self
691-
.interrupt_handle
694+
let exit_reason = if interrupt_handle_internal
692695
.is_cancel_requested_for_generation(generation)
693696
|| debug_interrupt
694697
{
@@ -716,9 +719,8 @@ impl Hypervisor for KVMDriver {
716719
// - kill() continues sending signals to this thread (running bit is still set)
717720
// - The signals are harmless (no-op handler), we just need to check cancel_requested
718721
// - We load cancel_requested below to determine if this run was cancelled
719-
let cancel_requested = self
720-
.interrupt_handle
721-
.is_cancel_requested_for_generation(generation);
722+
let cancel_requested =
723+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
722724
#[cfg(gdb)]
723725
let debug_interrupt = self
724726
.interrupt_handle
@@ -730,7 +732,7 @@ impl Hypervisor for KVMDriver {
730732
// - kill() continues sending signals until running bit is cleared
731733
// - The newly stamped cancel_requested will affect the NEXT vcpu.run() call
732734
// - Signals sent now are harmless (no-op handler)
733-
self.interrupt_handle.clear_running_bit();
735+
interrupt_handle_internal.clear_running_bit();
734736
// At this point, running bit is clear so kill() will stop sending signals.
735737
// However, we may still receive delayed signals that were sent before clear_running_bit.
736738
// These stale signals are harmless because:
@@ -794,7 +796,7 @@ impl Hypervisor for KVMDriver {
794796
// - A signal meant for a different sandbox on the same thread
795797
// In these cases, we return Retry to continue execution.
796798
if cancel_requested {
797-
self.interrupt_handle.clear_cancel_requested();
799+
interrupt_handle_internal.clear_cancel_requested();
798800
HyperlightExit::Cancelled()
799801
} else {
800802
#[cfg(gdb)]
@@ -835,7 +837,7 @@ impl Hypervisor for KVMDriver {
835837
self as &mut dyn Hypervisor
836838
}
837839

838-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
840+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
839841
self.interrupt_handle.clone()
840842
}
841843

0 commit comments

Comments
 (0)