Skip to content

Simplify GDB memory access by borrowing sandbox memory manager - #1735

Closed
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:simplify_gdb
Closed

Simplify GDB memory access by borrowing sandbox memory manager#1735
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:simplify_gdb

Conversation

@ludfjig

@ludfjig ludfjig commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Noticed this ugly code when reviewing another PR and thought it could be cleaned up. MemoryManager already contains everything needed for gdb so no need to clone it as we can borrow it instead. Also fixes potential stale memory access since snapshot restore can replace snapshot and scratch memory, and the cloned manager could potentially be out of sync. Also removed some now unnecessary synchronization and plumbing

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig changed the title borrow memory manager instead of cloning, make manager non-clone Simplify GDB memory access by borrowing the sandbox memory manager Aug 13, 2026
@ludfjig ludfjig added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Aug 13, 2026
@ludfjig ludfjig changed the title Simplify GDB memory access by borrowing the sandbox memory manager Simplify GDB memory access by borrowing sandbox memory manager Aug 13, 2026
@ludfjig ludfjig added the ready-for-review PR is ready for (re-)review label Aug 13, 2026
@ludfjig
ludfjig marked this pull request as ready for review August 13, 2026 19:42
Copilot AI lite review requested due to automatic review settings August 13, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the GDB memory-access path in hyperlight_host to borrow the sandbox’s in-use SandboxMemoryManager rather than cloning and mutex-wrapping it, aiming to avoid stale memory views after snapshot restore and to simplify the init/run/dispatch plumbing.

Changes:

  • Remove the cloned SandboxMemoryManager + Arc<Mutex<…>> plumbing from sandbox initialization and VM dispatch paths.
  • Replace DebugMemoryAccess (owned, mutex-backed) with DebugMemoryView (borrowed view) for GDB memory operations.
  • Drop Clone on SandboxMemoryManager and update call sites/tests accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/hyperlight_host/src/sandbox/uninitialized_evolve.rs Removes GDB-specific cloned/mutex memory-manager plumbing during evolve.
src/hyperlight_host/src/sandbox/initialized_multi_use.rs Removes stored debug memory manager and simplifies dispatch/init signatures.
src/hyperlight_host/src/mem/mgr.rs Removes Clone derive from SandboxMemoryManager.
src/hyperlight_host/src/hypervisor/mod.rs Updates hypervisor tests to match the simplified initialise signature.
src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs Updates initialise/dispatch/debug handling to use borrowed DebugMemoryView.
src/hyperlight_host/src/hypervisor/hyperlight_vm/mod.rs Updates run to pass the live mem_mgr into debug handling without extra handles.
src/hyperlight_host/src/hypervisor/hyperlight_vm/aarch64.rs Updates initialise/dispatch calls to match the simplified run signature.
src/hyperlight_host/src/hypervisor/gdb/mod.rs Introduces DebugMemoryView and refactors GDB mem-access tests/utilities.
Suppressed comments (1)

src/hyperlight_host/src/hypervisor/gdb/mod.rs:551

  • Same issue as the single-byte write test: this writes to a GPA that resolves to BaseGpaRegion::Mmap, but DebugMemoryView::write only permits scratch (and snapshot under unshared_snapshot_mem). The test should either expect WriteToReadOnly or write into scratch and validate scratch_mem.
            let write_data = [0xAAu8; 16];
            memory
                .access()
                .write(&write_data, (BASE_VIRT + offset) as u64)
                .unwrap();

            let slice = unsafe { memory.mmap_slice() };
            assert_eq!(slice[offset..offset + 16], write_data);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 521 to 528
let write_data = [0xCCu8; 1];
mem_access
memory
.access()
.write(&write_data, (BASE_VIRT + offset) as u64)
.unwrap();

let slice = unsafe { get_mmap_slice(&mut mem_access) };
let slice = unsafe { memory.mmap_slice() };
assert_eq!(slice[offset], write_data[0]);
@ludfjig ludfjig closed this Aug 13, 2026
@github-actions github-actions Bot removed the ready-for-review PR is ready for (re-)review label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants