Skip to content

[DO NOT REVIEW] debug_worker: detach the debugger when its session ends - #5280

Merged
Pedro Henrique Penna (ppenna) merged 10 commits into
feature/microvm/devfrom
copilot/nvx-issue-2094-gdb-detach
Nov 25, 2026
Merged

Pedro Henrique Penna (ppenna) merged 10 commits into
feature/microvm/devfrom
copilot/nvx-issue-2094-gdb-detach

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#2094.

Stacked on #5279, itself stacked on #5278, #5277, #5276, #5275, #5273, #5272, and #5271: this branch holds their eight commits (2d222dcdc of #5271, a8aeeb65e of #5272, 32e824728 of #5273, 5d3f172c3 of #5275, acfaa5199 of #5276, fa239c823 of #5277, 44747bf1c of #5278, 043083f40 of #5279), which follow the head of feature/microvm/dev, 3f5506f9d, directly, and three commits of its own on top of them: f06060dfe, 320e09cf5, and 1633b3797. Review only those three; #5271 to #5279 cover the others.

NVX pins the head of this branch, 1633b3797af878bc9a7c42e4b9c57a2925799d5d, in an NVX pull request stacked on the NVX pull request of microsoft/nvx#2093 (branch agents/issue-2093-virtiofs-hidden-entries). This pull request is therefore a prerequisite of that NVX change. It lands after #5271, #5272, #5273, #5275, #5276, #5277, #5278, and #5279, by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

Problem

OpenVMM's gdb stub, the debug worker that --gdb starts, sent DebugRequest::Attach when GDB connected, but never DebugRequest::Detach. After GDB detached, its connection dropped, or the worker stopped or restarted, the partition went on treating the gone debugger as attached:

  • the session's hardware breakpoints and single-stepping stayed set on the VPs, so the guest could still halt on them;
  • the halts that followed, a power-off, reset, or triple fault included, went to the gone debugger's stop channel instead of the VM's client, so a client set to exit or reset on them never heard of them;
  • a paused VM that a debugger's break held ([DO NOT REVIEW] vmm_core: keep a debugger break into a paused VM out of its saved state #5263) stayed held until a new session or a clear-halt;
  • the stub kept the session's hardware breakpoints, and the next session's first resume set them on the VPs again, unknown to its GDB.

Root cause

run_state_machine (workers/debug_worker/src/lib.rs) sends Attach, Resume, and Break as a session starts, and every way out of it returned without a Detach: 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 a session; and the worker dropping the session's future as it stops or restarts.

The partition's handling of Detach (PartitionUnitRunner::handle_gdb, vmm_core/src/partition_unit/debug.rs), which therefore never ran, had three defects that sending it would have exposed:

  • it left halt_reported set, so the next session's first resume, which the stub sends as it attaches, cleared a halt recorded after the detach, such as a power-off, as if the debugger had continued from it, 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 again, writing a triple fault's crash dump a second time, for example;
  • it cleared the debug state of every VP, which the ARM64 backends of KVM and OpenHCL do not implement and panic on (unimplemented!()), which ends the VMM, since it aborts on panic.

Fix

  • f06060dfe vmm_core: forget a debugger's halt reports when it detaches. Detach clears halt_reported, and reports the recorded halt to the client only when it went to the debugger instead, which record_halt now records as it routes each halt (DebuggerState::route_halt).
  • 320e09cf5 vmm_core: clear VP debug state on detach only if the debugger set it, as the stub does whenever it resumes the VM.
  • 1633b3797 debug_worker: detach the debugger when its session ends. run_state_machine attaches through a Session guard of the VM proxy (VmProxy::attach), which sends Detach when it is dropped, however the session ends, and forgets the proxy's breakpoints, stepping, and stop channel.

A VM that the debugger stopped stays halted after it detaches, as the partition's Detach already intended: the client hears of that halt, and clear-halt resumes it. The documentation of DebugRequest::Detach and DebugRequest::Break and the Guide's gdbstub page say what a detach does; the Guide also says that GDB's software breakpoints, which it writes into guest memory, stay there when it loses its connection while the VM runs.

No saved state, protocol, ABI, or format, and no version of any of them, changes; DebugRequest keeps its variants.

Not changed:

  • On ARM64 KVM and OpenHCL, a debugger that resumes the VM still meets the unimplemented!() of the backends' set_debug_state, as before; only a session that sets no debug state now detaches safely.
  • When the process that hosts the gdb worker dies, nothing sends Detach.

Tests

In vmm_core (gdb feature), in the partition unit's save and restore tests, which send the debugger's requests as the gdb stub does:

  • detach_hands_the_halt_that_the_debugger_took_to_the_client: a break into a running unit, then a detach, reports the break to the client; the client resumes the VM, which powers off, and a second debugger is told of the power-off, which stays recorded.
  • detach_leaves_the_client_a_halt_that_it_already_has: the client hears of a halt that preceded the debugger only once.
  • detach_clears_no_debug_state_that_the_debugger_did_not_set: a detach after a session that set no debug state completes without a request to the VPs.

In debug_worker, which run the stub on a loopback TCP connection, send GDB's packets, and serve the stub's requests as the partition does:

  • the_debugger_detaches_when_gdb_detaches: GDB sends D.
  • the_debugger_detaches_when_the_connection_drops: GDB's connection closes while the VM is stopped, and while it runs after vCont;c.
  • the_debugger_detaches_when_the_session_is_dropped: the worker drops the session, as it does when it stops or restarts.
  • a_session_does_not_set_the_breakpoints_of_the_previous_one: a session sets a hardware breakpoint with Z1 and drops; the next session's first resume sets none.

Validation

On d44a113be, the head of feature/microvm/dev before this stack:

  • On Windows 11 x64, with the new tests only, six of them fail: the second debugger is told of a break and the power-off is cleared, the client hears of a halt twice, and no Detach ends a debug worker session. detach_clears_no_debug_state_that_the_debugger_did_not_set fails when the detach clears the debug state unconditionally, as before. With the fix, all seven pass, also 50 times in a row (--stress-count 50).
  • On Windows 11 x64: 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 have no warnings; cargo nextest run --profile agent passes 62 tests of vmm_core with gdb and 55 without, 4 of debug_worker, and 1 of vmm_core_defs; each of the three commits builds and passes the tests of vmm_core and debug_worker; cargo xtask fmt reports nothing.
  • On Linux (Azure Linux 3, kernel 6.18, x86_64, Rust 1.97.1): cargo nextest run --profile agent -p vmm_core -p debug_worker --features vmm_core/gdb passes 66 tests, and without gdb, vmm_core passes 55; cargo clippy --all-targets -- -D warnings of both, with and without gdb, has no warnings.

The rebase onto #5279 applied without conflicts and left the three patches unchanged, as git range-diff reports. #5271 to #5279 change pal_async, vm_topology, and virt, on which these packages depend, so the Windows checks above ran again on this head, with the same results: no warnings, 62 and 55 tests of vmm_core, 4 of debug_worker, and 1 of vmm_core_defs pass, and cargo xtask fmt reports nothing. This head's CI, run 45529464352, passed unit tests [x64-linux] and unit tests [x64-windows], which ran the seven new tests, and the run vmm-tests jobs of x64-linux-amd-kvm, x64-linux-intel-mshv, x64-windows-intel, and x64-windows-amd; run vmm-tests [x64-windows-amd-snp] failed, as it does at #5277 and #5278.

Not run: VMM tests. No VMM test uses the gdb stub, and NVX does not start it.

Only the hypervisor's APIC suspends a VP that reads
HV_X64_MSR_GUEST_IDLE, which a save then records as the Hyper-V idle MP
state. The user-mode APIC, which `whp:user_mode_apic` selects, as does
`no_enlightenments` with `--hv`, never saves that state, but a snapshot
does not record which APIC captured it, so a restore with the user-mode
APIC can be given one, and restore_activity then reached
`unimplemented!()` and aborted the VMM.

The user-mode APIC cannot hold the state: an interrupt wakes an idle VP
even with its interrupts disabled, which a VP that it halts does not
take, so restoring the VP as halted would be wrong. restore_activity
now refuses the state before it changes anything, with the
UnsupportedState error that it returns for the other activity that WHP
cannot hold, as virt_kvm refuses the idle state with an error.

