From 9280f16345755708ebd9553b3caee077ade0e592 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Tue, 17 Jun 2025 15:26:47 -0700 Subject: [PATCH] UefiPayloadPkg: Don't Allocate Page 0 UefiPayloadPkg has copied the MdeModulePkg DxeIpl behavior to create a memory allocation HOB for page 0. That is being changed (see that commit for details), so also remove it here. Signed-off-by: Oliver Smith-Denny --- .../UefiPayloadEntry/Ia32/DxeLoadFunc.c | 8 --- .../UefiPayloadEntry/Ia32/DxeLoadFuncFit.c | 8 --- .../UefiPayloadEntry/X64/DxeLoadFunc.c | 8 --- .../UefiPayloadEntry/X64/DxeLoadFuncFit.c | 8 --- .../UefiPayloadEntry/X64/VirtualMemory.c | 66 ------------------- 5 files changed, 98 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c index 6009232524..3391da8446 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c +++ b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c @@ -280,14 +280,6 @@ HandOffToDxeCore ( IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF); IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF); - // - // Clear page 0 and mark it as allocated if NULL pointer detection is enabled. - // - if (IsNullDetectionEnabled ()) { - ClearFirst4KPage (HobList.Raw); - BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData); - } - BaseOfStack = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); ASSERT (BaseOfStack != 0); diff --git a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c index 439d5bee0b..d0f3143004 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c +++ b/UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFuncFit.c @@ -278,14 +278,6 @@ HandOffToDxeCore ( IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF); IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF); - // - // Clear page 0 and mark it as allocated if NULL pointer detection is enabled. - // - if (IsNullDetectionEnabled ()) { - ClearFirst4KPage (HobList.Raw); - BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData); - } - BaseOfStack = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE)); ASSERT (BaseOfStack != 0); diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c b/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c index 6c3603f120..6672740e47 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c @@ -52,14 +52,6 @@ HandOffToDxeCore ( IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF); IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF); - // - // Clear page 0 and mark it as allocated if NULL pointer detection is enabled. - // - if (IsNullDetectionEnabled ()) { - ClearFirst4KPage (HobList.Raw); - BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData); - } - // // Allocate 128KB for the Stack // diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFuncFit.c b/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFuncFit.c index 35b52a911d..37528d5fe2 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFuncFit.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFuncFit.c @@ -53,14 +53,6 @@ HandOffToDxeCore ( IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF); IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF); - // - // Clear page 0 and mark it as allocated if NULL pointer detection is enabled. - // - if (IsNullDetectionEnabled ()) { - ClearFirst4KPage (HobList.Raw); - BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData); - } - // // Allocate 128KB for the Stack // diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c index bfe1ba4d02..9e45ef31d9 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -37,72 +37,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // PAGE_TABLE_POOL *mPageTablePool = NULL; -/** - Clear legacy memory located at the first 4K-page, if available. - - This function traverses the whole HOB list to check if memory from 0 to 4095 - exists and has not been allocated, and then clear it if so. - - @param HobStart The start of HobList passed to DxeCore. - -**/ -VOID -ClearFirst4KPage ( - IN VOID *HobStart - ) -{ - EFI_PEI_HOB_POINTERS RscHob; - EFI_PEI_HOB_POINTERS MemHob; - BOOLEAN DoClear; - - RscHob.Raw = HobStart; - MemHob.Raw = HobStart; - DoClear = FALSE; - - // - // Check if page 0 exists and free - // - while ((RscHob.Raw = GetNextHob ( - EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, - RscHob.Raw - )) != NULL) - { - if ((RscHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && - (RscHob.ResourceDescriptor->PhysicalStart == 0)) - { - DoClear = TRUE; - // - // Make sure memory at 0-4095 has not been allocated. - // - while ((MemHob.Raw = GetNextHob ( - EFI_HOB_TYPE_MEMORY_ALLOCATION, - MemHob.Raw - )) != NULL) - { - if (MemHob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress - < EFI_PAGE_SIZE) - { - DoClear = FALSE; - break; - } - - MemHob.Raw = GET_NEXT_HOB (MemHob); - } - - break; - } - - RscHob.Raw = GET_NEXT_HOB (RscHob); - } - - if (DoClear) { - DEBUG ((DEBUG_INFO, "Clearing first 4K-page!\r\n")); - SetMem (NULL, EFI_PAGE_SIZE, 0); - } - - return; -} - /** Return configure status of NULL pointer detection feature.