From: "Tobin Feldman-Fitzthum" <tobin@linux.ibm.com>
To: tobin@ibm.com, dovmurik@linux.vnet.ibm.com, jejb@linux.ibm.com,
frankeh@us.ibm.com, pbonzini@redhat.com, ashish.kalra@amd.com,
thomas.lendacky@amd.com, brijesh.singh@amd.com,
dgilbert@redhat.com, srutherford@google.com,
devel@edk2.groups.io, ard.biesheuvel@arm.com,
jiewen.yao@intel.com
Subject: [RFC PATCH 4/9] OvmfPkg/AmdSev: MH support for mailbox protocol
Date: Wed, 18 Aug 2021 17:20:43 -0400 [thread overview]
Message-ID: <20210818212048.162626-5-tobin@linux.ibm.com> (raw)
In-Reply-To: <20210818212048.162626-1-tobin@linux.ibm.com>
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@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
next prev parent reply other threads:[~2021-08-18 21:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 21:20 [RFC PATCH 0/9] Firmware Support for Fast Live Migration for AMD SEV Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 1/9] OvmfPkg/AmdSev: Base for Confidential Migration Handler Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 2/9] OvmfPkg/PlatfomPei: Set Confidential Migration PCD Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 3/9] OvmfPkg/AmdSev: Setup Migration Handler Mailbox Tobin Feldman-Fitzthum
2021-08-18 21:20 ` Tobin Feldman-Fitzthum [this message]
2021-08-18 21:20 ` [RFC PATCH 5/9] OvmfPkg/AmdSev: Build page table for migration handler Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 6/9] OvmfPkg/AmdSev: Don't overwrite mailbox or pagetables Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 7/9] OvmfPkg/AmdSev: Don't overwrite MH stack Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 8/9] OvmfPkg/AmdSev: Add Migration Handler entry point Tobin Feldman-Fitzthum
2021-08-18 21:20 ` [RFC PATCH 9/9] OvmfPkg/ResetVector: Expose Migration Handler Entry Addresses Tobin Feldman-Fitzthum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210818212048.162626-5-tobin@linux.ibm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox