Skip to content

Commit d65d4bb

Browse files
committed
Change interrupt_handle state from AtomicU64 to AtomicU8
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 10fd6b4 commit d65d4bb

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

docs/cancellation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Hyperlight provides a mechanism to forcefully interrupt guest execution through
1010

1111
### LinuxInterruptHandle State
1212

13-
The `LinuxInterruptHandle` uses a packed atomic u64 to track execution state:
13+
The `LinuxInterruptHandle` uses a packed atomic u8 to track execution state:
1414

15-
- **state (AtomicU64)**: Packs three bits:
15+
- **state (AtomicU8)**: Packs three bits:
1616
- **Bit 2 (DEBUG_INTERRUPT_BIT)**: Set when debugger interrupt is requested (gdb feature only)
1717
- **Bit 1 (RUNNING_BIT)**: Set when vCPU is actively running in guest mode
1818
- **Bit 0 (CANCEL_BIT)**: Set when cancellation has been requested via `kill()`
@@ -255,7 +255,7 @@ While the core cancellation mechanism follows the same conceptual model on Windo
255255

256256
The `WindowsInterruptHandle` uses a simpler structure compared to Linux:
257257

258-
- **state (AtomicU64)**: Packs three bits (RUNNING_BIT, CANCEL_BIT and DEBUG_INTERRUPT_BIT)
258+
- **state (AtomicU8)**: Packs three bits (RUNNING_BIT, CANCEL_BIT and DEBUG_INTERRUPT_BIT)
259259
- **partition_handle**: Windows Hyper-V partition handle for the VM
260260
- **dropped (AtomicBool)**: Set when the corresponding VM has been dropped
261261

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate mshv_bindings;
1818
extern crate mshv_ioctls;
1919

2020
use std::fmt::{Debug, Formatter};
21-
use std::sync::atomic::{AtomicBool, AtomicU64};
21+
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64};
2222
use std::sync::{Arc, Mutex};
2323

2424
use log::{LevelFilter, error};
@@ -375,7 +375,7 @@ impl HypervLinuxDriver {
375375
})?;
376376

377377
let interrupt_handle: Arc<dyn InterruptHandleImpl> = Arc::new(LinuxInterruptHandle {
378-
state: AtomicU64::new(0),
378+
state: AtomicU8::new(0),
379379
#[cfg(all(
380380
target_arch = "x86_64",
381381
target_vendor = "unknown",

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
use std::fmt;
1818
use std::fmt::{Debug, Formatter};
1919
use std::string::String;
20-
use std::sync::atomic::{AtomicBool, AtomicU64};
20+
use std::sync::atomic::{AtomicBool, AtomicU8};
2121
use std::sync::{Arc, Mutex};
2222

2323
use log::LevelFilter;
@@ -324,7 +324,7 @@ impl HypervWindowsDriver {
324324
};
325325

326326
let interrupt_handle = Arc::new(WindowsInterruptHandle {
327-
state: AtomicU64::new(0),
327+
state: AtomicU8::new(0),
328328
partition_handle,
329329
dropped: AtomicBool::new(false),
330330
});

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
use std::fmt::Debug;
18-
use std::sync::atomic::{AtomicBool, AtomicU64};
18+
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64};
1919
use std::sync::{Arc, Mutex};
2020

2121
use kvm_bindings::{kvm_fpu, kvm_regs, kvm_sregs, kvm_userspace_memory_region};
@@ -333,7 +333,7 @@ impl KVMDriver {
333333
let rsp_gp = GuestPtr::try_from(RawPtr::from(rsp))?;
334334

335335
let interrupt_handle: Arc<dyn InterruptHandleImpl> = Arc::new(LinuxInterruptHandle {
336-
state: AtomicU64::new(0),
336+
state: AtomicU8::new(0),
337337
#[cfg(all(
338338
target_arch = "x86_64",
339339
target_vendor = "unknown",

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ pub(crate) mod crashdump;
6363

6464
use std::fmt::Debug;
6565
use std::str::FromStr;
66-
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
66+
#[cfg(any(kvm, mshv3))]
67+
use std::sync::atomic::AtomicU64;
68+
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
6769
use std::sync::{Arc, Mutex};
6870
#[cfg(any(kvm, mshv3))]
6971
use std::time::Duration;
@@ -588,7 +590,7 @@ pub(super) struct LinuxInterruptHandle {
588590
///
589591
/// CANCEL_BIT persists across vcpu exits/re-entries within a single `VirtualCPU::run()` call
590592
/// (e.g., during host function calls), but is cleared at the start of each new `VirtualCPU::run()` call.
591-
state: AtomicU64,
593+
state: AtomicU8,
592594

593595
/// Thread ID where the vcpu is running.
594596
///
@@ -608,10 +610,10 @@ pub(super) struct LinuxInterruptHandle {
608610

609611
#[cfg(any(kvm, mshv3))]
610612
impl LinuxInterruptHandle {
611-
const RUNNING_BIT: u64 = 1 << 1;
612-
const CANCEL_BIT: u64 = 1 << 0;
613+
const RUNNING_BIT: u8 = 1 << 1;
614+
const CANCEL_BIT: u8 = 1 << 0;
613615
#[cfg(gdb)]
614-
const DEBUG_INTERRUPT_BIT: u64 = 1 << 2;
616+
const DEBUG_INTERRUPT_BIT: u8 = 1 << 2;
615617

616618
/// Get the running, cancel and debug flags atomically.
617619
///
@@ -756,18 +758,18 @@ pub(super) struct WindowsInterruptHandle {
756758
///
757759
/// CANCEL_BIT persists across vcpu exits/re-entries within a single `VirtualCPU::run()` call
758760
/// (e.g., during host function calls), but is cleared at the start of each new `VirtualCPU::run()` call.
759-
state: AtomicU64,
761+
state: AtomicU8,
760762

761763
partition_handle: windows::Win32::System::Hypervisor::WHV_PARTITION_HANDLE,
762764
dropped: AtomicBool,
763765
}
764766

765767
#[cfg(target_os = "windows")]
766768
impl WindowsInterruptHandle {
767-
const RUNNING_BIT: u64 = 1 << 1;
768-
const CANCEL_BIT: u64 = 1 << 0;
769+
const RUNNING_BIT: u8 = 1 << 1;
770+
const CANCEL_BIT: u8 = 1 << 0;
769771
#[cfg(gdb)]
770-
const DEBUG_INTERRUPT_BIT: u64 = 1 << 2;
772+
const DEBUG_INTERRUPT_BIT: u8 = 1 << 2;
771773
}
772774

773775
#[cfg(target_os = "windows")]

0 commit comments

Comments
 (0)