Skip to content

Commit 0bd15f1

Browse files
committed
Relax snapshot restore layout compatibility
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 34c4b49 commit 0bd15f1

7 files changed

Lines changed: 371 additions & 154 deletions

File tree

src/hyperlight_host/src/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,6 @@ pub enum HyperlightError {
256256
#[error("Failed To Convert Return Value {0:?} to {1:?}")]
257257
ReturnValueConversionFailure(ReturnValue, &'static str),
258258

259-
/// Tried to restore a snapshot into a sandbox whose memory
260-
/// layout is not compatible with the snapshot's.
261-
#[error("Snapshot memory layout is not compatible with this sandbox")]
262-
SnapshotLayoutMismatch,
263-
264259
/// Tried to restore a snapshot into a sandbox whose registered
265260
/// host functions do not satisfy the snapshot's required set.
266261
#[error(
@@ -418,7 +413,6 @@ impl HyperlightError {
418413
| HyperlightError::RefCellMutBorrowFailed(_)
419414
| HyperlightError::ReturnValueConversionFailure(_, _)
420415
| HyperlightError::RestoreFailedUnrecoverably { .. }
421-
| HyperlightError::SnapshotLayoutMismatch
422416
| HyperlightError::SnapshotHostFunctionMismatch { .. }
423417
| HyperlightError::SystemTimeError(_)
424418
| HyperlightError::TryFromSliceError(_)

src/hyperlight_host/src/hypervisor/hyperlight_vm/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ impl HyperlightVm {
717717
self.rt_cfg.entry_point = Some(entry_point);
718718
}
719719

720+
#[cfg(crashdump)]
721+
pub(crate) fn clear_crashdump_binary_path(&mut self) {
722+
self.rt_cfg.binary_path = None;
723+
}
724+
720725
pub(crate) fn interrupt_handle(&self) -> Arc<dyn InterruptHandle> {
721726
self.interrupt_handle.clone()
722727
}

src/hyperlight_host/src/mem/layout.rs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -317,40 +317,6 @@ impl Debug for SandboxMemoryLayout {
317317
}
318318

319319
impl SandboxMemoryLayout {
320-
/// Whether `other` has the same layout configuration as `self`,
321-
/// i.e. the fields that come from the guest binary and the
322-
/// `SandboxConfiguration`. `snapshot_size` and `pt_size` are
323-
/// excluded because they are outputs of building a snapshot blob
324-
/// (the compacted data size and the size of the rebuilt
325-
/// page-table tail), not configuration inputs, so they differ
326-
/// between the sandbox's live layout and any snapshot taken
327-
/// from it.
328-
///
329-
/// TODO: separate/remove snapshot_size and pt_size from this struct.
330-
pub(crate) fn is_compatible_with(&self, other: &Self) -> bool {
331-
// Exhaustive destructure so adding a field to
332-
// `SandboxMemoryLayout` fails to compile here, forcing the
333-
// author to decide whether it participates in compatibility.
334-
let Self {
335-
input_data_size,
336-
output_data_size,
337-
heap_size,
338-
code_size,
339-
init_data_size,
340-
init_data_permissions,
341-
scratch_size,
342-
snapshot_size: _,
343-
pt_size: _,
344-
} = self;
345-
*input_data_size == other.input_data_size
346-
&& *output_data_size == other.output_data_size
347-
&& *heap_size == other.heap_size
348-
&& *code_size == other.code_size
349-
&& *init_data_size == other.init_data_size
350-
&& *init_data_permissions == other.init_data_permissions
351-
&& *scratch_size == other.scratch_size
352-
}
353-
354320
/// The maximum amount of memory a single sandbox will be allowed.
355321
///
356322
/// Both the scratch region and the snapshot region are bounded by
@@ -788,58 +754,6 @@ mod tests {
788754
assert!(matches!(layout.unwrap_err(), MemoryRequestTooBig(..)));
789755
}
790756

791-
#[test]
792-
fn is_compatible_with_identical_layouts() {
793-
let cfg = SandboxConfiguration::default();
794-
let a = SandboxMemoryLayout::new(cfg, 4096, 0, None).unwrap();
795-
let b = SandboxMemoryLayout::new(cfg, 4096, 0, None).unwrap();
796-
assert!(a.is_compatible_with(&b));
797-
assert!(b.is_compatible_with(&a));
798-
}
799-
800-
#[test]
801-
fn is_compatible_with_ignores_snapshot_size_and_pt_size() {
802-
// `snapshot_size` and `pt_size` are outputs of building a
803-
// snapshot blob, not configuration inputs, so flipping
804-
// them must not break compatibility.
805-
let cfg = SandboxConfiguration::default();
806-
let a = SandboxMemoryLayout::new(cfg, 4096, 0, None).unwrap();
807-
let mut b = a;
808-
b.snapshot_size = a.snapshot_size + PAGE_SIZE_USIZE;
809-
b.set_pt_size(PAGE_SIZE_USIZE).unwrap();
810-
assert!(a.is_compatible_with(&b));
811-
assert!(b.is_compatible_with(&a));
812-
}
813-
814-
#[test]
815-
fn is_compatible_with_rejects_each_configured_field() {
816-
let cfg = SandboxConfiguration::default();
817-
let base = SandboxMemoryLayout::new(cfg, 4096, 0, None).unwrap();
818-
819-
// Each mutation must independently break compatibility.
820-
let mutators: &[fn(&mut SandboxMemoryLayout)] = &[
821-
|l| l.input_data_size += PAGE_SIZE_USIZE,
822-
|l| l.output_data_size += PAGE_SIZE_USIZE,
823-
|l| l.heap_size += PAGE_SIZE_USIZE,
824-
|l| l.code_size += PAGE_SIZE_USIZE,
825-
|l| l.init_data_size += PAGE_SIZE_USIZE,
826-
|l| l.scratch_size += PAGE_SIZE_USIZE,
827-
|l| {
828-
l.init_data_permissions = Some(MemoryRegionFlags::READ);
829-
},
830-
];
831-
for mutate in mutators {
832-
let mut other = base;
833-
mutate(&mut other);
834-
assert!(
835-
!base.is_compatible_with(&other),
836-
"mutation should have broken compatibility: {:?} vs {:?}",
837-
base,
838-
other,
839-
);
840-
}
841-
}
842-
843757
/// Pinned region offsets. These methods place every region that a
844758
/// restored snapshot is interpreted against, so a change shifts
845759
/// where the loader reads captured bytes and breaks existing

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ impl PreparedMemoryRestore {
200200
pub(crate) fn replaces_snapshot(&self) -> bool {
201201
matches!(self.mapping_update, BaseMappingUpdate::ReplaceSnapshot(_))
202202
}
203+
204+
#[cfg(test)]
205+
pub(crate) fn replaces_all(&self) -> bool {
206+
matches!(self.mapping_update, BaseMappingUpdate::ReplaceAll { .. })
207+
}
203208
}
204209

205210
/// Buffer for building guest page tables during snapshot creation.

0 commit comments

Comments
 (0)