From nobody Wed May 15 12:11:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111464+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111464+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700469056; cv=none; d=zohomail.com; s=zohoarc; b=iXRDDZHfWc+b2o0DgkVhqmJdD4q9YwCQVExLMzwKF9ghdYvUj4NyGHbxMN7XxWEW1q/Ac85OZAv92o7z5Nb3TgheEm2D5lPn823MrS9siDkrq3urOKPmhsKiW2Rt4xPKCk3tmXBnlSrc3Dri02qNIBdI0KJPOtI0iCtMsAkDQa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700469056; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=u9/6DpF6hndhbcBmFkkCbmxkF/2g89l6UeJHAlgYz6A=; b=iqs5hodIkVPBsnzE0KLu7d3yjooFcBZr+mgtr9OM1BhiWZ+Ffl1IJt9LMubDuVRm/FO+456qABAaFReb8uAdY9LcKR8DRXiqd5PiC6IEJUlIGo1FNeDWyhxWSTbD8wlWeruBhzCJzhq9WxQoImkJpMMHU3oSdIIKYQ8SjYrmlUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111464+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1700469056789304.5262825648862; Mon, 20 Nov 2023 00:30:56 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=MM5leotY64CF7YL6V++MUW8V2EWuVz/5OZwvNBoBLv8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1700469056; v=1; b=t4KOuQqLFFFW2fDWutco3w42zzJFY224j4Bf7s30AKqlNGy0c8akbAbVqNtxm0wnIEiN4VYE qxxmBFTI84NB53qsFmTEX+wl9J3DTv7y+WwSI4+oM0b99mxHBhJHPw5ZYjSKolyRzPrWRA0gu4w vsLBqWeYMTeGv0FqN0J+aGRw= X-Received: by 127.0.0.2 with SMTP id m52XYY1788612xNK9bMVJeAg; Mon, 20 Nov 2023 00:30:56 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.46045.1700469051529709976 for ; Mon, 20 Nov 2023 00:30:55 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="4694572" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="4694572" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 00:30:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="856924634" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="856924634" X-Received: from shpfwdbuild003.ccr.corp.intel.com ([10.239.56.82]) by FMSMGA003.fm.intel.com with ESMTP; 20 Nov 2023 00:30:53 -0800 From: "Xu, Wei6" To: devel@edk2.groups.io Cc: Wei6 Xu , Ard Biesheuvel , Sami Mujawar , Ray Ni Subject: [edk2-devel] [PATCH 1/1] StandaloneMmPkg/Core: Restart dispatcher once MmEntryPoint is registered Date: Mon, 20 Nov 2023 16:30:32 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,wei6.xu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: vz7FEwGT02w5VBA2F43H58Ezx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700469058172100003 Content-Type: text/plain; charset="utf-8" Defer the dispatch of the remaining MM drivers once the CPU driver has been dispatched. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4599 In MmDispatcher, return immediately if the MM Entry Point was registered. Then the MM IPL will reinvoke the MM Core Dispatcher. This is required so MM Mode may be enabled as soon as all the dependent MM Drivers for MM Mode have been dispatched. Introduce a FeatureFlag PCD to control if MmDispatcher returns or not when MmEntryPointPoint is registered. Default value is FALSE. Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Ray Ni Signed-off-by: Wei6 Xu --- StandaloneMmPkg/Core/Dispatcher.c | 76 +++++++++++++++++++++++ StandaloneMmPkg/Core/StandaloneMmCore.c | 1 + StandaloneMmPkg/Core/StandaloneMmCore.inf | 3 + StandaloneMmPkg/StandaloneMmPkg.dec | 6 ++ 4 files changed, 86 insertions(+) diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispa= tcher.c index b1ccba15b060..a3983785070b 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -586,6 +586,7 @@ MmDispatcher ( LIST_ENTRY *Link; EFI_MM_DRIVER_ENTRY *DriverEntry; BOOLEAN ReadyToRun; + BOOLEAN PreviousMmEntryPointRegistered; =20 DEBUG ((DEBUG_INFO, "MmDispatcher\n")); =20 @@ -649,6 +650,11 @@ MmDispatcher ( DriverEntry->Initialized =3D TRUE; RemoveEntryList (&DriverEntry->ScheduledLink); =20 + // + // Cache state of MmEntryPointRegistered before calling entry point + // + PreviousMmEntryPointRegistered =3D gMmCorePrivate->MmEntryPointRegis= tered; + // // For each MM driver, pass NULL as ImageHandle // @@ -667,6 +673,22 @@ MmDispatcher ( DEBUG ((DEBUG_INFO, "StartImage Status - %r\n", Status)); MmFreePages (DriverEntry->ImageBuffer, DriverEntry->NumberOfPage); } + + if (!PreviousMmEntryPointRegistered && gMmCorePrivate->MmEntryPointR= egistered) { + if (FeaturePcdGet (PcdRestartMmDispatcherOnceMmEntryRegistered)) { + // + // Return immediately if the MM Entry Point was registered by th= e MM + // Driver that was just dispatched. The MM IPL will reinvoke the= MM + // Core Dispatcher. This is required so MM Mode may be enabled a= s soon + // as all the dependent MM Drivers for MM Mode have been dispatc= hed. + // Once the MM Entry Point has been registered, then MM Mode wil= l be + // used. + // + gRequestDispatch =3D TRUE; + gDispatcherRunning =3D FALSE; + return EFI_NOT_READY; + } + } } =20 // @@ -897,6 +919,60 @@ MmAddToDriverList ( return EFI_SUCCESS; } =20 +/** + Event notification that is fired MM IPL to dispatch the previously disco= vered MM drivers. + + @param[in] DispatchHandle The unique handle assigned to this hand= ler by MmiHandlerRegister(). + @param[in] Context Points to an optional handler context w= hich was specified when the + handler was registered. + @param[in, out] CommBuffer A pointer to a collection of data in me= mory that will + be conveyed from a non-MM environment i= nto an MM environment. + @param[in, out] CommBufferSize The size of the CommBuffer. + + @return EFI_SUCCESS Dispatcher is executed. + +**/ +EFI_STATUS +EFIAPI +MmDriverDispatchHandler ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL + ) +{ + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "MmDriverDispatchHandler\n")); + + // + // Execute the MM Dispatcher on MM drivers that have been discovered + // previously but not dispatched. + // + Status =3D MmDispatcher (); + + // + // Check to see if CommBuffer and CommBufferSize are valid + // + if ((CommBuffer !=3D NULL) && (CommBufferSize !=3D NULL)) { + if (*CommBufferSize > 0) { + if (!EFI_ERROR (Status)) { + // + // Set the flag to show that the MM Dispatcher executed without er= rors + // + *(UINT8 *)CommBuffer =3D COMM_BUFFER_MM_DISPATCH_SUCCESS; + } else { + // + // Set the flag to show that the MM Dispatcher encountered an error + // + *(UINT8 *)CommBuffer =3D COMM_BUFFER_MM_DISPATCH_ERROR; + } + } + } + + return EFI_SUCCESS; +} + /** Traverse the discovered list for any drivers that were discovered but no= t loaded because the dependency expressions evaluated to false. diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core= /StandaloneMmCore.c index d221f1d1115d..e65edee6d8c2 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.c +++ b/StandaloneMmPkg/Core/StandaloneMmCore.c @@ -84,6 +84,7 @@ EFI_MM_SYSTEM_TABLE gMmCoreMmst =3D { // Table of MMI Handlers that are registered by the MM Core when it is ini= tialized // MM_CORE_MMI_HANDLERS mMmCoreMmiHandlers[] =3D { + { MmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRU= E }, { MmReadyToLockHandler, &gEfiDxeMmReadyToLockProtocolGuid, NULL, TRU= E }, { MmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, FAL= SE }, { MmExitBootServiceHandler, &gEfiEventExitBootServicesGuid, NULL, FAL= SE }, diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Co= re/StandaloneMmCore.inf index c44b9ff33303..845fed831c47 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf @@ -76,6 +76,9 @@ [Guids] gEfiEventExitBootServicesGuid gEfiEventReadyToBootGuid =20 +[Pcd] + gStandaloneMmPkgTokenSpaceGuid.PcdRestartMmDispatcherOnceMmEntryRegister= ed + # # This configuration fails for CLANGPDB, which does not support PIE in the= GCC # sense. Such however is required for ARM family StandaloneMmCore diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec b/StandaloneMmPkg/Standalo= neMmPkg.dec index 46784d94e421..bb4d1520f7d9 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.dec +++ b/StandaloneMmPkg/StandaloneMmPkg.dec @@ -48,3 +48,9 @@ [Guids] gEfiStandaloneMmNonSecureBufferGuid =3D { 0xf00497e3, 0xbfa2, 0x41a= 1, { 0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }} gEfiArmTfCpuDriverEpDescriptorGuid =3D { 0x6ecbd5a1, 0xc0f8, 0x470= 2, { 0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }} =20 +[PcdsFeatureFlag] + ## Indicates if restart MM Dispatcher once MM Entry Point is registered.=

+ # TRUE - Restart MM Dispatcher once MM Entry Point is registered.
+ # FALSE - Do not restart MM Dispatcher once MM Entry Point is register= ed.
+ # @Prompt Restart MM Dispatcher once MM Entry Point is registered. + gStandaloneMmPkgTokenSpaceGuid.PcdRestartMmDispatcherOnceMmEntryRegister= ed|FALSE|BOOLEAN|0x00000001 --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111464): https://edk2.groups.io/g/devel/message/111464 Mute This Topic: https://groups.io/mt/102703852/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-