From: FangSheng Huang <[email protected]>

Soft Reserved (Specific Purpose Memory) regions carry the
EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE resource attribute.  Under
SEV-SNP that attribute is lost: AmdSevSnpInitialize() converts every
EFI_RESOURCE_SYSTEM_MEMORY HOB above 4GB to
EFI_RESOURCE_MEMORY_UNACCEPTED, and AcceptAllMemory() later re-adds the
region as plain SystemMemory, dropping the attribute.  A SEV-SNP guest
then sees the range as ordinary RAM instead of Soft Reserved.

Handle SPECIAL_PURPOSE regions in AmdSevSnpInitialize() by validating
them in place (like sub-4GB RAM) instead of deferring them, so the HOB
type and attribute survive into the EFI memory map.

Signed-off-by: FangSheng Huang <[email protected]>
---
PR: https://github.com/tianocore/edk2/pull/12774

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

diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index 8562787035..b3405bca1e 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -148,6 +148,18 @@ AmdSevSnpInitialize (
       ResourceHob = Hob.ResourceDescriptor;
 
       if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
+        //
+        // Specific Purpose Memory (SPM), exposed as E820 Soft Reserved,
+        // must keep its resource type so the SPECIAL_PURPOSE attribute
+        // survives into the EFI memory map and reaches the OS.
+        //
+        if (ResourceHob->ResourceAttribute & 
EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE) {
+          MemEncryptSevSnpPreValidateSystemRam (
+            ResourceHob->PhysicalStart,
+            EFI_SIZE_TO_PAGES ((UINTN)ResourceHob->ResourceLength)
+            );
+          continue;
+        }
         if (ResourceHob->PhysicalStart >= SIZE_4GB) {
           ResourceHob->ResourceType = EFI_RESOURCE_MEMORY_UNACCEPTED;
           continue;
-- 
2.34.1



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


Reply via email to