-
Notifications
You must be signed in to change notification settings - Fork 155
Unify page table manipulation code between the guest and the host #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify page table manipulation code between the guest and the host #1093
Conversation
ef2c3ea to
09cf019
Compare
There was a problem hiding this 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
vmmodule inhyperlight_commonwith aTableOpstrait 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 |
|
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!");
} |
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]>
Signed-off-by: Simon Davies <[email protected]>
Thanks, I fixed a bug in the |
d356a69 to
1049d4b
Compare
1049d4b to
5626c95
Compare
39ae653 to
6bdbd41
Compare
ludfjig
left a comment
There was a problem hiding this 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
72c40d0 to
5157170
Compare
Signed-off-by: Simon Davies <[email protected]>
5157170 to
0d0829d
Compare
Signed-off-by: Simon Davies <[email protected]>
ludfjig
left a comment
There was a problem hiding this 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
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_commonand factored into an architecture-independent interface and architecture-specific code parts).