Skip to content

feat: Secure TSC for AMD SEV-SNP, and secure_time refuses a host-controlled clock - #1642

Merged
kvinwang merged 12 commits into
nextfrom
feat/snp-secure-tsc
Nov 27, 2026
Merged

kvinwang merged 12 commits into
nextfrom
feat/snp-secure-tsc

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Without Secure TSC the hypervisor can intercept RDTSC and change the TSC offset and scale, so on AMD SEV-SNP guest time is host-controlled between NTS syncs.

VMM / verification

  • An SNP guest with secure_time on (the default when the app compose omits it) is launched with secure-tsc=on on the sev-snp-guest object and SEV_FEATURES bit 9 in the measurement document. Apps with secure_time: false launch exactly as before, with the same launch digest.
  • dstack-mr accepts SNPActive | SecureTSC in guest_features.
  • Launching with Secure TSC requires QEMU >= 11.2 (only v11.2.0-rc1 exists today; QEMU's docs say 11.1, but v11.1.3 lacks the property), host kernel >= 6.18 and a CPU that supports it. A KMS or verifier without this change rejects such a guest.

Guest

  • With secure_time enabled, dstack-util now refuses to boot unless the clocksource is tsc; on AMD SEV-SNP it also requires Secure TSC, and on AWS it always refuses.
  • The 6.18 guest kernel has no userspace interface for the Secure TSC status, so a mkosi kernel patch exposes the kernel's own sev_status bit as /sys/devices/system/cpu/sev/secure_tsc.

Breaking: an app with secure_time on, including one that omits the key, no longer boots on AWS, or on an SNP host that cannot launch with Secure TSC (an older QEMU exits on the unknown secure-tsc property). Apps with secure_time: false are unaffected, including on older QEMU.

Testing

Unit: cargo test -p dstack-mr --lib, cargo test -p dstack-vmm, cargo test -p dstack-util pass.

On SEV-SNP hardware: EPYC 7763 (Milan), host kernel 7.0.0, QEMU v11.2.0-rc1, VMM and verifier from 0c6923bbe6, dev image built from the same commit with mkosi (guest kernel 6.18.59), 2 vCPU / 4 GiB, no KMS or gateway.

Case Result
secure_time, launched by the VMM boots; SEV: Status: SEV SEV-ES SEV-SNP SecureTSC; sysfs secure_tsc = 1; clocksource tsc; NTS sync passes
same guest, attestation guest_features 513; verifier: is_valid, os_image_hash_verified
no secure_time launched without secure-tsc; sysfs secure_tsc = 0; guest_features 1; verifier: is_valid
secure_time, QEMU run by hand without secure-tsc=on dstack-prepare fails: secure_time requires amd sev-snp Secure TSC, which the host did not enable
secure_time on the released 0.6.5 image boots with Secure TSC; verifier: is_valid

On TDX (tdxlab): Xeon Gold 6526Y, host kernel 6.8.0-1028-intel, QEMU 8.2.2 (Ubuntu tdx1.1), shared VMM, KMS 0.6.5 with dev-auth webhook, dev image built from ea065c4b1b, 2 vCPU / 4 GiB.

Case Result
secure_time clocksource tsc; secure clock check passes, waits for NTS sync, gets app keys from KMS, containers start
no secure_time boots as before; app keys from KMS

Not tested: GCP and AWS guests with the new image.

@kvinwang kvinwang changed the title feat(vmm): launch AMD SEV-SNP guests with Secure TSC feat: Secure TSC for AMD SEV-SNP, and secure_time refuses a host-controlled clock Nov 24, 2026
@kvinwang
kvinwang force-pushed the feat/snp-secure-tsc branch from ea744bc to 1b97ccf Compare November 24, 2026 11:46
Without Secure TSC the hypervisor can intercept RDTSC and change the TSC
offset and scale, so guest time is host-controlled between NTS syncs.

Add cvm.snp_secure_tsc (off by default, needs QEMU >= 11.1 and host
kernel >= 6.18). It adds secure-tsc=on to the sev-snp-guest object and
sets SEV_FEATURES bit 9 in the measurement document; dstack-mr now
accepts that bit.

Signed-off-by: Kevin Wang <wy721@qq.com>
secure_time waits for an NTS sync, but between syncs the clock follows
the TSC. Before waiting, require the tsc clocksource, require Secure TSC
on AMD SEV-SNP, and reject AWS.

The guest kernel has no userspace interface for the Secure TSC status,
so add a kernel patch exposing it as /sys/devices/system/cpu/sev/secure_tsc.

Signed-off-by: Kevin Wang <wy721@qq.com>
Drop cvm.snp_secure_tsc. A host option could break every SNP guest on a
QEMU without secure-tsc, including apps that never asked for a secure
clock. Only an app whose compose sets secure_time now gets secure-tsc=on,
so every other app launches exactly as before, with the same launch
digest.

Signed-off-by: Kevin Wang <wy721@qq.com>
Move the secure_tsc -> SEV_FEATURES mapping into dstack-mr, build the
sev-snp-guest object in one function, and cover the secure_time launch on
both sides: guest_features in the measurement document and secure-tsc=on
on the QEMU object. Name secure_time when platform detection fails.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the feat/snp-secure-tsc branch from 3ef637a to 0c6923b Compare November 24, 2026 11:51
QEMU documents secure-tsc as "since 11.1", but v11.1.3 does not have the
property; v11.2.0-rc1 does. /proc/cpuinfo has no snp_secure_tsc flag
either: the kernel does not list that feature there.

Signed-off-by: Kevin Wang <wy721@qq.com>
The yocto backend is going away, so the new patch lives with the mkosi
kernel component instead.

Signed-off-by: Kevin Wang <wy721@qq.com>
requirements and secure_time both come from the app compose, so take
the compose itself instead of one argument per field.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang marked this pull request as ready for review November 26, 2026 06:47

@Leechael Leechael left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A note on the QEMU requirement, since it decides who this breaks on upgrade. I have no SNP host to launch on, so this is from reading the code at 3489413 and the upstream trees.

secure-tsc is not in any released QEMU yet. Checked target/i386/sev.c at each tag:

QEMU tag secure-tsc property
v10.2.0, v11.0.0, v11.1.0, v11.1.3 absent
v11.2.0-rc0 / rc1 / rc2, master present

The host side lines up with the description otherwise: KVM has Secure TSC from v6.18 (absent in v6.17), the guest from v6.14.

So after this merges and a VMM is upgraded, an SNP app with secure_time cannot launch on any host running a released QEMU, and the only way to run it is a release candidate. That is stated as breaking, but two things make it wider and harder to diagnose than the notes suggest, inline.

Suggest holding the VMM half until 11.2.0 is out, or gating it (see inline) so that hosts on a released QEMU keep launching what they launch today.

Comment thread dstack/vmm/src/app/qemu.rs Resolved
…P app

The upgrade note said apps without secure_time launch as before, but
secure_time defaults to true when the app compose omits it. Only apps
with secure_time: false are unaffected.

Signed-off-by: Kevin Wang <wy721@qq.com>
Signed-off-by: Kevin Wang <wy721@qq.com>

# Conflicts:
#	CHANGELOG.md
@kvinwang
kvinwang requested a review from Leechael November 27, 2026 05:38
@kvinwang
kvinwang enabled auto-merge November 27, 2026 06:52
@kvinwang
kvinwang merged commit b43a8a4 into next Nov 27, 2026
29 checks passed
@kvinwang
kvinwang deleted the feat/snp-secure-tsc branch November 27, 2026 06:58
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