Skip to content

feat: tie guest GPU telemetry to the host PCI address - #1710

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

Leechael wants to merge 6 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 (0001:1a:00.0).
  • Nothing either side sees today is shared. The guest address is assigned by QEMU and has no arithmetic relation to the host one. The control plane cannot read the VMM's slot order back either. So a "GPU 0 is at 95%" chart cannot be put next to a "0001:1a:00.0 dropped to x8" chart for the same card.

The VMM is the only party that knows both sides. Each vfio-pci,host=<host BDF> it puts on the QEMU command line hangs off its own pcie-root-port, and the guest firmware numbers those root-port buses in a fixed order.

Fix

Read the pairing from the command line of the running QEMU, and hand it out on two paths.

  1. vmm/src/app/passthrough.rs parses -device arguments into (guest BDF, host BDF) pairs. The QEMU arguments come from the supervisor process, or from the vm-launcher spec file when the VM runs under the launcher.
    • Root ports on pcie.0 get buses 1, 2, ... in command order. Root ports on a pxb-pcie get bus_nr + 1, bus_nr + 2, ...
    • Any layout dstack-vmm does not build is refused: another bridge type, an explicit addr=, a root port on an unknown bus, root ports on pcie.0 that run into the first expander's bus, or two devices on one guest address. The result is then no pairing rather than a guessed one.
    • It reads the running command, not the manifest. A VM keeps the layout of the VMM version that launched it, so this is also right for VMs started before a VMM upgrade.
  2. VMM ProxiedGuestApi.GpuInfo (the control plane's path) sets GpuDevice.host_pci_bus_id from its own reading. It always replaces what the guest sent, because the control plane must not take a card's identity from the guest it is monitoring. A disagreement is logged. This works with every existing guest image, because only the VMM changes.
  3. New HostApi.GpuTopology lets the guest agent ask for the table itself over vsock. The guest agent then fills host_pci_bus_id in its own GpuInfo, which is what in-guest callers of /var/run/dstack.sock see. It also publishes a new dstack_gpu_info{index, uuid, pci_bus_id, host_pci_bus_id} 1 series.
    • This is gated by a new cvm.gpu.share_host_address, default false. The address is not secret, but it is host topology a guest otherwise never sees, and /metrics is public when the app sets public_sysinfo.
  4. lspci::normalize_bdf gives one spelling, dddd:bb:dd.f. The same card arrives as 1b:00.0 (manifest, QEMU host=), 0000:1b:00.0 (lspci -D, sysfs) and 00000000:1b:00.0 (NVML).

host_pci_bus_id is documented in both protos as host-reported. It is for labelling telemetry and never for a security decision.

Compatibility

Guest agent VMM Result
old new The VMM relay fills host_pci_bus_id. The guest's own API and /metrics are unchanged.
new new, gate on The guest fills it itself, for in-guest callers and /metrics. The relay still overwrites it with the VMM's own reading and logs any disagreement.
new new, gate off / old GpuTopology errors. The guest leaves the field empty, logs at debug level and retries every 5 minutes, so a VMM upgraded under a running guest is picked up. The call has a 3 s timeout and only runs inside the background GPU sample, never on a request or boot path.
  • No QEMU argument, VmConfig field or app-compose field changes, so RTMR0, os_image_hash and KMS checks are untouched.
  • Wire format: new field 12 on GpuDevice and a new RPC. Nothing is renumbered. The generated serde code has #[serde(default)], so JSON from an older agent still parses.
  • Existing dstack_gpu_* series keep their exact label set. The host address is only on the new dstack_gpu_info, so upgrading does not split their history. Join with * on(index) group_left(host_pci_bus_id) dstack_gpu_info.
  • Rust callers that build GpuDevice { .. } without ..Default::default() need the new field. The 4 such literals in this repo are updated.

Alternatives considered

  • Give each vfio-pci an explicit id= or addr=. This changes the QEMU command line: addr= reshapes the guest's ACPI and therefore RTMR0. Rejected; the root ports already carry id=pci.N.
  • Put the table into VmConfig / sys-config at boot. VmConfig feeds KMS and measurement checks and its serialized form is a cache key. Rejected.
  • QMP query-pci. This would read the bus numbers the firmware actually assigned, instead of the rule above. The VMM has no QMP client today, and the socket is single-client. Left as a follow-up if the rule ever proves wrong.

Verification

  • Unit tests pin the pairing on the layouts dstack-vmm builds:
    • Four GPUs on a non-zero host PCI domain, one root port each (flat layout).
    • Eight GPUs plus four NVSwitches with short host addresses, 12 root ports.
    • A slot list out of BDF order.
    • A two-node pxb-pcie hugepage layout.
    • Unknown layouts are refused, including 5 NVSwitch root ports on pcie.0 reaching an expander at bus 5. With the overlap check disabled, that test fails.
  • The relay overwrite, the guest-agent fill (8-digit NVML domain against 4-digit host domain) and the /metrics label split each have a test.
  • cargo fmt --check, cargo check --workspace --all-features --tests, and cargo clippy -D warnings plus cargo test on the touched crates (lspci, guest-api, host-api, dstack-util, dstack-guest-agent, dstack-vmm).

Not yet verified on hardware: that guest bus N maps to root port N when the slot list is not in ascending host order, and in hugepage (pxb-pcie) mode. The CVMs checked so far all had their slots already sorted and used the flat layout, so they cannot tell list order from sorted order. To check it: boot a test CVM with the slots listed out of order, plus a hugepage one, and compare nvidia-smi --query-gpu=index,uuid,pci.bus_id in the guest against the host's lspci -vvv Device Serial Number. Until that is done, treat the pairing as derived from the layout rule, not observed.

Signed-off-by: Leechael Yim <yanleech@gmail.com>
…nning QEMU

Signed-off-by: Leechael Yim <yanleech@gmail.com>
Signed-off-by: Leechael Yim <yanleech@gmail.com>
Signed-off-by: Leechael Yim <yanleech@gmail.com>
Signed-off-by: Leechael Yim <yanleech@gmail.com>
… overlapping buses

Signed-off-by: Leechael Yim <yanleech@gmail.com>
@Leechael
Leechael force-pushed the feat/gpu-host-slot branch 2 times, most recently from ae0023e to 79ca0d3 Compare December 2, 2026 18:05

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