Skip to content

Conversation

@simongdavies
Copy link
Contributor

Currently, the guest and the host both have code that manipulates architecture-specific page table structures: the guest has a general map operation, and the host has a much more specific routine that builds an identity map. As we move to more complex virtual memory configurations in the guest, the host will need the ability to build more complex mappings in the guest, so this commit removes the simple implementation in the host, and replaces it with calls to the implementation originally written for the guest (now moved to hyperlight_common and factored into an architecture-independent interface and architecture-specific code parts).

@simongdavies simongdavies requested a review from danbugs as a code owner December 9, 2025 21:25
@simongdavies simongdavies added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Dec 9, 2025
@simongdavies simongdavies added the Guest-COW PRs that form part of the Guest-COW change label Dec 9, 2025
@simongdavies simongdavies force-pushed the unify-page-table-code branch 2 times, most recently from ef2c3ea to 09cf019 Compare December 10, 2025 11:57
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

This PR unifies page table manipulation code between the guest and host by extracting common functionality into hyperlight_common with an architecture-independent TableOps trait and x86-64-specific implementation. The host previously had a simple identity-mapping routine while the guest had a more general mapping function. Now both use the same underlying code, with different trait implementations to handle their specific contexts (the host builds tables in a buffer, the guest modifies live page tables).

Key Changes

  • Introduced a new vm module in hyperlight_common with a TableOps trait that abstracts page table operations
  • Replaced the host's hardcoded page table initialization with calls to the unified mapping code
  • Simplified the guest's paging code by refactoring it to use the shared implementation

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/hyperlight_common/src/vm.rs New architecture-independent interface defining the TableOps trait and Mapping structures
src/hyperlight_common/src/arch/amd64/vm.rs New x86-64-specific page table manipulation implementation
src/hyperlight_common/src/lib.rs Adds vm module export under init-paging feature
src/hyperlight_common/Cargo.toml Adds init-paging feature flag
src/hyperlight_host/src/mem/mgr.rs Replaces hardcoded page table setup with GuestPageTableBuffer implementing TableOps; removes old get_page_flags helper
src/hyperlight_host/src/sandbox/uninitialized_evolve.rs Removes mem_size parameter from set_up_shared_memory call
src/hyperlight_host/src/mem/memory_region.rs Removes translate_flags method and page flag imports
src/hyperlight_host/src/mem/layout.rs Removes obsolete PDPT, PD, and PT offset constants
src/hyperlight_host/Cargo.toml Adds init-paging feature to hyperlight-common dependency
src/hyperlight_guest_bin/src/paging.rs Refactors map_region to use common vm::map; removes duplicate helper structures and functions
src/hyperlight_guest_bin/Cargo.toml Adds init-paging feature to hyperlight-common dependency

@jprendes
Copy link
Contributor

The following test stalls when I execute it using the changes in this PR

use hyperlight_host::{GuestBinary, UninitializedSandbox, sandbox::SandboxConfiguration};
use hyperlight_testing::simple_guest_as_string;

#[test]
fn sandboxes_create_initialized_small() {
    let mut cfg = SandboxConfiguration::default();
    cfg.set_heap_size(8 * 1024 * 1024); // 8 MB

    let path = simple_guest_as_string().unwrap();
    let sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), Some(cfg))
        .unwrap()
        .evolve()
        .unwrap();

    drop(sbox);

    println!("done!");
}

syntactically and others added 2 commits December 15, 2025 21:02
Currently, the guest and the host both have code that manipulates
architecture-specific page table structures: the guest has a general
map operation, and the host has a much more specific routine that
builds an identity map.  As we move to more complex virtual memory
configurations in the guest, the host will need the ability to build
more complex mappings in the guest, so this commit removes the simple
implementation in the host, and replaces it with calls to the
implementation originally written for the guest (now moved to
`hyperlight_common` and factored into an architecture-independent
interface and architecture-specific code parts).

Signed-off-by: Simon Davies <[email protected]>
@simongdavies
Copy link
Contributor Author

simongdavies commented Dec 16, 2025

The following test stalls when I execute it using the changes in this PR

use hyperlight_host::{GuestBinary, UninitializedSandbox, sandbox::SandboxConfiguration};
use hyperlight_testing::simple_guest_as_string;

#[test]
fn sandboxes_create_initialized_small() {
    let mut cfg = SandboxConfiguration::default();
    cfg.set_heap_size(8 * 1024 * 1024); // 8 MB

    let path = simple_guest_as_string().unwrap();
    let sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), Some(cfg))
        .unwrap()
        .evolve()
        .unwrap();

    drop(sbox);

    println!("done!");
}

Thanks, I fixed a bug in the ModifyPteIterator which was causing early termination which meant that we were not creating all the PTEs required once a sandbox went beyond 2MB, I also created an issue #1118 for the infinite loop

@simongdavies simongdavies force-pushed the unify-page-table-code branch 2 times, most recently from d356a69 to 1049d4b Compare December 16, 2025 16:53
@simongdavies simongdavies force-pushed the unify-page-table-code branch 2 times, most recently from 39ae653 to 6bdbd41 Compare December 17, 2025 19:54
ludfjig
ludfjig previously approved these changes Dec 17, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

LGTM with some nits. Feel free to ignore

Signed-off-by: Simon Davies <[email protected]>
Signed-off-by: Simon Davies <[email protected]>
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

Approved. But we should follow up to deal with the potential silent errors

@ludfjig ludfjig merged commit c4ac95e into hyperlight-dev:main Dec 17, 2025
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guest-COW PRs that form part of the Guest-COW change kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants