Skip to content
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

Change host's memory setup to be minimally configured #297

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

danbugs
Copy link
Contributor

@danbugs danbugs commented Feb 27, 2025

We want to allow embedding custom guests in Hyperlight, but, currently, the static memory layout we configure in the host is too strict. This PR is modifying our memory layout to be minimally configured.

Here's a wip view of the memory layout for when this PR is finished:
image

Changes:

  • BASE_ADDRESS modified to be 0x0 instead of 0x200_000 (2MB), removing the arbitrary unmapped section of memory.
  • Moved guest code section to be at 0x0, shifting paging sections up.
  • Added undifferentiated custom guest memory section that the guest can address in any way it wants.

@danbugs danbugs added kind/refactor kind/enhancement New feature or request labels Feb 27, 2025
danbugs added a commit to danbugs/hyperlight that referenced this pull request Feb 27, 2025
…st code to start at 0x0

instead of after paging sections

This is the first step in moving memory sections around to provide a more generic
layout. After this, I'll move continue moving sections to fulfill the layout shown
in the description for PR hyperlight-dev#297.

Changes:
- removed no longer applicable checks in hypervisor_handler
- changed the way we build memory in get_memory_regions
- added functions to get the offsets/addresses to paging sections
as they are no longer static from 0x0 and are now relative to code size
- updated code docs
- changed set_up_shared_memory to properly place paging sections
- updated paging docs

Signed-off-by: danbugs <[email protected]>
danbugs added a commit to danbugs/hyperlight that referenced this pull request Feb 27, 2025
…st code to start at 0x0

instead of after paging sections

This is the first step in moving memory sections around to provide a more generic
layout. After this, I'll move continue moving sections to fulfill the layout shown
in the description for PR hyperlight-dev#297.

Changes:
- removed no longer applicable checks in hypervisor_handler
- changed the way we build memory in get_memory_regions
- added functions to get the offsets/addresses to paging sections
as they are no longer static from 0x0 and are now relative to code size
- updated code docs
- changed set_up_shared_memory to properly place paging sections
- updated paging docs

Signed-off-by: danbugs <[email protected]>
@danbugs danbugs force-pushed the danbugs/memory-layout branch from 56852a6 to 40a8091 Compare February 27, 2025 16:59
… be 0x0.

We had an arbitrary unmapped section of memory from 0x0 to 0x200_000 (2MB).
This was reported to be a point of friction when embedding custom guests.

Changes:
- removed custom write for page 0.
- fixed get_address macro to work properly when guest_offset == 0.
- removed test that no longer makes sense w/ starting mem at 0x0.
- cleaned docs/comments referring to mapped memory starting at 0x200_000.
- fixed some typos.

Signed-off-by: danbugs <[email protected]>
…st code to start at 0x0

instead of after paging sections

This is the first step in moving memory sections around to provide a more generic
layout. After this, I'll move continue moving sections to fulfill the layout shown
in the description for PR hyperlight-dev#297.

Changes:
- removed no longer applicable checks in hypervisor_handler
- changed the way we build memory in get_memory_regions
- added functions to get the offsets/addresses to paging sections
as they are no longer static from 0x0 and are now relative to code size
- updated code docs
- changed set_up_shared_memory to properly place paging sections
- updated paging docs

Signed-off-by: danbugs <[email protected]>
@danbugs danbugs force-pushed the danbugs/memory-layout branch 2 times, most recently from f692bda to b7435ae Compare February 28, 2025 01:38
…},sandbox/config},testing/lib,Justfile,Cargo.toml,.gitignore]

added custom guest memory region and tmp custom guest

Context: Instead of having a static memory layout set by the host, we want to provide the guest w/ a custom sized
allocated undifferentiated memory region for it address in any way it wants. This commit starts that by adding the
custom guest memory region.

Changes:
- added new section to SandboxMemoryLayout, and made getters for its offset and size.
- changed get_total_page_table_size calculation to account for custom section.
- added new section to builder in get_memory_regions.
- wrote address of custom guest memory region to custom guest memory offset.
- added new memory section to page table setup (i.e., set_up_shared_memory).
- added function to get custom guest memory region as Vec<u8>.
- made custom guest memory section size configurable via SandboxConfiguration.
- fixed existing tests.
- added new guest (customguest) to test custom setup. Modified Justfile to include it for easy builds too.
- added new test for custom init with the new customguest.

Signed-off-by: danbugs <[email protected]>
@danbugs danbugs force-pushed the danbugs/memory-layout branch from b7435ae to ce255f8 Compare February 28, 2025 02:06
danbugs added 4 commits March 1, 2025 03:11
Signed-off-by: danbugs <[email protected]>
Signed-off-by: danbugs <[email protected]>
Signed-off-by: danbugs <[email protected]>
Signed-off-by: danbugs <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request kind/refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant