Skip to content

openvmm: pin the gdb stub's detach when a debugger session ends - #2121

Merged
Pedro Henrique Penna (ppenna) merged 2 commits into
devfrom
agents/issue-2094-gdb-detach
Nov 25, 2026
Merged

Pedro Henrique Penna (ppenna) merged 2 commits into
devfrom
agents/issue-2094-gdb-detach

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2094

Stacked on #2120 (agents/issue-2093-virtiofs-hidden-entries), itself stacked on #2119 and the pull requests below it; only the top two commits belong to this pull request (see OpenVMM pin for the landing order).

What does this pull request change?

With OpenVMM's gdb stub (--gdb), the end of a debugger session now detaches the debugger from the VM, whether GDB detaches, its connection drops, or the debug worker stops or restarts. The partition then clears the session's hardware breakpoints and single-stepping, reports the VM's halts, such as a guest power-off, reset, or triple fault, to its client again rather than to the gone debugger, and ends the hold that a debugger's break into a paused VM takes (#1374). Before, the stub never sent DebugRequest::Detach, so all three outlived the session, and the next session's first resume set the previous session's hardware breakpoints on the VPs again. A VM that the debugger stopped stays halted after the detach, as the partition's handling of Detach already intended: its client hears of that halt, and clear-halt resumes it. nvx never starts the gdb stub, so only host debugging sessions reach this.

The fix is in OpenVMM, microsoft/openvmm#5280, which this pull request pins:

  • vmm_core: forget a debugger's halt reports when it detaches. A detach clears halt_reported, which the next session's first resume took for the debugger continuing from a halt recorded after the detach, and reports the recorded halt to the client only when the halt went to the debugger instead, which record_halt now records through DebuggerState::route_halt. Two tests in the partition unit's debugger tests.
  • vmm_core: clear VP debug state on detach only if the debugger set it, since the ARM64 backends of KVM and OpenHCL panic on any request to set it, which aborts the VMM. One test.
  • debug_worker: detach the debugger when its session ends. run_state_machine attaches through a Session guard of the worker's VM proxy (VmProxy::attach), which sends Detach when it is dropped, however the session ends, and forgets the proxy's hardware breakpoints, stepping, and stop channel. DebugRequest::Detach's documentation and the Guide's gdbstub page say what a detach does. Four tests, which run the stub on a loopback TCP connection, send GDB's packets, and serve the stub's requests as the partition does.

The NVX commits are the gitlink-only pin and the mapping of the commits, positions 386-388, in the OpenVMM roadmap. Start with the OpenVMM diff: git diff --submodule=diff origin/agents/issue-2093-virtiofs-hidden-entries...HEAD, at the Session guard in workers/debug_worker/src/gdb/mod.rs and run_state_machine in workers/debug_worker/src/lib.rs, then handle_gdb's Detach in vmm_core/src/partition_unit/debug.rs, then the tests at the ends of workers/debug_worker/src/lib.rs and vmm_core/src/partition_unit.rs.

Left out and limitations:

  • On ARM64, KVM's and OpenHCL's backends implement no guest debugging and panic when a debugger resumes the VM, which sets debug state; that is unchanged. A session that sets no debug state now detaches without reaching them.
  • GDB's software breakpoints, which GDB writes into guest memory, stay there when it loses its connection while the VM runs; the Guide's gdbstub page now says so.
  • When the process that hosts the gdb worker dies, nothing sends Detach.

Why is this change needed?

Root cause: upstream's run_state_machine (workers/debug_worker/src/lib.rs) sends Attach, Resume, and Break as a session starts, and returned without a Detach from every way the session ends: GDB's D or k packet and a target exit, which reach GdbStubStateMachine::Disconnected; an error, such as the read or packet error with which a dropped connection ends the session, which never reaches Disconnected, unlike what the issue assumed; and the worker dropping the session's future as it stops or restarts. The partition's handling of Detach (PartitionUnitRunner::handle_gdb), which therefore never ran, had three defects that sending it would expose, which the first two OpenVMM commits fix:

  • it left halt_reported set, so the next session's first resume cleared a halt recorded after the detach, such as a power-off, and ran the VM again;
  • it reported the recorded halt to the client even when the client had heard of it before the debugger attached, so the client acted on it twice, writing a triple fault's crash dump again, for example;
  • it cleared every VP's debug state, which the ARM64 backends of KVM and OpenHCL do not implement (unimplemented!()), and so would have aborted the VMM at every detach; the code review of this change found it.

Alternatives rejected:

  • Send Detach only when the state machine reaches Disconnected, as the issue suggests: a dropped connection ends the session with an error instead, and the worker drops the session when it stops or restarts, so neither would detach. A guard that sends it when the session is dropped covers every end.
  • Resume a VM that the debugger stopped when it detaches: the partition's Detach keeps such a VM halted and hands the halt to the client, whose clear-halt resumes it, so that a debugger that goes away mid-session does not let the guest run on unobserved; this change keeps that.
  • Make the ARM64 backends accept set_debug_state(None): it would change backends for a stub that does not otherwise set debug state on them; clearing only what the session set leaves them alone.

How was this change validated?

Checks and results. "Before" is OpenVMM d44a113be, the head of feature/microvm/dev when this work started, with the new tests only; "after" is the fix, as b3f686464, 66f661610, and 41fb8512f on d44a113be and, after the rebase onto microsoft/openvmm#5279, as the pinned f06060dfe, 320e09cf5, and 1633b3797, whose patches git range-diff reports equal.

Check Before After
cargo nextest run --profile agent -p vmm_core --features gdb -E 'test(/debugger/)', Windows 11 x64 detach_hands_the_halt_that_the_debugger_took_to_the_client fails: the second debugger is told of a break, and the power-off is cleared; detach_leaves_the_client_a_halt_that_it_already_has fails: the client hears of the halt twice 8 passed
detach_clears_no_debug_state_that_the_debugger_did_not_set, Windows 11 x64 fails when the detach clears the debug state unconditionally, as before: the detach waits for the VP passes
cargo nextest run --profile agent -p debug_worker, Windows 11 x64 the 4 new tests fail: no Detach ends a session 4 passed, also 50 times in a row (--stress-count 50)
cargo check, cargo clippy --all-targets -- -D warnings, and cargo doc --no-deps of vmm_core (with and without gdb), vmm_core_defs, and debug_worker, Windows 11 x64 no warnings, on d44a113be and at 1633b3797
cargo nextest run --profile agent of vmm_core (with and without gdb), debug_worker, and vmm_core_defs, Windows 11 x64 62, 55, 4, and 1 passed, on d44a113be and at 1633b3797; each of the three commits builds and passes the tests of vmm_core and debug_worker
cargo nextest run --profile agent -p vmm_core -p debug_worker --features vmm_core/gdb, then -p vmm_core, and cargo clippy --all-targets -- -D warnings of both, on nvx-kvm-test (Azure Linux 3, kernel 6.18, x86_64, Rust 1.97.1) 66 and 55 passed, no warnings (on d44a113be)
cargo xtask fmt no changes, on d44a113be and at 1633b3797
cargo test --locked --manifest-path nvx/Cargo.toml --no-default-features --test openvmm_vectors -- --ignored, and the same with --test openvmm_cpu_profiles pass, 4 and 1 tests: the vectors, excerpts, versions, activation bound, and CPU profiles that nvx copies are unchanged
python scripts/openvmm_pin.py check-branch --topic --target origin/agents/issue-2093-virtiofs-hidden-entries, python scripts/openvmm_pin.py check-roadmap --worktree, python scripts/check_markdown_links.py, git diff --check, python scripts/nvx.py verify pass; both commits are signed
python scripts/local_gates.py --base origin/agents/issue-2093-virtiofs-hidden-entries --run --keep-going test-changes, markdown-links, test-layout, openvmm-vectors, and openvmm-cpu-profiles pass. nvx-cli, whose Python tests this change does not reach, since it changes no Python or script, ran 1,961 tests, through test_openvmm_pin, in 90 minutes on this loaded workstation before I stopped it, with one error: the tcp-missed subtest of test_private_network_ingress_script_checks_policy_and_traffic, whose shell script exceeded its 10 s timeout under Git's sh, also when run alone. NVX CI's NVX CLI / Linux and NVX CLI / Windows pass the whole gate on this head (below). openvmm-ci is the next row's check
python scripts/nvx.py check-openvmm-ci --revision 1633b3797af878bc9a7c42e4b9c57a2925799d5d the six required jobs passed in microsoft/openvmm#5280's run 45529464352, whose unit tests [x64-linux] and unit tests [x64-windows] ran the seven new tests

CI: this head's run 45551161300 passed, with the microVM scenarios on KVM, MSHV, and WHP, the NVX CLI jobs on Linux and Windows, and the check of OpenVMM's CI of the pin. Copilot reviewed this head and raised no issue.

A code review of the whole OpenVMM diff found the ARM64 panic above, which vmm_core: clear VP debug state on detach only if the debugger set it fixes, and that the Guide's new paragraph promised to clear GDB's software breakpoints, which it now says a lost connection leaves in guest memory.

Backend, host OS, host type, and guest: unit tests only, on Windows 11 x64 and on nvx-kvm-test, a virtual machine; the change is platform-independent and has no effect without an attached gdb stub, which nvx does not start, so no microVM scenario reaches it. nvx-kvm-test stopped responding after the rebase, so the Linux runs at the rebased 1633b3797 are OpenVMM CI's.

Left to CI: NVX's microVM jobs on KVM, MSHV, and WHP; OpenVMM's VMM tests, which passed for this pin in the run above, and none of which uses the gdb stub. run vmm-tests [x64-windows-amd-snp] failed in that run; NVX does not require it, and it fails at microsoft/openvmm#5277 and #5278 too.

Checklist

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes.
  • A change to the public API of nvx updates nvx/public-api/ with
    python3 scripts/public_api.py --update.
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

Changes to existing tests

None: python scripts/check_test_changes.py --base origin/agents/issue-2093-virtiofs-hidden-entries lists no change to an existing test, and the OpenVMM pull request adds seven tests and changes none.

OpenVMM pin

OpenVMM's gdb stub never told the partition that the debugger had gone
(#2094). After GDB detached, its connection dropped, or the debug
worker stopped, the partition went on treating the debugger as
attached: the session's hardware breakpoints and single-stepping stayed
set on the VPs, the halts that followed, a power-off, reset, or triple
fault included, went to the gone debugger instead of the VM's client,
and a paused VM that a debugger's break held stayed held until a new
session or a clear-halt. nvx never starts the gdb stub, so only a host
debugging session reaches this.

Pin 1633b3797af878bc9a7c42e4b9c57a2925799d5d, the head of
microsoft/openvmm#5280, three commits on 043083f40, the head of
microsoft/openvmm#5279, which NVX pins below this commit:

- vmm_core: forget a debugger's halt reports when it detaches. A
  detach clears the partition's record that it told the debugger of
  the recorded halt, which the next session's first resume took for
  the debugger continuing from a halt recorded after the detach, such
  as a power-off, and so ran the VM again. It reports the recorded
  halt to the client only when the halt went to the debugger instead,
  no longer a second time when the client heard of it before the
  debugger attached.
- vmm_core: clear VP debug state on detach only if the debugger set
  it, since the ARM64 backends of KVM and OpenHCL, which implement no
  guest debugging, panic when asked to clear it, which aborts the VMM.
- debug_worker: detach the debugger when its session ends. The stub
  attaches through a guard that sends DebugRequest::Detach when it is
  dropped, however the session ends: GDB's D or k packet, a target
  exit, an error such as a dropped connection, or the worker dropping
  the session as it stops or restarts. The guard also forgets the
  session's hardware breakpoints, which the next session's first
  resume set on the VPs again. The Guide's gdbstub page says what a
  detach does.

No saved state, protocol, ABI, or format, and no version of any of
them, changes. NVX needs no coordinated change: the protocol vectors,
the source excerpts, the contract versions, the activation bound, and
the CPU profiles that nvx copies from OpenVMM match the revision's.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…enVMM roadmap

Map positions 386-388, the commits of microsoft/openvmm#5280, which
NVX now pins at 1633b3797, 262 commits past the mapped tip, on
043083f40, the head of microsoft/openvmm#5279, whose position 385
follows position 384, 44747bf1c, the head of microsoft/openvmm#5278,
whose position follows position 383, fa239c823, the head of
feature/microvm/dev since microsoft/openvmm#5277 landed it:

- 386, vmm_core: forget a debugger's halt reports when it detaches. A
  detach clears halt_reported, which the next session's first resume
  took for the debugger continuing from a halt recorded after the
  detach, and reports the recorded halt to the client only when the
  halt went to the debugger instead, which position 150's record_halt
  now records through DebuggerState::route_halt.
- 387, vmm_core: clear VP debug state on detach only if the debugger
  set it, since the ARM64 backends of KVM and OpenHCL panic on any
  request to set it.
- 388, debug_worker: detach the debugger when its session ends. The
  stub attaches through a guard that sends DebugRequest::Detach when
  it is dropped, however the session ends, and forgets the session's
  hardware breakpoints; the Guide's gdbstub page says what a detach
  does.

They are not fixups and stay unassigned to a PR: the missing detach
and the defects of its handling are upstream's, and positions 150 and
372, whose record_halt line and debugger tests they change or extend,
are not assigned to PRs. In partition_unit/debug.rs, they change
upstream's handling of Detach and SetDebugState, beside position 372's
hold, not the halt reasons that position 054 maps. No chain commit
changes the debug worker, and none of the 43 that change Cargo.lock
changes the entry of debug_worker. Of positions 373-385, only 378 and
384 change one of their files, other packages' entries of Cargo.lock.
Replaying them on upstream main, 8d4e03132, conflicts in
partition_unit.rs, partition_unit/debug.rs, and debug_rpc.rs, which
lack the code of positions 150 and 372, so they cannot go upstream on
their own.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🟢 Approval recommended

There are no active review issues for the roadmap update pinning the debugger-session cleanup fix.

No open issues 🎉

What changed in this PR

This PR pins OpenVMM’s debugger-session cleanup fix for #2094 and records it in NVX’s upstream roadmap. The fix detaches ended debugger sessions so their hardware breakpoints, stepping state, and halt routing do not persist.

Changes:

  • Updates the roadmap’s pinned revision to 1633b3797, at position 388.
  • Maps commits 386–388 and updates chain counts and ranges.
  • Documents the fixes, regression coverage, and dependencies affecting upstream submission.
File Description
doc/​openvmm-upstream-roadmap.md Records the new pin and maps the three debugger-detach commits, including their rationale and upstream dependencies.

Review effort: Balanced

Base automatically changed from agents/issue-2093-virtiofs-hidden-entries to dev November 25, 2026 06:11
@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 25, 2026
Merged via the queue into dev with commit 3881452 Nov 25, 2026
51 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2094-gdb-detach branch November 25, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openvmm: the gdb stub never detaches, so a debugger's breakpoints and halt routing outlive its session

2 participants