soc/amd/common/pi: Fix issue in AGESA heap allocator

The heap allocator would try to split a buffer node that
was too small for another node. In the failing case, the buffer
node was 0x140 bytes and the requested size was 0x133 bytes.
The logic would check that there was room for the header and
buffer and try to split the buffer node. The buffer node header
is 0xC bytes, so 0x13F bytes are need. The problem is that it didn't
leave room for another node header and a little space for a buffer.

BUG=b:71764350
TEST= Boot grunt.
BRANCH=none

Change-Id: Iece5e12d5787415a335bb953985331a5dc312152
Signed-off-by: Marc Jones <marcj303@gmail.com>
Reviewed-on: https://review.coreboot.org/23211
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martinroth@google.com>
Reviewed-by: Daniel Kurtz <djkurtz@google.com>
This commit is contained in:
Marc Jones 2018-01-10 16:41:46 -08:00 committed by Marc Jones
parent 3441292ecd
commit ca966f9a2d
2 changed files with 7 additions and 4 deletions

View File

@ -34,6 +34,8 @@ typedef struct _BIOS_BUFFER_NODE {
UINT32 NextNodeOffset;
} BIOS_BUFFER_NODE;
#define MIN_BUFFER_NODE_SIZE (sizeof(BIOS_BUFFER_NODE) + sizeof(uint32_t))
AGESA_STATUS agesa_AllocateBuffer(UINT32 Func, UINTN Data, VOID *ConfigPtr);
AGESA_STATUS agesa_DeallocateBuffer(UINT32 Func, UINTN Data, VOID *ConfigPtr);
AGESA_STATUS agesa_LocateBuffer(UINT32 Func, UINTN Data, VOID *ConfigPtr);

View File

@ -159,11 +159,12 @@ AGESA_STATUS agesa_AllocateBuffer (UINT32 Func, UINTN Data, VOID *ConfigPtr)
BestFitPrevNodeOffset);
/*
* If BestFitNode is larger than the requested buffer,
* fragment the node further
* If BestFitNode is larger than the requested buffer and
* has room for another buffer node, fragment the node further.
*/
if (BestFitNodePtr->BufferSize >
(AllocParams->BufferLength + sizeof(BIOS_BUFFER_NODE))) {
if (BestFitNodePtr->BufferSize >=
(AllocParams->BufferLength + sizeof(BIOS_BUFFER_NODE) +
MIN_BUFFER_NODE_SIZE)) {
NextFreeOffset = BestFitNodeOffset +
AllocParams->BufferLength +
sizeof(BIOS_BUFFER_NODE);