vmm: sanitize GPUs with SBR before QEMU attach - #1048
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a GPU “sanitize-on-attach” step in the VMM by issuing a PCIe Secondary Bus Reset (SBR) on each selected GPU’s dedicated upstream bridge immediately before QEMU attaches the device, with topology validation to avoid disrupting unrelated PCIe devices. It also enables this behavior by default via configuration, and applies it to both server-managed VM launches and one-shot launches.
Changes:
- Add
sanitize_on_attach(default: enabled) to the VMM GPU config and document it invmm.toml. - Introduce
gpu_resetmodule that resolves each GPU’s upstream bridge, rejects shared-bridge topologies, and performs SBR while preserving bridge control bits (except the SBR bit). - Invoke sanitization prior to QEMU attach for both the server flow (
App) and one-shot flow.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dstack/vmm/vmm.toml | Documents and enables cvm.gpu.sanitize_on_attach by default. |
| dstack/vmm/src/config.rs | Adds sanitize_on_attach field with a default-true serde default + a config default test. |
| dstack/vmm/src/gpu_reset.rs | New implementation for validating GPU PCIe topology and performing SBR resets + unit tests. |
| dstack/vmm/src/main.rs | Registers the new gpu_reset module. |
| dstack/vmm/src/app.rs | Calls GPU sanitization before building QEMU processes in the server-managed VM start path. |
| dstack/vmm/src/one_shot.rs | Calls GPU sanitization before executing QEMU in one-shot mode. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
cvm.gpu.sanitize_on_attachto enabled while allowing operators to disable itMotivation
An H200 CVM incident and a subsequent controlled reproduction established that terminating QEMU while GSP/SPDM initialization is in progress can leave stale FSP/SPDM session state in the GPU. VFIO's attach-time FLR did not clear that state, while a Secondary Bus Reset did. The next guest otherwise fails with an SPDM timeout followed by GSP/RmInitAdapter errors.
This implements sanitize-on-attach at the VMM ownership boundary. A reset or topology validation failure aborts the launch rather than handing a potentially contaminated GPU to the guest.
Safety
Tests
cargo check -p dstack-vmmcargo test -p dstack-vmm(116 passed)tdx-usc3: every GPU has a dedicated direct upstream PCIe bridge