[edk2-devel] [PATCH RESEND 1/4] OvmfPkg/AmdSevDxe: Allocate SEV-SNP CC blob as EfiACPIReclaimMemory

Roth, Michael via groups.io posted 4 patches 1 year, 2 months ago
There is a newer version of this series
[edk2-devel] [PATCH RESEND 1/4] OvmfPkg/AmdSevDxe: Allocate SEV-SNP CC blob as EfiACPIReclaimMemory
Posted by Roth, Michael via groups.io 1 year, 2 months ago
The SEV-SNP Confidential Computing blob contains metadata that should
remain accessible for the life of the guest. Allocate it as
EfiACPIReclaimMemory to ensure the memory isn't overwritten by the guest
operating system later.

Reported-by: Dov Murik <dovmurik@linux.ibm.com>
Suggested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
 OvmfPkg/AmdSevDxe/AmdSevDxe.c | 62 +++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 14 deletions(-)

diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
index a726498e27..7250cc90e5 100644
--- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c
+++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c
@@ -28,15 +28,36 @@
 // Present, initialized, tested bits defined in MdeModulePkg/Core/Dxe/DxeMain.h

 #define EFI_MEMORY_INTERNAL_MASK  0x0700000000000000ULL

 

-STATIC CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION  mSnpBootDxeTable = {

-  SIGNATURE_32 ('A',                                    'M', 'D', 'E'),

-  1,

-  0,

-  (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfSnpSecretsBase),

-  FixedPcdGet32 (PcdOvmfSnpSecretsSize),

-  (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfCpuidBase),

-  FixedPcdGet32 (PcdOvmfCpuidSize),

-};

+STATIC

+EFI_STATUS

+AllocateConfidentialComputingBlob (

+  OUT CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION  **CcBlobPtr

+  )

+{

+  EFI_STATUS                                Status;

+  CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION  *CcBlob;

+

+  Status = gBS->AllocatePool (

+                  EfiACPIReclaimMemory,

+                  sizeof (CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION),

+                  (VOID **)&CcBlob

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  CcBlob->Header                 = SIGNATURE_32 ('A', 'M', 'D', 'E');

+  CcBlob->Version                = 1;

+  CcBlob->Reserved1              = 0;

+  CcBlob->SecretsPhysicalAddress = (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfSnpSecretsBase);

+  CcBlob->SecretsSize            = FixedPcdGet32 (PcdOvmfSnpSecretsSize);

+  CcBlob->CpuidPhysicalAddress   = (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfCpuidBase);

+  CcBlob->CpuidLSize             = FixedPcdGet32 (PcdOvmfCpuidSize);

+

+  *CcBlobPtr = CcBlob;

+

+  return EFI_SUCCESS;

+}

 

 STATIC EFI_HANDLE  mAmdSevDxeHandle = NULL;

 

@@ -177,10 +198,11 @@ AmdSevDxeEntryPoint (
   IN EFI_SYSTEM_TABLE  *SystemTable

   )

 {

-  EFI_STATUS                       Status;

-  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *AllDescMap;

-  UINTN                            NumEntries;

-  UINTN                            Index;

+  EFI_STATUS                                Status;

+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR           *AllDescMap;

+  UINTN                                     NumEntries;

+  UINTN                                     Index;

+  CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION  *SnpBootDxeTable;

 

   //

   // Do nothing when SEV is not enabled

@@ -286,6 +308,18 @@ AmdSevDxeEntryPoint (
     }

   }

 

+  Status = AllocateConfidentialComputingBlob (&SnpBootDxeTable);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((

+      DEBUG_ERROR,

+      "%a: AllocateConfidentialComputingBlob(): %r\n",

+      __FUNCTION__,

+      Status

+      ));

+    ASSERT (FALSE);

+    CpuDeadLoop ();

+  }

+

   if (MemEncryptSevSnpIsEnabled ()) {

     //

     // Memory acceptance began being required in SEV-SNP, so install the

@@ -323,7 +357,7 @@ AmdSevDxeEntryPoint (
     //

     return gBS->InstallConfigurationTable (

                   &gConfidentialComputingSevSnpBlobGuid,

-                  &mSnpBootDxeTable

+                  SnpBootDxeTable

                   );

   }

 

-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101245): https://edk2.groups.io/g/devel/message/101245
Mute This Topic: https://groups.io/mt/97638492/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH RESEND 1/4] OvmfPkg/AmdSevDxe: Allocate SEV-SNP CC blob as EfiACPIReclaimMemory
Posted by Gerd Hoffmann 1 year, 2 months ago
On Wed, Mar 15, 2023 at 04:57:44PM -0500, Michael Roth wrote:
> The SEV-SNP Confidential Computing blob contains metadata that should
> remain accessible for the life of the guest. Allocate it as
> EfiACPIReclaimMemory to ensure the memory isn't overwritten by the guest
> operating system later.
> 
> Reported-by: Dov Murik <dovmurik@linux.ibm.com>
> Suggested-by: Dov Murik <dovmurik@linux.ibm.com>
> Reviewed-by: Dov Murik <dovmurik@linux.ibm.com>
> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> Signed-off-by: Michael Roth <michael.roth@amd.com>

Acked-by: Gerd Hoffmann <kraxel@redhat.com>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101417): https://edk2.groups.io/g/devel/message/101417
Mute This Topic: https://groups.io/mt/97638492/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-