Skip to content

Commit

Permalink
Change default alignment for ramdisk booting. (#480)
Browse files Browse the repository at this point in the history
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.

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [X] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
  - Alignment of ramdisk is changed from 4KB to 2MB.
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

This change was tested using HTTP ramdisk boot, targeting a flat windows
image.

## Integration Instructions

N/A
  • Loading branch information
ddeptford authored and kenlautner committed Dec 16, 2023
1 parent 9577713 commit 1d4a877
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 @@ -1435,7 +1435,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 @@ -1483,10 +1484,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 @@ -1527,7 +1535,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 1d4a877

Please sign in to comment.