From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.92.19.22]) by mx.groups.io with SMTP id smtpd.web12.1140.1608317432320617056 for ; Fri, 18 Dec 2020 10:50:32 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=U4PGrfum; spf=pass (domain: outlook.com, ip: 40.92.19.22, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g83GTi5IQbb0wwBKsBaBLGwEFuUMxsxIfVrS2M7mgJISEjlbw43+K15hp8tVI6Z9SUFakQX+Op24XAKB9rvsg/ktX7+S6daCFBHsbZPLvxLeQClaG6lbGBBD8yqDXH6GLJ8h9gFb8OIW4dhfo0qLz2mFLiDPFaDLwoNMiRZDStGVVDcNKsSgftK6t6WbXlWjYJtStOWlLBH/OObxRPg1BjsoXDwfHJUiOYvzSNILLYsNLm4vG3ltHX0sx6UYHNjkKVUW5KLZQwBenzGYvH+6dYAXqx/N+HYGepHu4Up8FU4dDU4RCKkWsgiLnQDA4XgFX3uirpxUUPD8UkD56Ix3Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=He0ATQDF9/fygTZXrRYIPvAglWb3PwdRU8RYj1I2O10=; b=ccsIS2nNokf9EpIxOJQEBaK1dAwCIMDsfXkXsTU9U3/ZzFwg0OrNnrk9glV4lH/WskW70/LI3Ubxi6bfzenbmOH2QmCE4j598laRFubi6OpLgB5OPIyuC0NVXOz8H7m9nbzo7ssfTlfQCHamGuREbrjKTT7yl9D0Jz4n+UOAWr+2F1f6diJU8ltU4Z1X5F+KRgZpCdB37JVOP+C/Afr+4E88t+M0T+6J0Ml3SOE5i0fIZDYzTv6ny5vND083zElRIfH3FUcJ6JbdWqC+zV6mb7JyuRQO0fboOAAZN11pNRKgaP4pRA2ulBYqxIO6b5AexInCxDsU9tQeCuylRpubMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=He0ATQDF9/fygTZXrRYIPvAglWb3PwdRU8RYj1I2O10=; b=U4PGrfumuijaj2qB2dbEl3SWjdFkU9jQdJF5esgNPgeALGwE1nyX7/oDJYXrKCVqFSPMYZ9mXfIx8F2IxXsvTVErJhUX9NjI9XLIfWbsG7XA0Y5NIzafRacT4cNbhJs8pLcDord/ByVnu032+BeDFGrHS/bjrX+Pnrk/q/k4G6M+PyAaunOpY5IpjBbObSPAYdqiHMv7LL1pFzD4++rxf/dKOL0pIDEcD4J2L3lyT+y1MEsVWCZil53J/H9XPYIRGoe7FirdoRl7mWe24qslKiHYO/QLhi9xD2aqMw68Qy9YZt3EhS/x1kLZb16IuqjgyMUCeG61JvLPGyHZobNSwQ== Received: from DM6NAM11FT039.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::48) by DM6NAM11HT250.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25; Fri, 18 Dec 2020 18:50:31 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:fc4d::48) by DM6NAM11FT039.mail.protection.outlook.com (2a01:111:e400:fc4d::83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.25 via Frontend Transport; Fri, 18 Dec 2020 18:50:31 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:36C592229DD7D48E5BBEEF5763088FA82BD4C3E0619C73C5639F735BD9BE083D;UpperCasedChecksum:D196B2AAA2B18C3EDF120848474125766C33C7D1EE9DB00E27B5F169AF953519;SizeAsReceived:7483;Count:47 Received: from MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6]) by MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::acb3:ab69:563d:b0d6%5]) with mapi id 15.20.3654.026; Fri, 18 Dec 2020 18:50:31 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Jian J Wang , Hao A Wu , Dandan Bi , Liming Gao Subject: [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Date: Fri, 18 Dec 2020 10:50:03 -0800 Message-ID: X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201218185011.1366-1-kun.q@outlook.com> References: <20201218185011.1366-1-kun.q@outlook.com> X-TMN: [BfFHLjn/gGoXLUS2j2tdmDHdSQd6TAOd] X-ClientProxiedBy: MW2PR16CA0018.namprd16.prod.outlook.com (2603:10b6:907::31) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20201218185011.1366-8-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MW2PR16CA0018.namprd16.prod.outlook.com (2603:10b6:907::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Fri, 18 Dec 2020 18:50:30 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 0c1e77fa-8fef-4e74-5966-08d8a385cb95 X-MS-TrafficTypeDiagnostic: DM6NAM11HT250: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2k1qPYv2tDNzzp7PGysF6GuWZcCmyhvc3Xvg/OF7DcvEvpjzgMhcavzzkbeMVW9kzqAW3wT3MTt4oqcv9JMmpV2Cz971ftrzgacJM1o5aANuN7brbIgZBy/LrqjhLE3zDbqwlIVxsyB9wb/aX6uO+vTvYt3BDlxmunK5ZPLohAKTKtnZbYpeY6VDoWcNv3xH1aZP626AAzOpr0PN/z6T3WAU9HhAfJCzkKT0NJTOKTxIwWtpaV8RYtfTswGqOQjJ X-MS-Exchange-AntiSpam-MessageData: cWIHmWgBhzUucy0WNzJherjkbX425SRcZ65BFteuDq7hfznmyqiQiwnFWn883kfXzzEopYY0zz67aOnterB85Gs4KfemvaEONtbHivINK9O4pc/i03wdEbekk8vnLZb9xPzYG5TcgmcM7XAhTmWXnw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2020 18:50:30.7489 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-Network-Message-Id: 0c1e77fa-8fef-4e74-5966-08d8a385cb95 X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM11HT250 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This change added support of FPDT driver under StandaloneMm. It replaces SMM version ReportStatusCode protocol with MM version. This patch also abstracts standalone and traditional MM interfaces into separate files to support each corresponding function prototypes and implementations. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Signed-off-by: Kun Qin --- MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerfo= rmanceSmm.c =3D> FirmwarePerformanceCommon.c} | 72 ++++++++++----= ------ MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceStandaloneMm.c | 62 ++++++++++++++++= + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceTraditional.c | 62 ++++++++++++++++= + MdeModulePkg/MdeModulePkg.dsc = | 2 + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceCommon.h | 55 +++++++++++++++ MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceSmm.inf | 11 +-- MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerfo= rmanceSmm.inf =3D> FirmwarePerformanceStandaloneMm.inf} | 31 ++++----- 7 files changed, 237 insertions(+), 58 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceSmm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDat= aTableSmm/FirmwarePerformanceCommon.c similarity index 77% rename from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir= mwarePerformanceSmm.c rename to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firmw= arePerformanceCommon.c index d6c6e7693e4d..c2aa9455f9c4 100644 --- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceSmm.c +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceCommon.c @@ -1,11 +1,11 @@ /** @file - This module collects performance data for SMM driver boot records and S3= Suspend Performance Record. + This module collects performance data for MM driver boot records and S3 = Suspend Performance Record. =20 This module registers report status code listener to collect performance= data - for SMM driver boot records and S3 Suspend Performance Record. + for MM driver boot records and S3 Suspend Performance Record. =20 Caution: This module requires additional review when modified. - This driver will have external input - communicate buffer in SMM mode. + This driver will have external input - communicate buffer in MM mode. This external input must be validated carefully to avoid security issue = like buffer overflow, integer overflow. =20 @@ -16,13 +16,13 @@ =20 **/ =20 -#include +#include =20 -#include +#include =20 #include =20 -#include +#include #include #include #include @@ -30,23 +30,22 @@ #include #include #include -#include #include -#include +#include "FirmwarePerformanceCommon.h" =20 -SMM_BOOT_PERFORMANCE_TABLE *mSmmBootPerformanceTable =3D NULL; +SMM_BOOT_PERFORMANCE_TABLE *mMmBootPerformanceTable =3D NULL; =20 -EFI_SMM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol =3D NULL; +EFI_MM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol =3D NULL; UINT64 mSuspendStartTime =3D 0; BOOLEAN mS3SuspendLockBoxSaved =3D FALSE; UINT32 mBootRecordSize =3D 0; UINT8 *mBootRecordBuffer =3D NULL; =20 -SPIN_LOCK mSmmFpdtLock; -BOOLEAN mSmramIsOutOfResource =3D FALSE; +SPIN_LOCK mMmFpdtLock; +BOOLEAN mMmramIsOutOfResource =3D FALSE; =20 /** - Report status code listener for SMM. This is used to record the performa= nce + Report status code listener for MM. This is used to record the performan= ce data for S3 Suspend Start and S3 Suspend End in FPDT. =20 @param[in] CodeType Indicates the type of status code being = reported. @@ -66,7 +65,7 @@ BOOLEAN mSmramIsOutOfResource =3D F= ALSE; **/ EFI_STATUS EFIAPI -FpdtStatusCodeListenerSmm ( +FpdtStatusCodeListenerMm ( IN EFI_STATUS_CODE_TYPE CodeType, IN EFI_STATUS_CODE_VALUE Value, IN UINT32 Instance, @@ -89,19 +88,19 @@ FpdtStatusCodeListenerSmm ( // Collect one or more Boot records in boot time // if (Data !=3D NULL && CompareGuid (&Data->Type, &gEdkiiFpdtExtendedFirmw= arePerformanceGuid)) { - AcquireSpinLock (&mSmmFpdtLock); + AcquireSpinLock (&mMmFpdtLock); // // Get the boot performance data. // - CopyMem (&mSmmBootPerformanceTable, Data + 1, Data->Size); - mBootRecordBuffer =3D ((UINT8 *) (mSmmBootPerformanceTable)) + sizeof = (SMM_BOOT_PERFORMANCE_TABLE); + CopyMem (&mMmBootPerformanceTable, Data + 1, Data->Size); + mBootRecordBuffer =3D ((UINT8 *) (mMmBootPerformanceTable)) + sizeof (= SMM_BOOT_PERFORMANCE_TABLE); =20 - ReleaseSpinLock (&mSmmFpdtLock); + ReleaseSpinLock (&mMmFpdtLock); return EFI_SUCCESS; } =20 if (Data !=3D NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformance= Guid)) { - DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerSmm: Performance data repo= rted through gEfiFirmwarePerformanceGuid will not be collected by FirmwareP= erformanceDataTableSmm\n")); + DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance data repor= ted through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePe= rformanceDataTableMm\n")); return EFI_UNSUPPORTED; } =20 @@ -157,7 +156,7 @@ FpdtStatusCodeListenerSmm ( /** Communication service SMI Handler entry. =20 - This SMI handler provides services for report SMM boot records. + This SMI handler provides services for report MM boot records. =20 Caution: This function may receive untrusted input. Communicate buffer and buffer size are external input, so this function = will do basic validation. @@ -166,7 +165,7 @@ FpdtStatusCodeListenerSmm ( @param[in] RegisterContext Points to an optional handler context whi= ch was specified when the handler was registered. @param[in, out] CommBuffer A pointer to a collection of data in memo= ry that will - be conveyed from a non-SMM environment in= to an SMM environment. + be conveyed from a non-MM environment int= o an MM environment. @param[in, out] CommBufferSize The size of the CommBuffer. =20 @retval EFI_SUCCESS The interrupt was handled an= d quiesced. No other handlers @@ -207,8 +206,8 @@ FpdtSmiHandler ( return EFI_SUCCESS; } =20 - if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize))= { - DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data buffer in= SMRAM or overflow!\n")); + if (!IsBufferOutsideMmValid ((UINTN)CommBuffer, TempCommBufferSize)) { + DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM communication data buffer in = MMRAM or overflow!\n")); return EFI_SUCCESS; } =20 @@ -218,8 +217,8 @@ FpdtSmiHandler ( =20 switch (SmmCommData->Function) { case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE : - if (mSmmBootPerformanceTable !=3D NULL) { - mBootRecordSize =3D mSmmBootPerformanceTable->Header.Length - size= of (SMM_BOOT_PERFORMANCE_TABLE); + if (mMmBootPerformanceTable !=3D NULL) { + mBootRecordSize =3D mMmBootPerformanceTable->Header.Length - sizeo= f (SMM_BOOT_PERFORMANCE_TABLE); } SmmCommData->BootRecordSize =3D mBootRecordSize; break; @@ -244,8 +243,8 @@ FpdtSmiHandler ( BootRecordSize =3D mBootRecordSize - BootRecordOffset; } SmmCommData->BootRecordSize =3D BootRecordSize; - if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData, BootRecordSi= ze)) { - DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM or = overflow!\n")); + if (!IsBufferOutsideMmValid ((UINTN)BootRecordData, BootRecordSize))= { + DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM Data buffer in MMRAM or o= verflow!\n")); Status =3D EFI_ACCESS_DENIED; break; } @@ -267,7 +266,7 @@ FpdtSmiHandler ( } =20 /** - The module Entry Point of the Firmware Performance Data Table SMM driver= . + The module Entry Point of the Firmware Performance Data Table MM driver. =20 @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. @param[in] SystemTable A pointer to the EFI System Table. @@ -278,9 +277,8 @@ FpdtSmiHandler ( **/ EFI_STATUS EFIAPI -FirmwarePerformanceSmmEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +FirmwarePerformanceCommonEntryPoint ( + VOID ) { EFI_STATUS Status; @@ -289,13 +287,13 @@ FirmwarePerformanceSmmEntryPoint ( // // Initialize spin lock // - InitializeSpinLock (&mSmmFpdtLock); + InitializeSpinLock (&mMmFpdtLock); =20 // - // Get SMM Report Status Code Handler Protocol. + // Get MM Report Status Code Handler Protocol. // - Status =3D gSmst->SmmLocateProtocol ( - &gEfiSmmRscHandlerProtocolGuid, + Status =3D gMmst->MmLocateProtocol ( + &gEfiMmRscHandlerProtocolGuid, NULL, (VOID **) &mRscHandlerProtocol ); @@ -304,14 +302,14 @@ FirmwarePerformanceSmmEntryPoint ( // // Register report status code listener for BootRecords and S3 Suspend S= tart and End. // - Status =3D mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm); + Status =3D mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm); ASSERT_EFI_ERROR (Status); =20 // // Register SMI handler. // Handle =3D NULL; - Status =3D gSmst->SmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerfo= rmanceGuid, &Handle); + Status =3D gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerfo= rmanceGuid, &Handle); ASSERT_EFI_ERROR (Status); =20 return Status; diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceStandaloneMm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerfo= rmanceDataTableSmm/FirmwarePerformanceStandaloneMm.c new file mode 100644 index 000000000000..2c4f40eceaea --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceStandaloneMm.c @@ -0,0 +1,62 @@ +/** @file + This module collects performance data for MM driver boot records and S3 = Suspend Performance Record. + + This module registers report status code listener to collect performance= data + for MM driver boot records and S3 Suspend Performance Record. + + Caution: This module requires additional review when modified. + This driver will have external input - communicate buffer in MM mode. + This external input must be validated carefully to avoid security issue = like + buffer overflow, integer overflow. + + FpdtSmiHandler() will receive untrusted input and do basic validation. + + Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c), Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include "FirmwarePerformanceCommon.h" + +/** + This function is an abstraction layer for implementation specific Mm buf= fer validation routine. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architecture and not ov= erlap with SMRAM. + @retval FALSE This buffer is not valid per processor architecture or ove= rlap with SMRAM. +**/ +BOOLEAN +EFIAPI +IsBufferOutsideMmValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return MmIsBufferOutsideMmValid (Buffer, Length); +} + +/** + The module Entry Point of the Firmware Performance Data Table MM driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point= . + +**/ +EFI_STATUS +EFIAPI +FirmwarePerformanceStandaloneMmEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *SystemTable + ) +{ + return FirmwarePerformanceCommonEntryPoint (); +} diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceTraditional.c b/MdeModulePkg/Universal/Acpi/FirmwarePerfor= manceDataTableSmm/FirmwarePerformanceTraditional.c new file mode 100644 index 000000000000..507aabcb4e88 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceTraditional.c @@ -0,0 +1,62 @@ +/** @file + This module collects performance data for MM driver boot records and S3 = Suspend Performance Record. + + This module registers report status code listener to collect performance= data + for MM driver boot records and S3 Suspend Performance Record. + + Caution: This module requires additional review when modified. + This driver will have external input - communicate buffer in MM mode. + This external input must be validated carefully to avoid security issue = like + buffer overflow, integer overflow. + + FpdtSmiHandler() will receive untrusted input and do basic validation. + + Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c), Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include "FirmwarePerformanceCommon.h" + +/** + This function is an abstraction layer for implementation specific Mm buf= fer validation routine. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architecture and not ov= erlap with SMRAM. + @retval FALSE This buffer is not valid per processor architecture or ove= rlap with SMRAM. +**/ +BOOLEAN +EFIAPI +IsBufferOutsideMmValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return SmmIsBufferOutsideSmmValid (Buffer, Length); +} + +/** + The module Entry Point of the Firmware Performance Data Table MM driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point= . + +**/ +EFI_STATUS +EFIAPI +FirmwarePerformanceSmmEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return FirmwarePerformanceCommonEntryPoint (); +} diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 05bf5fe08094..dc85d108d958 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -168,6 +168,7 @@ [LibraryClasses.common.MM_STANDALONE] StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint= /StandaloneMmDriverEntryPoint.inf MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.= inf + MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf =20 [LibraryClasses.ARM, LibraryClasses.AARCH64] ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf @@ -501,6 +502,7 @@ [Components.IA32, Components.X64] =20 [Components.X64] MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerf= ormanceStandaloneMm.inf =20 [BuildOptions] =20 diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceCommon.h b/MdeModulePkg/Universal/Acpi/FirmwarePerformance= DataTableSmm/FirmwarePerformanceCommon.h new file mode 100644 index 000000000000..ba01e28f2493 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceCommon.h @@ -0,0 +1,55 @@ +/** @file + This module collects performance data for SMM driver boot records and S3= Suspend Performance Record. + + This module registers report status code listener to collect performance= data + for SMM driver boot records and S3 Suspend Performance Record. + + Caution: This module requires additional review when modified. + This driver will have external input - communicate buffer in SMM mode. + This external input must be validated carefully to avoid security issue = like + buffer overflow, integer overflow. + + FpdtSmiHandler() will receive untrusted input and do basic validation. + + Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c), Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _FW_PERF_COMMON_H_ +#define _FW_PERF_COMMON_H_ + +/** + This function is an abstraction layer for implementation specific Mm buf= fer validation routine. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architecture and not ov= erlap with SMRAM. + @retval FALSE This buffer is not valid per processor architecture or ove= rlap with SMRAM. +**/ +BOOLEAN +EFIAPI +IsBufferOutsideMmValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ); + +/** + The module Entry Point of the Firmware Performance Data Table MM driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point= . + +**/ +EFI_STATUS +EFIAPI +FirmwarePerformanceCommonEntryPoint ( + VOID + ); + +#endif // _FW_PERF_COMMON_H_ diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceSmm.inf b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceD= ataTableSmm/FirmwarePerformanceSmm.inf index 618cbd56ca59..b7194bd899dd 100644 --- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceSmm.inf +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceSmm.inf @@ -26,7 +26,9 @@ [Defines] # =20 [Sources] - FirmwarePerformanceSmm.c + FirmwarePerformanceCommon.c + FirmwarePerformanceCommon.h + FirmwarePerformanceTraditional.c =20 [Packages] MdePkg/MdePkg.dec @@ -34,7 +36,7 @@ [Packages] =20 [LibraryClasses] UefiDriverEntryPoint - SmmServicesTableLib + MmServicesTableLib BaseLib DebugLib TimerLib @@ -42,12 +44,11 @@ [LibraryClasses] PcdLib BaseMemoryLib MemoryAllocationLib - UefiBootServicesTableLib SynchronizationLib SmmMemLib =20 [Protocols] - gEfiSmmRscHandlerProtocolGuid ## CONSUMES + gEfiMmRscHandlerProtocolGuid ## CONSUMES =20 [Guids] ## SOMETIMES_PRODUCES ## UNDEFINED # SaveLockBox @@ -61,7 +62,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd ## CONSUME= S =20 [Depex] - gEfiSmmRscHandlerProtocolGuid + gEfiMmRscHandlerProtocolGuid =20 [UserExtensions.TianoCore."ExtraFiles"] FirmwarePerformanceSmmExtra.uni diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceSmm.inf b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceD= ataTableSmm/FirmwarePerformanceStandaloneMm.inf similarity index 65% copy from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firmw= arePerformanceSmm.inf copy to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firmwar= ePerformanceStandaloneMm.inf index 618cbd56ca59..e6aad88be0ef 100644 --- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceSmm.inf +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceStandaloneMm.inf @@ -5,19 +5,19 @@ # for SMM boot performance records and S3 Suspend Performance Record. # # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D FirmwarePerformanceSmm - MODULE_UNI_FILE =3D FirmwarePerformanceSmm.uni - FILE_GUID =3D 044310AB-77FD-402a-AF1A-87D4120E7329 - MODULE_TYPE =3D DXE_SMM_DRIVER + BASE_NAME =3D FirmwarePerformanceStandaloneMm + FILE_GUID =3D 827AC29D-E52D-4B1A-874A-C6577E0699CF + MODULE_TYPE =3D MM_STANDALONE VERSION_STRING =3D 1.0 - PI_SPECIFICATION_VERSION =3D 0x0001000A - ENTRY_POINT =3D FirmwarePerformanceSmmEntryPoint + PI_SPECIFICATION_VERSION =3D 0x00010032 + ENTRY_POINT =3D FirmwarePerformanceStandaloneMmEntryP= oint =20 # # The following information is for reference only and not required by the = build tools. @@ -26,15 +26,18 @@ [Defines] # =20 [Sources] - FirmwarePerformanceSmm.c + FirmwarePerformanceCommon.c + FirmwarePerformanceCommon.h + FirmwarePerformanceStandaloneMm.c =20 [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + StandaloneMmPkg/StandaloneMmPkg.dec =20 [LibraryClasses] - UefiDriverEntryPoint - SmmServicesTableLib + StandaloneMmDriverEntryPoint + MmServicesTableLib BaseLib DebugLib TimerLib @@ -42,12 +45,11 @@ [LibraryClasses] PcdLib BaseMemoryLib MemoryAllocationLib - UefiBootServicesTableLib SynchronizationLib - SmmMemLib + MemLib =20 [Protocols] - gEfiSmmRscHandlerProtocolGuid ## CONSUMES + gEfiMmRscHandlerProtocolGuid ## CONSUMES =20 [Guids] ## SOMETIMES_PRODUCES ## UNDEFINED # SaveLockBox @@ -61,7 +63,4 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd ## CONSUME= S =20 [Depex] - gEfiSmmRscHandlerProtocolGuid - -[UserExtensions.TianoCore."ExtraFiles"] - FirmwarePerformanceSmmExtra.uni + gEfiMmRscHandlerProtocolGuid --=20 2.28.0.windows.1