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 <li...@google.com> --- .../X64/PeiDxeVirtualMemory.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index b9c0a5b25a..75c2c36bb4 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,22 @@ 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); + if (NewPageTable == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a:%a: failed to allocate a new PML4 entry\n", + gEfiCallerBaseName, + __FUNCTION__ + )); + Status = RETURN_NO_MAPPING; + goto Done; + } + SetMem (NewPageTable, EFI_PAGE_SIZE, 0); + PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)NewPageTable | AddressEncMask; + PageMapLevel4Entry->Bits.MustBeZero = 0; + PageMapLevel4Entry->Bits.ReadWrite = 1; + PageMapLevel4Entry->Bits.Present = 1; } PageDirectory1GEntry = (VOID *)( -- 2.39.1.456.gfc5497dd1b-goog -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99097): https://edk2.groups.io/g/devel/message/99097 Mute This Topic: https://groups.io/mt/96551964/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-