From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by mx.groups.io with SMTP id smtpd.web12.957.1664579197146991670 for ; Fri, 30 Sep 2022 16:06:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=P3wzstRL; spf=pass (domain: flex--dionnaglaze.bounces.google.com, ip: 209.85.216.73, mailfrom: 3e3y3ywskbwyhmsrrekpediksskpi.gsqhizipihog.kvsytw.ms@flex--dionnaglaze.bounces.google.com) Received: by mail-pj1-f73.google.com with SMTP id o11-20020a17090aac0b00b0020625062cbaso4451567pjq.2 for ; Fri, 30 Sep 2022 16:06:37 -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=ZsuJcgllTOfMKxpGLe4iG0P5cqi8RsiagAxVXa83zEo=; b=P3wzstRL0ZrPVLPu+fwoZb6jtK9L0/RRBTMs69oGNSUvPbI/sVhDEcGbCWvUQoEZte gBVOb+ncRAciaU94Wg5SvSlGCsKWQjmLKc/l9igWgrJQRJQ6mgNVHm4ljewX2vIIE7dI d560qfPFWrACx8bKBEi8XwxLJ4YN0+8p8MH46svdHoircS1DuD3mt5/RXL/t0mWjJ0x+ V/EE5cxTT1GoaFAotU38YC7AO1XPWWt3zGZ3Rh9vzodErvx+6JuZhuY47ZXMyfyBpDYp 0Jn/Nanwz1acRrtQYp+ylSgNs3ezvl6oQxmjq8lqKA2KBX9GopgRDHNtnsr/Jg4G7oKr RhaQ== 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=ZsuJcgllTOfMKxpGLe4iG0P5cqi8RsiagAxVXa83zEo=; b=sl6iqNuF36h0IO7vtFsJotgyPgxqBsqK/GaZIKnf9Qxcim6YSutac3P8ehhKvTHvGN l0rtOBX7l/SUybcZu4XAaw3q1nRlaiG/ujoSNgs06J8cHKhqi1/144hnTyXFdRbqIVE5 rZtLG4ByU9aNJHpE8q25J46ncDjxfBv2JeRCetUx8B6Ti17SycZuAD4XLOe9ayIzcpHP zz+iBvGWm5BueALzdzRWmGc8pgit0K3rGbOmdY+mGdRZyn327kQy9wXeASLResKiWBLs s98WYr2qcBu7rdAwVj5+7XjYeCWNOzgMP9a9aI42LnbPa7FUw6gRlTsBQKtUD8DijRbz XyVQ== X-Gm-Message-State: ACrzQf3rDiJ8iiAMf90ZcD6t9zGGqpA34D0UK5K+yi2oUkNXB6ZC27Jb jja0aSNUZpCvgCxuXaTz0WDI670OhFBFs7PJSmHtiXB0IioE1vxLQvBmFLkYI6VaUmRGk16epU7 o+cX98Pwc8KHR68+6BaIiHNknR6Lb7JUuvJ4Ip84Wy32wen8PU6hVcy9BPgZc0YyTy9SE6mke X-Google-Smtp-Source: AMsMyM54cdvr7Yk0CnLuPEwOHpGwB1N4FLZuw/T1Kz/GFALMZOm3ckKEiXl2IOFaGOXfDZQe8QgEkk4H233j37OLHQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:c986:b0:205:f08c:a82b with SMTP id w6-20020a17090ac98600b00205f08ca82bmr492431pjt.1.1664579195331; Fri, 30 Sep 2022 16:06:35 -0700 (PDT) Date: Fri, 30 Sep 2022 23:06:23 +0000 In-Reply-To: <20220930230627.3371754-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20220930230627.3371754-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930230627.3371754-4-dionnaglaze@google.com> Subject: [PATCH v5 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" 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" Signed-off-by: Dionna Glaze --- MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 62 ++++++++++++++++++++ 2 files changed, 63 insertions(+) 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..8cf7d6bcbf 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -6,6 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include "DxeMain.h" // @@ -744,6 +745,54 @@ CalculateEfiHdrCrc ( Hdr->CRC32 = Crc; } +/** + Invokes TerminateMemoryMapPrehook from every instance of the + EdkiiExitBootServicesProtocol. +**/ +STATIC +EFI_STATUS +InvokeTerminateMemoryMapPrehooks ( + VOID + ) +{ + UINTN NoHandles; + UINTN Index; + EFI_HANDLE *HandleBuffer; + EFI_STATUS Status; + EDKII_EXIT_BOOT_SERVICES_CALLBACK_PROTOCOL *Callback; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkiiExitBootServicesCallbackProtocolGuid, + NULL, + &NoHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status) && NoHandles == 0) { + return Status; + } + + for (Index = 0; Index < NoHandles; Index++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkiiExitBootServicesCallbackProtocolGuid, + (VOID **)&Callback + ); + if (EFI_ERROR (Status)) { + continue; + } + + Status = Callback->TerminateMemoryMapPrehook(Callback); + if (EFI_ERROR (Status) || Status == EFI_WARN_STALE_DATA) { + goto done; + } + } + +done: + FreePool(HandleBuffer); + return Status; +} + /** Terminates all boot services. @@ -768,6 +817,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