UefiCpuPkg/CpuDxe: fix page table walk in confidential VM

`PageStartAddress` variable was not set correctly because the encryption bit
was not considered, which broke the page walk logic.

Get the bitmask and mask the encryption bit.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
This commit is contained in:
Luigi Leonardi
2025-09-23 06:36:46 -04:00
committed by Ard Biesheuvel
parent 44214c0cdf
commit f64b4065b7

View File

@ -975,6 +975,7 @@ RefreshGcdMemoryAttributesFromPaging (
UINT64 Capabilities;
UINT64 NewAttributes;
UINTN Index;
UINT64 AddressEncMask;
//
// Assuming that memory space map returned is sorted already; otherwise sort
@ -1055,10 +1056,18 @@ RefreshGcdMemoryAttributesFromPaging (
break;
}
//
// Get the mask for the memory encryption bit for Tdx and Sev
//
AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask);
if (AddressEncMask == 0) {
AddressEncMask = PcdGet64 (PcdTdxSharedBitMask);
}
//
// Note current memory space might start in the middle of a page
//
PageStartAddress = (*PageEntry) & (UINT64)PageAttributeToMask (PageAttribute);
PageStartAddress = (*PageEntry) & (UINT64)PageAttributeToMask (PageAttribute) & ~AddressEncMask;
PageLength = PageAttributeToLength (PageAttribute) - (BaseAddress - PageStartAddress);
Attributes = GetAttributesFromPageEntry (PageEntry);
}