Abstract vGPU devices behind a framework dispatch - #366
Conversation
284269f to
c3d6a2f
Compare
Since vGPU devices attach through VGPUDevicePath, PCIDevices only carries whole-device passthrough paths; the mdev special case was unreachable.
c3d6a2f to
f677357
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f677357. Configure here.
| if err := releaseStoredVGPU(ctx, stored); err != nil { | ||
| log.ErrorContext(ctx, "failed to release stale vGPU before start", "instance_id", id, "error", err) | ||
| return nil, fmt.Errorf("release stale vGPU before start: %w", err) | ||
| } |
There was a problem hiding this comment.
Fork start can destroy source vGPU
Medium Severity
start now calls releaseStoredVGPU, which destroys whatever assignment is recorded in instance metadata. Stop also retains that assignment when destroy fails. Forks still copy GPUFramework, GPUDevicePath, and GPUMdevUUID from the source (unlike network identity, which is cleared), so starting such a fork can destroy the source’s still-tracked vGPU.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit f677357. Configure here.


Summary
Bottom layer of the vendor VFIO vGPU stack (this ← #322 ← #363 ← #364 ← #321). Behavior-preserving refactor only — no lifecycle semantics change in this layer.
Kernel 6.8 hosts assign NVIDIA vGPUs through a vendor-specific VFIO interface instead of mdev, so the mdev-shaped seams get generalized before the new backend lands above:
VGPUDevice/VGPUFrameworkabstraction — mdev moves behind a framework dispatch (CreateVGPU/DestroyVGPU/DiscoverVGPU), with assignments described by a framework + device path instead of a bare mdev UUID.GPUFramework/GPUDevicePathalongside the mdev UUID.sysfsdev, and the dead mdev branch is dropped from PCI passthrough args.Testing
go build ./...,go vetcleango test -race ./lib/devices/ ./lib/hypervisor/...and targetedlib/instancessuites pass (TestSocketCacheKeyChangesWhenSocketIsRecreatedand the network/image-dependent instances tests fail identically on the unmodified stack head in this environment)Note
Medium Risk
Changes GPU assignment lifecycle, persisted metadata, and hypervisor passthrough wiring; delete now blocks on failed vGPU release instead of best-effort cleanup.
Overview
Introduces a vGPU framework layer (
VGPUFramework,VGPUDevice,CreateVGPU/DestroyVGPU) so mdev is one backend today and future assignment styles can plug in without rewriting instance code. SR-IOV VF occupancy is exposed asallocatedinstead ofhas_mdev.Instance lifecycle now persists
GPUFrameworkandGPUDevicePath(with legacyGPUMdevUUIDfallback for paths), routes create/start/stop/delete throughreleaseStoredVGPU, and wires the hypervisor via dedicatedVGPUDevicePathrather than stuffing mdev sysfs intoPCIDevices. Delete fails and keeps metadata if vGPU teardown fails (so a compatible version can retry); stop logs and retains assignment metadata on failure; start clears stale assignments before boot.QEMU and Cloud Hypervisor always attach vGPUs with
vfio-pci,sysfsdev=…fromVGPUDevicePath. GPU.md adds rollback steps before downgrading off the active vGPU framework.Reviewed by Cursor Bugbot for commit f677357. Bugbot is set up for automated code reviews on this repo. Configure here.