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.web11.428.1614718135166558875 for ; Tue, 02 Mar 2021 12:48:55 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PWpAjPUW; spf=pass (domain: linux.ibm.com, ip: 148.163.156.1, mailfrom: tobin@linux.ibm.com) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 122KjLvQ043039; Tue, 2 Mar 2021 15:48:52 -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=unmeBUQUg7PW2f94ijuk5CA7ClbhffxM+AEQz/vS1/M=; b=PWpAjPUWJ+dCAZLqa0t64cqZVTQbHDgDfnF1LqBt5uH9mFiy8l65KGsT+p9c5mMG3A/f uoqjTfr3elJJwwZvhtIRWrqa4QDgw1a92dOaErCB/8ErFIATalXjG1wNBxlRhywh9jfe kRT4bgKpqS+CMc94zuSlY9CA4YkOVM+GxW3HGEAynhVOAbB92RkvZ1ELSC6xcn50Nl79 RUPUAvlTXVXTsK6PXVX3PXEa2hABN3CA9h5700C0GqxOw2N+nntz6NZQCB6lTzJZzKGa 4gI1eYUucF60DlsFNKuTLoxUp40AS8GRRH+QZlGR9mThbagxQgfHCAnedjqhjTh3I/SW 4A== Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 371vp083yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 15:48:52 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 122KkqnU028108; Tue, 2 Mar 2021 20:48:51 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma01dal.us.ibm.com with ESMTP id 371qmuagws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 20:48:51 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 122KmnAN8651486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Mar 2021 20:48:49 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C2A8C6057; Tue, 2 Mar 2021 20:48:49 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 877C0C6059; Tue, 2 Mar 2021 20:48:48 +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:48 +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 04/14] OvmfPkg/AmdSev: Base for Confidential Migration Handler Date: Tue, 2 Mar 2021 15:48:29 -0500 Message-Id: <20210302204839.82042-5-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 mlxlogscore=884 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 bulkscore=0 phishscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103020156 Content-Transfer-Encoding: 8bit Base enablement of DXE driver that supports confidential migration. Signed-off-by: Tobin Feldman-Fitzthum --- OvmfPkg/OvmfPkg.dec | 5 ++ OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | 1 + .../ConfidentialMigrationDxe.inf | 39 +++++++++ .../ConfidentialMigrationDxe.c | 83 +++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf create mode 100644 OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 4450d78b91..402c3b61fa 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -324,6 +324,11 @@ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0|UINT16|0x1b gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated|FALSE|BOOLEAN|0x21 + ## Set via FW_CFG to enable confidentialmigration as source or target. + # + gUefiOvmfPkgTokenSpaceGuid.PcdIsConfidentialMigrationTarget|FALSE|BOOLEAN|0x46 + gUefiOvmfPkgTokenSpaceGuid.PcdStartConfidentialMigrationHandler|FALSE|BOOLEAN|0x47 + ## The IO port aperture shared by all PCI root bridges. # gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0|UINT64|0x22 diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index ca21fd6e5f..fa68143663 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -787,6 +787,7 @@ !endif OvmfPkg/AmdSev/SecretDxe/SecretDxe.inf OvmfPkg/AmdSev/Grub/Grub.inf + OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf !if $(BUILD_SHELL) == TRUE ShellPkg/Application/Shell/Shell.inf { diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf index c0098502aa..6ef6dc89f2 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.fdf +++ b/OvmfPkg/AmdSev/AmdSevX64.fdf @@ -273,6 +273,7 @@ INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf !endif INF OvmfPkg/AmdSev/SecretDxe/SecretDxe.inf +INF OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf INF OvmfPkg/AmdSev/Grub/Grub.inf !if $(BUILD_SHELL) == TRUE INF ShellPkg/Application/Shell/Shell.inf diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf new file mode 100644 index 0000000000..a4906a2451 --- /dev/null +++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.inf @@ -0,0 +1,39 @@ +## @file +# +# Copyright (C) 2021 IBM Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ConfidentialMigration + FILE_GUID = 5c2978f4-f175-434b-9e6c-9b03bd7e346f + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = LaunchMigrationHandler + +[Sources] + ConfidentialMigrationDxe.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + MemoryAllocationLib + DebugLib + UefiBootServicesTableLib + MpInitLib + UefiDriverEntryPoint + +[Protocols] + gEfiMpServiceProtocolGuid + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdIsConfidentialMigrationTarget + gUefiOvmfPkgTokenSpaceGuid.PcdStartConfidentialMigrationHandler + +[Depex] + gEfiMpServiceProtocolGuid diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c new file mode 100644 index 0000000000..6d9fe7043b --- /dev/null +++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c @@ -0,0 +1,83 @@ +/** @file + In-guest support for confidential migration + + Copyright (C) 2021 IBM Coporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include +#include +#include +#include +#include + +UINTN MigrationHandlerCpuIndex; + +VOID +EFIAPI +MigrationHandlerMain ( + IN OUT VOID *Buffer + ) +{ + DebugPrint (DEBUG_INFO,"MIGRATION Handler Started\n"); +} + +EFI_STATUS +EFIAPI +LaunchMigrationHandler ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_MP_SERVICES_PROTOCOL *MpProto; + EFI_PROCESSOR_INFORMATION Tcb; + EFI_STATUS Status; + UINTN NumProc; + UINTN NumEnabled; + + gST = SystemTable; + gBS = gST->BootServices; + gRT = gST->RuntimeServices; + + Status = EFI_NOT_STARTED; + + if (!PcdGetBool(PcdStartConfidentialMigrationHandler)) { + return 0; + } + + // + // Use the MP Service protocol to start Migration Handler on AP + // + gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (void**)&MpProto); + MpProto->GetNumberOfProcessors (MpProto, &NumProc, &NumEnabled); + if (NumProc < 2) { + DebugPrint (DEBUG_ERROR,"Only one vCPU enabled. Please start an extra for the MH.\n"); + return 0; + } + + MigrationHandlerCpuIndex = NumProc - 1; + + EFI_EVENT Event; + MpProto->GetProcessorInfo (MpProto, MigrationHandlerCpuIndex, &Tcb); + if (Tcb.StatusFlag != 7) { + gBS->CreateEvent (EVT_TIMER, TPL_NOTIFY, NULL, NULL, &Event); + + Status = MpProto->StartupThisAP(MpProto, MigrationHandlerMain, 1, Event, + 0, MpProto, NULL); + } + if (Status != EFI_SUCCESS) { + DebugPrint (DEBUG_ERROR,"Failed to start Migration Handler\n"); + return 0; + } + + // + // If we are the target, wait for incoming migration. Otherwise, + // procede with the boot. + // + if (PcdGetBool(PcdIsConfidentialMigrationTarget)) { + DebugPrint (DEBUG_INFO,"Waiting for incoming confidential migration.\n"); + DisableInterrupts (); + CpuDeadLoop (); + } + + return 0; +} -- 2.20.1