Skip to content

Commit

Permalink
MdeModulePkg: UefiBootManagerLib: Change default alignment for ramdis…
Browse files Browse the repository at this point in the history
…k 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 <[email protected]>
  • Loading branch information
ddeptford authored and os-d committed Jun 24, 2024
1 parent b91a0b3 commit 5abeae3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5abeae3

Please sign in to comment.