From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by mx.groups.io with SMTP id smtpd.web08.1482.1664823245330759376 for ; Mon, 03 Oct 2022 11:54:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=pOF3n6gT; spf=pass (domain: flex--dionnaglaze.bounces.google.com, ip: 209.85.128.202, mailfrom: 3zc87ywskbtkydjiivbgvuzbjjbgz.xjhyzqzgzyfx.bmjpkn.dj@flex--dionnaglaze.bounces.google.com) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-3562f0fb5a7so93895027b3.1 for ; Mon, 03 Oct 2022 11:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=t+2jNS5H7G2MuWe7vAGm8XNnSh1/qj/OfkzpG9PnBO0=; b=pOF3n6gT0t8y14HMuyfyZv02HjVRjdmk9njpQnjgFXnZx71vACQWbPuVj9FDEF1IZS POFQGnfXBWZiWbuZ12o3nJXtWHWtgKBg4aOMgg11DA7yX5lJuFXW1jeAWo2hUGJicsO1 LtyN/YNZDDOOv/k66242AVjAguruGdzjYUDnhQ0tcfsvAYMoAibzMhOkQDHvFK5UDfjQ Chxi6qOUBmeonPUH3sfKiDv87GmWsLKmXgPcb46DB9M+A3KQp1Mr0stalZz8TjcJ+uUw wwg7ED1QGC4Py4jqycJoz06mYM1OwdrGiynsGxNT2jMfA1bXQHGndt/8FdT4L1m2Io0d k3rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=t+2jNS5H7G2MuWe7vAGm8XNnSh1/qj/OfkzpG9PnBO0=; b=mJx7vPhcT7YCmcteSFB1Wkg5QhmCOdB9gWOTVCurJKAceN5XrvwQLXVRccj7aQCPWH 6b4EJ3DbxA4fqT6ESwpdAc1V+sqDQPEnWBWaFQuXkVVvg3UFv6IVds4c5pG/1iG/zbRI QBxgLGAUHtp04m+NiOFhMjYFV9MWBtnsdG11ucjs+F8wdww3uyVF7WhTfJFRK+ubKj0E OPQF406beg+NxrFXOzSmnlds1IE9uZWxyNRaJgXjcS6iXsK38D21YVC7V87c4QU9EdAY PPF6PYGlt7as+Y9Z3LtnaGnGiIH0KraPHq0SQMdoENN11rpM7uDPpbjB+Qnn7otN/+hw VKzQ== X-Gm-Message-State: ACrzQf1Y0kTQcEjNDAc5sycoGOB26iRT3m5bRs8MBTQPbsN0siprRjCF qT4WaSzwdZ5ouWiZ+h+K7qB3cEfFoAmZgZ1MmTVH2FEBIAC6nVjBMd+jrcg1F6wjyhInNLo8MWM sx5BWkwcdSbTrHAAJQLRDcq2tZbVCc8kYAhBld5b6zz4/FzLt7Ll1+8TOkfo7nw8Qv9QR9bJY X-Google-Smtp-Source: AMsMyM6VDlt1Fk1VDTbz3lpBc2wNMXVJSmq24I8W0FlWCAvFa4nDVjwMfkkzUZV3FvuaqMjrmndO+EZwaMV+xvKPYQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a25:3bcd:0:b0:6b3:bb2d:8497 with SMTP id i196-20020a253bcd000000b006b3bb2d8497mr21460102yba.598.1664823244418; Mon, 03 Oct 2022 11:54:04 -0700 (PDT) Date: Mon, 3 Oct 2022 18:53:48 +0000 In-Reply-To: <20221003185352.3969999-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221003185352.3969999-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221003185352.3969999-4-dionnaglaze@google.com> Subject: [PATCH v6 3/7] MdeModulePkg: Invoke all ExitBootServicesCallback instances at ExitBootServices From: "Dionna Glaze" 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" , Ray Ni Content-Type: text/plain; charset="UTF-8" The protocol's intent is to allow drivers to install callbacks that can modify the memory map at ExitBootServices time, so that any changes will lead to the EFI_INVALID_PARAMETER error. This error is specified to require the EBS caller to call GetMemoryMap again if it already had. 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" Cc: Ray Ni Signed-off-by: Dionna Glaze --- MdeModulePkg/Core/Dxe/DxeMain.h | 1 + MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 41 ++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 815a6b4bd8..185b9dc3d6 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -45,6 +45,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index e4bca89577..bdd9cf8222 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -153,6 +153,7 @@ gEfiHiiPackageListProtocolGuid ## SOMETIMES_PRODUCES gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES + gEdkiiExitBootServicesCallbackProtocolGuid ## CONSUMES # Arch Protocols gEfiBdsArchProtocolGuid ## CONSUMES diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 5733f0c8ec..3270f9858d 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -744,6 +744,34 @@ CalculateEfiHdrCrc ( Hdr->CRC32 = Crc; } +/** + Invokes TerminateMemoryMapPrehook from the first located instance of + EdkiiExitBootServicesProtocol. +**/ +STATIC +EFI_STATUS +InvokeTerminateMemoryMapPrehooks ( + VOID + ) +{ + EFI_STATUS Status; + EDKII_EXIT_BOOT_SERVICES_CALLBACK_PROTOCOL *Callback; + + Status = gBS->LocateHandle ( + &gEdkiiExitBootServicesCallbackProtocolGuid, + NULL, + (VOID**)Callback + ); + if (Status == EFI_NOT_FOUND) { + return EFI_SUCCESS; + } + if (EFI_ERROR (Status)) { + return Status; + } + + return Callback->TerminateMemoryMapPrehook(Callback); +} + /** Terminates all boot services. @@ -768,6 +796,19 @@ CoreExitBootServices ( // gTimer->SetTimerPeriod (gTimer, 0); + // + // Invoke all protocols installed for ExitBootServices prior to + // CoreTerminateMemoryMap. + // + Status = InvokeTerminateMemoryMapPrehooks(); + if (EFI_ERROR (Status)) { + // + // Notify other drivers that ExitBootServices failed + // + CoreNotifySignalList (&gEventExitBootServicesFailedGuid); + return Status; + } + // // Terminate memory services if the MapKey matches // -- 2.38.0.rc1.362.ged0d419d3c-goog