From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by mx.groups.io with SMTP id smtpd.web08.482.1614718196826762954 for ; Tue, 02 Mar 2021 12:49:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=fo9oiZ3S; spf=pass (domain: linux.ibm.com, ip: 148.163.158.5, mailfrom: tobin@linux.ibm.com) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 122KhJHk124690; Tue, 2 Mar 2021 15:49:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ImgJCB1iEkUtjBsJmPvJXVYsljgWiRAb/dTBb7JwqoA=; b=fo9oiZ3SdzKmSgQxBYQQJ647W6IbeDEFKt0EBLncDaUtlwtHxqD0ehQ8PqiopyywMTIw fybR0rmLVKR/lPQHSYK4De0g1QzcdxaX7PwyXfG6pwosuVdGtxyZGa+JOCNpVHB3L0F5 8i7mWDO2d7SvcoxZd/4vIYn0xoEysSOowV5Z0i2tN411jB8h1WPpQjHgpN35x7vbgoYS 54JXBDsrEqpvdoANs8BRE6FTWzio0iEKWuI1W1Uev+Ud8QTAjmTayyFYVXEBxzAu15VX hdvNh5Lg0QTCIHGVwt9IfRQ6+C4OHa70BMN8BllaAE8UndYFmDL0bgylE3HUKo3sTDLl qQ== Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 371vn7r8un-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 15:49:54 -0500 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 122Km8v4014171; Tue, 2 Mar 2021 20:48:53 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma03dal.us.ibm.com with ESMTP id 37103w5sk0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 20:48:53 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 122KmpY917563910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Mar 2021 20:48:51 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 109FCC605B; Tue, 2 Mar 2021 20:48:51 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7C15BC6055; Tue, 2 Mar 2021 20:48:50 +0000 (GMT) Received: from amdrome1.watson.ibm.com (unknown [9.2.130.16]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 2 Mar 2021 20:48:50 +0000 (GMT) From: "Tobin Feldman-Fitzthum" To: devel@edk2.groups.io Cc: Dov Murik , Tobin Feldman-Fitzthum , Tobin Feldman-Fitzthum , James Bottomley , Hubertus Franke , Brijesh Singh , Ashish Kalra , Jon Grimm , Tom Lendacky Subject: [RFC PATCH 07/14] OvmfPkg/AmdSev: MH support for mailbox protocol Date: Tue, 2 Mar 2021 15:48:32 -0500 Message-Id: <20210302204839.82042-8-tobin@linux.ibm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210302204839.82042-1-tobin@linux.ibm.com> References: <20210302204839.82042-1-tobin@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-02_08:2021-03-01,2021-03-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 spamscore=0 bulkscore=0 adultscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103020156 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 | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf index a4906a2451..49457d5d17 100644 --- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf +++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf @@ -34,6 +34,7 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdIsConfidentialMigrationTarget gUefiOvmfPkgTokenSpaceGuid.PcdStartConfidentialMigrationHandler + gUefiOvmfPkgTokenSpaceGuid.PcdConfidentialMigrationMailboxBase [Depex] gEfiMpServiceProtocolGuid diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c index 6d9fe7043b..8402fcc4fa 100644 --- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c +++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c @@ -9,16 +9,94 @@ #include #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) + +// +// Index of CPU that MH runs on. +// UINTN MigrationHandlerCpuIndex; +// +// Mailbox for communication with hypervisor +// +typedef volatile struct { + UINT64 nr; + UINT64 gpa; + UINT32 do_prefetch; + UINT32 ret; + UINT32 go; + UINT32 done; +} MH_COMMAND_PARAMETERS; + + VOID EFIAPI MigrationHandlerMain ( IN OUT VOID *Buffer ) { + UINT64 params_base; + MH_COMMAND_PARAMETERS *params; + VOID *page_va; + DebugPrint (DEBUG_INFO,"MIGRATION Handler Started\n"); + + params_base = PcdGet32 (PcdConfidentialMigrationMailboxBase); + params = (VOID *)params_base; + page_va = (VOID *)params_base + 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(page_va, (VOID *)params->gpa, 4096); + params->ret = MH_SUCCESS; + break; + + case MH_FUNC_RESTORE_PAGE: + CopyMem((VOID *)params->gpa, page_va, 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; + + } } EFI_STATUS -- 2.20.1