Skip to content

feat(aarch64): add GDB debugging for Linux KVM - #2016

Open
cshung wants to merge 9 commits into
hyperlight-dev:mainfrom
cshung:cshung/kvm-aarch64-gdb
Open

cshung wants to merge 9 commits into
hyperlight-dev:mainfrom
cshung:cshung/kvm-aarch64-gdb

Conversation

@cshung

@cshung cshung commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

ARM64 Linux KVM GDB

KVM guests support register and memory access, two hardware breakpoints,
BRK software breakpoints, and hardware single-step.
KVM reports debug stops through KVM_EXIT_DEBUG.
Debug state survives vCPU reset, and register access respects the active stack pointer.

Dependencies

Requires shared debugger support in #2050. This PR provides KVM integration,
platform enablement, and native GDB CI. The full diff includes the shared
prerequisite. Default-driver builds retain non-debug MSHV use and reject
MSHV debugging. MSHV debugger support is independent in #2052.

KVM-only comparison.

Validation

November 23, base f297a914:

  • Formatting and ARM64 GDB-enabled cross-Clippy pass with default and KVM-only features.
  • Linux x64 GDB-enabled Clippy passes.
  • Windows x64 Clippy and focused debugger tests pass.
  • The shared prerequisite passes fresh guests, build, and the full Windows just test recipe.

Earlier Raspberry Pi 4 validation passed 16 targeted native unit tests and
six real GDB client tests. It uses a separate, uncommitted ARMv8.0 allocator
fix and guests built with RUSTFLAGS="-C target-feature=-lse".
Pi compatibility changes are outside this PR.

Shared support has November 19 native ARM64 MSHV validation through #2052.
Native ARM64 runtime tests have not been repeated on this base. The MSHV
unsupported-debug adapter regression test is cross-compiled only.

@cshung cshung added C-enhancement For PRs adding features, improving functionality, docs, tests, etc. S-needs-review PR is ready for (re-)review labels Nov 3, 2026
Copilot AI balanced review requested due to automatic review settings November 3, 2026 00:34
@cshung
cshung marked this pull request as draft November 3, 2026 00:36
@cshung cshung removed the S-needs-review PR is ready for (re-)review label Nov 3, 2026

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.

🟡 Changes recommended

Unresolved critical flaws allow guest modification of executable trampoline code and debugger memory corruption, while breakpoint cleanup and snapshot-ordering issues can leave sandboxes unrecoverable.

5 open issues
What changed in this PR

Adds ARM64 guest debugging on Linux/KVM, alongside the shared debugger infrastructure and Windows/WHP support from #1907.

Changes:

  • Supports ARM64 register and memory access, software and hardware breakpoints, and hardware single-step.
  • Adds instruction-cache synchronization, debug-state preservation across reset, and snapshot safeguards.
  • Adds debugger tests and documents platform capabilities.
File Description
src/​hyperlight_host/​src/​sandbox/​uninitialized_evolve.rs Initializes ARM64 debug vectors during VM setup.
src/​hyperlight_host/​src/​sandbox/​snapshot/​memory/​backing.rs Exposes backing ranges for cache synchronization.
src/​hyperlight_host/​src/​sandbox/​initialized.rs Guards snapshots and restores against active software breakpoints.
src/​hyperlight_host/​src/​mem/​mgr.rs Exposes checked host memory ranges to the debugger.
src/​hyperlight_host/​src/​mem/​exe.rs Carries debug-vector addresses in load metadata.
src/​hyperlight_host/​src/​mem/​elf.rs Finds and relocates the debug-vector symbol.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​whp/​x86_64.rs Adapts address translation to the shared interface.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​whp/​aarch64.rs Implements WHP debugging, cache synchronization, and tests.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​mshv/​x86_64.rs Adapts address translation to the shared interface.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​mod.rs Adds ARM64 debug exits and initialization errors.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​kvm/​x86_64.rs Adapts address translation to the shared interface.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​kvm/​aarch64.rs Implements KVM debugging and active-stack-pointer handling.
src/​hyperlight_host/​src/​hypervisor/​regs/​aarch64/​whp_reg.rs Defines WHP debug register identifiers.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​x86_64.rs Uses shared debugger handling and breakpoint storage.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​mod.rs Integrates ARM64 stops, stepping, and mapping safeguards.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​debug.rs Provides shared requests and software-breakpoint lifecycle handling.
src/​hyperlight_host/​src/​hypervisor/​hyperlight_vm/​aarch64.rs Connects ARM64 VM setup and execution to GDB.
src/​hyperlight_host/​src/​hypervisor/​gdb/​target.rs Adds ARM64 register conversion to the shared target.
src/​hyperlight_host/​src/​hypervisor/​gdb/​mod.rs Adds page-table translation and cache-flush support.
src/​hyperlight_host/​src/​hypervisor/​gdb/​event_loop.rs Reports ARM64 initial stops to GDB.
src/​hyperlight_host/​src/​hypervisor/​gdb/​arch/​x86_64.rs Houses x86 breakpoint constants and stop classification.
src/​hyperlight_host/​src/​hypervisor/​gdb/​arch/​aarch64.rs Defines ARM64 software breakpoints and alignment checks.
src/​hyperlight_host/​src/​hypervisor/​gdb/​arch.rs Selects architecture-specific debugger helpers.
src/​hyperlight_host/​examples/​guest-debugging/​main.rs Adds ARM64 breakpoint, stepping, and code-write integration tests.
src/​hyperlight_host/​build.rs Enables GDB for supported ARM64 platforms.
src/​hyperlight_guest_bin/​src/​arch/​aarch64/​exception/​entry.rs Exports debug vectors and forwards synchronous exceptions.
src/​hyperlight_common/​src/​arch/​aarch64/​exn.rs Defines the shared debug-exception HVC immediate.
docs/​how-to-debug-a-hyperlight-guest.md Documents ARM64 capabilities and guest-symbol requirements.
CHANGELOG.md Records Linux/KVM and Windows/WHP ARM64 debugging support.

