From 8a023422e9601e73883e0322219bc71606b9e74b Mon Sep 17 00:00:00 2001 From: danbugs Date: Wed, 27 May 2026 16:00:01 +0000 Subject: [PATCH 1/3] perf: use restore_preserving_file_mappings for initrd Call restore_preserving_file_mappings when a file mapping (initrd) exists, skipping the unmap/remap cycle on every snapshot restore. Remove the now-unused file_mapping_base field. Signed-off-by: danbugs --- host/src/lib.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/host/src/lib.rs b/host/src/lib.rs index 6425def..db14dc3 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -2008,10 +2008,9 @@ pub struct Sandbox { inner: MultiUseSandbox, /// Post-init snapshot for fast restore between calls. snapshot: Option>, - /// File mapping to re-register after snapshot restore. - /// Snapshot restore unmaps all non-snapshot regions. + /// When set, restore uses the preserving variant to keep the + /// read-only file mapping alive across restores. file_mapping_path: Option, - file_mapping_base: u64, exit_code: Arc, /// Shared socket table — cleared on [`Sandbox::restore`] so that /// host-side fds don't leak across guest restore cycles. @@ -2247,7 +2246,7 @@ impl Sandbox { tools_ref.dispatch(&payload) })?; - Self::finish_evolve(usbox, None, 0, exit_code, sleep_cancel, socket_table) + Self::finish_evolve(usbox, None, exit_code, sleep_cancel, socket_table) } /// Low-level: boot with a zero-copy mapped initrd file. Prefer the builder. @@ -2304,7 +2303,6 @@ impl Sandbox { Self::finish_evolve( usbox, initrd_path.map(|p| p.to_path_buf()), - INITRD_MAP_BASE, exit_code, sleep_cancel, socket_table, @@ -2314,7 +2312,6 @@ impl Sandbox { fn finish_evolve( usbox: UninitializedSandbox, file_mapping_path: Option, - file_mapping_base: u64, exit_code: Arc, sleep_cancel: SleepCancel, socket_table: Option>>, @@ -2325,7 +2322,6 @@ impl Sandbox { inner, snapshot, file_mapping_path, - file_mapping_base, exit_code, socket_table, sleep_cancel, @@ -2338,15 +2334,12 @@ impl Sandbox { /// guest memory to the state captured after init. pub fn restore(&mut self) -> Result<()> { if let Some(ref snap) = self.snapshot { - self.inner.restore(snap.clone())?; - } - // Re-register file mapping after restore (snapshot restore - // unmaps all non-snapshot regions including file mappings) - if let Some(ref path) = self.file_mapping_path { - self.inner - .map_file_cow(path, self.file_mapping_base, Some("initrd"))?; + if self.file_mapping_path.is_some() { + self.inner.restore_preserving_file_mappings(snap.clone())?; + } else { + self.inner.restore(snap.clone())?; + } } - // Close leaked host-side sockets the guest "forgot" about. if let Some(ref table) = self.socket_table { table.lock().unwrap().clear(); } @@ -2543,7 +2536,6 @@ impl Sandbox { inner, snapshot: Some(arc), file_mapping_path: initrd, - file_mapping_base: INITRD_MAP_BASE, exit_code, socket_table, sleep_cancel, From 3537f042a57930543b1313ae04bd8d9c7b3f07f1 Mon Sep 17 00:00:00 2001 From: danbugs Date: Wed, 27 May 2026 16:00:08 +0000 Subject: [PATCH 2/3] perf: pin hyperlight-host to whp-warm-start with no-surrogate mode Pin to rev 3ed18580 for reproducible builds. Enables whp-no-surrogate for VirtualAlloc allocation, direct WHvMapGpaRange, and demand-zero scratch reset. Signed-off-by: danbugs --- host/Cargo.lock | 10 +++++----- host/Cargo.toml | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/host/Cargo.lock b/host/Cargo.lock index 2eb902c..fc537f8 100644 --- a/host/Cargo.lock +++ b/host/Cargo.lock @@ -404,7 +404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -582,7 +582,7 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "hyperlight-common" version = "0.15.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?branch=disk_snapshot_copy#621cc03beadae3d9158e72d07d3d156abf2b21fd" +source = "git+https://github.com/danbugs/hyperlight?rev=3ed18580#3ed18580d7f3d0926a6b641159b13b0449b6d930" dependencies = [ "anyhow", "flatbuffers", @@ -596,7 +596,7 @@ dependencies = [ [[package]] name = "hyperlight-host" version = "0.15.0" -source = "git+https://github.com/hyperlight-dev/hyperlight?branch=disk_snapshot_copy#621cc03beadae3d9158e72d07d3d156abf2b21fd" +source = "git+https://github.com/danbugs/hyperlight?rev=3ed18580#3ed18580d7f3d0926a6b641159b13b0449b6d930" dependencies = [ "anyhow", "bitflags 2.11.1", @@ -1260,7 +1260,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1844,7 +1844,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/host/Cargo.toml b/host/Cargo.toml index 9b8a16b..93bebd7 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -27,9 +27,8 @@ name = "pyhl" path = "src/bin/pyhl.rs" [dependencies] -# hyperlight-dev/hyperlight#1373 — Ludvig's Snapshot::to_file/from_file -# Uses PAGE_READONLY mapping (no host commit charge per VM). -hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", branch = "disk_snapshot_copy", features = ["executable_heap", "hw-interrupts"] } +# danbugs/hyperlight perf/whp-warm-start — snapshot file support + WHP warm-start optimizations. +hyperlight-host = { git = "https://github.com/danbugs/hyperlight", rev = "3ed18580", features = ["executable_heap", "hw-interrupts", "whp-no-surrogate"] } clap = { version = "4", features = ["derive", "env"] } anyhow = "1" memmap2 = "0.9" From 1e95cc0e203cb712611dcf969aa242b532ea0aee Mon Sep 17 00:00:00 2001 From: danbugs Date: Wed, 27 May 2026 16:39:08 +0000 Subject: [PATCH 3/3] fix: update hyperlight rev to fix WHP GPA mapping desync in zero() The MEM_DECOMMIT+MEM_COMMIT optimization in zero() replaced physical pages without notifying WHP, causing FC-aware dispatch (pyhl, pydriver-run) to read stale input data on Windows. Signed-off-by: danbugs --- host/Cargo.lock | 10 +++++----- host/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/host/Cargo.lock b/host/Cargo.lock index fc537f8..2fc74fa 100644 --- a/host/Cargo.lock +++ b/host/Cargo.lock @@ -404,7 +404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -582,7 +582,7 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "hyperlight-common" version = "0.15.0" -source = "git+https://github.com/danbugs/hyperlight?rev=3ed18580#3ed18580d7f3d0926a6b641159b13b0449b6d930" +source = "git+https://github.com/danbugs/hyperlight?rev=5cf37d92#5cf37d92262c918e7d633577a6cf946fb1f069bd" dependencies = [ "anyhow", "flatbuffers", @@ -596,7 +596,7 @@ dependencies = [ [[package]] name = "hyperlight-host" version = "0.15.0" -source = "git+https://github.com/danbugs/hyperlight?rev=3ed18580#3ed18580d7f3d0926a6b641159b13b0449b6d930" +source = "git+https://github.com/danbugs/hyperlight?rev=5cf37d92#5cf37d92262c918e7d633577a6cf946fb1f069bd" dependencies = [ "anyhow", "bitflags 2.11.1", @@ -1260,7 +1260,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -1844,7 +1844,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/host/Cargo.toml b/host/Cargo.toml index 93bebd7..f6a7cca 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -28,7 +28,7 @@ path = "src/bin/pyhl.rs" [dependencies] # danbugs/hyperlight perf/whp-warm-start — snapshot file support + WHP warm-start optimizations. -hyperlight-host = { git = "https://github.com/danbugs/hyperlight", rev = "3ed18580", features = ["executable_heap", "hw-interrupts", "whp-no-surrogate"] } +hyperlight-host = { git = "https://github.com/danbugs/hyperlight", rev = "5cf37d92", features = ["executable_heap", "hw-interrupts", "whp-no-surrogate"] } clap = { version = "4", features = ["derive", "env"] } anyhow = "1" memmap2 = "0.9"