From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by mx.groups.io with SMTP id smtpd.web11.86793.1674767866615366150 for ; Thu, 26 Jan 2023 13:17:46 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=JuyHixfp; spf=pass (domain: flex--dionnaglaze.bounces.google.com, ip: 209.85.210.201, mailfrom: 3-e3sywskbuylqwvvioti7mowwotm.kwulm3mtmlsa.ozw2x0.qw@flex--dionnaglaze.bounces.google.com) Received: by mail-pf1-f201.google.com with SMTP id l7-20020a62be07000000b0058de3976793so1452955pff.18 for ; Thu, 26 Jan 2023 13:17:46 -0800 (PST) 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:message-id:reply-to; bh=pqQdjPEFdwnl8uizBAdWB+VYTqzx6xQyydlZA9uWBPk=; b=JuyHixfpACd+9LZkOTRijMpAu0FGUe/y3hrZvUFzF59zgFvpwfyqzpBUNV9hfJ4ZF+ t8aUCAxbC/tWkv6QQYOcoI1iZ4rA3AB85YlLU1/nEBVdvvWubC8IR2XjV9UYlPBxF24D rM5mc3L8D1kYfnVkrWKH6jv9N4TQWWAIcQCueA1hCYzv5dCysPvcYHge9ZBS+MEMymHD /sXdtZZy+nsNpJxcwlR9pSU/ReF52o0NLugmKgmSZZoXOH1PXJYCKzIsYsuT8ajLG7Rl mxiH6FMA2Iy34Qh0+5ztzqfKj77BnXQbSvqRWhRGSGb0cNiIVOJR2Xg14b7rkcvTIPIv Vcrg== 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:message-id:reply-to; bh=pqQdjPEFdwnl8uizBAdWB+VYTqzx6xQyydlZA9uWBPk=; b=xMqI17LYUNEExkv3hI//jYjvQoeREWeL468sTqU5WeiKdat68NWC/bhJ/u0AMyqmKI jtEZYTRwJsw1fVa80dmpv7Ia0dHd4zw/sGLmgVsnIudzudX8fHfASB7ohdFEVM9DhLos 8/rZ8gmI8DpF9KM1VKYD5RYCEjC/v3zVW1MCzc436Rb+6TPNv8l/X1e2E1lhXGjFDtZY ngv6TtHr/iin+qoPwtDO2vXgnhjaGwjYlaEpNLAi3bXztDWYJJltZJiXQMvpeVZJkB3Y D7vXgRut2tcEIQ/nWMoQ+QbZPVHtxji6iBOTye/ufKxsCN4qAKjiDOGvQfoqmkZgkaUT vuxg== X-Gm-Message-State: AO0yUKWWm9KbNc6bAI9NfnlhRcigy+1so1MCUGBskY/PaybC1LKskpW1 t4Z9bWstUC+4pq/ed9DmaUmSo8pqDNxnpkGUZx2Mmwtti73dA3WZ639g3mYPP8/P05QrC/zMbl+ YQySdyCDf8wC84QGryNY18oSE4TN22ZL1s3GydsiGT0yVkrAn9kFlnUXvTgOh0HVMJ0JdOOV+ X-Google-Smtp-Source: AK7set9ZVscUe8N3PHiZIjl6PIBgpqr7rZoBUSX5IyYIsufHnx9rl7Evvp6qlILsFcjV3K9s+lI2tjTQZclyYmqVMA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:5995:b0:22c:158d:88be with SMTP id l21-20020a17090a599500b0022c158d88bemr959931pji.90.1674767865779; Thu, 26 Jan 2023 13:17:45 -0800 (PST) Date: Thu, 26 Jan 2023 21:17:36 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230126211740.3235408-1-dionnaglaze@google.com> Subject: [PATCH v11 0/4] 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" We make eager memory acceptance the default behavior at ExitBootServices for SEV-SNP machines by using the standard-enforced behavior that if the call returns an error code, then the map key is incorrect and the caller must re-call GetMemoryMap to ensure the contents are correct. Eager memory acceptance is implemented by using the UEFI v2.9-added EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES to check a support condition before changing all unaccepted memory type regions to conventional memory after first using the MemoryAccept protocol to accept all memory in each region. This update to the memory map only happens once, since there are no extra unaccepted memory regions to change on the forced second call to ExitBootServices. The new acceptance logic is required only for SEV-SNP since it is the only memory-accepting virtualization technology with kernel support live without unaccepted memory support. To allow the OS loader to prevent the eager acceptance, and thus pass the before-mentioned "support condition", we add a new protocol, OvmfSevMemoryAcceptance. This protocol has one interface, AllowUnacceptedMemory(). The OS loader can inform the UEFI that it supports the unaccepted memory type and accepts the responsibility to accept it. The OvmfSevMemoryAcceptance protocol is necessary for safe rollout of the unaccepted memory type in SEV-SNP-enabled kernels, given the gradual update of guest OS kernels. All images that support unaccepted memory must now locate and call this new OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL and call the AllowUnacceptedMemory function. Changes since v10: - AmdSevDxe called AcceptMemory directly without locating the MemoryAccept protocol. - The protocol is no longer a candidate for standardization and has moved to OvmfPkg/Include/Protocol. Changes since v9: - Renamed protocol to SevMemoryAcceptance. - Removed CocoDxe and moved all contained code to AmdSevDxe. - Renamed protocol header file to reference the bugzilla number. Changes since v8: - First 3 patches removed since they were submitted separately. - Later patches rebased on edk2/master and modified to work with the current locations and namings of the unaccepted memory constants. Changes since v7: - Rebased onto lazy accept v4 patch series, so memory accept protocol has the EDKII prefix, and the unaccepted memory type has the BZ3937 prefix. - Removed a bad #include to a header removed in v7. - Renamed the protocol to BZ3987_MEMORY_ACCEPTANCE_PROTOCOL as per the discussion on the buganizer issue. - Uncrustify formatting 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 (4): OvmfPkg: Add memory acceptance event in AmdSevDxe MdePkg: Introduce the SevMemoryAcceptance protocol OvmfPkg: Implement AcceptAllUnacceptedMemory in AmdSevDxe OvmfPkg/PlatformPei: SEV-SNP make >=4GB unaccepted OvmfPkg/AmdSevDxe/AmdSevDxe.c | 123 ++++++++++++++++++++ OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 2 + OvmfPkg/Include/Protocol/SevMemoryAcceptance.h | 42 +++++++ OvmfPkg/OvmfPkg.dec | 1 + OvmfPkg/PlatformPei/AmdSev.c | 5 + 5 files changed, 173 insertions(+) create mode 100644 OvmfPkg/Include/Protocol/SevMemoryAcceptance.h -- 2.39.1.456.gfc5497dd1b-goog