Review effort: Balanced

@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from a60be9b to 55da94f Compare November 3, 2026 01:58
@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 55da94f to 2418379 Compare November 3, 2026 19:28
@hyperlight-gh-bot

This comment has been minimized.

@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from a26c2d9 to 11361ca Compare November 4, 2026 16:37
@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 11361ca to 4849110 Compare November 5, 2026 17:24
@hyperlight-gh-bot

This comment has been minimized.

@yoshuawuyts yoshuawuyts added O-aarch64 Specific to 64-bit Arm processors O-kvm Linux KVM backend O-linux Linux host support S-needs-review PR is ready for (re-)review labels Nov 16, 2026
@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 68a8704 to 45810c6 Compare November 16, 2026 18:16
@hyperlight-gh-bot

This comment has been minimized.

@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 4bfc023 to a44091d Compare November 24, 2026 19:30
@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch 3 times, most recently from b23e24c to 89968c9 Compare November 25, 2026 17:22
@hyperlight-gh-bot

This comment has been minimized.

@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 89968c9 to a32acde Compare November 25, 2026 18:40
cshung and others added 4 commits November 25, 2026 10:41
Architecture adapters, software breakpoints, page-sized memory access and recovery handling are shared by backend layers. Guest debug vectors and common tests support ARM64. Backend layers control platform enablement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
ARM64 page-table translation lives with the architecture helpers. Software breakpoint storage stays behind its methods. Debug-exit bindings and cfg placement follow the surrounding style.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Keep the initial stop in the run loop. Let GDB own software breakpoint step-over and use hardware single-step for step requests. Apply snapshot breakpoint guards to both architectures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Debugger register and memory edits can violate guest invariants. Reject snapshot creation for the lifetime of debug-configured sandboxes on x86_64 and ARM64, including after detach. Keep loading and restoring existing snapshots available with the existing breakpoint safeguards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from a32acde to 339504e Compare November 25, 2026 18:42
Match the error directly so the regression test does not require Snapshot to implement Debug.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 339504e to 977d7da Compare November 25, 2026 19:20
cshung and others added 4 commits November 25, 2026 11:46
The initialized-snapshot regression builds a memory manager inside the ARM64-only test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
KVM debug exits provide hardware breakpoints and single-step. Register access respects the active stack pointer. Native ARM64 GDB tests run in debug CI. Shared debugger behavior belongs to the parent commit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Preserve debug enablement and hardware breakpoints across reset. Keep single-step transient and require explicit unsupported-backend handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
@cshung
cshung force-pushed the cshung/kvm-aarch64-gdb branch from 977d7da to 00436e3 Compare November 25, 2026 19:46
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 00436e37a814
Baseline commit: c46735cd076c

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 282.98 ns (➖ 1.03x slower)
vec_bytes 79.00 ns (➖ 1.03x faster)
372.40 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
65536 141.78 ns (➖ 1.00x slower)
262144 523.78 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 13.59 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
7.68 ns (➖ 1.00x faster) 7.68 ns (➖ 1.00x faster) 9.50 ns (➖ 1.24x slower)

snapshot_files

