summaryrefslogtreecommitdiffstats
path: root/IntelFrameworkModulePkg
diff options
context:
space:
mode:
authorStar Zeng <star.zeng@intel.com>2015-09-30 04:30:34 +0000
committerlzeng14 <lzeng14@Edk2>2015-09-30 04:30:34 +0000
commit201d2d21bdc88f85d85f30cd92d6d00b7e25301c (patch)
tree324e7bb45f36cee8bcdc0f3f8b685e4d3cfae7a4 /IntelFrameworkModulePkg
parent2f931dda52dc6e20643c0842acf18c9f0b5a0097 (diff)
downloadedk2-201d2d21bdc88f85d85f30cd92d6d00b7e25301c.tar.gz
edk2-201d2d21bdc88f85d85f30cd92d6d00b7e25301c.tar.bz2
edk2-201d2d21bdc88f85d85f30cd92d6d00b7e25301c.zip
IntelFrameworkModulePkg GenericBdsLib: Do not assume perf entry count has no change
Current implementation assumes the performance entry count has no change from multiple GetPerformanceMeasurement() while loops, it may cause the allocated buffer for PerfEntriesAsDxeHandle at the first loop to be overflowed if the following loop has the count changed. This patch is also to sync the change at commit R18417 "MdeModulePkg: Fix a performance data buffer overrun issue". Cc: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18562 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg')
-rw-r--r--IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c111
1 files changed, 33 insertions, 78 deletions
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
index 78039e79a5..e50345a597 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c
@@ -168,13 +168,8 @@ WriteBootToOsPerformanceData (
UINT64 StartValue;
UINT64 EndValue;
BOOLEAN CountUp;
- UINTN EntryIndex;
- UINTN NumPerfEntries;
- //
- // List of flags indicating PerfEntry contains DXE handle
- //
- BOOLEAN *PerfEntriesAsDxeHandle;
UINTN VarSize;
+ BOOLEAN Found;
//
// Record the performance data for End of BDS
@@ -203,6 +198,11 @@ WriteBootToOsPerformanceData (
CountUp = FALSE;
}
+ //
+ // Reset the entry count
+ //
+ mPerfHeader.Count = 0;
+
if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
Status = gRT->GetVariable (
@@ -238,73 +238,10 @@ WriteBootToOsPerformanceData (
Ptr = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER));
LimitCount = (UINT32) (PERF_DATA_MAX_LENGTH - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
- NumPerfEntries = 0;
- LogEntryKey = 0;
- while ((LogEntryKey = GetPerformanceMeasurement (
- LogEntryKey,
- &Handle,
- &Token,
- &Module,
- &StartTicker,
- &EndTicker)) != 0) {
- NumPerfEntries++;
- }
- PerfEntriesAsDxeHandle = AllocateZeroPool (NumPerfEntries * sizeof (BOOLEAN));
- ASSERT (PerfEntriesAsDxeHandle != NULL);
-
- //
- // Get DXE drivers performance
- //
- for (Index = 0; Index < NoHandles; Index++) {
- Ticker = 0;
- LogEntryKey = 0;
- EntryIndex = 0;
- while ((LogEntryKey = GetPerformanceMeasurement (
- LogEntryKey,
- &Handle,
- &Token,
- &Module,
- &StartTicker,
- &EndTicker)) != 0) {
- if (Handle == Handles[Index] && !PerfEntriesAsDxeHandle[EntryIndex]) {
- PerfEntriesAsDxeHandle[EntryIndex] = TRUE;
- }
- EntryIndex++;
- if ((Handle == Handles[Index]) && (EndTicker != 0)) {
- if (StartTicker == 1) {
- StartTicker = StartValue;
- }
- if (EndTicker == 1) {
- EndTicker = StartValue;
- }
- Ticker += CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
- }
- }
-
- Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
-
- if (Duration > 0) {
-
- GetNameFromHandle (Handles[Index], GaugeString);
-
- AsciiStrCpyS (mPerfData.Token, PERF_TOKEN_SIZE, GaugeString);
- mPerfData.Duration = Duration;
-
- CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
- Ptr += sizeof (PERF_DATA);
-
- mPerfHeader.Count++;
- if (mPerfHeader.Count == LimitCount) {
- goto Done;
- }
- }
- }
-
//
- // Get inserted performance data
+ // Get performance data
//
LogEntryKey = 0;
- EntryIndex = 0;
while ((LogEntryKey = GetPerformanceMeasurement (
LogEntryKey,
&Handle,
@@ -312,11 +249,7 @@ WriteBootToOsPerformanceData (
&Module,
&StartTicker,
&EndTicker)) != 0) {
- if (!PerfEntriesAsDxeHandle[EntryIndex] && EndTicker != 0) {
-
- ZeroMem (&mPerfData, sizeof (PERF_DATA));
-
- AsciiStrnCpyS (mPerfData.Token, PERF_TOKEN_SIZE, Token, PERF_TOKEN_LENGTH);
+ if (EndTicker != 0) {
if (StartTicker == 1) {
StartTicker = StartValue;
}
@@ -325,7 +258,31 @@ WriteBootToOsPerformanceData (
}
Ticker = CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
- mPerfData.Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
+ Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
+ if (Duration == 0) {
+ continue;
+ }
+
+ ZeroMem (&mPerfData, sizeof (PERF_DATA));
+
+ mPerfData.Duration = Duration;
+
+ //
+ // See if the Handle is in the handle buffer
+ //
+ Found = FALSE;
+ for (Index = 0; Index < NoHandles; Index++) {
+ if (Handle == Handles[Index]) {
+ GetNameFromHandle (Handles[Index], GaugeString);
+ AsciiStrCpyS (mPerfData.Token, PERF_TOKEN_SIZE, GaugeString);
+ Found = TRUE;
+ break;
+ }
+ }
+
+ if (!Found) {
+ AsciiStrnCpyS (mPerfData.Token, PERF_TOKEN_SIZE, Token, PERF_TOKEN_LENGTH);
+ }
CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
Ptr += sizeof (PERF_DATA);
@@ -335,13 +292,11 @@ WriteBootToOsPerformanceData (
goto Done;
}
}
- EntryIndex++;
}
Done:
FreePool (Handles);
- FreePool (PerfEntriesAsDxeHandle);
mPerfHeader.Signiture = PERFORMANCE_SIGNATURE;