Skip to content

Implement map_file_cow before a sandbox is initialised#1320

Merged
simongdavies merged 1 commit intohyperlight-dev:mainfrom
simongdavies:prepare-map-file-cow
Mar 18, 2026
Merged

Implement map_file_cow before a sandbox is initialised#1320
simongdavies merged 1 commit intohyperlight-dev:mainfrom
simongdavies:prepare-map-file-cow

Conversation

@simongdavies
Copy link
Contributor

@simongdavies simongdavies commented Mar 18, 2026

Overview

This pull request implements map_file_cow on UninitializedSandbox so 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:

    • Added file_mapping module and PreparedFileMapping abstraction for two-phase file mapping (host-side preparation and VM-side application), with safe cleanup and platform-specific handling.
    • Refactored MultiUseSandbox::map_file_cow to use the new abstraction, removing duplicated platform-specific code.
  • Support for Deferred File Mapping:

    • Added pending_file_mappings to UninitializedSandbox and a new map_file_cow method to defer mapping until VM creation.
  • Code Cleanup and Dependency Updates:

    • Removed obsolete imports and platform-specific code from initialized_multi_use.rs, consolidating logic in file_mapping.
  • Test and API Adaptations:

    • Updated call sites and tests to use the new file mapping API and pass page_size as needed.

Also fixes a bug where the mmap memory access flags were too permissive (remove wx for KVM and x for mshv)

@simongdavies simongdavies added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Mar 18, 2026
@simongdavies simongdavies force-pushed the prepare-map-file-cow branch from cd8b9ac to 08de4c8 Compare March 18, 2026 15:43
@danbugs danbugs requested a review from Copilot March 18, 2026 15:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_mapping with PreparedFileMapping to encapsulate host OS mapping resources with RAII cleanup.
  • Added pending_file_mappings to UninitializedSandbox plus a new map_file_cow that prepares mappings pre-VM and applies them during evolve.
  • Refactored MultiUseSandbox::map_file_cow to 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.

@danbugs danbugs mentioned this pull request Mar 18, 2026
@simongdavies simongdavies force-pushed the prepare-map-file-cow branch 2 times, most recently from 898f9a2 to a7decbe Compare March 18, 2026 20:09
@ppenna ppenna moved this to In Progress in HL-NVX Mar 18, 2026
@ppenna ppenna added this to HL-NVX Mar 18, 2026
danbugs
danbugs previously approved these changes Mar 18, 2026
Copy link
Contributor

@danbugs danbugs left a comment

Choose a reason for hiding this comment

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

Two minor non-blocking NITs you might want to look at. Otherwise LGTM.

before a VM is initialised

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies simongdavies force-pushed the prepare-map-file-cow branch from 168fcc7 to 7804836 Compare March 18, 2026 22:49
Copy link
Contributor

@danbugs danbugs left a comment

Choose a reason for hiding this comment

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

LGTM

@simongdavies simongdavies enabled auto-merge (squash) March 18, 2026 23:01
@simongdavies simongdavies merged commit 137e964 into hyperlight-dev:main Mar 18, 2026
48 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in HL-NVX Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants