From 4ece247e627956cd357baa5690a4856d9ffd2978 Mon Sep 17 00:00:00 2001 From: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:34:04 +0000 Subject: [PATCH 1/2] fix(vmm): give SEV-SNP guests the host's physical address width 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> --- dstack/vmm/src/app/qemu.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/dstack/vmm/src/app/qemu.rs b/dstack/vmm/src/app/qemu.rs index 9e8029102..17a07139d 100644 --- a/dstack/vmm/src/app/qemu.rs +++ b/dstack/vmm/src/app/qemu.rs @@ -679,7 +679,11 @@ impl QemuCommandBuilder<'_> { let mut command = Command::new(&self.cfg.qemu_path); command.arg("-accel").arg("kvm"); command.arg("-cpu").arg(if self.is_amd_sev_snp() { - "EPYC-v4" + // A named model gets QEMU's default 40 phys-bits (1 TiB), too small + // for the 64-bit MMIO window of large-BAR GPUs; `-cpu host` (TDX) + // already takes the host's. The CPUID page is not part of the SNP + // launch measurement, so this does not change it. + "EPYC-v4,host-phys-bits=on" } else { "host" }); @@ -1336,6 +1340,32 @@ mod tests { assert_eq!(params.reduced_phys_bits, 1); } + #[test] + fn amd_sev_snp_cpu_takes_host_phys_bits() { + let (config, mut vm, mut prepared) = test_launch_fixture(); + vm.manifest.no_tee = false; + prepared.platform = CvmPlatform::AmdSevSnp; + prepared.snp_host_data = Some("00".repeat(32)); + prepared.snp_launch_params = Some(AmdSevSnpLaunchParams { + cbitpos: 51, + reduced_phys_bits: 1, + }); + + let process = QemuCommandBuilder { + vm: &vm, + cfg: &config.cvm, + gpus: &GpuConfig::default(), + prepared: &prepared, + } + .build() + .unwrap(); + + assert!(process + .args + .windows(2) + .any(|args| args == ["-cpu", "EPYC-v4,host-phys-bits=on"])); + } + #[test] fn amd_sev_snp_uses_confidential_virtio_pci_options() { assert_eq!( From 180e2982790a17fecbdce50eacb42049f5f0e78a Mon Sep 17 00:00:00 2001 From: Pierre LE GUEN <26087574+PierreLeGuen@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:34:36 +0000 Subject: [PATCH 2/2] fix(os): build the SEV-SNP OVMF with 1 GiB page tables 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> --- os/mkosi/components/ovmf/ovmf-build.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/os/mkosi/components/ovmf/ovmf-build.sh b/os/mkosi/components/ovmf/ovmf-build.sh index d365d1ea0..8a8a4bbdf 100755 --- a/os/mkosi/components/ovmf/ovmf-build.sh +++ b/os/mkosi/components/ovmf/ovmf-build.sh @@ -77,9 +77,13 @@ rm -f "$src/Conf/tools_def.txt" build -a X64 -t GCC5 -b RELEASE -n "${JOBS:-$(nproc)}" \ -p OvmfPkg/IntelTdx/IntelTdxX64.dsc) install -Dm0644 "$src/Build/IntelTdx/RELEASE_GCC5/FV/OVMF.fd" "$OUT" +# Without 1 GiB page tables OVMF caps the guest physical address width at 40 +# bits, which limits its 64-bit PCI MMIO window to 128 GiB: too small for +# large-BAR GPUs (a B200 BAR1 is 256 GiB). # shellcheck source=/dev/null (cd "$src" && set +u && source edksetup.sh BaseTools >/dev/null && \ build -a X64 -t GCC5 -b RELEASE -n "${JOBS:-$(nproc)}" \ + --pcd gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable=TRUE \ -p OvmfPkg/AmdSev/AmdSevX64.dsc) install -Dm0644 "$src/Build/AmdSev/RELEASE_GCC5/FV/OVMF.fd" "$SEV_OUT" touch -d "@${SOURCE_DATE_EPOCH:?}" "$OUT" "$SEV_OUT"