[edk2] [patch 7/8] MdeModulePkg/FirmwarePerfSmm: Add check for collecting SMM records

Dandan Bi posted 8 patches 6 years, 9 months ago
There is a newer version of this series
[edk2] [patch 7/8] MdeModulePkg/FirmwarePerfSmm: Add check for collecting SMM records
Posted by Dandan Bi 6 years, 9 months ago
After DXE driver communicating with SMM driver to get the size and
contents of the SMM records, make SMM driver not to allocate buffer
to collect new SMM records if the pre-allocate buffer is not enough.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../FirmwarePerformanceSmm.c                               | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
index c750331..160f6c0 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
@@ -9,11 +9,11 @@
   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 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
   http://opensource.org/licenses/bsd-license.php
 
@@ -49,10 +49,11 @@ UINT32                        mBootRecordSize = 0;
 UINT32                        mBootRecordMaxSize = 0;
 UINT8                         *mBootRecordBuffer = NULL;
 
 SPIN_LOCK                     mSmmFpdtLock;
 BOOLEAN                       mSmramIsOutOfResource = FALSE;
+BOOLEAN                       mHaveReportedSmmRecord = FALSE;
 
 /**
   Report status code listener for SMM. This is used to record the performance
   data for S3 Suspend Start and S3 Suspend End in FPDT.
 
@@ -90,19 +91,27 @@ FpdtStatusCodeListenerSmm (
   // Check whether status code is what we are interested in.
   //
   if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {
     return EFI_UNSUPPORTED;
   }
-  
+
   //
   // Collect one or more Boot records in boot time
   //
   if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {
     AcquireSpinLock (&mSmmFpdtLock);
     
     if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {
       //
+      // If SMM records have been reported to DXE driver, don't re-allocate buffer
+      // to collect the new SMM records when pre-allocate buffer is not enough.
+      //
+      if (mHaveReportedSmmRecord) {
+        ReleaseSpinLock (&mSmmFpdtLock);
+        return EFI_OUT_OF_RESOURCES;
+      }
+      //
       // Try to allocate big SMRAM data to store Boot record. 
       //
       if (mSmramIsOutOfResource) {
         ReleaseSpinLock (&mSmmFpdtLock);
         return EFI_OUT_OF_RESOURCES;
@@ -237,10 +246,11 @@ FpdtSmiHandler (
 
   Status = EFI_SUCCESS;
 
   switch (SmmCommData->Function) {
     case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :
+      mHaveReportedSmmRecord      = TRUE;
       SmmCommData->BootRecordSize = mBootRecordSize;
       break;
 
     case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA :
       Status = EFI_UNSUPPORTED;
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel