From mboxrd@z Thu Jan 1 00:00:00 1970 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.432.1665002018990310210 for ; Wed, 05 Oct 2022 13:33:39 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=YRFs4cVB; spf=pass (domain: flex--dionnaglaze.bounces.google.com, ip: 209.85.215.202, mailfrom: 3ieo9ywskbq4rw211ouzodsu22uzs.q20rs9szsryg.u52836.w2@flex--dionnaglaze.bounces.google.com) Received: by mail-pg1-f202.google.com with SMTP id a33-20020a630b61000000b00429d91cc649so10989165pgl.8 for ; Wed, 05 Oct 2022 13:33:38 -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=mnGuc8ayKN/lYpCp7tJJL6kXmu2zQkrovvPz06Nb0jE=; b=YRFs4cVBLh+o1Yng/H96pgo+r2yQHI2Rn8anD60UhTJU2qRViR1j5F3FqpuomF1EHt 0jqssLlYsnXE3A95ROZw4bka0Bla5Nt2WlOFkVG4pcX1dId+rtIWNA8dJy/7SIisa3AH EXStkzAOvlEO8nC45T0P5OLVl1mhHrUBEtk5diuWUtdOvLnpxowIAikzSNJ+KkcinOLG qztRDqfG67SSWjGrGgmBhAAY1ata2pNPLeitZG0FVF8sg0Ulc6CL5/GeoFMrmjb/PiGu GRNrcV2/UGCkdYolcVW0mFgKGF5YqVFwC8RuZzxKIMhq5r/hOqz7tB3s43zv66kn8NzX 1Tjw== 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=mnGuc8ayKN/lYpCp7tJJL6kXmu2zQkrovvPz06Nb0jE=; b=XA+lBpwJUQIblYJlVtTx7BTXwE7YlcIVSec+TAleXfx8ILKvuBXv/AkKzYy0w1X4EQ 0SVZhd7IsNNRaPKZBqItez0uqhteqBQ8nzq7UFe3IhBAkNyXhx3B6AQVX/NlSp5aXMmO H0aTrY/cz1B+i9sEd2hz4JJEZN5JXBaFrjTMZzMpaSIyKjWVs5d0CD2ETIHRy1NXBA9k 5S0FRwvloce769W+wCNTrrdgeJjplGVk/FSXOVUIONGSEduTX88f0lkn4lLp1RdjCI9l pdo+x+3f/flmHYptwTrkSsrUQyz8DEi9/Uk+EuBGPwdIcb5Hr3hj9B5inwmdrAVlzP8u SkgQ== X-Gm-Message-State: ACrzQf20yfjcjn0ajIBFQbRQ53FYoCOFQ5XCuFPfaSV2R7xgjgfdmW2M 9rKudHdVhaRUBwvIUn74hxaNhRUCN9ou2vYWNooPKxc8jlLuOlLjTSDxDxIrtfs/Mtp7G1Rt074 M7h3REWZplH/BL9ZBVE9+3Yelu2RI2AgdjIeNJ9ObG02MMoVt7gTIz1MvtWljFRLgtmS2bhMf X-Google-Smtp-Source: AMsMyM4OPaHDkCiHzXPy51xAdAzYS2vLJcu7Mj1jxBv4cKE2CAnxuGKQ54Ymsotz8X5qWEUuNAbUE3ofm2QtJkUqHQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:cd06:b0:203:ae0e:6a21 with SMTP id d6-20020a17090acd0600b00203ae0e6a21mr99669pju.0.1665002017651; Wed, 05 Oct 2022 13:33:37 -0700 (PDT) Date: Wed, 5 Oct 2022 20:33:22 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221005203329.469866-1-dionnaglaze@google.com> Subject: [PATCH v7 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 implement a standardized event group from UEFI v2.9, EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES, since it provides exactly the right invocation point for eagerly accepting memory if eager acceptance has not been disabled. To make use of this event group, 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, we add a new 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 v6: - Added implementation of EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES. - Changed callback protocol of v5 to instead use the standardized event group for before_exit_boot_services. Changes since v5: - Generic callback protocol moved to MdeModulePkg - Removed use of EFI_WARN_STALE_DATA and added comment that the callback should only return EFI_SUCCESS or EFI_INVALID_PARAMETER. - Removed errant log statement and fixed formatting. 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" Signed-off-by: Dionna Glaze Dionna Glaze (7): OvmfPkg: Realize EfiMemoryAcceptProtocol in AmdSevDxe MdePkg: Add EFI_EVENT_BEFORE_EXIT_BOOT_SERVICES_GUID MdeModulePkg: Notify BeforeExitBootServices in CoreExitBootServices 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 | 6 + MdePkg/Include/Guid/EventGroup.h | 5 + MdePkg/Include/Protocol/Bz3987AcceptAllUnacceptedMemory.h | 40 +++++ MdePkg/MdePkg.dec | 8 +- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | 1 + OvmfPkg/AmdSevDxe/AmdSevDxe.c | 55 ++++++- OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 3 + OvmfPkg/CocoDxe/CocoDxe.c | 165 ++++++++++++++++++++ OvmfPkg/CocoDxe/CocoDxe.inf | 46 ++++++ 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, 357 insertions(+), 9 deletions(-) create mode 100644 MdePkg/Include/Protocol/Bz3987AcceptAllUnacceptedMemory.h create mode 100644 OvmfPkg/CocoDxe/CocoDxe.c create mode 100644 OvmfPkg/CocoDxe/CocoDxe.inf -- 2.38.0.rc1.362.ged0d419d3c-goog