Revision: 14654
          http://sourceforge.net/p/edk2/code/14654
Author:   vanjeff
Date:     2013-09-11 03:36:59 +0000 (Wed, 11 Sep 2013)
Log Message:
-----------
Sync patch r14386 from main trunk.
Move the memory allocation and variable set to BdsEntry, use VariableLock 
protocol to lock the L?\226?\128?\157PerfDataMemAddr?\226?\128?\157 variable 
and prevent malware to update it.

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/14386

Modified Paths:
--------------
    branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
    
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
    
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
    branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
    branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
    branches/UDK2010.SR1/MdeModulePkg/Include/Guid/Performance.h

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
===================================================================
--- 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c    
    2013-09-11 03:33:55 UTC (rev 14653)
+++ 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c    
    2013-09-11 03:36:59 UTC (rev 14654)
@@ -1,7 +1,7 @@
 /** @file
   BDS Lib functions which relate with create or process the boot option.
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2013, 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
@@ -634,10 +634,6 @@
   LIST_ENTRY                TempBootLists;
   EFI_BOOT_LOGO_PROTOCOL    *BootLogo;
 
-  PERF_CODE (
-    AllocateMemoryForPerformanceData ();
-  );
-
   *ExitDataSize = 0;
   *ExitData     = NULL;
 

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
===================================================================
--- 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
 2013-09-11 03:33:55 UTC (rev 14653)
+++ 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
 2013-09-11 03:36:59 UTC (rev 14654)
@@ -85,16 +85,6 @@
 
 /**
 
-  Allocates a block of memory to store performance data.
-
-**/
-VOID
-AllocateMemoryForPerformanceData (
-  VOID
-  );
-
-/**
-
   Writes performance data of booting into the allocated memory.
   OS can process these records.
 

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
===================================================================
--- 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
    2013-09-11 03:33:55 UTC (rev 14653)
+++ 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
    2013-09-11 03:36:59 UTC (rev 14654)
@@ -3,7 +3,7 @@
   performance, all the function will only include if the performance
   switch is set.
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2013, 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
@@ -19,7 +19,6 @@
 PERF_HEADER               mPerfHeader;
 PERF_DATA                 mPerfData;
 EFI_PHYSICAL_ADDRESS      mAcpiLowMemoryBase = 0x0FFFFFFFFULL;
-UINT32                    mAcpiLowMemoryLength = 0x4000;
 
 /**
   Get the short verion of PDB file name to be
@@ -136,40 +135,6 @@
 
 /**
 
-  Allocates a block of memory to store performance data.
-
-**/
-VOID
-AllocateMemoryForPerformanceData (
-  VOID
-  )
-{
-  EFI_STATUS    Status;
-
-  if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
-    //
-    // Allocate a block of memory that contain performance data to OS
-    //
-    Status = gBS->AllocatePages (
-                    AllocateMaxAddress,
-                    EfiReservedMemoryType,
-                    EFI_SIZE_TO_PAGES (mAcpiLowMemoryLength),
-                    &mAcpiLowMemoryBase
-                    );
-    if (!EFI_ERROR (Status)) {
-      gRT->SetVariable (
-             L"PerfDataMemAddr",
-             &gPerformanceProtocolGuid,
-             EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
-             sizeof (EFI_PHYSICAL_ADDRESS),
-             &mAcpiLowMemoryBase
-             );
-    }
-  }
-}
-
-/**
-
   Writes performance data of booting into the allocated memory.
   OS can process these records.
 
@@ -209,16 +174,13 @@
   // List of flags indicating PerfEntry contains DXE handle
   //
   BOOLEAN                   *PerfEntriesAsDxeHandle;
+  UINTN                     VarSize;
 
   //
   // Record the performance data for End of BDS
   //
   PERF_END(NULL, "BDS", NULL, 0);
 
-  if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
-    return;
-  }
-
   //
   // Retrieve time stamp count as early as possible
   //
@@ -241,6 +203,23 @@
     CountUp            = FALSE;
   }
 
+  if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
+    VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
+    Status = gRT->GetVariable (
+                    L"PerfDataMemAddr",
+                    &gPerformanceProtocolGuid,
+                    NULL,
+                    &VarSize,
+                    &mAcpiLowMemoryBase
+                    );
+    if (EFI_ERROR (Status)) {
+      //
+      // Fail to get the variable, return.
+      //
+      return;
+    }
+  }
+
   //
   // Put Detailed performance data into memory
   //
@@ -257,7 +236,7 @@
   }
 
   Ptr        = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER));
-  LimitCount = (mAcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof 
(PERF_DATA);
+  LimitCount = (UINT32) (PERF_DATA_MAX_LENGTH - sizeof (PERF_HEADER)) / sizeof 
(PERF_DATA);
 
   NumPerfEntries = 0;
   LogEntryKey    = 0;

Modified: branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
===================================================================
--- branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h 
2013-09-11 03:33:55 UTC (rev 14653)
+++ branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h 
2013-09-11 03:36:59 UTC (rev 14654)
@@ -35,6 +35,7 @@
 #include <Guid/LegacyDevOrder.h>
 #include <Guid/BdsHii.h>
 #include <Guid/ConnectConInEvent.h>
+#include <Guid/Performance.h>
 #include <Protocol/GenericMemoryTest.h>
 #include <Protocol/FormBrowser2.h>
 #include <Protocol/HiiConfigAccess.h>
@@ -66,7 +67,6 @@
 #include <Library/CapsuleLib.h>
 #include <Library/HiiLib.h>
 #include <Library/DevicePathLib.h>
-#include <Library/PcdLib.h>
 #include <Library/UefiHiiServicesLib.h>
 
 #include <Library/GenericBdsLib.h>

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
===================================================================
--- branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c    
2013-09-11 03:33:55 UTC (rev 14653)
+++ branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c    
2013-09-11 03:36:59 UTC (rev 14654)
@@ -452,6 +452,54 @@
 
 /**
 
+  Allocate a block of memory that will contain performance data to OS.
+
+**/
+VOID
+BdsAllocateMemoryForPerformanceData (
+  VOID
+  )
+{
+  EFI_STATUS                    Status;
+  EFI_PHYSICAL_ADDRESS          AcpiLowMemoryBase;
+  EDKII_VARIABLE_LOCK_PROTOCOL  *VariableLock;
+
+  AcpiLowMemoryBase = 0x0FFFFFFFFULL;
+
+  //
+  // Allocate a block of memory that will contain performance data to OS.
+  //
+  Status = gBS->AllocatePages (
+                  AllocateMaxAddress,
+                  EfiReservedMemoryType,
+                  EFI_SIZE_TO_PAGES (PERF_DATA_MAX_LENGTH),
+                  &AcpiLowMemoryBase
+                  );
+  if (!EFI_ERROR (Status)) {
+    //
+    // Save the pointer to variable for use in S3 resume.
+    //
+    Status = gRT->SetVariable (
+               L"PerfDataMemAddr",
+               &gPerformanceProtocolGuid,
+               EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
+               sizeof (EFI_PHYSICAL_ADDRESS),
+               &AcpiLowMemoryBase
+               );
+    ASSERT_EFI_ERROR (Status);
+    //
+    // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock 
protocol exists
+    //
+    Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID 
**) &VariableLock);
+    if (!EFI_ERROR (Status)) {
+      Status = VariableLock->RequestToLock (VariableLock, L"PerfDataMemAddr", 
&gPerformanceProtocolGuid);
+      ASSERT_EFI_ERROR (Status);
+    }
+  }
+}
+
+/**
+
   Service routine for BdsInstance->Entry(). Devices are connected, the
   consoles are initialized, and the boot options are tried.
 
@@ -479,6 +527,10 @@
   PERF_END (NULL, "DXE", NULL, 0);
   PERF_START (NULL, "BDS", NULL, 0);
 
+  PERF_CODE (
+    BdsAllocateMemoryForPerformanceData ();
+  );
+
   //
   // Initialize the global system boot option and driver option
   //

Modified: branches/UDK2010.SR1/MdeModulePkg/Include/Guid/Performance.h
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Include/Guid/Performance.h        
2013-09-11 03:33:55 UTC (rev 14653)
+++ branches/UDK2010.SR1/MdeModulePkg/Include/Guid/Performance.h        
2013-09-11 03:36:59 UTC (rev 14654)
@@ -4,7 +4,7 @@
   * performance protocol interfaces.
   * performance variables.  
 
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2013, 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 that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -48,6 +48,7 @@
 #define PERF_TOKEN_SIZE         28
 #define PERF_TOKEN_LENGTH       (PERF_TOKEN_SIZE - 1)
 #define PERF_PEI_ENTRY_MAX_NUM  50
+#define PERF_DATA_MAX_LENGTH    0x4000
 
 typedef struct {
   CHAR8   Token[PERF_TOKEN_SIZE];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to