Skip to content

feat: label guest GPU telemetry with the PCIe Device Serial Number - #1710

Open
Leechael wants to merge 2 commits into
Dstack-TEE:nextfrom
Leechael:feat/gpu-host-slot
Open

Leechael wants to merge 2 commits into
Dstack-TEE:nextfrom
Leechael:feat/gpu-host-slot

Conversation

@Leechael

@Leechael Leechael commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Guest GPU telemetry and host GPU telemetry cannot be joined.

  • The guest agent reports each GPU by NVML index, UUID and the guest PCI address (00000000:01:00.0).
  • Host-side monitoring (link speed/width, VFIO occupancy) labels the same card by its host PCI address.
  • The two addresses have no relation: QEMU assigns the guest one. So a "GPU 0 is at 95%" chart cannot be put next to a "link dropped to x8" chart for the same card.

Fix

Report each GPU's PCIe Device Serial Number (DSN). It is burned into the card and passes through VFIO unchanged, so the host reads the same value from the same card. Both sides label with it and join on it.

  1. dstack-util gpu-info reads /sys/bus/pci/devices/<bdf>/config for each NVML device and walks the extended capabilities from 0x100 to the DSN (ID 0x0003). It formats the 8 bytes as lspci does (xx-xx-…-xx).
    • VFIO rewrites the first extended header to ID 0 but keeps its next pointer, so the walk follows ID-0 headers instead of stopping.
    • It reads only the dwords it visits, not the whole 4 KiB, because every config access from a CVM traps to the host.
    • No DSN capability, or no extended config space (pci=nommconf, as on older images), leaves the field empty. A failed read is added to the card's errors.
  2. GpuDevice.pci_dsn (field 12) carries it through GpuInfo, so in-guest callers and the VMM's ProxiedGuestApi.GpuInfo relay both see it.
  3. /metrics gets a new dstack_gpu_info{index, uuid, pci_bus_id, pci_dsn} 1 series. Existing dstack_gpu_* series keep their label set, so upgrading does not split their history. Join with * on(index) group_left(pci_dsn) dstack_gpu_info.

Host-side collectors add the same pci_dsn label from host sysfs (root needed). That lives outside this repo.

Compatibility

  • No VMM, host-api, sys-config, QEMU argument or measured-config change.
  • Wire format: one new field, nothing renumbered. The generated serde code has #[serde(default)], so JSON from an older agent still parses with an empty pci_dsn.
  • CVMs on images whose kernel boots with pci=nommconf cannot reach extended config space. They report an empty pci_dsn and get it after an image upgrade.
  • Rust callers that build GpuDevice { .. } without ..Default::default() need the new field. The 2 such literals in this repo are updated.

Verification

  • Unit tests for the capability walk: DSN found past a VFIO-hidden ID-0 header; 64- and 256-byte config space; a list without a DSN; a looping list; a truncated DSN. With the walk changed to stop at ID 0, the VFIO test fails.
  • On a host, read returns the same value lspci -vvv prints for a device's Device Serial Number. A non-root read returns empty.
  • Guest and host DSN for a passed-through GPU were checked to be identical on current images (see the review comment).
  • cargo fmt --check, cargo check --workspace --all-features --tests, cargo clippy -D warnings and cargo test on dstack-util, dstack-guest-agent, guest-api.

@Leechael
Leechael force-pushed the feat/gpu-host-slot branch 2 times, most recently from ae0023e to 79ca0d3 Compare December 2, 2026 18:05
@kvinwang

kvinwang commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Suggest joining guest and host telemetry by the PCIe Device Serial Number (DSN) instead of deriving the guest↔host BDF pairing in the VMM.

Why. DSN is a hardware identity readable on both sides, so the join is observed rather than inferred from a bus-numbering rule (which this PR notes is not yet verified for out-of-order slots and pxb-pcie). It also removes most of this PR: no QEMU command-line parser, no HostApi.GpuTopology, no share_host_address gate, no guest-side retry/cache, and no trust question about who fills the field: the guest reports its own device's DSN, which is no less trustworthy than the utilization numbers it already reports.

Verified on hardware (8× H200 + 4× NVSwitch host, kernel 6.14, QEMU 9.2.1, one GPU passed through via pcie-root-port on pcie.0 + vfio-pci,iommufd):

Side Address DSN
Host 0000:4c:00.0 (bound to vfio-pci) bd-26-…-b0-48 (redacted, identical on both sides)
Guest, dstack-0.6.0 0000:01:00.0 bd-26-…-b0-48 (redacted, identical on both sides)
Guest, dstack-nvidia-0.5.9 0000:01:00.0 not readable
  • All 8 GPUs and 4 NVSwitches on the host have distinct DSNs.
  • The 0.5.9 image boots with pci=nommconf, so the guest only sees 256 bytes of config space and DSN (an extended capability) is unreachable; the standard capabilities (PM, MSI, PCIe, vendor-specific, MSI-X) carry no VPD or other identifier. Current images drop pci=nommconf (os/image/kernel-cmdline.sh, needed for Blackwell anyway), so DSN works there. CVMs on older images get the label after an image upgrade.
  • vfio rewrites the guest's first extended capability header at 0x100 to ID 0 but keeps the next pointer, so the walk must follow the chain past it.

Minimal shape:

  1. dstack-util GPU collector: for each NVML pci_bus_id, read /sys/bus/pci/devices/<bdf>/config, walk extended capabilities from 0x100 to ID 0x0003, and format the 8 bytes like lspci (xx-xx-…-xx).
  2. GpuDevice gets a serial_number (DSN) field; /metrics exposes it on a separate info series (as this PR does with dstack_gpu_info) so existing series keep their label set.
  3. Host-side collectors add the same DSN label (sysfs config space, root needed).

No VMM, host-api or sys-config change is needed.

Signed-off-by: Leechael Yim <yanleech@gmail.com>
Signed-off-by: Leechael Yim <yanleech@gmail.com>
@Leechael Leechael changed the title feat: tie guest GPU telemetry to the host PCI address feat: label guest GPU telemetry with the PCIe Device Serial Number Dec 3, 2026
@Leechael

Leechael commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Reworked to the DSN approach as suggested: the VMM parser, HostApi.GpuTopology, the share_host_address gate and the guest-side retry are all gone. dstack-util gpu-info walks the extended capabilities (following the VFIO-hidden ID-0 header) and reports GpuDevice.pci_dsn, and /metrics carries it on a separate dstack_gpu_info series. Description updated.

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.

2 participants