From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mx.groups.io with SMTP id smtpd.web12.61483.1629321677815119949 for ; Wed, 18 Aug 2021 14:21:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=h/BAI+/O; spf=pass (domain: linux.ibm.com, ip: 148.163.156.1, mailfrom: tobin@linux.ibm.com) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17IL41tO041091; Wed, 18 Aug 2021 17:21:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=50kmKPql4GZ7Xi+sm4dxQl7IYoLYxkpkCqClF81xWbw=; b=h/BAI+/O6Vxa70Hc8LQqzXpMcJXqD8nC6KY7NPXEIv/lIwcvsSKYycbgw8XwKkPt+X8z jQC2q+FihA8c7ayDjwW9D++0m8tLDXJ2GldhDTkZiDx+nqFai4W/zJOkZbXDqlZ9yPTc Oo3BVBsRBOwI08sg3s9jgMkZJO1dSCCKA+GKY9Gm8lyEzuFu6X5Y+63H5Zfk22X/O75k uciBadgOnElTdkdjZ6r2QHiAc9jRxabknMcT/SnOi5Wpu1y4n0CXr5NPZIUiREM/Rji4 /02Z+MNU2U7p02tVibo35dSLYWWhgs3R1VrnM51dfN3fYrEXq1G+YDEN4sdTQ8ZH+Lcl Gg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agc2h2j7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:13 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17ILGr86076556; Wed, 18 Aug 2021 17:21:13 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agc2h2j6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:13 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17ILGx71002790; Wed, 18 Aug 2021 21:21:12 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma03wdc.us.ibm.com with ESMTP id 3ae5fe595r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 21:21:12 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17ILLASM47841784 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Aug 2021 21:21:10 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 957EDBE054; Wed, 18 Aug 2021 21:21:10 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8158FBE059; Wed, 18 Aug 2021 21:21:09 +0000 (GMT) Received: from amdrome1.watson.ibm.com (unknown [9.2.130.16]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 18 Aug 2021 21:21:09 +0000 (GMT) From: "Tobin Feldman-Fitzthum" 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 Message-Id: <20210818212048.162626-5-tobin@linux.ibm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210818212048.162626-1-tobin@linux.ibm.com> References: <20210818212048.162626-1-tobin@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 1lSJQpp-_RIqxHBpsypM6p4d57tAnIo- X-Proofpoint-GUID: wtTMdvFtj_JFoDIzELmA0LuV7wIpcAdG X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-18_07:2021-08-17,2021-08-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 bulkscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108180130 Content-Transfer-Encoding: 8bit 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 --- .../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 +#include #include +// +// 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