Implement map_file_cow before a sandbox is initialised#1320
Merged
simongdavies merged 1 commit intohyperlight-dev:mainfrom Mar 18, 2026
Merged
Implement map_file_cow before a sandbox is initialised#1320simongdavies merged 1 commit intohyperlight-dev:mainfrom
simongdavies merged 1 commit intohyperlight-dev:mainfrom
Conversation
cd8b9ac to
08de4c8
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Implements deferred map_file_cow for UninitializedSandbox by introducing a two-phase host-prepare / VM-apply file mapping flow, enabling mappings to be created before VM initialization and applied during evolve.
Changes:
- Added
sandbox::file_mappingwithPreparedFileMappingto encapsulate host OS mapping resources with RAII cleanup. - Added
pending_file_mappingstoUninitializedSandboxplus a newmap_file_cowthat prepares mappings pre-VM and applies them duringevolve. - Refactored
MultiUseSandbox::map_file_cowto use the new shared preparation path and added tests for deferred mapping behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/hyperlight_host/src/sandbox/uninitialized_evolve.rs | Applies deferred prepared mappings before vm.initialise(); threads page size into VM setup. |
| src/hyperlight_host/src/sandbox/uninitialized.rs | Stores pending prepared mappings and exposes UninitializedSandbox::map_file_cow. |
| src/hyperlight_host/src/sandbox/mod.rs | Exposes new file_mapping module. |
| src/hyperlight_host/src/sandbox/initialized_multi_use.rs | Refactors map_file_cow to use shared preparation; adds deferred-mapping tests. |
| src/hyperlight_host/src/sandbox/file_mapping.rs | New module implementing PreparedFileMapping, OS-specific preparation, and RAII cleanup. |
| src/hyperlight_host/src/hypervisor/mod.rs | Updates tests/call sites to pass page size into hypervisor setup. |
| src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs | Plumbs page size into HyperlightVm::new and removes setting it in initialise. |
You can also share your feedback on Copilot code review. Take the survey.
Open
898f9a2 to
a7decbe
Compare
danbugs
previously approved these changes
Mar 18, 2026
Contributor
danbugs
left a comment
There was a problem hiding this comment.
Two minor non-blocking NITs you might want to look at. Otherwise LGTM.
jsturtevant
reviewed
Mar 18, 2026
jsturtevant
reviewed
Mar 18, 2026
a7decbe to
168fcc7
Compare
before a VM is initialised Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
168fcc7 to
7804836
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request implements
map_file_cowonUninitializedSandboxso file mappings can be created before a VM exists.It refactors the file mapping logic for guest sandboxes, splitting the process into two distinct phases: host-side preparation and VM-side application. The main goal is to allow file mappings to be prepared before the VM exists and then applied any later when the VM is created (i.e., during
evolve).Changes
File Mapping Refactor and Modularization:
file_mappingmodule andPreparedFileMappingabstraction for two-phase file mapping (host-side preparation and VM-side application), with safe cleanup and platform-specific handling.MultiUseSandbox::map_file_cowto use the new abstraction, removing duplicated platform-specific code.Support for Deferred File Mapping:
pending_file_mappingstoUninitializedSandboxand a newmap_file_cowmethod to defer mapping until VM creation.Code Cleanup and Dependency Updates:
initialized_multi_use.rs, consolidating logic infile_mapping.Test and API Adaptations:
page_sizeas needed.Also fixes a bug where the
mmapmemory access flags were too permissive (removewxfor KVM andxfor mshv)