Skip to content

Commit 7d82a71

Browse files
Merge branch 'tianocore:master' into master
2 parents 679bf47 + 5bc52de commit 7d82a71

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c

+9-18
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,7 @@ CoreNewDebugImageInfoEntry (
177177

178178
Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
179179

180-
if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {
181-
//
182-
// We still have empty entires in the Table, find the first empty entry.
183-
//
184-
Index = 0;
185-
while (Table[Index].NormalImage != NULL) {
186-
Index++;
187-
}
188-
189-
//
190-
// There must be an empty entry in the in the table.
191-
//
192-
ASSERT (Index < mMaxTableEntries);
193-
} else {
180+
if (mDebugInfoTableHeader.TableSize >= mMaxTableEntries) {
194181
//
195182
// Table is full, so re-allocate another page for a larger table...
196183
//
@@ -218,10 +205,12 @@ CoreNewDebugImageInfoEntry (
218205
// Enlarge the max table entries and set the first empty entry index to
219206
// be the original max table entries.
220207
//
221-
Index = mMaxTableEntries;
222208
mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
223209
}
224210

211+
// We always put the next entry at the end of the currently consumed table (i.e. first free entry)
212+
Index = mDebugInfoTableHeader.TableSize;
213+
225214
//
226215
// Allocate data for new entry
227216
//
@@ -264,11 +253,13 @@ CoreRemoveDebugImageInfoEntry (
264253
for (Index = 0; Index < mMaxTableEntries; Index++) {
265254
if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) {
266255
//
267-
// Found a match. Free up the record, then NULL the pointer to indicate the slot
268-
// is free.
256+
// Found a match. Free up the record, then move the final entry down to this slot; we don't care about the
257+
// order of the array
269258
//
270259
CoreFreePool (Table[Index].NormalImage);
271-
Table[Index].NormalImage = NULL;
260+
Table[Index].NormalImage = Table[mDebugInfoTableHeader.TableSize - 1].NormalImage;
261+
Table[mDebugInfoTableHeader.TableSize - 1].NormalImage = NULL;
262+
272263
//
273264
// Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
274265
//

MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ SetUefiImageMemoryAttributes (
196196
UINT64 FinalAttributes;
197197
UINT64 CurrentAddress;
198198
UINT64 CurrentLength;
199+
UINT64 ImageEnd;
200+
UINT64 DescEnd;
199201

200202
CurrentAddress = BaseAddress;
203+
ImageEnd = BaseAddress + Length;
201204

202205
// we loop here because we may have multiple memory space descriptors that overlap the requested range
203206
// this will definitely be the case for unprotecting an image, because that calls this function for the entire image,
@@ -216,11 +219,14 @@ SetUefiImageMemoryAttributes (
216219
return;
217220
}
218221

219-
// ensure that we only change the attributes for the range that we are interested in, not the entire descriptor
220-
if (BaseAddress + Length > CurrentAddress + Descriptor.Length) {
221-
CurrentLength = Descriptor.Length;
222+
DescEnd = Descriptor.BaseAddress + Descriptor.Length;
223+
224+
// ensure that we only change the attributes for the range that we are interested in, not the entire descriptor, we
225+
// may also be in the middle of a descriptor, so ensure our length is not larger than the descriptor length
226+
if (ImageEnd > DescEnd) {
227+
CurrentLength = DescEnd - CurrentAddress;
222228
} else {
223-
CurrentLength = BaseAddress + Length - CurrentAddress;
229+
CurrentLength = ImageEnd - CurrentAddress;
224230
}
225231

226232
// Preserve the existing caching and virtual attributes, but remove the hardware access bits
@@ -291,10 +297,9 @@ SetUefiImageMemoryAttributes (
291297
}
292298
}
293299

294-
// we have CurrentLength, also, but that is just to handle the final descriptor case where we might take only
295-
// part of a descriptor, so we can use Descriptor.Length here to move to the next descriptor, which for the final
296-
// descriptor will exit the loop, regardless of whether we truncated or not
297-
CurrentAddress += Descriptor.Length;
300+
// we may have started in the middle of a descriptor, so we need to move to the beginning of the next descriptor,
301+
// or the end of the image, whichever is smaller
302+
CurrentAddress += CurrentLength;
298303
}
299304
}
300305

UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c

+5
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,10 @@ InitializeMpSyncData (
18681868
UINTN CpuIndex;
18691869

18701870
if (mSmmMpSyncData != NULL) {
1871+
if (mSmmMpSyncData->SyncContext != NULL) {
1872+
SmmCpuSyncContextDeinit (mSmmMpSyncData->SyncContext);
1873+
}
1874+
18711875
//
18721876
// mSmmMpSyncDataSize includes one structure of SMM_DISPATCHER_MP_SYNC_DATA, one
18731877
// CpuData array of SMM_CPU_DATA_BLOCK and one CandidateBsp array of BOOLEAN.
@@ -1968,6 +1972,7 @@ InitializeMpServiceData (
19681972
mSmmMpSyncData = (SMM_DISPATCHER_MP_SYNC_DATA *)AllocatePages (EFI_SIZE_TO_PAGES (mSmmMpSyncDataSize));
19691973
ASSERT (mSmmMpSyncData != NULL);
19701974

1975+
ZeroMem (mSmmMpSyncData, mSmmMpSyncDataSize);
19711976
RelaxedMode = FALSE;
19721977
GetSmmCpuSyncConfigData (&RelaxedMode, NULL, NULL);
19731978
mCpuSmmSyncMode = RelaxedMode ? MmCpuSyncModeRelaxedAp : MmCpuSyncModeTradition;

0 commit comments

Comments
 (0)