Skip to content

Commit c34ddfa

Browse files
Copilotjsturtevant
andcommitted
Remove misleading boolean return from InterruptHandle::kill()
Co-authored-by: jsturtevant <[email protected]>
1 parent f936bc0 commit c34ddfa

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

docs/cancellation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ sequenceDiagram
166166
end
167167
168168
deactivate IH
169-
IH-->>Caller: sent_signal
170169
deactivate IH
171170
```
172171

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn bench_guest_call_interrupt_latency(b: &mut criterion::Bencher, size: SandboxS
245245
// Small delay to ensure the guest function is running in VM before interrupting
246246
thread::sleep(std::time::Duration::from_millis(10));
247247
let kill_start = Instant::now();
248-
assert!(interrupt_handle.kill());
248+
interrupt_handle.kill();
249249
kill_start
250250
});
251251

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ pub(crate) trait InterruptHandleImpl: InterruptHandle {
208208
pub trait InterruptHandle: Send + Sync + Debug {
209209
/// Interrupt the corresponding sandbox from running.
210210
///
211-
/// - If this is called while the the sandbox currently executing a guest function call, it will interrupt the sandbox and return `true`.
212-
/// - If this is called while the sandbox is not running (for example before or after calling a guest function), it will do nothing and return `false`.
211+
/// This method sets a cancellation flag that prevents or stops the execution of guest code:
212+
/// - If called while the sandbox is currently executing a guest function, it will interrupt the vCPU.
213+
/// - If called before the sandbox starts executing (e.g., before a guest function call), it will prevent execution from starting.
213214
///
214215
/// # Note
215216
/// This function will block for the duration of the time it takes for the vcpu thread to be interrupted.
216-
fn kill(&self) -> bool;
217+
fn kill(&self);
217218

218219
/// Used by a debugger to interrupt the corresponding sandbox from running.
219220
///
@@ -374,13 +375,13 @@ impl InterruptHandleImpl for LinuxInterruptHandle {
374375

375376
#[cfg(any(kvm, mshv3))]
376377
impl InterruptHandle for LinuxInterruptHandle {
377-
fn kill(&self) -> bool {
378+
fn kill(&self) {
378379
// Release ordering ensures that any writes before kill() are visible to the vcpu thread
379380
// when it checks is_cancelled() with Acquire ordering
380381
self.state.fetch_or(Self::CANCEL_BIT, Ordering::Release);
381382

382383
// Send signals to interrupt the vcpu if it's currently running
383-
self.send_signal()
384+
self.send_signal();
384385
}
385386

386387
#[cfg(gdb)]
@@ -513,7 +514,7 @@ impl InterruptHandleImpl for WindowsInterruptHandle {
513514

514515
#[cfg(target_os = "windows")]
515516
impl InterruptHandle for WindowsInterruptHandle {
516-
fn kill(&self) -> bool {
517+
fn kill(&self) {
517518
use windows::Win32::System::Hypervisor::WHvCancelRunVirtualProcessor;
518519

519520
// Release ordering ensures that any writes before kill() are visible to the vcpu thread
@@ -524,7 +525,7 @@ impl InterruptHandle for WindowsInterruptHandle {
524525
// This ensures we see the running state set by the vcpu thread
525526
let state = self.state.load(Ordering::Acquire);
526527
if state & Self::RUNNING_BIT == 0 {
527-
return false;
528+
return;
528529
}
529530

530531
// Take read lock to prevent race with WHvDeletePartition in set_dropped().
@@ -534,15 +535,15 @@ impl InterruptHandle for WindowsInterruptHandle {
534535
Ok(guard) => guard,
535536
Err(e) => {
536537
log::error!("Failed to acquire partition_state read lock: {}", e);
537-
return false;
538+
return;
538539
}
539540
};
540541

541542
if guard.dropped {
542-
return false;
543+
return;
543544
}
544545

545-
unsafe { WHvCancelRunVirtualProcessor(guard.handle, 0, 0).is_ok() }
546+
unsafe { WHvCancelRunVirtualProcessor(guard.handle, 0, 0).ok() };
546547
}
547548
#[cfg(gdb)]
548549
fn kill_from_debugger(&self) -> bool {

src/hyperlight_host/src/metrics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mod tests {
118118
// interrupt the guest function call to "Spin" after 1 second
119119
let thread = thread::spawn(move || {
120120
thread::sleep(Duration::from_secs(1));
121-
assert!(interrupt_handle.kill());
121+
interrupt_handle.kill();
122122
});
123123

124124
multi

src/hyperlight_host/tests/integration_test.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn interrupt_in_progress_guest_call() {
8787
// kill vm after 1 second
8888
let thread = thread::spawn(move || {
8989
thread::sleep(Duration::from_secs(1));
90-
assert!(interrupt_handle.kill());
90+
interrupt_handle.kill();
9191
barrier2.wait(); // wait here until main thread has returned from the interrupted guest call
9292
barrier2.wait(); // wait here until main thread has dropped the sandbox
9393
assert!(interrupt_handle.dropped());
@@ -122,7 +122,7 @@ fn interrupt_guest_call_in_advance() {
122122

123123
// kill vm before the guest call has started
124124
let thread = thread::spawn(move || {
125-
assert!(!interrupt_handle.kill()); // should return false since vcpu is not running yet
125+
interrupt_handle.kill();
126126
barrier2.wait();
127127
barrier2.wait(); // wait here until main thread has dropped the sandbox
128128
assert!(interrupt_handle.dropped());
@@ -274,10 +274,9 @@ fn interrupt_moved_sandbox() {
274274
let thread2 = thread::spawn(move || {
275275
barrier.wait();
276276
thread::sleep(Duration::from_secs(1));
277-
assert!(interrupt_handle.kill());
277+
interrupt_handle.kill();
278278

279-
// make sure this returns true, which means the sandbox wasn't killed incorrectly before
280-
assert!(interrupt_handle2.kill());
279+
interrupt_handle2.kill();
281280
});
282281

283282
let res = sbox2.call::<i32>("Spin", ()).unwrap_err();

0 commit comments

Comments
 (0)