From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.92.4.92]) by mx.groups.io with SMTP id smtpd.web12.1580.1609873197436716749 for ; Tue, 05 Jan 2021 10:59:57 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=mx9ulpde; spf=pass (domain: outlook.com, ip: 40.92.4.92, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b5rMnlltWBajprXhViOa9GiazPFx+gqSzAkyUx0syYGTfowcz/gSoPZV5e4m3xdJy9MpHvFOOipI+6EeACeZ8zTPIWdVNDuHL3zUkmmZKcDkG5QrsuL3sBHnsXYwGWqbWAwKFZSbteVy+dLyOH9IqZO2MqfKzBZUv2iZMFtQFHYvnI0Aej/Bq7sVP8dYpK3Is1zi7EA0qP1yYiGQ7hCUcteRD6VOZkN0EeZYZUE9A3XBCItt7mGSkbe1AbraHyRDd9NqxB3skxyMy4o1VztZuvoqckcnb7Fh1Pl3DBBD00QjlS0G/g8vKMqK0srvCzKC4qq+v6SEWqsHbvtfKjtYVg== 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=TzGtGjh277W30V58gjezElTZlVJI2ZYmB+cjyCArBTc=; b=U2M+zdtWubzCTuzOfAvDCCIImnJl0rn5bs/7tvCXMS1pcjy1foYny7GDB7cO0ay8P7FVfAiBbRAlD3cXS2j5UhE57y5GHhncUi0OZDjUu+4/2pVcIJG96GN64k24yz2IAOujEdoLtyeVeiwNf1RiTV7Dr3he5HxXvCEJ/W3DCajSKtBI+zNnJERfoMX+zQ2XvCH53FECUWMHZZPtAy2NTMHPtYLl2X+Qry/I37fPMKd9h3+spU7bjegDdkyvDspqRcvcXdDKYTM7kite8EE3ktzAMQFAJgWmWs11op4nMX/WV4wZ0hIMFleyewXIIJQDgOTuGcCzveuIhfU8ugysrw== 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=TzGtGjh277W30V58gjezElTZlVJI2ZYmB+cjyCArBTc=; b=mx9ulpder6cS5o+VElRBPhpz1mZlyn5KnkdzjgjnImVaz7c9DEjK9ZQ7jKiNMglpm1rQ41dkBB5zefb4i/dgguT6loppIlmCq++uHiZDCIrgEi5Z9p3OW3Iji6PEtN9VRwDXeK1If/wGl9SA2/DaXuSmPmxWt+OmgMWo7RQ0qJcf0bjB8mEE2JR+MyclJatTEc+z0GaoPn8VKXrnq48qrY3xn6XUSENAF1vCXxLZ79D6JDImpDiCwpw0vpF08zY9gSC3AhV4YiM3Nycl3c7/F8vVWKApmlb7TnAmW1A0L9AINIczS9938KP5NV3nbNBydnFtk77Zt6DmzokwJn7fFw== Received: from CY1NAM02FT003.eop-nam02.prod.protection.outlook.com (10.152.74.57) by CY1NAM02HT187.eop-nam02.prod.protection.outlook.com (10.152.74.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.22; Tue, 5 Jan 2021 18:59:56 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:7e45::53) by CY1NAM02FT003.mail.protection.outlook.com (2a01:111:e400:7e45::151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.22 via Frontend Transport; Tue, 5 Jan 2021 18:59:56 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:825D599A3DEC444633E8D1CA30DBA3260619DE54CF317CCB8A44A89B4914C9D2;UpperCasedChecksum:7ED89444F10AF902A80ED757594E6C266D780274A80806F8244F1E6A14210E58;SizeAsReceived:7481;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.3721.024; Tue, 5 Jan 2021 18:59:56 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Jian J Wang , Hao A Wu , Dandan Bi , Liming Gao Subject: [PATCH v2 08/16] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Date: Tue, 5 Jan 2021 10:59:27 -0800 Message-ID: X-Mailer: git-send-email 2.30.0.windows.1 In-Reply-To: <20210105185935.3769-1-kun.q@outlook.com> References: <20210105185935.3769-1-kun.q@outlook.com> X-TMN: [EOK1aQ4phz9GBQ9UZyhk8Dot9iZL4qdX] X-ClientProxiedBy: MWHPR22CA0045.namprd22.prod.outlook.com (2603:10b6:300:69::31) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20210105185935.3769-9-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MWHPR22CA0045.namprd22.prod.outlook.com (2603:10b6:300:69::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Tue, 5 Jan 2021 18:59:55 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 3928433d-fa17-48c2-1bbf-08d8b1ac17b0 X-MS-TrafficTypeDiagnostic: CY1NAM02HT187: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e+gZVdUMgp172mlbxOyibfhKIbKTAJ9hTsNtoX9ZHw98JJJY4G44s9+62nXLtwOj5desDzkosYmLPgE2aRef3HTmRCr3St9srFUbH1pE4AzSS0gPfTP1/NnqcHI/TpAaEKEejsB85ppjt9Hydyk4AkkuQOvAx/JfEdRvuy+pKiXYVqYFVY+wDrlENevQ3+bkSzDngaqTxr1g1Ol8n9WCR5IV7C01C4VC4RvOE1Se1LJZ4vBSLGtpAkWAZ9T4xwhy X-MS-Exchange-AntiSpam-MessageData: 9k2839LUBlNlr0sDUN6bGyEs73g092PkKFPMkph5b75u1p0Wy0lGRB5Ki4qq/kQq648aEo6o0cjFT7+TS4xTo34gM4oGbModFF3UfHKVGPA5KKX/SuB5keRi/23KuW9+Y8FRG145JAcjx++Bf9z4/w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2021 18:59:56.2444 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-Network-Message-Id: 3928433d-fa17-48c2-1bbf-08d8b1ac17b0 X-MS-Exchange-CrossTenant-AuthSource: CY1NAM02FT003.eop-nam02.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: CY1NAM02HT187 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 --- Notes: v2: - Removed "EFIAPI" for internally abstracted functions [Hao] - Support driver for both IA32 and X64 in dsc file [Hao] MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerfo= rmanceSmm.c =3D> FirmwarePerformanceCommon.c} | 76 +++++++++-----= ------ MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceStandaloneMm.c | 61 ++++++++++++++++ MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceTraditional.c | 61 ++++++++++++++++ MdeModulePkg/MdeModulePkg.dsc = | 2 + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceCommon.h | 50 +++++++++++++ MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerfor= manceSmm.inf | 11 +-- MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerfo= rmanceSmm.inf =3D> FirmwarePerformanceStandaloneMm.inf} | 31 ++++---- 7 files changed, 230 insertions(+), 62 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceSmm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDat= aTableSmm/FirmwarePerformanceCommon.c similarity index 75% rename from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir= mwarePerformanceSmm.c rename to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firmw= arePerformanceCommon.c index d6c6e7693e4d..ecadef8711ed 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,20 +266,15 @@ FpdtSmiHandler ( } =20 /** - The module Entry Point of the Firmware Performance Data Table SMM driver= . - - @param[in] ImageHandle The firmware allocated handle for the EFI ima= ge. - @param[in] SystemTable A pointer to the EFI System Table. + The module Entry Point of the Firmware Performance Data Table MM driver. =20 @retval EFI_SUCCESS The entry point is executed successfully. @retval Other Some error occurs when executing this entry point= . =20 **/ EFI_STATUS -EFIAPI -FirmwarePerformanceSmmEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +FirmwarePerformanceCommonEntryPoint ( + VOID ) { EFI_STATUS Status; @@ -289,13 +283,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 +298,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..d7da61c98c66 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceStandaloneMm.c @@ -0,0 +1,61 @@ +/** @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 +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 MM 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..43c050d6b516 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceTraditional.c @@ -0,0 +1,61 @@ +/** @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 +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 098909490095..34ca571ca662 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 @@ -495,6 +496,7 @@ [Components.IA32, Components.X64] MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.inf MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerf= ormanceSmm.inf + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerf= ormanceStandaloneMm.inf MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.in= f MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fi= rmwarePerformanceCommon.h b/MdeModulePkg/Universal/Acpi/FirmwarePerformance= DataTableSmm/FirmwarePerformanceCommon.h new file mode 100644 index 000000000000..0fbdac02de4c --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwareP= erformanceCommon.h @@ -0,0 +1,50 @@ +/** @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 +IsBufferOutsideMmValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ); + +/** + The module Entry Point of the Firmware Performance Data Table MM driver. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point= . + +**/ +EFI_STATUS +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.30.0.windows.1