diff --git a/dstack/vmm/src/app/qemu.rs b/dstack/vmm/src/app/qemu.rs index 9e80291026..17a07139d0 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!( diff --git a/os/mkosi/components/ovmf/ovmf-build.sh b/os/mkosi/components/ovmf/ovmf-build.sh index d365d1ea0b..8a8a4bbdf8 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"