load_snapshot_unverified
small 116.49 µs (➖ 1.08x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 1.92 µs (➖ 1.07x faster) 2.05 µs (➖ 1.07x slower)
262144 6.98 µs (➖ 1.05x faster) 7.29 µs (➖ 1.03x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 6.17 µs (➖ 1.07x faster) 6.14 µs (➖ 1.05x faster)
262144 27.39 µs (➖ 1.00x faster)
8192 1.03 µs (➖ 1.01x slower) 1.05 µs (➖ 1.04x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 261.73 ns (➖ 1.04x faster)
vec_bytes 83.50 ns (➖ 1.00x faster)
666.82 µs (➖ 1.02x faster)

payload_allocation

slot_pool_segmented
65536 134.78 ns (➖ 1.01x faster)
262144 499.48 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 15.18 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
6.89 ns (➖ 1.00x faster) 6.89 ns (➖ 1.00x faster) 6.90 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 53.92 µs (➖ 1.00x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.14 µs (➖ 1.01x slower) 2.11 µs (➖ 1.01x faster)
262144 7.48 µs (➖ 1.00x slower) 7.48 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 6.98 µs (➖ 1.01x faster) 6.98 µs (➖ 1.01x faster)
262144 29.15 µs (➖ 1.00x faster)
8192 724.18 ns (➖ 1.03x slower) 717.52 ns (➖ 1.01x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 365.57 ns (➖ 1.06x faster)
vec_bytes 96.38 ns (➖ 1.00x faster)
302.62 µs (➖ 1.13x slower)

payload_allocation

slot_pool_segmented
65536 194.04 ns (➖ 1.01x faster)
262144 738.25 ns (➖ 1.02x slower)

sandboxes

create_initialized_and_drop
medium 63.00 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
9.86 ns (➖ 1.01x faster) 9.87 ns (➖ 1.00x faster) 9.87 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 100.20 µs (➖ 1.03x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.23 µs (➖ 1.00x faster) 2.41 µs (➖ 1.01x faster)
262144 9.52 µs (➖ 1.01x faster) 10.55 µs (➖ 1.07x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.14 µs (➖ 1.26x faster) 8.37 µs (➖ 1.15x faster)
262144 35.94 µs (➖ 1.06x faster)
8192 1.27 µs (➖ 1.04x slower) 1.26 µs (➖ 1.01x slower)
mshv3 / intel (Linux) (❌ 1.98x)

Top regressions

  • function_call_codec/decode_vec_bytes_copy — ❌ 1.98x slower

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 359.19 ns (➖ 1.01x slower)
vec_bytes 86.44 ns (➖ 1.01x slower)
1.26 ms (❌ 1.98x slower)

payload_allocation

slot_pool_segmented
65536 171.17 ns (➖ 1.01x faster)
262144 687.90 ns (➖ 1.09x slower)

sandboxes

create_initialized_and_drop
medium 88.96 ms (➖ 1.25x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
8.70 ns (➖ 1.01x faster) 9.12 ns (➖ 1.00x slower) 8.69 ns (➖ 1.09x faster)

snapshot_files

load_snapshot_unverified
small 59.66 µs (➖ 1.06x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.28 µs (➖ 1.00x faster) 2.26 µs (➖ 1.02x faster)
262144 7.90 µs (➖ 1.00x faster) 7.96 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 7.44 µs (➖ 1.04x faster) 7.43 µs (➖ 1.01x faster)
262144 41.18 µs (➖ 1.01x faster)
8192 895.79 ns (➖ 1.02x faster) 884.18 ns (➖ 1.03x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 565.99 ns (➖ 1.02x faster)
vec_bytes 157.94 ns (➖ 1.00x faster)
2.32 ms (➖ 1.05x slower)

payload_allocation

slot_pool_segmented
65536 232.53 ns (➖ 1.04x faster)
262144 834.36 ns (➖ 1.41x faster)

sandboxes

create_initialized_and_drop
medium 14.58 ms (➖ 1.03x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.70 ns (➖ 1.04x faster) 10.30 ns (➖ 1.04x faster) 10.59 ns (➖ 1.05x faster)

snapshot_files

load_snapshot_unverified
small 849.28 µs (➖ 1.03x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.34 µs (➖ 1.01x faster) 2.32 µs (➖ 1.02x faster)
262144 9.12 µs (➖ 1.02x faster) 9.08 µs (➖ 1.05x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.81 µs (➖ 1.02x faster) 9.17 µs (➖ 1.03x faster)
262144 38.85 µs (➖ 1.03x faster)
8192 1.28 µs (➖ 1.04x faster) 1.30 µs (➖ 1.02x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 611.33 ns (➖ 1.08x slower)
vec_bytes 177.82 ns (➖ 1.11x slower)
2.92 ms (➖ 1.02x faster)

payload_allocation

slot_pool_segmented
65536 209.26 ns (➖ 1.02x faster)
262144 778.34 ns (➖ 1.20x faster)

sandboxes

create_initialized_and_drop
medium 14.04 ms (➖ 1.02x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.09 ns (➖ 1.01x slower) 9.72 ns (➖ 1.00x faster) 9.91 ns (➖ 1.08x faster)

snapshot_files

load_snapshot_unverified
small 598.92 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.29 µs (➖ 1.00x faster) 2.30 µs (➖ 1.00x faster)
262144 7.70 µs (➖ 1.00x faster) 7.75 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 9.33 µs (➖ 1.13x slower) 8.17 µs (➖ 1.03x faster)
262144 42.05 µs (➖ 1.01x slower)
8192 1.05 µs (➖ 1.11x faster) 1.05 µs (➖ 1.01x slower)

Reported by cargo ci bench-report --candidate run:45688504129 --config-file bench_report.toml.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement For PRs adding features, improving functionality, docs, tests, etc. O-aarch64 Specific to 64-bit Arm processors O-kvm Linux KVM backend O-linux Linux host support S-needs-review PR is ready for (re-)review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants