Skip to content

Commit dbb34ad

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 dbb34ad

File tree

5 files changed

+98
-114
lines changed

5 files changed

+98
-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: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
use crate::hypervisor::get_memory_access_violation;
1718
use std::fmt;
1819
use std::fmt::{Debug, Formatter};
1920
use std::string::String;
@@ -55,8 +56,8 @@ use super::{
5556
};
5657
use super::{HyperlightExit, Hypervisor, InterruptHandle, VirtualCPU};
5758
use crate::hypervisor::fpu::FP_CONTROL_WORD_DEFAULT;
58-
use crate::hypervisor::get_memory_access_violation;
5959
use crate::hypervisor::wrappers::WHvGeneralRegisters;
60+
use crate::hypervisor::InterruptHandleInternal;
6061
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
6162
use crate::mem::ptr::{GuestPtr, RawPtr};
6263
use crate::mem::shared_mem::HostSharedMemory;
@@ -737,8 +738,12 @@ impl Hypervisor for HypervWindowsDriver {
737738

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

743748
#[cfg(not(gdb))]
744749
let debug_interrupt = false;
@@ -749,8 +754,7 @@ impl Hypervisor for HypervWindowsDriver {
749754
.load(Ordering::Relaxed);
750755

751756
// Check if cancellation was requested for THIS generation
752-
let exit_context = if self
753-
.interrupt_handle
757+
let exit_context = if interrupt_handle_internal
754758
.is_cancel_requested_for_generation(generation)
755759
|| debug_interrupt
756760
{
@@ -773,18 +777,17 @@ impl Hypervisor for HypervWindowsDriver {
773777
};
774778

775779
// Clear running bit
776-
self.interrupt_handle.clear_running_bit();
780+
interrupt_handle_internal.clear_running_bit();
777781

778782
let is_canceled = exit_context.ExitReason == WHV_RUN_VP_EXIT_REASON(8193i32); // WHvRunVpExitReasonCanceled
779783

780784
// 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);
785+
let cancel_was_requested_manually =
786+
interrupt_handle_internal.is_cancel_requested_for_generation(generation);
784787

785788
// Only clear cancel_requested if we're actually processing a cancellation for this generation
786789
if is_canceled && cancel_was_requested_manually {
787-
self.interrupt_handle.clear_cancel_requested();
790+
interrupt_handle_internal.clear_cancel_requested();
788791
}
789792

790793
#[cfg(gdb)]
@@ -915,7 +918,7 @@ impl Hypervisor for HypervWindowsDriver {
915918
Ok(result)
916919
}
917920

918-
fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
921+
fn interrupt_handle(&self) -> Arc<dyn super::InterruptHandleInternal> {
919922
self.interrupt_handle.clone()
920923
}
921924

@@ -1204,19 +1207,22 @@ impl InterruptHandle for WindowsInterruptHandle {
12041207
// Only call WHvCancelRunVirtualProcessor if VCPU is actually running in guest mode
12051208
running && unsafe { WHvCancelRunVirtualProcessor(self.partition_handle, 0, 0).is_ok() }
12061209
}
1210+
12071211
#[cfg(gdb)]
12081212
fn kill_from_debugger(&self) -> bool {
12091213
self.debug_interrupt.store(true, Ordering::Relaxed);
12101214
let (running, _) = self.get_running_and_generation();
12111215
running && unsafe { WHvCancelRunVirtualProcessor(self.partition_handle, 0, 0).is_ok() }
12121216
}
12131217

1214-
fn get_call_active(&self) -> &AtomicBool {
1215-
&self.call_active
1218+
fn dropped(&self) -> bool {
1219+
self.dropped.load(Ordering::Relaxed)
12161220
}
1221+
}
12171222

1218-
fn get_dropped(&self) -> &AtomicBool {
1219-
&self.dropped
1223+
impl InterruptHandleInternal for WindowsInterruptHandle {
1224+
fn get_call_active(&self) -> &AtomicBool {
1225+
&self.call_active
12201226
}
12211227

12221228
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)