From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by mx.groups.io with SMTP id smtpd.web12.956.1664579191692652493 for ; Fri, 30 Sep 2022 16:06:31 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=WeOSqeen; spf=pass (domain: flex--dionnaglaze.bounces.google.com, ip: 209.85.215.201, mailfrom: 3d3y3ywskbwidionnaglazegoogle.comdeveledkc.groups.io@flex--dionnaglaze.bounces.google.com) Received: by mail-pg1-f201.google.com with SMTP id i22-20020a63e456000000b0043c096be700so3572558pgk.1 for ; Fri, 30 Sep 2022 16:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date; bh=zaJ+WiH2Y8K/C1jbhBGJ1Qc+nWNyn4jpUc55xHD8Tso=; b=WeOSqeenboBHW3H6OBthXBPBwsx1LzIHfSieiQIMo14jYbu+aldCcMI6FOPlJ2owOf 7B8VZlrLWy2gaYc+yRhI1SBiLq3Cr4yUEgohpfHHk5Se8C5871B8AKAgABvbukQWI+op CpQIDS/bRccekuAf43whd+Di/JLRlhrXoSKCCsMjHLGPTg+V11MwR101wcu8aJUieiAA 5XL5rKJj48cNxrhEMG5qggbEa1BNvc5wqCYQSMf19KJzVyquAxoXHOjFpYmakKEj9qdd xQw00XhS9rmxxmXBoFls5Xn25LWctss1WUcaDKLf6h+9hd5tVr9XrUjB+BQSjFrBd2K1 RPMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date; bh=zaJ+WiH2Y8K/C1jbhBGJ1Qc+nWNyn4jpUc55xHD8Tso=; b=XRi08UusAjFvzoaqBW2VLThfTo42LcJ2ZsjOlkDfJCb9CIDw5SxSMYW09gIms94oEp LzmA8c8p2q6gSgeifjXPLmVPVzm6o5pqZMd6TnLpB+5NxX962w4+Cnnx5pqY7qJylGkg nnNwtbCV9lIDI22GUIQ8WNn+ZZ9PGFZuf6Ovu+6bAd20YgrVqeNpkIi5HEF/h2//TXfS lY7qsNx9tE4PvsceQ7NvWM6be2UHT3ku82qKGtlLuxzt1ij0/cstoMm0ynxsCCZ43fbq KzhyBAVTrsp8TvS0Tk1cfEzeh6bfoYcHmWe8qWXBSd7OvXV14AOtA0qaQprDazEHTVdb h9jw== X-Gm-Message-State: ACrzQf2sGsiGCAP9m948eC48ZHxHQmTIlpeSqdjUSOsiBfRMuB/cM4rP 7X6IYEw5QZwtPD48kZ9Yk5wEoXz+SUTy+XXEuFJtZjSIqwnNwXXiKXD37FbuM2Bk1qnVy5joZ97 QoSVUckgmOGWzhAi/FBdLeQe3dCmg2Uea8AmI6ZDOlF3HWidtbP4X13B21SJy3LlhI5uEL0oO X-Google-Smtp-Source: AMsMyM6d4S+jszaMWE9Q+9vnpil4gEoXGiEZXUdBlztfvFqmQsPIVwdWgOPEbY1DP3qXuCPwQFy7JGjd7sSsyQhjCA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:f64f:b0:179:edcc:2bf4 with SMTP id m15-20020a170902f64f00b00179edcc2bf4mr11120853plg.70.1664579191042; Fri, 30 Sep 2022 16:06:31 -0700 (PDT) Date: Fri, 30 Sep 2022 23:06:20 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930230627.3371754-1-dionnaglaze@google.com> Subject: [PATCH v5 0/7] Add safe unaccepted memory behavior From: "Dionna Glaze" To: devel@edk2.groups.io Cc: Dionna Glaze , Ard Biescheuvel , "Min M. Xu" , Gerd Hoffmann , James Bottomley , Tom Lendacky , Jiewen Yao , Erdem Aktas , Andrew Fish , "Michael D. Kinney" Content-Type: text/plain; charset="UTF-8" These seven patches build on the lazy-accept patch series "Introduce Lazy-accept for Tdx guest" by adding SEV-SNP support for the MemoryAccept protocol, and importantly making eager memory acceptance the default behavior. We add a new protocol, ExitBootServicesCallbackProtocol, with a single interface: TerminateMemoryMapPrehook(). We invoke all prehooks in CoreExitBootServices after disabling the timer and before TerminateMemoryMap. This gives hooks the chance to change the memory map and cause ExitBootServices to fail with EFI_INVALID_PARAMETER. The failure is specified to require the caller to update their view of the MemoryMap and call ExitBootServices again. To make use of this new protocol, we add a new driver that is meant to carry behavior that is needed for all confidential compute technologies, not just specific platforms, CocoDxe. In CocoDxe we implement the default safe behavior to accept all unaccepted memory and invalidate the MemoryMap on ExitBootServices. To allow the OS loader to prevent the eager acceptance, add another protocol, up for standardization, AcceptAllUnacceptedMemoryProtocol. This protocol has one interface, Disable(). The OS loader can inform the UEFI that it supports the unaccepted memory type and accepts the responsibility to accept it. All images that support unaccepted memory must now locate and call this new BZ3987_ACCEPT_ALL_UNACCEPTED_MEMORY_PROTOCOL and call the Disable function. Changes since v4: - Commit message wording - Replaced direct change to DxeMain with a more generic callback protocol. - Implemented the direct change as an instance of the callback protocol from a new CocoDxe driver. - Replaced "enable" protocol with a "disable" protocol, since the name was confusing. The AcceptAllUnacceptedMemory protocol directly names the behavior that is disabling. Changes since v3: - "DxeMain accepts all memory" patch split into 3 to make each patch affect only one package at a time. Changes since v2: - Removed the redundant memory accept interface and added the accept behavior to the DXE implementation of MemEncryptSevSnpPreValidateSystemRam. - Fixed missing #include in >=4GB patch. Changes since v1: - Added a patch to classify SEV-SNP memory above 4GB unaccepted. - Fixed style problems in EfiMemoryAcceptProtocol implementation. Cc: Ard Biescheuvel Cc: "Min M. Xu" Cc: Gerd Hoffmann Cc: James Bottomley Cc: Tom Lendacky Cc: Jiewen Yao Cc: Erdem Aktas Cc: Andrew Fish Cc: "Michael D. Kinney" Dionna Glaze (7): OvmfPkg: Realize EfiMemoryAcceptProtocol in AmdSevDxe MdePkg: Introduce ExitBootServicesCallbackProtocol MdeModulePkg: Invoke all ExitBootServicesCallback instances at ExitBootServices OvmfPkg: Introduce CocoDxe driver MdePkg: Introduce the AcceptAllUnacceptedMemory protocol OvmfPkg: Implement AcceptAllUnacceptedMemory in CocoDxe OvmfPkg/PlatformPei: SEV-SNP make >=4GB unaccepted MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 62 +++++++ MdePkg/Include/Protocol/AcceptAllUnacceptedMemory.h | 40 +++++ MdePkg/Include/Protocol/ExitBootServicesCallback.h | 38 +++++ MdePkg/MdePkg.dec | 6 + OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | 1 + OvmfPkg/AmdSevDxe/AmdSevDxe.c | 57 ++++++- OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 3 + OvmfPkg/CocoDxe/CocoDxe.c | 174 ++++++++++++++++++++ OvmfPkg/CocoDxe/CocoDxe.inf | 44 +++++ OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/IntelTdx/IntelTdxX64.fdf | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c | 24 ++- OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/PlatformPei/AmdSev.c | 5 + 19 files changed, 454 insertions(+), 8 deletions(-) create mode 100644 MdePkg/Include/Protocol/AcceptAllUnacceptedMemory.h create mode 100644 MdePkg/Include/Protocol/ExitBootServicesCallback.h create mode 100644 OvmfPkg/CocoDxe/CocoDxe.c create mode 100644 OvmfPkg/CocoDxe/CocoDxe.inf -- 2.38.0.rc1.362.ged0d419d3c-goog