Skip to content

Commit 564aacb

Browse files
authored
refactor: replace init-paging feature with nanvix-unstable (#1291)
Make init-paging behavior (CoW guest paging) always-on by removing it from the feature definitions and all cfg gates. Add a new nanvix-unstable feature that opts out of CoW paging for guests that manage their own page tables (e.g., Nanvix). This inverts the polarity: previously you opted IN to init-paging, now you opt IN to nanvix-unstable to disable it. Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent b1028ae commit 564aacb

File tree

15 files changed

+53
-53
lines changed

15 files changed

+53
-53
lines changed

Justfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ test-like-ci config=default-target hypervisor="kvm":
8484
@# with default features
8585
just test {{config}}
8686

87-
@# with only one driver enabled + build-metadata + init-paging
88-
just test {{config}} build-metadata,init-paging,{{ if hypervisor == "mshv3" {"mshv3"} else {"kvm"} }}
87+
@# with only one driver enabled + build-metadata
88+
just test {{config}} build-metadata,{{ if hypervisor == "mshv3" {"mshv3"} else {"kvm"} }}
8989

9090
@# make sure certain cargo features compile
9191
just check
@@ -212,31 +212,31 @@ test target=default-target features="": (test-unit target features) (test-isolat
212212

213213
# runs unit tests
214214
test-unit target=default-target features="":
215-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --lib
215+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --lib
216216

217217
# runs tests that requires being run separately, for example due to global state
218218
test-isolated target=default-target features="" :
219-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_log_trace --exact --ignored
220-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::outb::tests::test_log_outb_log --exact --ignored
221-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --test integration_test -- log_message --exact --ignored
219+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_log_trace --exact --ignored
220+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::outb::tests::test_log_outb_log --exact --ignored
221+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --test integration_test -- log_message --exact --ignored
222222
@# metrics tests
223-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F function_call_metrics,init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- metrics::tests::test_metrics_are_emitted --exact
223+
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- metrics::tests::test_metrics_are_emitted --exact
224224

225225
# runs integration tests
226226
test-integration target=default-target features="":
227227
@# run execute_on_heap test with feature "executable_heap" on (runs with off during normal tests)
228-
{{ cargo-cmd }} test {{ if features =="" {"--features executable_heap"} else if features=="no-default-features" {"--no-default-features --features executable_heap"} else {"--no-default-features -F init-paging,executable_heap," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test integration_test execute_on_heap
228+
{{ cargo-cmd }} test {{ if features =="" {"--features executable_heap"} else if features=="no-default-features" {"--no-default-features --features executable_heap"} else {"--no-default-features -F executable_heap," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test integration_test execute_on_heap
229229

230230
@# run the rest of the integration tests
231-
{{ cargo-cmd }} test -p hyperlight-host {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test '*'
231+
{{ cargo-cmd }} test -p hyperlight-host {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} --test '*'
232232

233233
# tests compilation with no default features on different platforms
234234
test-compilation-no-default-features target=default-target:
235235
@# Linux should fail without a hypervisor feature (kvm or mshv3)
236236
{{ if os() == "linux" { "! " + cargo-cmd + " check -p hyperlight-host --no-default-features "+target-triple-flag+" 2> /dev/null" } else { "" } }}
237237
@# Windows should succeed even without default features
238238
{{ if os() == "windows" { cargo-cmd + " check -p hyperlight-host --no-default-features" } else { "" } }}
239-
@# Linux should succeed with a hypervisor driver but without init-paging
239+
@# Linux should succeed with a hypervisor driver but without default features
240240
{{ if os() == "linux" { cargo-cmd + " check -p hyperlight-host --no-default-features --features kvm" } else { "" } }} {{ target-triple-flag }}
241241
{{ if os() == "linux" { cargo-cmd + " check -p hyperlight-host --no-default-features --features mshv3" } else { "" } }} {{ target-triple-flag }}
242242

src/hyperlight_common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fuzzing = ["dep:arbitrary"]
3131
trace_guest = []
3232
mem_profile = []
3333
std = ["thiserror/std", "log/std", "tracing/std"]
34-
init-paging = []
34+
nanvix-unstable = []
3535

3636
[lib]
3737
bench = false # see https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options

src/hyperlight_guest_bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macros = ["dep:hyperlight-guest-macro", "dep:linkme"]
2323

2424
[dependencies]
2525
hyperlight-guest = { workspace = true, default-features = false }
26-
hyperlight-common = { workspace = true, default-features = false, features = [ "init-paging" ] }
26+
hyperlight-common = { workspace = true, default-features = false }
2727
hyperlight-guest-tracing = { workspace = true, default-features = false }
2828
hyperlight-guest-macro = { workspace = true, default-features = false, optional = true }
2929
buddy_system_allocator = "0.12.0"

src/hyperlight_host/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tracing = { version = "0.1.44", features = ["log"] }
4040
tracing-log = "0.2.0"
4141
tracing-core = "0.1.36"
4242
tracing-opentelemetry = { version = "0.32.1", optional = true }
43-
hyperlight-common = { workspace = true, default-features = true, features = [ "std", "init-paging" ] }
43+
hyperlight-common = { workspace = true, default-features = true, features = [ "std" ] }
4444
hyperlight-guest-tracing = { workspace = true, default-features = true, optional = true }
4545
vmm-sys-util = "0.15.0"
4646
crossbeam-channel = "0.5.15"
@@ -122,7 +122,7 @@ cfg_aliases = "0.2.1"
122122
built = { version = "0.8.0", optional = true, features = ["chrono", "git2"] }
123123

124124
[features]
125-
default = ["kvm", "mshv3", "build-metadata", "init-paging"]
125+
default = ["kvm", "mshv3", "build-metadata"]
126126
function_call_metrics = []
127127
executable_heap = []
128128
# This feature enables printing of debug information to stdout in debug builds
@@ -137,7 +137,7 @@ mshv3 = ["dep:mshv-bindings", "dep:mshv-ioctls"]
137137
gdb = ["dep:gdbstub", "dep:gdbstub_arch"]
138138
fuzzing = ["hyperlight-common/fuzzing"]
139139
build-metadata = ["dep:built"]
140-
init-paging = []
140+
nanvix-unstable = []
141141

142142
[[bench]]
143143
name = "benchmarks"

src/hyperlight_host/src/hypervisor/hyperlight_vm.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ impl HyperlightVm {
443443
None => return Err(CreateHyperlightVmError::NoHypervisorFound),
444444
};
445445

446-
#[cfg(feature = "init-paging")]
446+
#[cfg(not(feature = "nanvix-unstable"))]
447447
vm.set_sregs(&CommonSpecialRegisters::standard_64bit_defaults(_pml4_addr))
448448
.map_err(VmError::Register)?;
449-
#[cfg(not(feature = "init-paging"))]
449+
#[cfg(feature = "nanvix-unstable")]
450450
vm.set_sregs(&CommonSpecialRegisters::standard_real_mode_defaults())
451451
.map_err(VmError::Register)?;
452452

@@ -691,16 +691,16 @@ impl HyperlightVm {
691691

692692
/// Get the current base page table physical address.
693693
///
694-
/// With `init-paging`, reads CR3 from the vCPU special registers.
695-
/// Without `init-paging`, returns 0 (identity-mapped, no page tables).
694+
/// By default, reads CR3 from the vCPU special registers.
695+
/// With `nanvix-unstable`, returns 0 (identity-mapped, no page tables).
696696
pub(crate) fn get_root_pt(&self) -> Result<u64, AccessPageTableError> {
697-
#[cfg(feature = "init-paging")]
697+
#[cfg(not(feature = "nanvix-unstable"))]
698698
{
699699
let sregs = self.vm.sregs()?;
700700
// Mask off the flags bits
701701
Ok(sregs.cr3 & !0xfff_u64)
702702
}
703-
#[cfg(not(feature = "init-paging"))]
703+
#[cfg(feature = "nanvix-unstable")]
704704
{
705705
Ok(0)
706706
}
@@ -1043,7 +1043,7 @@ impl HyperlightVm {
10431043
self.vm.set_debug_regs(&CommonDebugRegs::default())?;
10441044
self.vm.reset_xsave()?;
10451045

1046-
#[cfg(feature = "init-paging")]
1046+
#[cfg(not(feature = "nanvix-unstable"))]
10471047
{
10481048
// Restore the full special registers from snapshot, but update CR3
10491049
// to point to the new (relocated) page tables
@@ -1052,11 +1052,11 @@ impl HyperlightVm {
10521052
self.pending_tlb_flush = true;
10531053
self.vm.set_sregs(&sregs)?;
10541054
}
1055-
#[cfg(not(feature = "init-paging"))]
1055+
#[cfg(feature = "nanvix-unstable")]
10561056
{
10571057
let _ = (cr3, sregs); // suppress unused warnings
10581058
// TODO: This is probably not correct.
1059-
// Let's deal with it when we clean up the init-paging feature
1059+
// Let's deal with it when we clean up the nanvix-unstable feature
10601060
self.vm
10611061
.set_sregs(&CommonSpecialRegisters::standard_real_mode_defaults())?;
10621062
}
@@ -1591,7 +1591,7 @@ mod debug {
15911591
}
15921592

15931593
#[cfg(test)]
1594-
#[cfg(feature = "init-paging")]
1594+
#[cfg(not(feature = "nanvix-unstable"))]
15951595
#[allow(clippy::needless_range_loop)]
15961596
mod tests {
15971597
use std::sync::{Arc, Mutex};

src/hyperlight_host/src/hypervisor/regs/special_regs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use windows::Win32::System::Hypervisor::*;
2828
use super::FromWhpRegisterError;
2929

3030
cfg_if::cfg_if! {
31-
if #[cfg(feature = "init-paging")] {
31+
if #[cfg(not(feature = "nanvix-unstable"))] {
3232
pub(crate) const CR4_PAE: u64 = 1 << 5;
3333
pub(crate) const CR4_OSFXSR: u64 = 1 << 9;
3434
pub(crate) const CR4_OSXMMEXCPT: u64 = 1 << 10;
@@ -69,7 +69,7 @@ pub(crate) struct CommonSpecialRegisters {
6969
}
7070

7171
impl CommonSpecialRegisters {
72-
#[cfg(feature = "init-paging")]
72+
#[cfg(not(feature = "nanvix-unstable"))]
7373
pub(crate) fn standard_64bit_defaults(pml4_addr: u64) -> Self {
7474
CommonSpecialRegisters {
7575
cs: CommonSegmentRegister {
@@ -104,7 +104,7 @@ impl CommonSpecialRegisters {
104104
}
105105
}
106106

107-
#[cfg(not(feature = "init-paging"))]
107+
#[cfg(feature = "nanvix-unstable")]
108108
pub(crate) fn standard_real_mode_defaults() -> Self {
109109
CommonSpecialRegisters {
110110
cs: CommonSegmentRegister {

src/hyperlight_host/src/hypervisor/virtual_machine/kvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::hypervisor::regs::{
3333
CommonDebugRegs, CommonFpu, CommonRegisters, CommonSpecialRegisters, FP_CONTROL_WORD_DEFAULT,
3434
MXCSR_DEFAULT,
3535
};
36-
#[cfg(all(test, feature = "init-paging"))]
36+
#[cfg(all(test, not(feature = "nanvix-unstable")))]
3737
use crate::hypervisor::virtual_machine::XSAVE_BUFFER_SIZE;
3838
use crate::hypervisor::virtual_machine::{
3939
CreateVmError, MapMemoryError, RegisterError, RunVcpuError, UnmapMemoryError, VirtualMachine,
@@ -305,7 +305,7 @@ impl VirtualMachine for KvmVm {
305305
}
306306

307307
#[cfg(test)]
308-
#[cfg(feature = "init-paging")]
308+
#[cfg(not(feature = "nanvix-unstable"))]
309309
fn set_xsave(&self, xsave: &[u32]) -> std::result::Result<(), RegisterError> {
310310
if std::mem::size_of_val(xsave) != XSAVE_BUFFER_SIZE {
311311
return Err(RegisterError::XsaveSizeMismatch {

src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub(crate) const XSAVE_MIN_SIZE: usize = 576;
108108

109109
/// Standard XSAVE buffer size (4KB) used by KVM and MSHV.
110110
/// WHP queries the required size dynamically.
111-
#[cfg(all(any(kvm, mshv3), test, feature = "init-paging"))]
111+
#[cfg(all(any(kvm, mshv3), test, not(feature = "nanvix-unstable")))]
112112
pub(crate) const XSAVE_BUFFER_SIZE: usize = 4096;
113113

114114
// Compiler error if no hypervisor type is available
@@ -341,7 +341,7 @@ pub(crate) trait VirtualMachine: Debug + Send {
341341
fn reset_xsave(&self) -> std::result::Result<(), RegisterError>;
342342
/// Set xsave - only used for tests
343343
#[cfg(test)]
344-
#[cfg(feature = "init-paging")]
344+
#[cfg(not(feature = "nanvix-unstable"))]
345345
fn set_xsave(&self, xsave: &[u32]) -> std::result::Result<(), RegisterError>;
346346

347347
/// Get partition handle

src/hyperlight_host/src/hypervisor/virtual_machine/mshv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::hypervisor::regs::{
3939
CommonDebugRegs, CommonFpu, CommonRegisters, CommonSpecialRegisters, FP_CONTROL_WORD_DEFAULT,
4040
MXCSR_DEFAULT,
4141
};
42-
#[cfg(all(test, feature = "init-paging"))]
42+
#[cfg(all(test, not(feature = "nanvix-unstable")))]
4343
use crate::hypervisor::virtual_machine::XSAVE_BUFFER_SIZE;
4444
use crate::hypervisor::virtual_machine::{
4545
CreateVmError, MapMemoryError, RegisterError, RunVcpuError, UnmapMemoryError, VirtualMachine,
@@ -330,7 +330,7 @@ impl VirtualMachine for MshvVm {
330330
}
331331

332332
#[cfg(test)]
333-
#[cfg(feature = "init-paging")]
333+
#[cfg(not(feature = "nanvix-unstable"))]
334334
fn set_xsave(&self, xsave: &[u32]) -> std::result::Result<(), RegisterError> {
335335
if std::mem::size_of_val(xsave) != XSAVE_BUFFER_SIZE {
336336
return Err(RegisterError::XsaveSizeMismatch {

src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl VirtualMachine for WhpVm {
581581
}
582582

583583
#[cfg(test)]
584-
#[cfg(feature = "init-paging")]
584+
#[cfg(not(feature = "nanvix-unstable"))]
585585
fn set_xsave(&self, xsave: &[u32]) -> std::result::Result<(), RegisterError> {
586586
// Get the required buffer size by calling with NULL buffer.
587587
// If the buffer is not large enough (0 won't be), WHvGetVirtualProcessorXsaveState returns

0 commit comments

Comments
 (0)