Test: the WHP case user_mode_apic_refuses_an_idle_vp_hv1, in the
suspend module of virt_backend_tests, restores an idle activity into the
VP of a partition with the user-mode APIC and Hv1, and requires that
the restore fails with UnsupportedState and leaves the activity as it
was. The activity differs from the VP's in the pending NMI, which the
user-mode APIC keeps, and in the NMI mask and the interrupt shadow,
which WHP's registers keep, so the case also fails when
restore_activity sets the pending NMI or writes the interrupt state
before it refuses the state. On Windows 11 build 26300 with an Intel
Core i9-12900H, at d44a113 the case panics at apic.rs:261 with "not
implemented", and with this commit it passes, as do the other 26 cases
of virt_backend_tests that run on WHP there and the 45 tests of
virt_whp. There, a snapshot's restore does not reach the activity: the
VP that the hypervisor's APIC saves holds a TSC deadline, which the
partition with the user-mode APIC does not support, so restore_all
refuses that element first. A saved state without one reaches the
activity. The Guide's page on the backend contract tests names the case.
cargo check, cargo clippy --all-targets, and cargo doc for virt_whp,
cargo clippy --all-targets for vmm_tests, and cargo xtask fmt have no
warnings.

Refs microsoft/nvx#1475

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A KVM partition with Hyper-V enlightenments routes the SynIC of each VP
through a GSI of its own, VMBUS_BASE_GSI, after the 24 lines of the I/O
APIC, plus the VP's index, which build claims in the partition's routing
table of NUM_GSIS, 2048, GSIs. Nothing checked the number of VPs against
that table, so build, on a host whose KVM allows that many vCPUs,
created every vCPU of a partition of more than 2024 enlightened VPs and
then panicked in GsiRouting::claim, "index out of bounds: the len is
2048 but the index is 2048", in debug and release builds alike
(microsoft/nvx#1377). Only the VM's configuration reaches it, before the
guest runs.

new_partition now refuses such a configuration before it creates the
VM, with the new KvmError::TooManyVps, which names the number of VPs and
the limit, MAX_SYNIC_VPS, NUM_GSIS less VMBUS_BASE_GSI, or 2024. A
partition without enlightenments, such as an NVX microVM, routes nothing
for its VPs, and is not limited. No saved state, format, or version
changes.

On nvx-kvm-test (Azure Linux 3, Linux 6.18.57, KVM built with
CONFIG_KVM_MAX_NR_VCPUS=4096), with RLIMIT_NOFILE raised to 8192, a
scratch /dev/kvm test of virt_kvm built partitions at d44a113: one of
2024 enlightened VPs built, one of 2025 enlightened VPs panicked as
above, and one of 2025 VPs without enlightenments built. With the fix,
new_partition refuses the second with "a partition with Hyper-V
enlightenments supports at most 2024 VPs, not 2025", and the others
build as before.

Tests: a KVM-only contract test of virt_backend_tests, which OpenVMM's
CI runs on its KVM hosts, creates partitions without building them, so
without creating their VPs, and requires that one of 2025 enlightened
VPs is refused with KvmError::TooManyVps, and that one of 2024
enlightened VPs, and one of 2025 VPs without enlightenments, are not.
It fails on nvx-kvm-test with the check disabled, and passes with it.
The Guide's section on the backend contract tests lists it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
An AP of an SEV-ES or SEV-SNP guest waits in its AP reset hold once the
guest asks for it through the GHCB, with the AP Reset Hold VMGEXIT or
the GHCB MSR protocol's request, and KVM_GET_MP_STATE then reports
KVM_MP_STATE_AP_RESET_HOLD (9). The activity of a VP panicked on any MP
state that it did not map, with "unrecognized mp state 9", although it
returns a Result, so a save of such a VP, and an inspection of its state
(vp/N/vtl0), which both read the activity, aborted the VM worker's
process, whose dev and release profiles abort on a panic
(microsoft/nvx#1383). Its arm for KVM_MP_STATE_SIPI_RECEIVED, which KVM
never reports, was a todo!().

The activity now maps the MP state with mp_state_from_kvm, which keeps
the four mappings and refuses every other state with the new
KvmError::UnsupportedMpState, which names the VP and the state. KVM
wakes an AP in its reset hold as it wakes a halted one, but keeps the
guest's request, which an INIT and a SIPI complete instead of starting
the AP at the SIPI's vector, so no MP state of the activity describes
the hold. A save of such a VP now fails, so a capture rolls back and
the guest continues, and an inspection shows the rest of the VP's state
without its activity. No saved element, format, or version changes,
and a partition without isolation, such as NVX's microVM, never holds
a vCPU in the hold.

Tests: a unit test maps each MP state that the activity describes, and
requires the refusal, with the VP and the state, of the reset hold, of
SIPI_RECEIVED, of an aarch64 state, and of an undefined one. A KVM
test, ignored for its need of /dev/kvm, binds the second VP of a
partition without isolation, puts it in the reset hold with
KVM_SET_MP_STATE, which KVM accepts for any vCPU with an in-kernel
LAPIC, and requires that its activity and its save fail with the error
and that it stays in the hold. On nvx-kvm-test, an Intel Xeon Platinum
8573C VM that runs Linux 6.18.57, the KVM test panicked at d44a113
with "unrecognized mp state 9", and passes with the fix, as do all 156
virt_kvm tests, the ignored ones included. cargo check, cargo clippy
--all-targets -- -D warnings, and cargo doc with -D warnings pass for
virt_kvm there, and cargo xtask fmt is clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On Intel, topology_cpuid reports in leaf 4 that the VPs of a socket
share its L3 cache: cache_parameters_cpuid encodes the topology's
reserved VPs per socket, less one, as the number of logical processors
sharing the cache, a 12-bit field (EAX[25:14]). The topology builder
accepts up to 32768 VPs per socket and reserves that count rounded up to
a power of two, so a socket of more than 4096 VPs overflowed the field,
and its bitfield setter panicked with "value out of bounds [0, 4095]" in
debug and release builds, whatever the VM's VP count
(microsoft/nvx#1379). That aborted the creation of a standard VM on an
Intel host with KVM, without a time ABI, or with WHP, which build the
topology CPUID from the host's, when --vps-per-socket asked for more
than 4096 VPs per socket, or when the host topology that the standard VM
starts from had that many, as that of a host whose leaf 0Bh core level
has an x2APIC shift above 12 does. The microVM, which refuses
--vps-per-socket, starts from its own topology, and has at most 8 VPs in
its one socket, never reached it, nor did a time ABI partition, which
only the microVM has.

The count now saturates at the field's maximum, 4096 logical processors,
as the core count of the same leaf and the sharing count of AMD's leaf
8000001Dh already do, so the guest of such a socket sees an L3 cache per
4096 APIC IDs. Counts of up to 4096 VPs per socket, and every other
field of the leaf, are unchanged, so no CPUID that OpenVMM produced
before changes, the time ABI's effective CPUID included.

Tests: l3_sharing_saturates_above_4096_vps_per_socket builds the
topology CPUID of a VM with one VP and 4096, 4097, or 32768 VPs per
socket, with and without SMT, from an Intel and an AMD CPUID, and finds
the L3 cache shared by 4096 logical processors and each L1 and L2 cache
by the threads of a core. At d44a113, it panics as above on Intel.
On Intel hosts, the standard VM with one VP and --vps-per-socket 8192
panicked so at d44a113 on KVM (Xeon Platinum 8573C) and WHP (Xeon
Platinum 8370C); with the fix applied there, it starts and runs its
guest on both with 8192 and 32768 VPs per socket, as it did with 4096.
virt's unit tests pass on Windows and Linux.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
With the APIC that the VMM emulates, as `whp:user_mode_apic` gives it,
and as Hv1 without the hypervisor's enlightenments does, every restore
of a VP's activity failed, and so did every INIT to an AP.
restore_activity wrote the four registers of vp::Activity, the internal
activity state among them, and with LocalApicEmulationMode None WHP
denies a write of that register with HV_STATUS_ACCESS_DENIED, even of
the running state that it holds. So restore_all failed at "activity"
for every saved state, even the save of a new VP, and x86_init, which
makes an AP wait for a SIPI through set_activity, failed in inject_init,
which unwraps the error and aborts the VMM: every multiprocessor guest
sends its APs an INIT. hv1_emulator's set_x86_vp_context, which starts
a VP for HvCallStartVirtualProcessor, failed the same way.

In this mode the VMM keeps the VP's halt and its wait for a SIPI itself,
and the hypervisor's internal activity state stays running, which is
all that the restore wrote there. restore_activity now writes only the
other three activity registers, the pending interruption, the interrupt
state, and the pending event, which WHP accepts.

Test: the new `user_mode_apic` module of virt_backend_tests registers
four cases for `whp_user_mode_apic`, a WHP backend whose APIC the VMM
emulates. restores_the_activity_in_each_state restores an activity in
each state that the VMM keeps, with an NMI pending, NMIs masked, an
interrupt shadow, and a pending exception as both an interruption and
an event, and requires that it reads back as given, in the VP and, from
a save of it, in a new partition's VP. The interruption is an exception
because WHP refuses a pending interrupt with HV_STATUS_INVALID_VP_STATE
while RFLAGS.IF is clear, as it is in a new VP.
restores_a_new_vp_into_a_new_partition restores a save of a new VP into
a new partition, without Hv1 and with it.
an_init_makes_an_ap_wait_for_a_sipi sends the AP of a two-VP partition
an INIT and then a SIPI, twice, and flushes the AP's requests after
each, as the VMM does before it saves a VP, and requires that the INIT
makes the AP wait for a SIPI, at its reset RIP, and that the SIPI starts
it at the SIPI's vector. The fixture gains build_all, and with_vps for a
fixture of more than one VP, for it. The Guide describes the cases.

On Windows 11 build 26300 with an Intel Core i9-12900H, at d44a113,
the four cases fail: restores_the_activity_in_each_state with "failed to
set registers: Access to the specified object was denied. (os error
-1070268410)", both cases of restores_a_new_vp_into_a_new_partition with
the same error at phase restore "activity", and
an_init_makes_an_ap_wait_for_a_sipi with the panic at apic.rs:764 that
the issue reports. With this change on d44a113 they pass, as do the
other 26 cases of virt_backend_tests that run there (10 report ignored),
and the 64 tests of virt_whp, those that need WHP included. cargo clippy
--all-targets for virt_whp and vmm_tests, which also passes for
virt_backend_tests on x86_64-unknown-linux-gnu, cargo doc, and cargo
xtask fmt have no warnings.

Refs microsoft/nvx#1472

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On a heavily loaded Linux host, about one microVM start in eight
failed with "driver does not support io-uring" (microsoft/nvx#1909).
The epoll driver sets up its io-uring lazily, at its first probe or
submission, and dropped the error of that set-up with `.ok()`, so a
failed `io_uring_setup`, such as one that fails with ENOMEM, read as a
driver without io-uring support, and its errno was lost.

`IoUringDriver::io_uring_submitter` and `Driver::io_uring_probe` now
return the error that keeps a driver from providing an io-uring: the
error of the epoll driver's set-up, or an `Unsupported` error of a
driver without io-uring. A failed set-up still leaves the epoll driver
without a ring, so its next probe tries again. `disk_blockdevice` fails
a device with "failed to set up io-uring" and that error as its source,
and a submission through a driver that cannot set up its io-uring fails
with that error rather than `Unsupported`. `disk_vmdk` still falls back
to its portable reads when the probe fails.

With `io_uring_setup` refused with ENOMEM by a seccomp filter, the
fatal error of a `nvx sandbox run` on a Linux/KVM host ended with

    3: failed to create new device
    4: driver does not support io-uring

and now ends with

    3: failed to create new device
    4: failed to set up io-uring
    5: Cannot allocate memory (os error 12)

Tests: the epoll driver reports the ENOMEM of a refused
`io_uring_setup` and sets its ring up at the next probe, and a block
device over a driver whose `io_uring_setup` fails names the set-up and
its errno.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A microVM directory listing that already holds 4,096 entries, `.` and
`..` included, failed with E2BIG when the host listed another entry
that the access policy hides, although the guest never sees that entry
(microsoft/nvx#2093). The same directory listed all 4,096 entries when
the host listed the hidden entries first, so whether the first
FUSE_READDIR or FUSE_READDIRPLUS of a handle failed depended on the
host's enumeration order, which the guest cannot control.

build_microvm_directory_snapshot checked the 4,096-entry bound at the
top of its read_dir callback, before the name check and the policy
filter, so a hidden entry counted toward the bound as if it were
listed. The check now runs where an entry is about to join the
listing, after the filter, beside the check of the 64 KiB bound on
names, which already ran there. Only the entries that the guest can
list count toward either bound, and a 4,097th of them still fails the
listing with E2BIG.

A test at the real bound needs a directory of more than 4,096 entries,
which takes seconds to create on Windows, past the 1 s after which
OpenVMM's CI profile calls a test slow and close to the 10 s after
which it ends one. build_microvm_directory_snapshot therefore lists
through build_microvm_directory_snapshot_within, which takes the bound
as a parameter, so that a test can pass a smaller one.

microvm_listings_count_only_the_entries_that_the_policy_shows hides
each of three files in turn, so that one of them is the last that the
host lists, and expects a bound of four entries to hold `.`, `..`, and
the two shown files, and a bound of three to fail with E2BIG. With the
check back at the top of the callback, it fails with E2BIG for the
file that the host lists last: `c` on NTFS, which lists names in
order, and `a` on the tmpfs of the Linux host, which lists the newest
first.

At feature/microvm/dev d44a113, a one-off test, not committed, that
fills a handle's listing with 4,094 shown files and hides one more file
fails the first FUSE_READDIR and FUSE_READDIRPLUS of the root with
E2BIG when the hidden file is the last that the host lists, and lists
all 4,096 entries when it is the first, on Windows 11 Enterprise (build
26300, NTFS) and on Azure Linux 3 (kernel 6.18, tmpfs). With the fix,
it lists all 4,096 entries in both cases on both hosts, and a listing
of 4,095 shown files still fails with E2BIG; the other tests of the
virtiofs package pass there too.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A DebugRequest::Detach, which ends a gdb stub session, left two of the
session's halt reports behind (microsoft/nvx#2094):

- halt_reported, which says that the debugger was told of the recorded
  halt, stayed set, so the next session's first resume, which the stub
  sends as it attaches, cleared the recorded halt as if the debugger had
  continued from it. A VM that powered off after the client resumed it
  from the first session's break thus ran again as soon as a second
  debugger attached, and that debugger was told of a break instead of
  the power-off.
- Detach reported the recorded halt to the client whenever there was
  one, so a halt that the client had heard of before the debugger
  attached reached the client a second time, which, for a triple fault,
  makes OpenVMM write its crash dump again.

Detach now clears halt_reported, and reports the recorded halt to the
client only when it went to the debugger instead, which the partition
unit now records as it routes each halt. DebugRequest's documentation
says what a detach does, and that it ends the hold that a break into a
paused VM takes. The debug worker sends no Detach yet; the next commit
makes it.

Tests, in the partition unit's save and restore tests:

- detach_hands_the_halt_that_the_debugger_took_to_the_client breaks into
  a running unit and detaches, which must report the break to the
  client; the client then resumes the VM, which powers off, and a second
  debugger must be told of the power-off, which stays recorded.
- detach_leaves_the_client_a_halt_that_it_already_has halts the unit,
  attaches and detaches a debugger, and checks that the client hears of
  the halt only once.

On d44a113, on Windows x64, both fail: the second debugger is told of
a break, and the client hears of the power-off twice. With the change,
the 61 tests of vmm_core with the gdb feature and the 55 without it
pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A DebugRequest::Detach cleared the debug state of every VP, which asks
each VP's backend to set it to None. The ARM64 backends of KVM and
OpenHCL implement no guest debugging, and panic on any such request,
which, with panic = 'abort', ends the VMM. The gdb stub never sent a
Detach (microsoft/nvx#2094), so nothing reached this; once it does,
attaching a debugger to such a VM and detaching it, or losing its
connection, would abort the VMM, although the session set no debug
state.

The partition unit now records whether the debugger set debug state
since it attached, which the stub does whenever it resumes the VM, and
clears it on detach only then. A debugger that resumes such a VM still
meets the backend's panic, as before.

Test, in the partition unit's save and restore tests:
detach_clears_no_debug_state_that_the_debugger_did_not_set attaches a
debugger to a unit with a VP whose runner does not run, and checks that
the detach completes at once, without asking the VP to clear its debug
state, which would wait for the runner. On Windows x64, it fails
without the change; with it, the 62 tests of vmm_core with the gdb
feature and the 55 without it pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The gdb stub sent DebugRequest::Attach when GDB connected, but never
DebugRequest::Detach, whether GDB detached, its connection dropped, or
the worker stopped or restarted (microsoft/nvx#2094). The partition
went on treating the gone 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
debugger instead of the VM's client, so a client set to exit or reset
on them never heard of them; and a paused VM that the debugger held
stayed held until a new session or a clear-halt. The stub's VM proxy
also kept the session's hardware breakpoints, which the next session's
first resume set on the VPs again, unknown to its GDB.

run_state_machine now attaches through a Session guard of the VM proxy,
which sends Detach when it is dropped, so that every end of a session
detaches: GDB's D or k packet and a target exit, which reach
GdbStubStateMachine::Disconnected; an error, which returns early, as a
dropped connection does whether the VM is stopped or running; and the
worker dropping the session as it stops or restarts. The guard also
clears the proxy's breakpoints, stepping, and stop channel. The Guide's
gdbstub page and DebugRequest::Detach say what a detach does; the Guide
also says that GDB's software breakpoints, which it writes into guest
memory, stay there when it loses its connection while the VM runs.

Tests, in the debug worker, which run the stub on a TCP connection,
send GDB's packets, and serve the stub's requests as the partition
does:

- the_debugger_detaches_when_gdb_detaches sends D.
- the_debugger_detaches_when_the_connection_drops closes the connection
  while the VM is stopped, and while it runs after a vCont;c.
- the_debugger_detaches_when_the_session_is_dropped drops the session,
  as the worker does when it stops or restarts.
- a_session_does_not_set_the_breakpoints_of_the_previous_one sets a
  hardware breakpoint with Z1 in a session that then drops, and checks
  the debug state that the next session's first resume sets.

On d44a113, on Windows x64, all four fail, since no Detach ends a
session. With the change, they pass, as do the tests of vmm_core and
vmm_core_defs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added Guide release-nvx Targets a branch under feature/microvm/. unsafe Related to unsafe code labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@ppenna
Pedro Henrique Penna (ppenna) merged commit 1633b37 into feature/microvm/dev Nov 25, 2026
104 of 105 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the copilot/nvx-issue-2094-gdb-detach branch November 25, 2026 06:37
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 25, 2026
…M roadmap

Map position 389, the commit of microsoft/openvmm#5281, which NVX now
pins at 350018ce4, 263 commits past the mapped tip, on 1633b3797,
position 388, the head of feature/microvm/dev since
microsoft/openvmm#5280 landed positions 386-388:

- 389, virtiofs: let a new microVM object take the last node ID. The
  insert of the node of an object that FUSE_MKDIR, FUSE_MKNOD,
  FUSE_SYMLINK, or FUSE_CREATE makes, with the node ID that the request
  reserved before it made the object, no longer requires that the
  table can hand out another node ID, so that the object takes the
  last node ID, u64::MAX - 1, rather than stay on the host without a
  node after the request fails with ENOSPC (#2135). The inode and
  alias limits still apply to that insert.

Position 389 is a PR18 fixup. It fixes a defect of PR18's position
081, whose InodeReservation::insert check required another free node
ID, which position 083's restore makes reachable and position 350
moved to u64::MAX - 1, and it needs nothing that a later position adds
but, for its test, position 350's table and position 164's helpers.
Fold it into position 081, where its changes of lib.rs and limits.rs
apply as they are, as git merge-tree shows, and its test into position
350, where only the imports conflict: at 301937559, position 350, with
the fix and the test so placed, the virtiofs tests pass on Windows,
and without the fix the test fails. The Scope, the DAG, the fold
sentences, the PR summary, the dependency graph, and the commit
mapping record the fixup. Of positions 372-388, only 385 changes one
of its files, fs_tests.rs. Upstream main, 8d4e03132, lacks the defect,
since it lacks the microVM's limits, and replaying the commit there
conflicts in lib.rs and in the microVM's limits.rs and fs_tests.rs, so
it follows PR18 upstream. The Scope also records that
microsoft/openvmm#5277, microsoft/openvmm#5278, microsoft/openvmm#5279,
and microsoft/openvmm#5280 have landed positions 383-388 on
feature/microvm/dev.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Aaqibhafeez Khan (Aaqibhafeezkhan) pushed a commit to Aaqib-OSS/nvx that referenced this pull request Nov 25, 2026
OpenVMM's gdb stub never told the partition that the debugger had gone
(microsoft#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>
Aaqibhafeez Khan (Aaqibhafeezkhan) pushed a commit to Aaqib-OSS/nvx that referenced this pull request Nov 25, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guide release-nvx Targets a branch under feature/microvm/. unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant