OvmfPkg/PlatformPei: retain SoftReserved memory under SEV-SNP

Soft Reserved (Specific Purpose Memory) regions carry the
EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE attribute, which the OS sees as
EFI_MEMORY_SP (E820 Soft Reserved).  Under SEV-SNP this does not reach the
guest: AmdSevSnpInitialize() changes every EFI_RESOURCE_SYSTEM_MEMORY HOB
above 4GB to EFI_RESOURCE_MEMORY_UNACCEPTED, and AcceptAllMemory() later
re-adds the region as plain system memory without EFI_MEMORY_SP, so the
guest sees ordinary RAM instead of Soft Reserved.

Exclude SPECIAL_PURPOSE regions from the unaccepted conversion so they keep
the EFI_RESOURCE_SYSTEM_MEMORY type and are pre-validated in place, like
sub-4GB memory.

Signed-off-by: FangSheng Huang <FangSheng.Huang@amd.com>
This commit is contained in:
FangSheng Huang 2026-06-30 16:22:25 +08:00 committed by mergify[bot]
parent 9e3e68218c
commit 6c6d0a72c2

View file

@ -148,7 +148,17 @@ AmdSevSnpInitialize (
ResourceHob = Hob.ResourceDescriptor;
if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
if (ResourceHob->PhysicalStart >= SIZE_4GB) {
//
// Defer acceptance of memory above 4GB, which the OS accepts lazily.
// Specific Purpose Memory (E820 Soft Reserved) is excepted: it must
// keep the EFI_RESOURCE_SYSTEM_MEMORY type so its SPECIAL_PURPOSE
// attribute reaches the EFI memory map, and it is never handed to the
// OS allocator, so it would never be accepted lazily. Pre-validate
// it in place, like sub-4GB memory.
//
if ((ResourceHob->PhysicalStart >= SIZE_4GB) &&
((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE) == 0))
{
ResourceHob->ResourceType = EFI_RESOURCE_MEMORY_UNACCEPTED;
continue;
}