Skip to content

fix(sev-snp): support firmware 1.58+ v5 reports, large-BAR GPUs, and single-node dstackup - #1703

Closed
PierreLeGuen wants to merge 12 commits into
Dstack-TEE:nextfrom
nearai:fix/sev-snp-b200-fixes
Closed

PierreLeGuen wants to merge 12 commits into
Dstack-TEE:nextfrom
nearai:fix/sev-snp-b200-fixes

Conversation

@PierreLeGuen

Copy link
Copy Markdown
Contributor

Summary

A set of 12 focused fixes required to bring up AMD SEV-SNP hosts (EPYC Turin, firmware 1.58+) with large-BAR GPUs (e.g. 8x NVIDIA B200 with 256 GiB BAR1 in Confidential Computing mode) and single-node dstackup deployments cleanly on 0.6.7 / next:

SEV-SNP firmware 1.58+ & large-BAR GPU passthrough

  • fix(sev-snp): accept version 5 attestation reports — bump sev from 6.0.0 to 6.3.0 (parses LAUNCH_MIT_VECTOR / CURRENT_MIT_VECTOR instead of failing with Skipped bytes were expected to be zeroed), allow report versions 3..=5 in sev-snp-qvl, and populate version/sig_algo/chip_id before AttestationReport::write_bytes in mock-attestation.
  • fix(vmm): give SEV-SNP guests the host's physical address width — pass -cpu EPYC-v4,host-phys-bits=on (instead of QEMU's 40-bit default) so guests can map multi-TiB 64-bit PCI MMIO windows; does not alter the SNP launch measurement.
  • fix(os): build the SEV-SNP OVMF with 1 GiB page tables — build AmdSevX64.dsc with PcdUse1GPageTable=TRUE so OVMF opens an 8 TiB 64-bit PCI MMIO window instead of capping at 40-bit / 128 GiB (too small for a single 256 GiB B200 BAR1). TDX ovmf.fd is unchanged.

Large verity volumes

  • fix(volume): share extents when packing a volume — use FICLONERANGE on Linux when packing dm-verity GPT volumes (with copy fallback), avoiding a 2x disk and I/O copy for TB-scale model weight volumes on XFS/Btrfs.

dstackup, dstack-cli, and 0.6.7 single-node SEV-SNP KMS / app_epoch_pin

  • fix(dstackup): write WorkingDirectory as a bare path in unit files — systemd 259 rejects quoted WorkingDirectory=.
  • fix(dstackup): load vhost_vsock before starting the VMM — add ExecStartPre=/sbin/modprobe vhost_vsock so CID 2 host-API bind works on fresh hosts.
  • fix(dstackup): find mkosi-os-v guest-OS releases — look up mkosi-os-v* release tags first (keeping guest-os-v* fallback) and exclude *-kernel-devel.tar.gz.
  • fix(dstack-cli): pick auto host ports inside the VMM port-mapping range — pick from 10000..=19999 instead of kernel ephemeral ports rejected by vmm.toml.
  • fix(dstackup): render the KMS 0.6 listener layout — render [listeners.*] and core.keyring_dir and update DEFAULT_KMS_IMAGE to digest-pinned 0.6.7.
  • fix(vmm): prefer host kms_url when querying SEV-SNP app epoch — on 0.6.7+ images (app_epoch_pin: true), try host-reachable top-level kms_url before guest-only cvm.kms_urls (10.0.2.2) when manifest.kms_urls is unset.
  • fix(dstackup): set host kms_url in vmm.toml — render kms_url = "https://127.0.0.1:<port>" alongside guest cvm.kms_urls.
  • fix(vmm-cli): allow --env-file with --kms-encrypt-url alone — match update_vm so create_vm can encrypt envs against a host-reachable KMS without overriding guest kms_urls.

Verification

  • cargo test --workspace --locked: all 1,861 tests across 134 suites pass (including new unit tests for report v5, EPYC-v4,host-phys-bits=on, app_epoch_kms_urls, dstackup config/systemd/image/port rendering, and test_vmm_cli.py 23/23 passing).
  • cargo clippy --locked (-D warnings --allow unused_variables) and cargo fmt --all -- --check pass cleanly.
  • End-to-end verified on real AMD EPYC Turin (SEV-SNP API 1.58 build 10) + 8x NVIDIA B200 (Blackwell CC=ON) hardware: reproducible mkosi prod guest image (0.6.7), dstack-kms bootstrap + LUKS unseal across VMM restart, and an 8-GPU SEV-SNP CVM with app_epoch_pin, two dm-verity volumes (1.1 TB + 66 MiB), and full SEV-SNP + 8-GPU attestation.

Happy to split into separate PRs (e.g. SEV-SNP/OVMF/volume vs. dstackup/CLI) if preferred.

SEV-SNP firmware 1.58 and later returns version 5 attestation reports, which
put LAUNCH_MIT_VECTOR and CURRENT_MIT_VECTOR in bytes that sev 6.0.0 parses
as reserved and requires to be zero. On such hosts every report fails to
parse ("Skipped bytes were expected to be zeroed"), so an SNP guest stops at
boot when it reads its HOST_DATA, and the KMS cannot verify SNP guests.

Bump sev to 6.3.0, which parses and re-serializes version 5 reports, and let
sev-snp-qvl verify versions 3 to 5: it rejected anything newer than 3, and
the fields it reads are laid out the same in version 5.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
systemd does not unquote `WorkingDirectory=`, so the quoted value dstackup
wrote is read as a relative path. systemd 259 rejects it ("path is not
absolute"), and `dstackup install` then fails to start dstack-auth. Write
the path bare, escaping only `%`.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
The VMM host API binds vsock CID 2, which needs the vhost_vsock transport.
/dev/vhost-vsock is a static device node that loads the module only on
first open, so on a fresh host the bind fails with EADDRNOTAVAIL and the
VMM exits ("Failed to bind host API"). Load the module in ExecStartPre.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
Guest-OS releases are tagged `mkosi-os-v<version>` by the mkosi release
workflow, but `dstackup image pull` only looked for `guest-os-v`, so both a
pinned `--version` and the latest-release lookup found nothing for 0.6.x.
Look up `mkosi-os-v` first and keep `guest-os-v` as a fallback.

These releases also publish `dstack-<version>-kernel-devel.tar.gz`, which
the asset picker accepted as a host image; skip it like the `-uki` archive.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
`free_local_port()` bound port 0, which returns a kernel ephemeral port
(32768 and up). The vmm.toml that `dstackup install` writes only allows tcp
1-20000, so the VMM refused every auto-picked port: the KMS CVM deploy in
`dstackup install` failed with "Port mapping is not allowed", and so did
`dstack deploy --port <vm>` without a host port.

Pick a free loopback port from 10000-19999 instead, and test that the
rendered port-mapping range covers it.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
dstackup wrote kms.toml with the listener settings at their pre-0.6
locations ([rpc], [core.admin], core.onboard.address/port), had no
core.keyring_dir, and deployed KMS 0.5.11 by default. The 0.6 KMS refuses
that config at startup ("the config sets listener settings at their old
locations", and keyring_dir has no default), and 0.5.11 has no SEV-SNP
support, so a dstackup install on an SNP host never gets a working KMS.

Render [listeners.default.tls], [listeners.guest], [listeners.admin] and
[listeners.onboard], put the keyring on the persistent KMS volume
(/kms/keyring), and default to the 0.6.7 KMS image, which reads that layout.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
SEV-SNP guests run with `-cpu EPYC-v4`. A named CPU model gets QEMU's
default of 40 physical address bits, so the guest has 1 TiB of address
space and OVMF sizes its 64-bit PCI MMIO window from that. GPUs with large
BARs (a B200 BAR1 is 256 GiB) then cannot be mapped. TDX guests use
`-cpu host`, which already takes the host's width.

Pass host-phys-bits=on with the SEV-SNP CPU model. The CPUID page is
measured as zeros, so the launch measurement does not change.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
PcdUse1GPageTable defaults to FALSE and AmdSevX64.dsc does not set it, so
OVMF caps the guest physical address width at 40 bits even when the vCPU
reports more. Its dynamic 64-bit PCI MMIO window is then at most 128 GiB,
smaller than a single B200 BAR1 (256 GiB), and an SEV-SNP guest cannot map
the GPU.

Build the AmdSev firmware with PcdUse1GPageTable=TRUE. With 46 physical
address bits OVMF then opens an 8 TiB window. This changes ovmf-sev.fd and
so the SEV-SNP launch measurement; the TDX firmware is unchanged.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
Building a volume copied the filesystem image twice: into a scratch file, then
into the GPT image through a 1 MiB userspace buffer. For a large image that
doubles the disk space and the time. Clone instead with FICLONE /
FICLONERANGE: the partitions are 1 MiB aligned and the data and hash images
are padded to whole blocks, so XFS and Btrfs share the extents. Fall back to
a copy where cloning is not supported. copy_file_range is not used because it
does not reliably clone (it did not on Linux 7.0 with XFS).

Tested: packing a 1.1 TB squashfs on XFS no longer needs a second 1.1 TB, and
the scratch copy completes immediately.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
On SEV-SNP launches with a 0.6.7+ guest image (app_epoch_pin: true), the VMM
queries the KMS from the host to resolve the current app epoch before starting
QEMU. Under single-node user-mode networking (as configured by dstackup),
cvm.kms_urls holds the guest-only 10.0.2.2 alias, which is not routable from
the host.

When the VM manifest does not override kms_urls, try the host-side top-level
kms_url first and fall back to cvm.kms_urls (deduplicated).

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
dstackup install writes cvm.kms_urls with the QEMU user-mode guest alias
(https://10.0.2.2:<port>), which is not routable from the host, and left
the top-level host kms_url empty. Set kms_url = https://127.0.0.1:<port>
when KMS is enabled so host-side VMM RPCs (app-epoch resolution on 0.6.7
SEV-SNP launches and env-key lookups) can reach the local KMS.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
create_vm rejected --env-file when --kms-url was omitted even if
--kms-encrypt-url was given (unlike update_vm, which already allowed it).
Allowing --kms-encrypt-url without --kms-url lets single-node hosts encrypt
envs against the host-side KMS without overriding cvm.kms_urls on the VM.

Signed-off-by: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T13:14:36.389570Z 1e908f9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e908f978e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// compose hash.
pub const DEFAULT_KMS_IMAGE: &str = "dstacktee/dstack-kms:0.5.11@sha256:84b793feed825a5b5e70d04386e931e0e110461492793f17ab2128e39808d989";
/// compose hash. It has to read the `[listeners.*]` layout `kms_toml` renders.
pub const DEFAULT_KMS_IMAGE: &str = "ghcr.io/dstack-tee/dstack-kms:0.6.7@sha256:693b7c80bad6f759a17f3cc62503eb1ef768852527d448dcfbbb9edb3e8f99f3";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Register root epochs before selecting the epoch-aware KMS

On a fresh default dstackup install, auth_allowlist_json() still writes neither rootEpochs nor kmsContractAddr, and cmd_install() never populates them after bootstrap. Unlike the previous 0.5.11 default, KMS 0.6.7 authorizes application key release through /authorizeApp; dstack/crates/dstack-auth/src/main.rs:435-455 rejects non-bootstrap operations without registered roots and also requires the KMS app ID. Consequently, installation can report success, but even a subsequently allowlisted application cannot obtain its boot keys without an additional manual migration. Populate the verified epoch-zero roots and KMS app ID during installation before making this image the default.

Useful? React with 👍 / 👎.

@PierreLeGuen

Copy link
Copy Markdown
Contributor Author

Split this PR into six focused PRs by purpose against next:

  1. SEV-SNP firmware 1.58+ v5 attestation reports: fix(sev-snp): accept version 5 attestation reports #1704
  2. SEV-SNP large-BAR GPU passthrough (host-phys-bits=on + 1 GiB OVMF page tables): fix(sev-snp): support large-BAR GPU passthrough (host-phys-bits + 1 GiB OVMF page tables) #1705
  3. Volume extent sharing via FICLONERANGE when packing dm-verity images: fix(volume): share extents via FICLONERANGE when packing volumes #1706
  4. dstackup / dstack-cli install fixes (systemd WorkingDirectory, vhost_vsock, mkosi-os-v discovery, auto host ports): fix(dstackup): fix systemd units, mkosi image discovery, and auto host ports #1707
  5. Host-side kms_url for single-node SEV-SNP app_epoch_pin and vmm-cli env encryption: fix(vmm): use host kms_url for single-node SEV-SNP app epoch and env encryption #1708
  6. dstackup KMS 0.6 listener layout + default image bump (separated so fix(sev-snp): accept version 5 attestation reports #1704–fix(vmm): use host kms_url for single-node SEV-SNP app epoch and env encryption #1708 can land independently of auth-allowlist.json root-epoch registration): fix(dstackup): render the KMS 0.6 listener layout and default to KMS 0.6.7 #1709

Closing this combined PR in favor of the split PRs above.

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