From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by mx.groups.io with SMTP id smtpd.web10.74390.1673571429489721484 for ; Thu, 12 Jan 2023 16:57:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=ZKaVLLLq; spf=pass (domain: flex--lisik.bounces.google.com, ip: 209.85.216.74, mailfrom: 3zkzaywukbemqnxnplttlqj.htrijajqjiph.lwtzux.nt@flex--lisik.bounces.google.com) Received: by mail-pj1-f74.google.com with SMTP id me17-20020a17090b17d100b0022901e51ab3so2125599pjb.2 for ; Thu, 12 Jan 2023 16:57:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Uc2MtF4qGLVjP1xLt/3jOEUJgql3J31nJFUPOv2slbQ=; b=ZKaVLLLqp5qPP4nEx3/kcL5M4nig3SOjY++WPoui4yYYJDYSWEWTQbvs06q3T+Q4gu 7K8A5FllXFBRNFE44kK38Wx6+Ak4hCda8WxUvwElkd8jPlknd+DaX9ZhbgA50LP7wnex DSuAOp+DvpohTXYjVAGrsKIiF4yuEUVtNr5AphMMqWS8RnnVBGgKt9txy5HYDot9vQLw 2u1hWC+JKFLAZziTCC0QwUd3fn8Lxpd3txvsF7PMIlzkV0DMgh4WOzmgDZ2KVc4pjwlS WSUEcZpTE62Q3VEU6BE922fOi/kT1ORQyW4twy/DDuKDlvcMQPyuKV1wARgv55/ycB9F XBEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Uc2MtF4qGLVjP1xLt/3jOEUJgql3J31nJFUPOv2slbQ=; b=OiYDEXdrGsZCt8l5mtNYgPUzjj/1wGqe0+kWhAZCNnkBoeyN/bZEA4QsFUGSfrdC+K kjsx/evoFyLEJZ3c3aQ8hz+TF4sKzs90DD85/uw4WHItf0BZlzhfBJB1HZullun5eQuh PlSMsSECIbx0Yi/J/RWvKwmS694G/Va1/c3LW8zfiKgTn1hB6ISec/iGPPGOnXlcwLZ8 QPmCGDReXvu1KWENzTHMZqX3Rp1uSlAJDyODCXsHCiHQQid7UaZzETncuY3eAPVkqQRf 74oX2/DtY4ji9CvOqiFF0sEKU5cH5TgeSXo0C9Djtyf3VgjoA42q7uKIzTATRDOIJEE0 Iv3w== X-Gm-Message-State: AFqh2kpnxMVRKyHK9Oke7tek7eaG/KRyOB8idYttO2g7FjYEJUtZCEE+ D/Png9TsfmyRtMzfiztVXk5EWznKPQa6bM0774BhHAtNgkKR1AudiZ3f9ENoPcytKdBm7PnRPM7 B8J6dtpLJhPOLdWmChkgG1GsizRHHq/Qbme2piTqKa84O7imxr34PZobC X-Google-Smtp-Source: AMrXdXtVocylIZSVRIvNHNrrxelXdsocfkP9gt/un6p23ZW/3cYSGDgyFbx2smD1rGlPchSr7txbSuXzpA== X-Received: from lisik.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:6647]) (user=lisik job=sendgmr) by 2002:aa7:8d52:0:b0:578:8850:fe65 with SMTP id s18-20020aa78d52000000b005788850fe65mr6345958pfe.65.1673571428763; Thu, 12 Jan 2023 16:57:08 -0800 (PST) Date: Fri, 13 Jan 2023 00:57:05 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <5e1916c6669ee2a918a2c22b7698e96f7dbf5488.1673568149.git.lisik@google.com> Subject: [PATCH] OvmfPkg: Create additional PML4 entries for large SEV-SNP VMs From: lisik@google.com To: devel@edk2.groups.io Cc: Mikolaj Lisik Content-Type: text/plain; charset="UTF-8" Edk2 was failing, rather than creating more PML4 entries, when they weren't present in the initial memory acceptance flow. Because of that VMs with more than 512G memory were crashing. This code fixes that. This change affects only SEV-SNP VMs. The code was tested by successfully booting a 512G SEV-SNP VM. Signed-off-by: Mikolaj Lisik --- .../X64/PeiDxeVirtualMemory.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index b9c0a5b25a..3dbff51ac2 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -548,6 +548,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; UINT64 PgTableMask; + UINT64 *NewPageTable; UINT64 AddressEncMask; BOOLEAN IsWpEnabled; RETURN_STATUS Status; @@ -602,15 +603,13 @@ InternalMemEncryptSevCreateIdentityMap1G ( PageMapLevel4Entry = (VOID *)(Cr3BaseAddress & ~PgTableMask); PageMapLevel4Entry += PML4_OFFSET (PhysicalAddress); if (!PageMapLevel4Entry->Bits.Present) { - DEBUG (( - DEBUG_ERROR, - "%a:%a: bad PML4 for Physical=0x%Lx\n", - gEfiCallerBaseName, - __FUNCTION__, - PhysicalAddress - )); - Status = RETURN_NO_MAPPING; - goto Done; + NewPageTable = AllocatePageTableMemory(1); + ASSERT(NewPageTable != NULL); + SetMem (NewPageTable, EFI_PAGE_SIZE, 0); + PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)NewPageTable | AddressEncMask; + PageMapLevel4Entry->Bits.Present = 1; + PageMapLevel4Entry->Bits.MustBeZero = 0; + PageMapLevel4Entry->Bits.ReadWrite = 1; } PageDirectory1GEntry = (VOID *)( @@ -640,7 +639,6 @@ InternalMemEncryptSevCreateIdentityMap1G ( // CpuFlushTlb (); -Done: // // Restore page table write protection, if any. // -- 2.39.0.314.g84b9a713c41-goog