Skip to content

Give VFIO guests time to exit when many are terminated together - #556

Draft
yummybomb wants to merge 6 commits into
mainfrom
hypeship/vfio-teardown-queue
Draft

yummybomb wants to merge 6 commits into
mainfrom
hypeship/vfio-teardown-queue

Conversation

@yummybomb

@yummybomb yummybomb commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Deleting 16 or more vGPU guests on one host at the same moment failed most of the deletes with a 500, about a second before their VMMs had exited. The grace a VMM with VFIO devices gets after SIGTERM now grows with the number of such teardowns in flight.

Why it happened

A delete asks the guest to shut down and waits up to 5 s, then sends the VMM SIGTERM and waits 5 s, then SIGKILL and two waits of 2 s. A VMM with VFIO devices releases them on its way out, and the host driver is slower at that when many go at once. On a host with two L40S, with 6 GB guests on a 3 GB vGPU profile, on a build of #552, which does not change how a delete stops the VMM:

Deleted together Guests Deletes that failed VMMs gone, from the delete request
1 forked from a snapshot 0 5.4 s
8 forked 0 5.9 to 6.1 s
16 forked 15 of 16 14.0 to 15.3 s
26 forked 15 of 26 10.4 to 15.3 s
16 cold-booted 15 of 16 14.0 to 15.4 s

SIGTERM goes out 5 s in, so the VMMs needed up to 10 s after it. SIGKILL followed at 10 s and the request gave up at 14 s. Kernel stacks sampled while they waited were in the vGPU driver, under nv_vgpu_vfio_migration_set_state and nv_vgpu_vfio_close; the kernel log showed no errors.

Every failed delete succeeded on retry and no device was left behind. But 42 VMMs across the two forked batches were hard-killed while they were releasing their device, which is what the SIGTERM grace is there to prevent.

What changes

Stops, deletes and QEMU failed-start rollbacks now count overlapping VFIO teardowns together. Each VMM gets the base SIGTERM grace (5 s) plus one second per other teardown, up to one minute extra. The wait remembers the largest overlap it sees, including teardowns that start after SIGTERM.

Stop and delete leave 1 s for cleanup. They reserve another 4 s for the two SIGKILL waits only if the deadline can fit the full base grace and those waits. Otherwise the VMM can still exit cleanly, but a timeout does not authorize SIGKILL. After a 5 s guest shutdown, that leaves at most 20 s for SIGTERM under the 30 s TTL reaper deadline, or 50 s under the 60 s API deadline. A canceled request or a budget too short for the base grace doesn't authorize SIGKILL; the instance is retained for retry. Failed-start rollback still has to reap its child and gives it the same overlap-based grace even if startup was canceled (at most 65 s before escalation).

A failed fork gets one minute to delete the child. For a fork from a running source, restoring the source and checking its readiness share a separate two-minute budget, independent of the failed request. Stop and delete record the VMM owner and pending cleanup before signaling a VFIO guest. If the socket disappears before cleanup finishes, the instance reports Shutdown, not Stopped. A retried stop confirms exit, releases the TAP and vGPU, and saves StoppedAt, including after the server restarts.

A TTL update preserves the pending stop. Start and in-place snapshot restore reject it; a failed vGPU reset returns an error so stop can retry. Startup PCI reconciliation and TAP garbage collection preserve resources owned by a pending stop. The restart controller persists a reserved start with the completed VFIO stop, so a server restart in between does not consume another attempt. During health-check recovery, restart-policy updates return 409 invalid_state; manual stop still takes precedence. See GPU downgrade instructions before rolling back.

Testing

  • Five regression tests failed against the 700c9b0 implementation and passed ten consecutive runs under -race on ee5e16b: startup PCI/TAP preservation with a live owner, a crash between stop and start with max_attempts=1, a policy update after a failed reset, a canceled running-source fork, and a canceled QEMU rollback during another teardown. 91 targeted instance tests, the QEMU and restart-policy package tests, the VFIO wait tests, and go vet on all four packages passed. These checks did not rerun the physical GPU batch.

  • On 24289f1, regression tests reproduced premature detach on direct delete retry, a TTL update erasing the stop, restore replacing the pending instance, a failed device reset reported as success, and a health-check restart stuck in Shutdown. The five regression cases passed 10 runs with -race after the fixes; 118 targeted instance tests, QEMU and restart-policy package tests, VFIO wait tests and go vet passed locally. The GPU hardware batch was not rerun.

  • On 202e651, Linux subprocess tests reproduced canceled fork rollback leaving the child running and stop retry returning success without releasing its TAP or vGPU. A clock-controlled test with 8 s left gave up at 3 s on a child exiting at 4 s. All three regressions pass after the fixes (10 runs under -race). The lifecycle fixtures do not use GPU hardware.

  • Before the first deadline fix, a clock-controlled test of a non-exiting process reproduced 35 s of guest + SIGTERM wait against the 30 s deadline, and 70 s against 60 s. The original overlap tests also passed when the queue was sampled only at entry.

  • The new tests check the reaper/API budgets, clean exit of both overlapping processes, and overlap between QEMU rollback and lifecycle teardown. Sampling only at entry or restoring fixed-grace QEMU rollback now fails the corresponding test. Focused Linux tests passed under -race; go vet passed for the affected packages.

  • The full QEMU package passed. Two unrelated socket tests in lib/hypervisor failed locally and on unchanged main: TestSocketCacheKeyChangesWhenSocketIsRecreated and TestResolveProcessPIDDuringProcessChurn.

  • The following hardware results are from the original run on Add opt-in vGPU snapshots and forks on a managed QEMU runtime #552 plus the queue change; the hardware batch was not rerun after the deadline and rollback fixes:

Deleted together Guests Deletes that failed VMMs gone, from the delete request
12 forked 0 11.6 to 12.8 s
16 forked 0 13.9 to 15.3 s
26 forked 0 10.4 to 15.4 s
16 cold-booted 0 14.1 to 15.6 s

No VMM was hard-killed and no device was left behind.

Not covered

  • The deletes still take as long as the driver needs: about 15 s per request for 16 or more together, against 5.5 s for one alone. Of that, 5 s is the graceful shutdown wait, which these guests never finished within.
  • More than 26 guests, or other GPU models and vGPU profiles. The allowance is a second per teardown because 16 to 26 needed about 10 s in total; I have no measurement that says how that grows beyond 26.

A VMM with VFIO devices releases them on its way out, and the host driver
is slower at that when many guests go down at once. The grace after
SIGTERM was fixed, so deleting 16 or more vGPU guests together hard-killed
them mid-release and then failed most of the deletes about a second before
the VMMs were gone, leaving the instances for a retry.

The grace now grows by one second for every other VFIO teardown in
flight, up to a minute. A guest terminated alone waits as before.
Confirm the VMM owner before direct deletes as well as stops. Keep cleanup pending if vGPU release fails or metadata is updated, and reject start and in-place restore until the stop is complete. Resume interrupted health-check restarts without charging the same attempt twice.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant