From: FangSheng Huang <[email protected]>

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 <[email protected]>
Reviewed-by: Tom Lendacky <[email protected]>
---
v1 -> v2:
- Fold the SPECIAL_PURPOSE handling into the existing >=4GB
  unaccepted-conversion guard instead of a separate block with a
  duplicate MemEncryptSevSnpPreValidateSystemRam() call (Tom Lendacky).

PR: https://github.com/tianocore/edk2/pull/12774

 OvmfPkg/PlatformPei/AmdSev.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index 8562787035..9a77a34ecf 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -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;

         }

-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#122040): https://edk2.groups.io/g/devel/message/122040
Mute This Topic: https://groups.io/mt/120317055/21656
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to