Skip to content

gpu: fix panic on adapters without a PCI device ID - #2872

Draft
jkroepke wants to merge 2 commits into
mainfrom
claude/project-thread-4ti5t8
Draft

jkroepke wants to merge 2 commits into
mainfrom
claude/project-thread-4ti5t8

Conversation

@jkroepke

@jkroepke jkroepke commented Dec 4, 2026

Copy link
Copy Markdown
Member

Requested by Joe · project thread

What this PR does / why we need it

Paravirtualized adapters, e.g. NVIDIA GRID vGPU on a VMware VM, may not report a physical device ID (KMTQAITYPE_PHYSICALADAPTERDEVICEIDS returns ERROR_FILE_NOT_FOUND, which gdi32 tolerates). The gpu collector then looks up PCI\VEN_0000&DEV_0000&... in cfgmgr32. When nothing matches, CM_Get_Device_ID_List_Size can report a size of 0, and CMGetDeviceIDList took &buf[0] of the empty buffer, which panics with index out of range during Build.

  • GetDevicesInstanceIDs returns no devices for an empty list. The gpu collector then falls back to the gdi32 device ID, as it already does when no PnP instance matches.
  • CMGetDeviceIDList returns ErrEmptyBuffer for an empty buffer, and CMLocateDevNode returns ErrInvalidDeviceID for an empty or not NUL-terminated ID, instead of indexing it.
  • getDevice passes a NUL-terminated copy of the instance ID to CM_Locate_DevNodeW. Before, it relied on the NUL that happens to follow the slice returned by ParseMultiSz in the list buffer.

Embedders that don't recover panics in Build (Grafana Alloy 1.12.x pins v0.31.3) crash on this and restart in a loop, without logs because the trace goes to stderr: grafana/alloy#7678. windows_exporter itself on main already recovers panics in Build and Collect, so it would only report the gpu collector as failed.

Which issue this PR fixes

None in this repository.

Special notes for your reviewer

The root cause comes from reading the code, not from a reproduction on a vGPU host. The new TestGetDevicesInstanceIDsNoMatch runs the lookup for PCI\VEN_0000&DEV_0000&SUBSYS_00000000&REV_00 on the Windows CI runner.

Particularly user-facing changes

The gpu collector no longer fails (or crashes embedders) on adapters without a PCI device ID.

Checklist

  • DCO signed
  • The PR title has a summary of the changes and the area they affect
  • The PR body has a summary to reflect any significant (and particularly user-facing) changes introduced by this PR

Generated by Claude Code

Paravirtualized adapters, e.g. NVIDIA GRID vGPU on VMware, may not report
a physical device ID. The gpu collector then looks up
PCI\VEN_0000&DEV_0000 in cfgmgr32. If no device matches,
CM_Get_Device_ID_List_Size can return a size of 0, and CMGetDeviceIDList
indexed the empty buffer, which panicked during Build.

Return no devices for an empty list, and let the cfgmgr32 wrappers return
an error for an empty buffer or a device instance ID without a NUL
terminator. getDevice now passes a NUL-terminated copy of the ID to
CM_Locate_DevNodeW instead of relying on the terminator that follows the
slice in the list buffer.

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
@jkroepke jkroepke added the 🐞 bug label Dec 4, 2026 — with Claude
@jkroepke jkroepke self-assigned this Dec 4, 2026
Windows may return an error instead of an empty list for a device ID that
doesn't exist. Assert that the lookup doesn't panic and returns no devices,
and log the size reported by CM_Get_Device_ID_List_SizeW.

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant