[edk2-devel] [RFC PATCH 4/9] OvmfPkg/AmdSev: MH support for mailbox protocol

Tobin Feldman-Fitzthum tobin at linux.ibm.com
Wed Aug 18 21:20:43 UTC 2021


The migration handler communicates with the hypervisor
via a shared mailbox page. The MH can perform four functions
at the behest of the HV: init, save page, restore page, and
reset.

Signed-off-by: Tobin Feldman-Fitzthum <tobin at linux.ibm.com>
---
 .../ConfidentialMigrationDxe.inf              |  1 +
 .../ConfidentialMigrationDxe.c                | 74 +++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf
index 6e3fa7e51c..cb5609271c 100644
--- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf
+++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf
@@ -29,6 +29,7 @@
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdIsConfidentialMigrationTarget
   gUefiOvmfPkgTokenSpaceGuid.PcdStartConfidentialMigrationHandler
+  gUefiOvmfPkgTokenSpaceGuid.PcdConfidentialMigrationMailboxBase
 
 [Depex]
   TRUE
diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
index f0dfbd279e..a981aaeac7 100644
--- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
+++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
@@ -6,14 +6,88 @@
 **/
 
 #include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
 #include <Library/UefiLib.h>
 
+//
+// Functions implemented by the migration handler
+//
+#define MH_FUNC_INIT          0
+#define MH_FUNC_SAVE_PAGE     1
+#define MH_FUNC_RESTORE_PAGE  2
+#define MH_FUNC_RESET         3
+
+//
+// Return codes for MH functions
+//
+#define MH_SUCCESS            0
+#define MH_INVALID_FUNC     (-1)
+#define MH_AUTH_ERR         (-2)
+
+//
+// Mailbox for communication with hypervisor
+//
+typedef volatile struct {
+  UINT64       Nr;
+  UINT64       Gpa;
+  UINT32       DoPrefetch;
+  UINT32       Ret;
+  UINT32       Go;
+  UINT32       Done;
+} MH_COMMAND_PARAMETERS;
+
+
 VOID
 EFIAPI
 MigrationHandlerMain ()
 {
+  UINT64                       MailboxStart;
+  MH_COMMAND_PARAMETERS        *Params;
+  VOID                         *PageVa;
+
   DebugPrint (DEBUG_INFO,"Migration Handler Started\n");
 
+  MailboxStart = PcdGet32 (PcdConfidentialMigrationMailboxBase);
+  Params = (VOID *)MailboxStart;
+  PageVa = (VOID *)(MailboxStart + 0x1000);
+
+  DisableInterrupts ();
+  Params->Go = 0;
+
+  while (1) {
+    while (!Params->Go) {
+      CpuPause ();
+    }
+    Params->Done = 0;
+
+    switch (Params->Nr) {
+    case MH_FUNC_INIT:
+      Params->Ret = MH_SUCCESS;
+      break;
+
+    case MH_FUNC_SAVE_PAGE:
+      CopyMem (PageVa, (VOID *)Params->Gpa, 4096);
+      Params->Ret = MH_SUCCESS;
+      break;
+
+    case MH_FUNC_RESTORE_PAGE:
+      CopyMem ((VOID *)Params->Gpa, PageVa, 4096);
+      Params->Ret = MH_SUCCESS;
+      break;
+
+    case MH_FUNC_RESET:
+      Params->Ret = MH_SUCCESS;
+      break;
+
+    default:
+      Params->Ret = MH_INVALID_FUNC;
+      break;
+    }
+
+    Params->Go = 0;
+    Params->Done = 1;
+
+  }
 }
 
 /**
-- 
2.20.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79521): https://edk2.groups.io/g/devel/message/79521
Mute This Topic: https://groups.io/mt/84982983/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list