OvmfPkg: Create additional PML1 entries for large SEV-SNP VMs

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 <lisik@google.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
This commit is contained in:
Mikolaj Lisik via groups.io 2023-01-26 20:26:40 +00:00 committed by mergify[bot]
parent 8fbf857a0b
commit c1dd400a13
1 changed files with 18 additions and 9 deletions

View File

@ -548,6 +548,7 @@ InternalMemEncryptSevCreateIdentityMap1G (
PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry;
PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry;
UINT64 PgTableMask; UINT64 PgTableMask;
UINT64 *NewPageTable;
UINT64 AddressEncMask; UINT64 AddressEncMask;
BOOLEAN IsWpEnabled; BOOLEAN IsWpEnabled;
RETURN_STATUS Status; RETURN_STATUS Status;
@ -602,15 +603,23 @@ InternalMemEncryptSevCreateIdentityMap1G (
PageMapLevel4Entry = (VOID *)(Cr3BaseAddress & ~PgTableMask); PageMapLevel4Entry = (VOID *)(Cr3BaseAddress & ~PgTableMask);
PageMapLevel4Entry += PML4_OFFSET (PhysicalAddress); PageMapLevel4Entry += PML4_OFFSET (PhysicalAddress);
if (!PageMapLevel4Entry->Bits.Present) { if (!PageMapLevel4Entry->Bits.Present) {
DEBUG (( NewPageTable = AllocatePageTableMemory (1);
DEBUG_ERROR, if (NewPageTable == NULL) {
"%a:%a: bad PML4 for Physical=0x%Lx\n", DEBUG ((
gEfiCallerBaseName, DEBUG_ERROR,
__func__, "%a:%a: failed to allocate a new PML4 entry\n",
PhysicalAddress gEfiCallerBaseName,
)); __func__
Status = RETURN_NO_MAPPING; ));
goto Done; 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 *)( PageDirectory1GEntry = (VOID *)(