Skip to content

[REBASE & FF] [CHERRY-PICK] Cherry-Pick PEI Memory Bins Commits#1838

Merged
os-d merged 30 commits into
microsoft:release/202511from
os-d:cp_pei_bins
Jun 26, 2026
Merged

[REBASE & FF] [CHERRY-PICK] Cherry-Pick PEI Memory Bins Commits#1838
os-d merged 30 commits into
microsoft:release/202511from
os-d:cp_pei_bins

Conversation

@os-d

@os-d os-d commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

PEI memory bins has been merged in edk2. This reverts the Mu changes and pulls in the edk2 commits. It also cherry-picks some other related commits that had been upstreamed to edk2 but not pulled down to Mu related to memory bins.

Finally, the resource descriptor HOB v2 change needed to be reverted and reapplied so the logic would go in the correct spot with the PEI memory bins changes.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Booting patina-qemu to shell and confirming PEI memory bins worked and are inherited in DXE.

Integration Instructions

N/A.

@os-d os-d requested review from apop5, kuqin12 and makubacki June 25, 2026 17:58
@mu-automation

mu-automation Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

❌ QEMU Validation Failed

Source Dependencies

Repository Commit
mu_basecore 880e892
mu_tiano_platforms 7c3c4bb

Results

Platform Target Build Boot Overall Boot Time Build Logs Boot Logs
Q35 DEBUG ❌ failure ⏩ skipped N/A Build Logs N/A
ArmVirt DEBUG ✅ success ✅ success 0m 15s Build Logs Boot Logs

Workflow run: https://github.com/microsoft/mu_basecore/actions/runs/28244324279

This comment was automatically generated by the Mu QEMU PR Validation workflow.

@codecov-commenter

codecov-commenter commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.80597% with 82 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/202511@cb410d0). Learn more about missing BASE report.

Files with missing lines Patch % Lines
MdeModulePkg/Core/Pei/Memory/MemoryBin.c 0.00% 58 Missing ⚠️
MdeModulePkg/Core/Dxe/Mem/Page.c 0.00% 17 Missing ⚠️
MdeModulePkg/Core/Dxe/Mem/MemoryBin.c 91.22% 3 Missing and 2 partials ⚠️
MdeModulePkg/Core/Pei/Memory/MemoryServices.c 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             release/202511    #1838   +/-   ##
=================================================
  Coverage                  ?    1.88%           
=================================================
  Files                     ?     1157           
  Lines                     ?   377893           
  Branches                  ?     3295           
=================================================
  Hits                      ?     7129           
  Misses                    ?   370699           
  Partials                  ?       65           
Flag Coverage Δ
FmpDevicePkg 9.53% <ø> (?)
MdeModulePkg 1.65% <38.80%> (?)
NetworkPkg 0.55% <ø> (?)
PolicyServicePkg 30.42% <ø> (?)
SecurityPkg 1.56% <ø> (?)
UefiCpuPkg 4.78% <ø> (?)
UnitTestFrameworkPkg 11.70% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@makubacki

Copy link
Copy Markdown
Member

@os-d, I assume you saw the Uncrustify errors?

@os-d

os-d commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@os-d, I assume you saw the Uncrustify errors?

Yes, just pushed the fix and also made sure the PEI MemoryBin.c had the resc desc hob v2 change.

@os-d

os-d commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

This is going to fail the QEMU validation until microsoft/mu_plus#909 merges. I will hold it until then.

os-d and others added 18 commits June 26, 2026 07:15
This reverts commit d210225 as it
has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit 59002db as it
has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit ae6343c as it
has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit bd8c2bb as it
has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit c2a07d5 as it
was removed in upstreaming.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
…d()"

This reverts commit 8bc20a2 as it
has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit 906650b as
it has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit e248a90
as it has been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
…source descriptor hobs (microsoft#1549)"

This reverts commit c0ab3a2 as it has
been upstreamed to edk2.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
…icrosoft#1258)"

This reverts commit 221fa7a to apply
it on top of the PEI memory bin changes so it lands in the correct
places.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
…urce hob memory top

Current GCD logic uses plain addition calulation when iterating through
the resource descriptor hobs. However, if the resource descriptor is
incorrectly prepared, this could cause incorrect memory initialization
and other failures down the boot process.

This change adds an overflow check before using the value.

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
(cherry picked from commit 5be1bcc)
…ries

Fix alignment issues in memory map entries returned by
GetMemoryMap() when RUNTIME_PAGE_ALLOCATION_GRANULARITY is
larger than DEFAULT_PAGE_ALLOCATION_GRANULARITY.

Alignment issues are addressed in the initial memory map
layout when Memory Type Information is provided with memory
bins that use RUNTIME_PAGE_ALLOCATION_GRANULARITY.

There are no issues in the Page/Pool Allocation/Free services.

* CoreSetMemoryTypeInformationRange() make sure there is room
  for all bins when accounting for alignment requirements.
  Allocate space for bins with base and length following
  alignment requirements.

* CoreSetMemoryTypeInformationRange() round up NumberOfPages in
  Memory Type Information based on alignment requirements.
  This is required so GetMemoryMap() will generate memory
  map entries that always follow alignment requirements.

* CoreAddMemoryDescriptor() round up NumberOfPages in
  Memory Type Information based on alignment requirements.
  This is required so GetMemoryMap() will generate memory
  map entries that always follow alignment requirements.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
(cherry picked from commit 6834d43)
… Issues

Fix alignment issues in memory map entries returned by
GetMemoryMap() when RUNTIME_PAGE_ALLOCATION_GRANULARITY is
larger than DEFAULT_PAGE_ALLOCATION_GRANULARITY.

There are no issues in the Page/Pool Allocation/Free services.

Logic issues issues are addressed in the memory map returned
by GetMemoryMap() due to missing cases for memory map entries
of type EfiConventionalMemory that overlap special memory bins.
Add logic to handle all possible memory map splits required to
convert internal memory map entries into an EFI Memory Map with
EFI Memory Map entries the follow alignment requirements when
the EFI Memory Map entries cover memory bins.

The four cases that must be handled are:
* Memory map entry contained within a bin.    [Already covered]
  Convert memory map entry type
* Memory map entry overlaps beginning of bin. [Added]
  Split memory map entry at beginning of bin.
* Memory map entry overlaps end of bin.       [Added]
  Split memory map entry at end of bin.
* Memory map entry overlaps entire bin.       [Added]
  Split memory map entry at both ends of bin.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
(cherry picked from commit d419725)
…e Calc

Currently CalculateTotalMemoryBinSizeNeeded() does not take
runtime alignment granularity considerations into account. This
means that the GCD initialization code can choose resource desc
HOBs to use for the bin region that are actually too small and
fail to initialize the bins.

This fixes CalculateTotalMemoryBinSizeNeeded() to take the
alignment requirements into consideration, both for size and for
alignment of the bin address range.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 2be91af0cc5881e5cca63545ae7a4abe03ab76a0)
…Needed()

CoreSetMemoryTypeInformationRange() currently calculates the bin
size needed independently from the CalculateTotalMemoryBinSizeNeeded()
function. This commit updates to use that function and remove the
duplication.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit ab3097d457ac1e284ffcaded9d83a7687c65cc13)
Currently, there is no guarantee that the memory bins will be
allocated contiguously. However, there are assumptions in the
code that bins are allocated contiguously, such as the GCD
init code requiring a free memory region be large enough for
a contiguous bin range on DXE Core init.

Ensuring contiguous bins also makes a cleaner model for the
bins and keeps the memory map in a more standard configuration
between different configurations, as platforms today can
pass a resource descriptor HOB to DXE core to describe the bin
range and this only supports a contiguous range.

This also sets up reusing the memory bin logic for PEI memory
bin support which will use the aforementioned resource descriptor
HOB to pass the bin range to DXE.

This commit updates CoreAddMemoryDescriptor() to
allocate a contiguous range.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit d93ad5f525e5a994a0b51fb46bea5fe8c0bbb98e)
In preparation for sharing memory bin logic between
PEI and DXE, update CaclulateTotalMemoryBinSizeNeeded()
to take gMemoryTypeInformation by reference.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit b2c33619f76fc3aff547db9ee410c8f91da8395a)
…tion Helper

In preparation for supporting shared memory bin logic in DXE
and PEI, create a PopulateMemoryTypeInformation() helper function.
This function searches for a Memory Type Information Hob and
populates an EFI_MEMORY_TYPE_INFORMATION struct with it.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit d77628d4c1bf410eb86c5994389a19d9f43de197)
os-d and others added 12 commits June 26, 2026 07:15
…urceHob Helper

In preparation for sharing memory bin logic with PEI, create a
helper function that finds and validates a resource descriptor
HOB owned by gEfiMemoryTypeInformationGuid.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 1c8c92b7cc24be5f88b2685b87371facba9bd8ac)
In preparation for sharing logic with PEI for memory bins,
add AllocateMemoryTypeInformationBins().

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 47e73e61c6eaca1c611c9ba19eb5a92f16139613)
…er Fn

In preparation for sharing logic with PEI, create a helper
function to update the memory bin statistics.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 6b838a0d44edcf95c4edfa12212e19c7b79ab721)
…onRange for PEI

Migrate CoreSetMemoryTypeInformationRange() to not use globals so
it can be used in PEI as well.

This temporarily moves the EFI_MEMORY_STATISTICS structure to
DxeMain.h so that it can be used in Gcd.c as well as Page.c.
This will migrate to a different private header once that is included.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 81bec6f0fbf686fa94b193eb16cba4729dfbc98b)
This adds a helper function to initialize the
memory bin statistics as the same logic is
repeated in several places.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit b33c1b9f7d00e1b06910385dcfac2174f2f081f9)
This commit adds a parameter to the memory bin allocation function
to tell it whether it should create the Resource Descriptor HOB
owned by gMemoryTypeInformationGuid. This will be used by PEI to
tell DXE where the memory bins are.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit a196ef6db5c77708dde3528dc735494037f16ab3)
…arate File

This commits splits out logic currently contained in
Gcd.c and Page.c to a new file called
MemoryBin.c. This is set up in preparation to
add support to PEI for memory bins (an S4 resume stability
feature).

MemoryBin.c takes all global state in as parameters so that
DXE core can use globals and PEI core can use HOBs.

There is no logic change here, just consolidating the
functionality to share with PEI.

This was requested not to be a library.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit eab3300622876b674cf22c5c56f899b0a6df1087)
This adds a PCD, FALSE by default, that enables the memory
bin feature in PEI.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 840d07abb15a722f47bfd9151681207246b71573)
…em PEI

This commit adds opt-in support for post-mem PEI memory bins.
See the README for full details.

MemoryBin.c is duplicated to PeiCore per request.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 2e7aa4810bd3e4008e561f2ea5a9de1dc189c817)
If memory bins are enabled for PEI, PEI will produce
Memory Allocation HOBs marked with gEfiMemoryTypeInformationGuid.
If these exist, DXE core will now process the stats from them
to have accurate numbers.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit cf1a2a541e1fa19a0117a952fece30de1928caae)
This commit adds unit tests and documentation for the Memory Bin
feature.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
(cherry picked from commit 1b39cb1d816a870a44fbeeaaf092773b1b08b179)
…age (microsoft#1258)

This change adds the implementation of supporting "resource descriptor
hob type 2", which will extends the existing definition of resource
descriptor hob with an attribute field.

This field can be used to provide the actual attributes needs to be set
for the memory region, instead of relying on the state of the system.

- [x] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?
- [ ] Backport to release branch?

This change was tested on QEMU Q35 and SBSA systems and booted to
Windows.

For platforms needing to propagate specific memory attributes
(especially the cache attributes) to the DXE phase,
`BuildResourceDescriptorWithCacheHob` should be used to produce resource
descriptors (v2).

(cherry picked from commit 221fa7a)
@os-d os-d merged commit f11f110 into microsoft:release/202511 Jun 26, 2026
90 checks passed
@os-d os-d deleted the cp_pei_bins branch June 26, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants