Skip to content

Add provenance-validated snapshot overlay loading - #2117

Open
jprendes wants to merge 10 commits into
hyperlight-dev:mainfrom
jprendes:feat/snapshot-overlay-loading
Open

jprendes wants to merge 10 commits into
hyperlight-dev:mainfrom
jprendes:feat/snapshot-overlay-loading

Conversation

@jprendes

@jprendes jprendes commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add explicit, provenance-validated loading of snapshot descendants while reusing immutable memory layers from a caller-authorized base.

let snapshot = base.load_overlay(path, reference)?;
let checked = base.checked_load_overlay(path, reference)?;

Atomic commits

  1. Reuse declared memory digests on ordinary snapshot saves
    • Retain ordinary-load digest declarations separately from computed or verified hashes.
    • Avoid hashing trusted loaded memory again on ordinary save.
    • Preserve checked-save verification and repair; document that incorrect declarations are deliberately preserved by ordinary load/save.
  2. Add provenance-validated snapshot overlay loading
    • Require a declaration identifying the whole supplied base, rather than accepting any snapshot with a matching layer.
    • Persist snapshot IDs and inherited base IDs in the OCI config.
    • Propagate ancestry directly through the existing whole-snapshot memory backing during capture, including without compaction.
    • Record explicitly supplied compaction bases without retaining unused layers.
    • Share matching layers by digest and geometry; their files may be omitted from the descendant layout.

Semantics and trust

  • The saved descendant supplies the complete target state. Overlay loading reuses backing memory; it does not merge registers/metadata or append unused base layers.
  • Ordinary loading trusts declared memory hashes. Checked overlay loading reuses only computed or verified base-layer hashes and verifies newly loaded content.
  • Snapshot IDs and base declarations are trusted provenance, not cryptographic proof of ancestry or authorization, even in checked mode.
  • Callers must authorize the base and keep all backing files immutable; this is not a cross-actor content cache.
  • Writers emit config v7 with provenance; legacy v6 configs still load standalone without it. Save the resulting base to persist its assigned ID before relying on independently loaded copies for overlay.
  • There are no changes to the memory manager, no extra retained base layers, and no newly introduced memory hashing for ancestry.

Validation

  • First commit independently: 174 host loader tests passed.
  • Final tree: 255 snapshot/memory-manager tests passed, with one existing hardware-specific test ignored.
  • Copied-memory/GDB path: 6 targeted provenance and compaction tests passed.
  • Existing hash-reuse and omitted-layer/backing-lifetime assertions passed.

Review follow-ups

  • Versioned the config as v7, preserving strict legacy v6 loading and updating schema/ABI tripwires. The format-fix commit independently passed 16 focused tests.
  • compact(None) clears provenance. compact(Some(base)) replaces the target's history with the selected base's inherited list plus its ID. This provides an explicit reset while retaining a caller-selected base, rather than silently imposing an ancestry cap.
  • Inheritance now copies one validated, ordered list and appends its unique parent ID in linear time, eliminating quadratic membership scans.
  • Regression coverage seeds 30,000 ancestor IDs, verifies both save APIs hit the actual 1 MiB config limit, and verifies compaction recovers save capacity.
  • Uncompacted ancestry can still grow; callers should periodically compact without a base or against a fixed base with a short ancestry list.
  • Command snapshot/checkpoint tests (10), copied-memory/GDB tests (6), and static worker KVM lifecycle tests (2) passed. Performance benchmarks were not rerun.

jprendes and others added 2 commits November 26, 2026 12:28
Keep asserted layer digests separate from computed or verified hashes. Ordinary load/save avoids rehashing trusted memory, while checked_save continues to verify and repair content.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Add load_overlay and checked_load_overlay methods that require a declared whole-snapshot base and reuse matching immutable layers. Persist snapshot IDs and inherit provenance through capture and compaction without retaining unused layers or adding memory-manager bookkeeping.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Newly saved configs break compatibility with existing v6 readers, which reject the added provenance fields despite the unchanged media type and ABI.

3 open issues
What changed in this PR

This PR adds provenance-validated snapshot overlay loading to Hyperlight’s host snapshot APIs. Descendants can reuse immutable memory layers from a caller-authorized base while supplying their complete saved state.

Changes:

  • Add ordinary and checked overlay loaders with provenance, digest, and geometry checks.
  • Persist snapshot identities and ancestry through capture and compaction.
  • Reuse declared digests on ordinary saves, with tests and documentation for verification and trust requirements.
File Description
src/​hyperlight_host/​src/​sandbox/​snapshot/​mod.rs Inherit base provenance during capture.
src/​hyperlight_host/​src/​sandbox/​snapshot/​memory/​mod.rs Store snapshot IDs, ancestors, and declared digests.
src/​hyperlight_host/​src/​sandbox/​snapshot/​memory/​backing.rs Expose backing snapshot memory for provenance inheritance.
src/​hyperlight_host/​src/​sandbox/​snapshot/​file/​mod.rs Implement overlay loading and declared-digest reuse.
src/​hyperlight_host/​src/​sandbox/​snapshot/​file/​config.rs Serialize and validate provenance fields.
src/​hyperlight_host/​src/​sandbox/​snapshot/​file_tests.rs Cover provenance, layer sharing, verification, and legacy loading.
src/​hyperlight_host/​src/​sandbox/​snapshot/​compact.rs Preserve ancestry and record explicit compaction bases.
docs/​snapshot-oci-format.md Describe overlay semantics and trust requirements.
CHANGELOG.md Document the public APIs and save behavior.

Review effort: Balanced

@jprendes jprendes added the C-enhancement For PRs adding features, improving functionality, docs, tests, etc. label Nov 26, 2026
jprendes and others added 2 commits November 26, 2026 13:00
Emit config v7 with explicit loader dispatch and require its snapshot ID. Keep strict v6 loading without provenance, update schema and ABI tripwires, and cover legacy and mislabeled layouts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Clear base provenance when compacting without a base. With a base, replace target ancestry with that base inherited list and ID. Copy the validated ordered list directly instead of quadratic membership scans, and cover config-limit recovery and repeated checkpoint cycles.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@hyperlight-gh-bot

This comment has been minimized.

Drop the derived snapshot as well as the trusted base before shortening their shared blob. Windows rejects truncation while either snapshot retains the mapped section.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@hyperlight-gh-bot

This comment has been minimized.

@yoshuawuyts yoshuawuyts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filing this @jprendes! - I'm not yet in a position where I can review the correctness of the implementation, so I will defer that to someone else. But I took a pass on reviewing the actual code and read the PR line by line, and I hope that's helpful too.

jprendes and others added 2 commits November 27, 2026 12:58
Require declared ancestors for base-preserving compaction. Encapsulate digest trust in BlobHash with terminal atomic invalidation and byte/file verification. Reject inconsistent existing memory blobs without repair, and document and test the updated policies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@jprendes
jprendes force-pushed the feat/snapshot-overlay-loading branch from 0278560 to 4c00c28 Compare November 27, 2026 12:58
@hyperlight-gh-bot

This comment has been minimized.

jprendes and others added 2 commits November 27, 2026 14:58
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Exercise checked no-clobber publication directly on every platform. The whole-save test also raced metadata replacement, which can fail with access denied on Windows and was outside the publication behavior under test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@hyperlight-gh-bot

This comment has been minimized.

Replace digest state and save expects with descriptive errors, and reject unexpected internal state values without unreachable panics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: ab8c1150073a
Baseline commit: f926224158f0

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 294.98 ns (➖ 1.01x slower)
vec_bytes 78.89 ns (➖ 1.02x faster)
379.29 µs (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 141.42 ns (➖ 1.01x faster)
262144 520.80 ns (➖ 1.06x faster)

sandboxes

create_initialized_and_drop
medium 13.09 ms (➖ 1.07x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
7.72 ns (➖ 1.00x faster) 7.81 ns (➖ 1.02x slower) 7.72 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 110.30 µs (➖ 1.06x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 1.94 µs (➖ 1.08x faster) 2.05 µs (➖ 1.08x slower)
262144 7.32 µs (➖ 1.03x slower) 7.18 µs (➖ 1.02x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 6.17 µs (➖ 1.02x faster) 6.18 µs (➖ 1.22x faster)
262144 26.98 µs (➖ 1.02x faster)
8192 1.01 µs (➖ 1.02x faster) 1.09 µs (➖ 1.03x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 258.11 ns (➖ 1.02x slower)
vec_bytes 76.05 ns (➖ 1.09x faster)
681.49 µs (➖ 1.00x slower)

payload_allocation

slot_pool_segmented
65536 140.16 ns (➖ 1.00x slower)
262144 522.93 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 15.69 ms (➖ 1.11x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
7.22 ns (➖ 1.01x slower) 7.29 ns (➖ 1.00x faster) 7.16 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 55.84 µs (➖ 1.04x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.13 µs (➖ 1.00x faster) 2.15 µs (➖ 1.01x slower)
262144 7.62 µs (➖ 1.02x slower) 7.52 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 6.97 µs (➖ 1.01x faster) 7.11 µs (➖ 1.01x slower)
262144 30.19 µs (➖ 1.02x faster)
8192 704.07 ns (➖ 1.02x faster) 713.47 ns (➖ 1.02x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 363.90 ns (➖ 1.02x faster)
vec_bytes 98.21 ns (➖ 1.04x faster)
269.32 µs (➖ 1.13x faster)

payload_allocation

slot_pool_segmented
65536 252.53 ns (➖ 1.00x slower)
262144 814.66 ns (➖ 1.11x slower)

sandboxes

create_initialized_and_drop
medium 67.96 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
9.86 ns (➖ 1.00x faster) 9.87 ns (➖ 1.00x faster) 9.87 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 101.85 µs (➖ 1.03x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.22 µs (➖ 1.01x slower) 2.41 µs (➖ 1.02x faster)
262144 10.08 µs (➖ 1.02x slower) 9.98 µs (➖ 1.00x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 9.43 µs (➖ 1.14x faster) 9.93 µs (➖ 1.04x slower)
262144 36.02 µs (➖ 1.08x faster)
8192 1.27 µs (➖ 1.05x slower) 1.26 µs (➖ 1.05x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 354.67 ns (➖ 1.11x faster)
vec_bytes 88.13 ns (➖ 1.03x faster)
1.00 ms (➖ 1.22x faster)

payload_allocation

slot_pool_segmented
65536 172.11 ns (➖ 1.00x slower)
262144 925.17 ns (➖ 1.45x slower)

sandboxes

create_initialized_and_drop
medium 67.48 ms (➖ 1.30x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
9.99 ns (➖ 1.14x slower) 9.14 ns (➖ 1.01x slower) 8.71 ns (➖ 1.00x slower)

snapshot_files

load_snapshot_unverified
small 56.75 µs (➖ 1.05x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.30 µs (➖ 1.02x slower) 2.28 µs (➖ 1.01x slower)
262144 7.96 µs (➖ 1.01x faster) 8.04 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 7.46 µs (➖ 1.02x faster) 7.52 µs (➖ 1.01x faster)
262144 39.66 µs (➖ 1.11x faster)
8192 901.06 ns (➖ 1.02x faster) 898.60 ns (➖ 1.04x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 547.24 ns (➖ 1.03x slower)
vec_bytes 160.29 ns (➖ 1.04x slower)
2.20 ms (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
65536 229.16 ns (➖ 1.00x slower)
262144 797.68 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 13.44 ms (➖ 1.03x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.62 ns (➖ 1.03x slower) 11.65 ns (➖ 1.15x slower) 10.82 ns (➖ 1.04x slower)

snapshot_files

load_snapshot_unverified
small 854.27 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.32 µs (➖ 1.01x faster) 2.31 µs (➖ 1.01x faster)
262144 9.52 µs (➖ 1.05x slower) 9.05 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 9.26 µs (➖ 1.05x slower) 8.77 µs (➖ 1.02x faster)
262144 38.57 µs (➖ 1.00x slower)
8192 1.26 µs (➖ 1.04x faster) 1.32 µs (➖ 1.01x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 482.14 ns (➖ 1.03x faster)
vec_bytes 136.80 ns (➖ 1.02x faster)
3.25 ms (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 195.61 ns (➖ 1.02x slower)
262144 670.12 ns (➖ 1.03x slower)

sandboxes

create_initialized_and_drop
medium 13.28 ms (➖ 1.02x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
8.73 ns (➖ 1.01x slower) 8.85 ns (➖ 1.03x slower) 8.79 ns (➖ 1.02x slower)

snapshot_files

load_snapshot_unverified
small 463.42 µs (➖ 1.44x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.59 µs (➖ 1.05x slower) 2.53 µs (➖ 1.02x slower)
262144 8.71 µs (➖ 1.02x slower) 8.74 µs (➖ 1.02x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 9.17 µs (➖ 1.01x faster) 9.25 µs (➖ 1.01x slower)
262144 35.44 µs (➖ 1.02x slower)
8192 1.11 µs (➖ 1.06x slower) 1.07 µs (➖ 1.03x slower)

Reported by cargo ci bench-report --candidate run:46053462387 --config-file bench_report.toml.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants