Integrate vendor VFIO vGPUs into the instance lifecycle - #321
Open
yummybomb wants to merge 76 commits into
Open
Conversation
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
July 28, 2026 21:32
199b1d1 to
a93d009
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
4 times, most recently
from
July 29, 2026 15:15
d893fce to
de4742a
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
July 29, 2026 16:09
de4742a to
18e047f
Compare
Contributor
Author
|
Trimmed over-engineering after an architectural review against the parent task (host kernel 6.8 / Ubuntu 24.04 support). Most of the removed weight came from earlier review-round additions rather than the original design: |
yummybomb
marked this pull request as ready for review
August 5, 2026 19:47
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 5, 2026 19:57
7ef1f8d to
bf21162
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 5, 2026 20:24
bf21162 to
83c53ea
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 5, 2026 20:39
83c53ea to
79eef07
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 6, 2026 17:08
ab2b0e8 to
19b9602
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 6, 2026 19:06
d92201d to
f177335
Compare
yummybomb
changed the base branch from
hypeship/generalize-vgpu-device
to
hypeship/vendor-vfio-backend
August 6, 2026 19:08
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 6, 2026 19:26
f177335 to
1d875f2
Compare
yummybomb
force-pushed
the
hypeship/vendor-vfio-vgpu
branch
from
August 6, 2026 19:40
1d875f2 to
23fb2f5
Compare
A concurrent instance deletion between the claim scan's metadata listing and load turned ErrNotFound into a host-wide fail-closed release error, even though a vanished record cannot be a live claimant; skip it. Stop on a delete-only retention stub released its VF while leaving GPURetainedForCleanup set, so the stub's start/fork/snapshot errors kept claiming an assignment that no longer existed. Retention stubs now release only through delete, as documented.
The two rollback paths carried near-identical retention-stub literals that would drift as fields are added. Build both from one helper, use nowUTC like the rest of the file, and drop the starter guard that is dead since create fails on a nil starter long before the vGPU block.
Replace the listMetadataFilesWithStatErrors(bool) mode flag with listMetadataFiles / listMetadataFilesStrict so call sites say which failure semantics they rely on.
ListInstancesForReconcile failed hard when an instance was deleted between the metadata listing and its load. The startup call runs before the API serves, but the grace-period retry fires while deletes are in flight; one racing delete errored the whole list, which zeroed the retry and left vendor VFIO reconciliation disabled until the next restart. Skip ErrNotFound like the release claim scan does: a vanished record cannot claim a VF.
Giving up on an orphaned release leaves the VF allocated while /resources still advertises it, until startup reconciliation or manual remediation. That was visible only as a log line; count it so capacity leaks can alert.
Start, fork, and snapshot each carried a verbatim copy of the rejection error and its rationale; the stub fill in create's cleanup closure duplicated retainedVGPUFromCreateError field-for-field. One error value and one device-to-stub helper replace the copies.
The create and start handlers carried near-identical 20-line blocks deriving the vgpu_cleanup_pending message and inner error detail, differing only in the verb and release guidance.
- Retry the vendor VFIO reconcile sweep with a bounded delay when the startup instance listing fails, instead of disabling orphan recovery until the next process restart. One pending retry at a time. - Schedule the in-process orphaned-release retry when a rollback's retention record cannot be saved (create and start), instead of leaking the VF until restart. The retry scans claims without a self-exclusion because a restarted instance may hold the same VF. - Reject snapshot restore into a vGPU retention stub, matching start, fork, and snapshot. - Give passthrough PCI instances the same SIGTERM grace as vGPU instances on stop/delete, matching the QEMU-side vfioTermGraceFor. - Render the vgpu_cleanup_pending API detail from the error itself instead of duplicating its prose; use the manager clock in the claim scan; collapse the create-rollback retention branch. - Move ReconcileVGPUs off the Manager interface to a startup type assertion and unexport listInstancesForReconcile and hypervisorMayBeAlive.
Record the owning instance and assignment time for each vendor VFIO VF so a reconcile sweep can run while instances are being created: recently assigned VFs get a grace period before they are eligible (mirroring orphanedMdevGracePeriod), and owned VFs are destroyed with their recorded owner ID instead of failing the ownership check.
Run the fail-closed vGPU reconcile once at startup and every minute after, skipping hosts without a vGPU framework. Each pass retries releases for assignments whose owner is no longer live (re-verified under the instance lock) and then sweeps device-level leftovers with no live metadata claim. This deletes the per-path orphan retry goroutines - whose path-keyed dedup could drop cleanup for a newer assignment reusing the same VF - the CAS/timer retry in ReconcileVGPUs, the stopped-instance release special case in StopInstance, the retention fallbacks that scheduled background retries, and the orphan-abandoned metric.
An assignment could lose its persisted hypervisor PID while its VM stays alive - a post-boot metadata save failure or a hypeman crash before the save. The liveness checks gated the socket-ownership scan on a non-nil PID, so once the startup grace expired the reconciler considered such an assignment stale and could remove an mdev out from under the live VM (DestroyMdev has no in-use guard). Run the socket-ownership scan unconditionally: a live VMM always holds its control-socket listener, and a missing listener still resolves to not-alive, so genuinely stopped instances are released as before. The claim scan in releaseStoredVGPUExcluding gets the same treatment.
The five-minute fresh-assignment protection existed three times: the instances startup grace, the mdev orphan grace, and the vendor VFIO sweep grace. Define it once in lib/devices and alias the instances constant to it.
A wedged or leaked VF presents as reduced GPU capacity while /resources still reports full capacity, and reconcile, stale-release, and retention failures were visible only as log lines. Count failed reconcile stages, failed stale releases, and retained assignments (by operation and whether the retention record persisted) so sustained failure can alert.
When rollback release fails and the subsequent retention save also fails, the assignment save from earlier in start may still hold the claim on disk. Check for that surviving claim before reporting the retention as unpersisted, so the API does not emit vgpu_unretained_instance for an assignment that is still durably attributed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Top layer of the vendor VFIO vGPU stack (
generalize-vgpu-device#322 ←hypervisor-liveness#363 ←vendor-vfio-backend#364 ← this). The backend itself is in #364; this layer wires it into the instance lifecycle and adds the release guards that make reusable-VF assignments safe:ListInstancesForReconcile, which fails on any unreadable metadata instead of silently skipping it. Recent assignments receive bounded startup protection when their PID is absent or stale; when the inventory is unavailable, vendor VFIO reconciliation is skipped entirely while mdev reconciliation still runs.vgpu_cleanup_pendingwith retained/unretained guidance; the retention record keeps identity fields (name, image, hypervisor) so it lists as a recognizable, deletable instance. The instance API exposesgpu.device_path, the assignment identity on vendor VFIO hosts wheremdev_uuidis empty.Testing
go build ./...,go vet ./...cleango test -racepasses forlib/instancestargeted suites,lib/devices,lib/resources,lib/builds(TestCreateInstanceWithNetworkneeds image pulls + iptables and fails in this environment on the unmodified base as well)Note
High Risk
Changes core GPU assignment, release, and hypervisor teardown paths on production hosts; incorrect reconciliation or release ordering could leak VFs or disrupt live VMs.
Overview
Vendor VFIO vGPUs are wired into create/start/stop/delete: assignments are persisted with
GPUAssignedAt, released through the instance manager, and protected on release by scanning live instance metadata so a stale claim cannot clear a VF owned by another instance.When create or start rollback cannot release a vGPU, the manager retains a delete-only metadata stub (
GPURetainedForCleanup); start, fork, snapshot, and restore refuse that record until delete succeeds. API create/start mapVGPUCleanupPendingErrorto 500vgpu_cleanup_pendingwith retained vs unretained guidance; instance responses can includegpu.device_path.Startup mdev-only reconcile is replaced by
StartVGPUReconciler: an initial pass plus minute periodic cleanup that releases stale metadata claims, then sweeps orphaned mdev/vendor assignments (5-minute grace, live VFIO/socket protection, mdevs claimed in metadata). Listing metadata for reconcile fails closed—unreadable inventory skips the device sweep.QEMU/hypervisor kill path for vGPU and passthrough devices SIGTERMs first (
VFIOTermGrace) before SIGKILL to reduce VF wedge risk; docs and tests reflect that behavior. Metrics cover reconcile failures, stale releases, and retained assignments.Reviewed by Cursor Bugbot for commit 081d9f7. Bugbot is set up for automated code reviews on this repo. Configure here.