From f6c07313d1f7317c328e9ef80cfb272beec0a249 Mon Sep 17 00:00:00 2001 From: lzeng14 Date: Thu, 23 May 2013 02:56:41 +0000 Subject: =?UTF-8?q?Move=20the=20memory=20allocation=20and=20variable=20set?= =?UTF-8?q?=20to=20BdsEntry,=20use=20VariableLock=20protocol=20to=20lock?= =?UTF-8?q?=20the=20L=E2=80=9DPerfDataMemAddr=E2=80=9D=20variable=20and=20?= =?UTF-8?q?prevent=20malware=20to=20update=20it.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Star Zeng Reviewed-by: Ruiyu Ni git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14386 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/GenericBdsLib/BdsBoot.c | 6 +-- .../Library/GenericBdsLib/InternalBdsLib.h | 10 ---- .../Library/GenericBdsLib/Performance.c | 61 +++++++--------------- IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h | 2 +- .../Universal/BdsDxe/BdsEntry.c | 52 ++++++++++++++++++ 5 files changed, 74 insertions(+), 57 deletions(-) (limited to 'IntelFrameworkModulePkg') diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c index c04c586f50..06ba0fcf79 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c @@ -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.
+Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
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 @@ -2229,10 +2229,6 @@ BdsLibBootViaBootOption ( LIST_ENTRY TempBootLists; EFI_BOOT_LOGO_PROTOCOL *BootLogo; - PERF_CODE ( - AllocateMemoryForPerformanceData (); - ); - *ExitDataSize = 0; *ExitData = NULL; diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h b/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h index 5d51635bf1..1384febc98 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h @@ -85,16 +85,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #endif #endif -/** - - Allocates a block of memory to store performance data. - -**/ -VOID -AllocateMemoryForPerformanceData ( - VOID - ); - /** Writes performance data of booting into the allocated memory. diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c index 7e6d358d84..047d2a7dbc 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c @@ -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.
+Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
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 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. PERF_HEADER mPerfHeader; PERF_DATA mPerfData; EFI_PHYSICAL_ADDRESS mAcpiLowMemoryBase = 0x0FFFFFFFFULL; -UINT32 mAcpiLowMemoryLength = 0x4000; /** Get the short verion of PDB file name to be @@ -134,40 +133,6 @@ GetNameFromHandle ( return ; } -/** - - 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. @@ -209,16 +174,13 @@ WriteBootToOsPerformanceData ( // 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 @@ WriteBootToOsPerformanceData ( 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 @@ WriteBootToOsPerformanceData ( } 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; diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h b/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h index 14996f63e6..0aba09c1bf 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h @@ -35,6 +35,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include @@ -66,7 +67,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #include #include diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c index 91c6dc72dd..77c88b0d24 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c @@ -450,6 +450,54 @@ BdsFormalizeEfiGlobalVariable ( } +/** + + 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 @@ -479,6 +527,10 @@ BdsEntry ( PERF_END (NULL, "DXE", NULL, 0); PERF_START (NULL, "BDS", NULL, 0); + PERF_CODE ( + BdsAllocateMemoryForPerformanceData (); + ); + // // Initialize the global system boot option and driver option // -- cgit v1.2.3