Skip to content

Commit 8950f2e

Browse files
authored
feat: use i686 layout for nanvix-unstable guests and make snapshot RWX (#1271)
When nanvix-unstable is enabled, select the i686 layout module on x86_64 hosts. This ensures MAX_GPA/MAX_GVA use 32-bit address space limits and the scratch region is placed at the top of 4 GiB. Also makes the snapshot region RWX for nanvix-unstable guests since they have no CoW page tables and need direct write access. Key changes: - Propagate nanvix-unstable from hyperlight-host to hyperlight-common - Use i686 layout when nanvix-unstable is enabled on x86_64 - Gate SNAPSHOT_PT_GVA_* exports behind not(nanvix-unstable) and target_arch = "x86_64" (i686 layout never defines these symbols) - Make snapshot writable for nanvix-unstable (no CoW means hardware needs direct write access) Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 3c19ca9 commit 8950f2e

5 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/hyperlight_common/src/arch/i686/layout.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ limitations under the License.
1717
// This file is just dummy definitions at the moment, in order to
1818
// allow compiling the guest for real mode boot scenarios.
1919

20-
pub const MAX_GVA: usize = 0xffff_efff;
21-
pub const SNAPSHOT_PT_GVA_MIN: usize = 0xef00_0000;
22-
pub const SNAPSHOT_PT_GVA_MAX: usize = 0xefff_efff;
20+
pub const MAX_GVA: usize = 0xffff_ffff;
2321
pub const MAX_GPA: usize = 0xffff_ffff;
2422

25-
pub fn min_scratch_size() -> usize {
26-
1 * crate::vmem::PAGE_SIZE
23+
pub fn min_scratch_size(_input_data_size: usize, _output_data_size: usize) -> usize {
24+
crate::vmem::PAGE_SIZE
2725
}

src/hyperlight_common/src/layout.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/layout.rs")]
1817
#[cfg_attr(target_arch = "x86", path = "arch/i686/layout.rs")]
18+
#[cfg_attr(
19+
all(target_arch = "x86_64", not(feature = "nanvix-unstable")),
20+
path = "arch/amd64/layout.rs"
21+
)]
22+
#[cfg_attr(
23+
all(target_arch = "x86_64", feature = "nanvix-unstable"),
24+
path = "arch/i686/layout.rs"
25+
)]
1926
mod arch;
2027

21-
pub use arch::{MAX_GPA, MAX_GVA, SNAPSHOT_PT_GVA_MAX, SNAPSHOT_PT_GVA_MIN};
28+
pub use arch::{MAX_GPA, MAX_GVA};
29+
#[cfg(all(target_arch = "x86_64", not(feature = "nanvix-unstable")))]
30+
pub use arch::{SNAPSHOT_PT_GVA_MAX, SNAPSHOT_PT_GVA_MIN};
2231

2332
// offsets down from the top of scratch memory for various things
2433
pub const SCRATCH_TOP_SIZE_OFFSET: u64 = 0x08;

src/hyperlight_host/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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-
nanvix-unstable = []
140+
nanvix-unstable = ["hyperlight-common/nanvix-unstable"]
141141

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

src/hyperlight_host/src/mem/shared_mem.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,22 @@ impl GuestSharedMemory {
679679
MemoryRegionType::Scratch => {
680680
MemoryRegionFlags::READ | MemoryRegionFlags::WRITE | MemoryRegionFlags::EXECUTE
681681
}
682-
MemoryRegionType::Snapshot => MemoryRegionFlags::READ | MemoryRegionFlags::EXECUTE,
682+
// Without nanvix-unstable (default), the snapshot is read-only
683+
// because guest page tables provide CoW semantics for writable
684+
// pages. With nanvix-unstable there are no guest page tables,
685+
// so the snapshot must be writable — otherwise writes (including
686+
// the CPU setting the "Accessed" bit in GDT descriptors during
687+
// segment loads) cause EPT violations that KVM retries forever.
688+
MemoryRegionType::Snapshot => {
689+
#[cfg(not(feature = "nanvix-unstable"))]
690+
{
691+
MemoryRegionFlags::READ | MemoryRegionFlags::EXECUTE
692+
}
693+
#[cfg(feature = "nanvix-unstable")]
694+
{
695+
MemoryRegionFlags::READ | MemoryRegionFlags::WRITE | MemoryRegionFlags::EXECUTE
696+
}
697+
}
683698
#[allow(clippy::panic)]
684699
// In the future, all the host side knowledge about memory
685700
// region types should collapse down to Snapshot vs

src/hyperlight_host/src/sandbox/snapshot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ fn filtered_mappings<'a>(
265265
return None;
266266
}
267267
// neither does the mapping of the snapshot's own page tables
268+
#[cfg(not(feature = "nanvix-unstable"))]
268269
if mapping.virt_base >= hyperlight_common::layout::SNAPSHOT_PT_GVA_MIN as u64
269270
&& mapping.virt_base <= hyperlight_common::layout::SNAPSHOT_PT_GVA_MAX as u64
270271
{

0 commit comments

Comments
 (0)