From 5abeae3c091ca9421c29c1ba03d25e814a5f398c Mon Sep 17 00:00:00 2001 From: ddeptford <136014411+ddeptford@users.noreply.github.com> Date: Fri, 7 Jul 2023 08:49:45 -0700 Subject: [PATCH] MdeModulePkg: UefiBootManagerLib: Change default alignment for ramdisk boot The ramdisk is modelled as an NVDIMM which have a naturally higher alignment than 4K. Operating systems may wish to map NVDIMMs using large pages, so force the allocation alignment to 2MB. This change was tested using HTTP ramdisk boot, targeting a flat windows image. Signed-off-by: Kun Qin --- MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index 7a97f7cdcc..4986f9b598 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1398,7 +1398,8 @@ BmDestroyRamDisk ( Status = mRamDisk->Unregister (RamDiskDevicePath); ASSERT_EFI_ERROR (Status); - FreePages (RamDiskBuffer, RamDiskSizeInPages); + // MU_CHANGE - Ramdisk is now allocated with alignment. + FreeAlignedPages (RamDiskBuffer, RamDiskSizeInPages); } /** @@ -1446,10 +1447,17 @@ BmExpandLoadFile ( return DuplicateDevicePath (DevicePathFromHandle (LoadFileHandle)); } + // MU_CHANGE [BEGIN] - Ramdisk is now allocated with 2MB alignment. + // // The load option resides in a RAM disk. + // Use a reasonable default of 2MB for alignment as the ramdisk device is + // implemented as an NVDIMM persistent memory and operating systems may + // wish to map this with huge page support. // - FileBuffer = AllocateReservedPages (EFI_SIZE_TO_PAGES (BufferSize)); + + FileBuffer = AllocateAlignedReservedPages (EFI_SIZE_TO_PAGES (BufferSize), SIZE_2MB); + // MU_CHANGE [END] - Ramdisk is now allocated with 2MB alignment. if (FileBuffer == NULL) { DEBUG_CODE_BEGIN (); EFI_DEVICE_PATH *LoadFilePath; @@ -1490,7 +1498,8 @@ BmExpandLoadFile ( Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer); if (EFI_ERROR (Status)) { - FreePages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize)); + // MU_CHANGE - Ramdisk is now allocated with alignment. + FreeAlignedPages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize)); return NULL; }