From nobody Thu Nov 14 07:10:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98403+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98403+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673568887; cv=none; d=zohomail.com; s=zohoarc; b=XTPLZ2PGVMgZXMzVCZwVrRi0SJd59NDHaNiiNjCFmSWNi/orK4sIreuVaJMsPLnztJP3ol48g8oe26b1kNunNXXfCUrgjt40gnQFwsCasAF83vkzJuJifuq3H7XOmLrbLZmylcaKE2MZDtFe2/pOzRhyzWpBxbz12kwIF98QvyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673568887; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+LEuHDkDLRBauv+RbgW9ab+FcREQAoH1VYAayG3lqas=; b=a3thqMWsqH52WnBgKdIzi0Wa38w46lcTIV7+UGEiKfPM3qsVyFsDdJtspVSFo/P9FpaWrE5Ot662dSaF5YpIJ3UZHXaYPEsMD4+gXBija+Rgg1M138dPnrnmHEIgY7VRXkZ1h+iw6DEH9ptnYWkPzWEUiwuC0QwjhPhG/zA9+R4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98403+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673568887122363.63290568350646; Thu, 12 Jan 2023 16:14:47 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id zHsOYY1788612xCJNYL0D02X; Thu, 12 Jan 2023 16:14:46 -0800 X-Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by mx.groups.io with SMTP id smtpd.web11.73499.1673568886321517598 for ; Thu, 12 Jan 2023 16:14:46 -0800 X-Received: by mail-pg1-f202.google.com with SMTP id e11-20020a63d94b000000b0048988ed9a6cso8878378pgj.1 for ; Thu, 12 Jan 2023 16:14:46 -0800 (PST) X-Gm-Message-State: 0A9PCIGM2AEca5puEzMjfBaZx1787277AA= X-Google-Smtp-Source: AMrXdXsX8CTZYZFYai2UdQfx6Gn2qk7cUi1WddIc0/oKWX2Z8BvzcPMF1ozhhK8UfJJ9PmwrnTqct+Uddc+s03P04Q== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:aa7:8051:0:b0:582:e939:183d with SMTP id y17-20020aa78051000000b00582e939183dmr3391582pfm.63.1673568885394; Thu, 12 Jan 2023 16:14:45 -0800 (PST) Date: Fri, 13 Jan 2023 00:14:16 +0000 In-Reply-To: <20230113001419.2519031-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230113001419.2519031-1-dionnaglaze@google.com> Message-ID: <20230113001419.2519031-2-dionnaglaze@google.com> Subject: [edk2-devel] [PATCH v9 1/4] OvmfPkg: Introduce CocoDxe driver From: "Dionna Glaze via groups.io" To: devel@edk2.groups.io Cc: Dionna Glaze , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Ard Biesheuvel , "Min M. Xu" , Andrew Fish , "Michael D. Kinney" Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dionnaglaze@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673568886; bh=47Zzd8m8FO0xwvj8hpbTkpxpI9PJfR/6O27AgNcy22M=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=d19NGZPVKjxoeVid6Q58RQTTThawU189wXcLMbbnrEt2zHoawijGy+Rkab0VKHu60n1 lfEPSLl8P3PQ6Hcx3LTVgVe66QUh8prG909ZN0a/JvlQD/xV2nXoEuskO3jkRsC182Bii rKOyoikT+dj781WSsVpB38DEeg1aLXEhuHI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673568887520100004 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This driver is meant as a join point for all Confidential Compute technologies to put shared behavior that doesn't belong anywhere else. The first behavior added here is to accept all unaccepted memory at ExitBootServices if the behavior is not disabled. This allows safe upgrades for OS loaders to affirm their support for the unaccepted memory type. Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Ard Biesheuvel Cc: "Min M. Xu" Cc: Andrew Fish Cc: "Michael D. Kinney" Signed-off-by: Dionna Glaze --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | 1 + OvmfPkg/CocoDxe/CocoDxe.c | 147 +++++++++++++++++++++++++++++++ OvmfPkg/CocoDxe/CocoDxe.inf | 45 ++++++++++ OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/IntelTdx/IntelTdxX64.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + 10 files changed, 200 insertions(+) create mode 100644 OvmfPkg/CocoDxe/CocoDxe.c create mode 100644 OvmfPkg/CocoDxe/CocoDxe.inf diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 36100f5fdc..5e5e9887bb 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -749,6 +749,7 @@ PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf } + OvmfPkg/CocoDxe/CocoDxe.inf OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 # diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf index 5fb3b5d276..ae64693c28 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.fdf +++ b/OvmfPkg/AmdSev/AmdSevX64.fdf @@ -302,6 +302,7 @@ INF OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf +INF OvmfPkg/CocoDxe/CocoDxe.inf INF OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 =20 diff --git a/OvmfPkg/CocoDxe/CocoDxe.c b/OvmfPkg/CocoDxe/CocoDxe.c new file mode 100644 index 0000000000..da16af32a3 --- /dev/null +++ b/OvmfPkg/CocoDxe/CocoDxe.c @@ -0,0 +1,147 @@ +/** @file + + Confidential Compute Dxe driver. This driver installs protocols that are + generic over confidential compute techonology. + + Copyright (c) 2022, Google LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC BOOLEAN mAcceptAllMemoryAtEBS =3D TRUE; + +STATIC EFI_EVENT mAcceptAllMemoryEvent =3D NULL; + +STATIC +EFI_STATUS +AcceptAllMemory ( + IN EDKII_MEMORY_ACCEPT_PROTOCOL *AcceptMemory + ) +{ + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *AllDescMap; + UINTN NumEntries; + UINTN Index; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "Accepting all memory\n")); + + /* + * Get a copy of the memory space map to iterate over while + * changing the map. + */ + Status =3D gDS->GetMemorySpaceMap (&NumEntries, &AllDescMap); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < NumEntries; Index++) { + CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc; + + Desc =3D &AllDescMap[Index]; + if (Desc->GcdMemoryType !=3D EFI_GCD_MEMORY_TYPE_UNACCEPTED) { + continue; + } + + Status =3D AcceptMemory->AcceptMemory ( + AcceptMemory, + Desc->BaseAddress, + Desc->Length + ); + if (EFI_ERROR (Status)) { + break; + } + + Status =3D gDS->RemoveMemorySpace (Desc->BaseAddress, Desc->Length); + if (EFI_ERROR (Status)) { + break; + } + + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeSystemMemory, + Desc->BaseAddress, + Desc->Length, + EFI_MEMORY_CPU_CRYPTO | EFI_MEMORY_XP | EFI_MEMORY_RO = | EFI_MEMORY_RP + ); + if (EFI_ERROR (Status)) { + break; + } + } + + gBS->FreePool (AllDescMap); + return Status; +} + +VOID +EFIAPI +ResolveUnacceptedMemory ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EDKII_MEMORY_ACCEPT_PROTOCOL *AcceptMemory; + EFI_STATUS Status; + + if (!mAcceptAllMemoryAtEBS) { + return; + } + + Status =3D gBS->LocateProtocol ( + &gEdkiiMemoryAcceptProtocolGuid, + NULL, + (VOID **)&AcceptMemory + ); + if (Status =3D=3D EFI_NOT_FOUND) { + return; + } + + ASSERT_EFI_ERROR (Status); + + Status =3D AcceptAllMemory (AcceptMemory); + ASSERT_EFI_ERROR (Status); +} + +EFI_STATUS +EFIAPI +CocoDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Do nothing when confidential compute technologies that require memory + // acceptance are not enabled. + // + if (!MemEncryptSevSnpIsEnabled () && + !MemEncryptTdxIsEnabled ()) + { + return EFI_UNSUPPORTED; + } + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + ResolveUnacceptedMemory, + NULL, + &gEfiEventBeforeExitBootServicesGuid, + &mAcceptAllMemoryEvent + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "AllowUnacceptedMemory event creation for EventBe= foreExitBootServices failed.\n")); + } + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/CocoDxe/CocoDxe.inf b/OvmfPkg/CocoDxe/CocoDxe.inf new file mode 100644 index 0000000000..8d4452e94d --- /dev/null +++ b/OvmfPkg/CocoDxe/CocoDxe.inf @@ -0,0 +1,45 @@ +#/** @file +# +# Driver installs shared protocols needed for confidential compute +# technologies. +# +# Copyright (c) 2022, Google LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D CocoDxe + FILE_GUID =3D 08162f1e-5147-4d3e-b5a9-fa48c9808419 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D CocoDxeEntryPoint + +[Sources] + CocoDxe.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + MemEncryptSevLib + MemEncryptTdxLib + MemoryAllocationLib + UefiDriverEntryPoint + +[Depex] + TRUE + +[Guids] + gEfiEventBeforeExitBootServicesGuid + +[Protocols] + gEdkiiMemoryAcceptProtocolGuid diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 81511e3556..c3e64d97c0 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -754,6 +754,7 @@ OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 OvmfPkg/TdxDxe/TdxDxe.inf + OvmfPkg/CocoDxe/CocoDxe.inf =20 # # Variable driver stack (non-SMM) diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.fdf b/OvmfPkg/IntelTdx/IntelTdxX6= 4.fdf index a57bbcee89..f5765b50eb 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.fdf +++ b/OvmfPkg/IntelTdx/IntelTdxX64.fdf @@ -269,6 +269,7 @@ INF ShellPkg/Application/Shell/Shell.inf INF MdeModulePkg/Logo/LogoDxe.inf =20 INF OvmfPkg/TdxDxe/TdxDxe.inf +INF OvmfPkg/CocoDxe/CocoDxe.inf =20 # # Usb Support diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index a9d422bd91..8e4d31bcea 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -966,6 +966,7 @@ PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf } + OvmfPkg/CocoDxe/CocoDxe.inf OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 4c5bd0dbc3..7d75140fe3 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -343,6 +343,7 @@ INF OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf +INF OvmfPkg/CocoDxe/CocoDxe.inf INF OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 8401d73900..a728610c86 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -1037,6 +1037,7 @@ OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 OvmfPkg/TdxDxe/TdxDxe.inf + OvmfPkg/CocoDxe/CocoDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE OvmfPkg/SmmAccess/SmmAccess2Dxe.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 8c02dfe11e..9e0aee225c 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -370,6 +370,7 @@ INF OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf +INF OvmfPkg/CocoDxe/CocoDxe.inf INF OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE --=20 2.39.0.314.g84b9a713c41-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98403): https://edk2.groups.io/g/devel/message/98403 Mute This Topic: https://groups.io/mt/96236147/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Nov 14 07:10:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98404+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98404+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673568888; cv=none; d=zohomail.com; s=zohoarc; b=SasmrxaIyVKUhsu+itsw870eQ0lNx4hK0IvzemTfJj4RnPZshHlNVBxB6prKuyBXlJLX99x8lKXpXgPrTBVKcXH5AH6Wh87bGCbYzMX56w1fbbqnPVJQJSGvNc1sMb5c/JUzbKIu1ha6Z1WzJ08QKUg8zvhBd0R1Y+dJfKnKrZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673568888; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6Khkr5DYtrI1PVxNtD/cu99wyK7IsjONosOisuA5/gU=; b=UqbEdrz9BdiwXYckunHoyuwbNORSWOPWicQFsBZgfo18WMFmeAntkXPBu3v41DNMxFNI71Etk8nPXYh5dcQag7/8JjEEk9PoO9MgHSTDBB9NMclKE1l/tuK7vh8HonSBs0L0sdTHV8DxNhZViQGj2aCGdXFo0W3ScuVJEZQ4a2g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98404+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673568888799171.47419015700984; Thu, 12 Jan 2023 16:14:48 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SMI9YY1788612xPSPaZyMR7L; Thu, 12 Jan 2023 16:14:48 -0800 X-Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by mx.groups.io with SMTP id smtpd.web10.73512.1673568887825865822 for ; Thu, 12 Jan 2023 16:14:47 -0800 X-Received: by mail-yb1-f201.google.com with SMTP id n203-20020a2572d4000000b0078f09db9888so21056968ybc.18 for ; Thu, 12 Jan 2023 16:14:47 -0800 (PST) X-Gm-Message-State: SSTDMZn5QJVsLMft7UBMdGdCx1787277AA= X-Google-Smtp-Source: AMrXdXsZux/wW9iKD0rDS1Scj73klVryYIAcUUDzmyZ5T27pePthrVrUZul7zIkySUUdNVeleqt7J6rp64aVAYy5AQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a05:6902:11c6:b0:6fe:3d7f:d04a with SMTP id n6-20020a05690211c600b006fe3d7fd04amr8202121ybu.617.1673568887042; Thu, 12 Jan 2023 16:14:47 -0800 (PST) Date: Fri, 13 Jan 2023 00:14:17 +0000 In-Reply-To: <20230113001419.2519031-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230113001419.2519031-1-dionnaglaze@google.com> Message-ID: <20230113001419.2519031-3-dionnaglaze@google.com> Subject: [edk2-devel] [PATCH v9 2/4] MdePkg: Introduce the MemoryAcceptance protocol From: "Dionna Glaze via groups.io" To: devel@edk2.groups.io Cc: Dionna Glaze , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Ard Biesheuvel , "Min M. Xu" , Andrew Fish , "Michael D. Kinney" Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dionnaglaze@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673568888; bh=FbpGv5heP5jmfhoFRBLy3kXY4DaoOdewpfJ+e0GiCes=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=G3vr3i64Lau+XMkz/ZBUNyt+j8bk1jE4PwXU7/4nAxly0GLvxU9C6usIbFlxoRTJ6P6 5rS46RFBfRccj5qy27tJTPJqwtVgB5OXMVCeRYDeANqiMBiPKQR16OsyBqBTGXVwaH4KY 1zt0o9CHqVqBEtxreBw0U2U7pSNAIEpG8Mw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673568889799100011 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The default behavior for unaccepted memory is to accept all memory when ExitBootServices is called. An OS loader can use this protocol to disable this behavior to assume responsibility for memory acceptance and to affirm that the OS can handle the unaccepted memory type. This is a candidate for standardization. Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Ard Biesheuvel Cc: "Min M. Xu" Cc: Andrew Fish Cc: "Michael D. Kinney" Signed-off-by: Dionna Glaze --- MdePkg/Include/Protocol/MemoryAcceptance.h | 40 ++++++++++++++++++++++ MdePkg/MdePkg.dec | 3 ++ 2 files changed, 43 insertions(+) create mode 100644 MdePkg/Include/Protocol/MemoryAcceptance.h diff --git a/MdePkg/Include/Protocol/MemoryAcceptance.h b/MdePkg/Include/Pr= otocol/MemoryAcceptance.h new file mode 100644 index 0000000000..0b305b016f --- /dev/null +++ b/MdePkg/Include/Protocol/MemoryAcceptance.h @@ -0,0 +1,40 @@ +/** @file + The file provides the protocol that disables the behavior that all memory + gets accepted at ExitBootServices(). This protocol is only meant to be c= alled + by the OS loader, and not EDK2 itself. + + Copyright (c) 2022, Google LLC. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MEMORY_ACCEPTANCE_H_ +#define MEMORY_ACCEPTANCE_H_ + +#define BZ3987_MEMORY_ACCEPTANCE_PROTOCOL_GUID \ + {0xc5a010fe, \ + 0x38a7, \ + 0x4531, \ + {0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49}} + +typedef struct _BZ3987_MEMORY_ACCEPTANCE_PROTOCOL BZ3987_MEMORY_ACCEPTANCE= _PROTOCOL; + +/** + @param This A pointer to a BZ3987_MEMORY_ACCEPTANCE_PROTOCOL. +**/ +typedef + EFI_STATUS +(EFIAPI *BZ3987_ALLOW_UNACCEPTED_MEMORY)( + IN BZ3987_MEMORY_ACCEPTANCE_PROTOCOL *This + ); + +/// +/// The BZ3987_MEMORY_ACCEPTANCE_PROTOCOL allows the OS loader to +/// indicate to EDK2 that ExitBootServices should not accept all memory. +/// +struct _BZ3987_MEMORY_ACCEPTANCE_PROTOCOL { + BZ3987_ALLOW_UNACCEPTED_MEMORY AllowUnacceptedMemory; +}; + +extern EFI_GUID gBz3987MemoryAcceptanceProtocolGuid; + +#endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 3d08f20d15..bc3d897248 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -1031,6 +1031,9 @@ gEfiPeiDelayedDispatchPpiGuid =3D { 0x869c711d, 0x649c, 0x44fe, { 0x8b,= 0x9e, 0x2c, 0xbb, 0x29, 0x11, 0xc3, 0xe6 }} =20 [Protocols] + ## Include/Protocol/Bz3987MemoryAcceptance.h + gBz3987MemoryAcceptanceProtocolGuid =3D { 0xc5a010fe, 0x38a7, 0x4531, {0= x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49 }} + ## Include/Protocol/MemoryAccept.h gEdkiiMemoryAcceptProtocolGuid =3D { 0x38c74800, 0x5590, 0x4db4, { 0xa0,= 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 }} =20 --=20 2.39.0.314.g84b9a713c41-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98404): https://edk2.groups.io/g/devel/message/98404 Mute This Topic: https://groups.io/mt/96236150/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Nov 14 07:10:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98405+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98405+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673568890; cv=none; d=zohomail.com; s=zohoarc; b=eDUyF35a7PB0WkyWTEjXcDHX71vv3DChoAvEJ939gp2q7YDpUMzfsCsnA2KtfBtHQ1ecMvFJWVBJ2wDaIQ8VKbCtdMflSFVbkBYRaIWkX1Q6h5eysbgz9e3NcNkchNrygIZ7t3hoZ0ZPfaRptyv/TJ9GmMGR2Ro+9HFbZYpu/kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673568890; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MkvOCXgc5D+V2QF0HzZoNUatyd4WDEpB/HIKNe3UXJ8=; b=aOR3rYtqyBtNSbE0eX+5e0m6bc9HSYo6MkZlFMgEIySt0DVKSxN290BH+IlCLVsgw5WyyndvcaH6ma70xW0VZzJHS/ce5eERljr3UZrJT60hJztmHWhNx4OrOie9xdbFmLH/DKbsLFk7hDNO7M0QAAT7JohPjU+W65UZYJf254E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98405+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 167356889058248.640599574064936; Thu, 12 Jan 2023 16:14:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id a5T0YY1788612xlnWNfCfchq; Thu, 12 Jan 2023 16:14:50 -0800 X-Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by mx.groups.io with SMTP id smtpd.web11.73501.1673568889664138301 for ; Thu, 12 Jan 2023 16:14:49 -0800 X-Received: by mail-pl1-f201.google.com with SMTP id u13-20020a170902e5cd00b001946b7ded08so531219plf.12 for ; Thu, 12 Jan 2023 16:14:49 -0800 (PST) X-Gm-Message-State: SWjU1CcNOZE1u62pWHNy4FENx1787277AA= X-Google-Smtp-Source: AMrXdXsjKCGM90hybDGLXtJwWK8J3OtbD1rQA/4OdaxJHKlXrMew1V9wtzwTRwum6uMLa16b++btDYWd8JvM9YHpTw== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:7401:b0:194:52ed:7a29 with SMTP id g1-20020a170902740100b0019452ed7a29mr614996pll.66.1673568888764; Thu, 12 Jan 2023 16:14:48 -0800 (PST) Date: Fri, 13 Jan 2023 00:14:18 +0000 In-Reply-To: <20230113001419.2519031-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230113001419.2519031-1-dionnaglaze@google.com> Message-ID: <20230113001419.2519031-4-dionnaglaze@google.com> Subject: [edk2-devel] [PATCH v9 3/4] OvmfPkg: Implement AcceptAllUnacceptedMemory in CocoDxe From: "Dionna Glaze via groups.io" To: devel@edk2.groups.io Cc: Dionna Glaze , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Ard Biesheuvel , "Min M. Xu" , Andrew Fish , "Michael D. Kinney" Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dionnaglaze@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673568890; bh=mKVyuEfgejgzTgk+wtDtvf+JaaY33dPHwQLTixDvyjw=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=dFBU0P2yUjIa2M2CI8As7K06VYwvDZ8qHbnk80aSddPC4IBp0hVCs4guuZfyBWFVDSI vQt3B/hXis+bEE1E+aXrS5EyMwUk0RznMrZg4OupVXac0dC0dBgeWtU4tHaCvEu8LSTmv /ebEL8Im1wD2EkT4ZoMAw7YX6oO1z27ijmA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673568891496100014 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This protocol implementation disables the accept-all-memory behavior of the BeforeExitBootServices event this driver adds. Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Ard Biesheuvel Cc: "Min M. Xu" Cc: Andrew Fish Cc: "Michael D. Kinney" Signed-off-by: Dionna Glaze --- OvmfPkg/CocoDxe/CocoDxe.c | 28 ++++++++++++++++++++++++++++ OvmfPkg/CocoDxe/CocoDxe.inf | 1 + 2 files changed, 29 insertions(+) diff --git a/OvmfPkg/CocoDxe/CocoDxe.c b/OvmfPkg/CocoDxe/CocoDxe.c index da16af32a3..57169b0481 100644 --- a/OvmfPkg/CocoDxe/CocoDxe.c +++ b/OvmfPkg/CocoDxe/CocoDxe.c @@ -18,11 +18,14 @@ #include #include #include +#include =20 STATIC BOOLEAN mAcceptAllMemoryAtEBS =3D TRUE; =20 STATIC EFI_EVENT mAcceptAllMemoryEvent =3D NULL; =20 +STATIC EFI_HANDLE mCocoDxeHandle =3D NULL; + STATIC EFI_STATUS AcceptAllMemory ( @@ -111,6 +114,21 @@ ResolveUnacceptedMemory ( ASSERT_EFI_ERROR (Status); } =20 +STATIC +EFI_STATUS +EFIAPI +AllowUnacceptedMemory ( + IN BZ3987_MEMORY_ACCEPTANCE_PROTOCOL *This + ) +{ + mAcceptAllMemoryAtEBS =3D FALSE; + return EFI_SUCCESS; +} + +STATIC +BZ3987_MEMORY_ACCEPTANCE_PROTOCOL + mMemoryAcceptanceProtocol =3D { AllowUnacceptedMemory }; + EFI_STATUS EFIAPI CocoDxeEntryPoint ( @@ -143,5 +161,15 @@ CocoDxeEntryPoint ( DEBUG ((DEBUG_ERROR, "AllowUnacceptedMemory event creation for EventBe= foreExitBootServices failed.\n")); } =20 + Status =3D gBS->InstallProtocolInterface ( + &mCocoDxeHandle, + &gBz3987MemoryAcceptanceProtocolGuid, + EFI_NATIVE_INTERFACE, + &mMemoryAcceptanceProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Install Bz3987MemoryAcceptanceProtocol failed.\n= ")); + } + return EFI_SUCCESS; } diff --git a/OvmfPkg/CocoDxe/CocoDxe.inf b/OvmfPkg/CocoDxe/CocoDxe.inf index 8d4452e94d..05c2651a89 100644 --- a/OvmfPkg/CocoDxe/CocoDxe.inf +++ b/OvmfPkg/CocoDxe/CocoDxe.inf @@ -42,4 +42,5 @@ gEfiEventBeforeExitBootServicesGuid =20 [Protocols] + gBz3987MemoryAcceptanceProtocolGuid gEdkiiMemoryAcceptProtocolGuid --=20 2.39.0.314.g84b9a713c41-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98405): https://edk2.groups.io/g/devel/message/98405 Mute This Topic: https://groups.io/mt/96236151/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Nov 14 07:10:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98406+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98406+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673568892; cv=none; d=zohomail.com; s=zohoarc; b=XmO1e09gLEopjwBdrFWE2Adeu9pgCDI2zV6HwUQu6n6x9o4bFEgde3ockmVA7DeRgolO1JHyf7oUtf2AhHo7F9KUfByp2ZNVv09yUkhOw/tLlMphSa+YTB30kCHb6FL+WlrB0JjKRiCcaKUuLHmF5n2rU2hGfvTHssYdf+JU7AY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673568892; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TzG5VuX92a7OqtN+df+wMyHiDljyizF3kzi8iA9aUvA=; b=NlBC9TVGOc5ukDvzzH5lwYhMcWYB2vy9zrpR1aVWZg3GfY23STVZB0OyNm/p+owbd8pbtaor6Ei/fBlOh87JwSG4WkKV7UMSVEWOyJUyOLCtewnJ63TuJb2ibtj0ePa8V8WMUapI03vD+Gb/p3R1qI4wg2KdzgWowqiBPbOvFpc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98406+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673568892213620.3526320704563; Thu, 12 Jan 2023 16:14:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7ogSYY1788612xWhKCmmIwCF; Thu, 12 Jan 2023 16:14:51 -0800 X-Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by mx.groups.io with SMTP id smtpd.web11.73502.1673568891161659521 for ; Thu, 12 Jan 2023 16:14:51 -0800 X-Received: by mail-pj1-f73.google.com with SMTP id h1-20020a17090a470100b0022646263abfso9037958pjg.6 for ; Thu, 12 Jan 2023 16:14:51 -0800 (PST) X-Gm-Message-State: jdwYVd6nM9dUAamsNqKUJWh9x1787277AA= X-Google-Smtp-Source: AMrXdXvZ/8r1h0+JzA31pstDLmeVwSI9YakjiVMiVj5eKgzkmZjVBBbukXqKkzkAjo4+hLJnIYg0N6tL21sDQI8QJg== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a05:6a00:1244:b0:56b:8181:fe3e with SMTP id u4-20020a056a00124400b0056b8181fe3emr5309022pfi.57.1673568890528; Thu, 12 Jan 2023 16:14:50 -0800 (PST) Date: Fri, 13 Jan 2023 00:14:19 +0000 In-Reply-To: <20230113001419.2519031-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230113001419.2519031-1-dionnaglaze@google.com> Message-ID: <20230113001419.2519031-5-dionnaglaze@google.com> Subject: [edk2-devel] [PATCH v9 4/4] OvmfPkg/PlatformPei: SEV-SNP make >=4GB unaccepted From: "Dionna Glaze via groups.io" To: devel@edk2.groups.io Cc: Dionna Glaze , Ard Biescheuvel , "Min M. Xu" , Gerd Hoffmann , James Bottomley , Tom Lendacky , Jiewen Yao , Erdem Aktas Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dionnaglaze@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673568891; bh=IM+nfntfWGiNkjZm4yEcpQc70my5yKzAHDjneEhtLdc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=B7zBu4SrNRzGgeRzhIQfIv2r8Pk3kBUrb8+fLWrTZErhNN9MYWl8aw0nYscfGlZDaMB ld29kdTVKc60+0WAiansKM4OnKkKsTUkAClIkVFnTBMqeeXKY1Y0pIOZVt3s+47ZMdGfC wovbiBPH8AFNpDRsm5r9ayqMTv2v1dWX6OY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673568893507100017 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of eagerly accepting all memory in PEI, only accept memory under the 4GB address. This allows a loaded image to use the MEMORY_ACCEPTANCE_PROTOCOL to disable the accept behavior and indicate that it can interpret the memory type accordingly. This classification is safe since ExitBootServices will accept and reclassify the memory as conventional if the disable protocol is not used. Cc: Ard Biescheuvel Cc: "Min M. Xu" Cc: Gerd Hoffmann Cc: James Bottomley Cc: Tom Lendacky Cc: Jiewen Yao Cc: Erdem Aktas Signed-off-by: Dionna Glaze --- OvmfPkg/PlatformPei/AmdSev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index e4e7b72e67..7d824cc282 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,10 @@ AmdSevSnpInitialize ( for (Hob.Raw =3D GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw =3D GET_= NEXT_HOB (Hob)) { if ((Hob.Raw !=3D NULL) && (GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_RES= OURCE_DESCRIPTOR)) { ResourceHob =3D Hob.ResourceDescriptor; + if (ResourceHob->PhysicalStart >=3D SIZE_4GB) { + ResourceHob->ResourceType =3D BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTE= D; + continue; + } =20 if (ResourceHob->ResourceType =3D=3D EFI_RESOURCE_SYSTEM_MEMORY) { MemEncryptSevSnpPreValidateSystemRam ( --=20 2.39.0.314.g84b9a713c41-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98406): https://edk2.groups.io/g/devel/message/98406 Mute This Topic: https://groups.io/mt/96236152/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-