Skip to content

patina-v21.1.1

Choose a tag to compare

@github-actions github-actions released this 29 May 22:07
· 96 commits to refs/heads/main since this release
e9d665e

What's Changed

  • Add PEI memory bin support [Rebase \& FF] @makubacki (#1486)
    Change Details
      ## Description

    Closes #1175

    A few small commits for miscellaneous changes followed by the main commit for PEI memory bins.


    sdk: Derive Clone and Copy for EFiMemoryTypeInformation

    Allow EfiMemoryTypeInformation to be easily duplicated, as it is a simple struct containing only Copy types.


    sdk: Add EFI_MAX_MEMORY_TYPE and INVALID_INFORMATION_INDEX constants

    Provide a stable constant to represent the maximum valid EFI memory instead of hardcoding the value based on the last valid memory type.

    INVALID_INFORMATION_INDEX is added as a sentinel value to indicate an invalid memory type index in the memory type information table.


    sdk: Add page_shift_from_alignment() to base.rs

    Adds the following helper for working with page operations:

    • page_shift_from_alignment(alignment) - Converts a page-aligned byte granularity to the corresponding bit shift value. This is useful for determining the shift needed to convert between addresses and page frame numbers.

    patina_dxe_core: Add PEI memory bin support

    Memory bins are pre-allocated, per-type regions of memory for EFI runtime memory types (ReservedMemory, RuntimeServicesCode, RuntimeServicesData, ACPIMemoryNVS, ACPIReclaimMemory). By over reserving these regions at a fixed size, the memory map presented to the OS has a much greater chance of remaining stable across boots, which is required for S4 (hibernate) resume.

    This commit adds support for PEI memory bins allocated prior to DXE, such as in PEI, where the bin information is given to the Patina DXE core via HOBs.

    A new module called MemoryBinManager is added. It tracks bin state: preferred ranges, allocation statistics, and the memory type information published to the EFI config table in addition to related bin logic for when producing the EFI memory map.

    Two initialization paths are supported:

    • Path A - PEI-provided bins: A Resource Descriptor HOB with owner GUID gEfiMemoryTypeInformationGuid describes a contiguous region PEI set aside for bins. Bins are divided within that region with per-type granularity. Free GCD pages within each bin range are claimed with ownership preservation so other allocators cannot expand into them.

    • Path B - DXE-allocated bins: If a PEI region HOB does not exist, each bin type is allocated directly from the GCD using allocate-then-free with ownership preservation.

    After bin initialization, seed_bin_statistics_from_hobs() scans Memory Allocation HOBs whose Name matches gEfiMemoryTypeInformationGuid to account for these potential PEI-phase allocations inside bin regions in initial bin statistics.

    On every AllocatePages()/FreePages() call, record_allocation() and record_free() update the bin statistics for the relevant type. On free, if the pages fall within a bin range, GCD ownership is re-established to prevent other allocators from reclaiming those pages.

    GetMemoryMap() calls apply_bin_descriptors() after populating the EFI memory map. This post-processing step converts EfiConventionalMemory entries that overlap bin ranges to the bin's memory type, splitting entries at bin boundaries as needed. The buffer-size calculation is updated to account for up to two extra descriptors per active bin.

    install_memory_type_info_table() is updated to use the bin manager's data.

    The previous reserve_memory_pages() API on PageAllocator and SpinLockedFixedSizeBlockAllocator is removed with logic moved into MemoryBinManager.


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

    How This Was Tested

    • PEI bins active and inactive on QEMU Q35
    • Boot to EFI shell with SBSA
    • Boot to OS on 64-bit Intel physical platform
    • Note: Some additional physical platform testing with various features such as performance enabled is still in progress (PR in draft until done)

    Integration Instructions

    • If using edk2, ensure edk2 PR 12086 is present
    • If using Mu, ensure mu_basecore PR 1759 is present
    • Set the Feature PCD gEfiMdeModulePkgTokenSpaceGuid.PcdPeiMemoryBinsEnable to TRUE
    • Refer to edk2 memory bin and Patina memory bin documentation for further details

    PEI Bins Active Example

    PEI Output: Bin allocation

    AllocateMemoryTypeInformationBins: Attempting to allocate 0xDBB000 bytes for all memory bins
    InitializeMemoryTypeInformationBins: Memory bins address range 0x7E233000 - 0x7EFEDFFF
    

    Patina DXE Output

    • memory_bin log target at trace
    Patina DXE Output: Init
    Found Memory Type Information HOB (48 bytes, 6 entries)
      MemTypeInfo: ACPIMemoryNVS pages=128 (GCD alloc will use 128)
      MemTypeInfo: ACPIReclaimMemory pages=43 (GCD alloc will use 43)
      MemTypeInfo: ReservedMemoryType pages=1296 (GCD alloc will use 1296)
      MemTypeInfo: RuntimeServicesCode pages=256 (GCD alloc will use 256)
      MemTypeInfo: RuntimeServicesData pages=1792 (GCD alloc will use 1792)
    Memory Type Information HOB found with 6 entries.
    Found MemoryTypeInformation Resource Descriptor HOB: base=0x7E233000 length=0xDBB000
    Found PEI bin region at 0x7E233000, length 0xDBB000.
    Initializing memory bins from PEI range: base=0x7E233000 length=0xDBB000 total_needed=0xDBB000
      Bin[10] ACPIMemoryNVS: base=0x7EF6E000 max=0x7EFEDFFF pages=0x80 (128 pages)
      Bin[9] ACPIReclaimMemory: base=0x7EF43000 max=0x7EF6DFFF pages=0x2B (43 pages)
      Bin[0] ReservedMemoryType: base=0x7EA33000 max=0x7EF42FFF pages=0x510 (1296 pages)
      Bin[5] RuntimeServicesCode: base=0x7E933000 max=0x7EA32FFF pages=0x100 (256 pages)
      Bin[6] RuntimeServicesData: base=0x7E233000 max=0x7E932FFF pages=0x700 (1792 pages)
    Memory bins initialized from pre-allocated range.
    Reserving bin[0] ReservedMemoryType range=[0x7EA33000..0x7EF42FFF] (1296 pages)
    Reserved bin[0] ReservedMemoryType: claimed=1296 pages, existing=0 pages, conflicting=0 pages (of 1296 total)
    Reserving bin[5] RuntimeServicesCode range=[0x7E933000..0x7EA32FFF] (256 pages)
    Reserved bin[5] RuntimeServicesCode: claimed=256 pages, existing=0 pages, conflicting=0 pages (of 256 total)
    Reserving bin[6] RuntimeServicesData range=[0x7E233000..0x7E932FFF] (1792 pages)
    Reserved bin[6] RuntimeServicesData: claimed=1663 pages, existing=129 pages, conflicting=0 pages (of 1792 total)
    Reserving bin[9] ACPIReclaimMemory range=[0x7EF43000..0x7EF6DFFF] (43 pages)
    Reserved bin[9] ACPIReclaimMemory: claimed=43 pages, existing=0 pages, conflicting=0 pages (of 43 total)
    Reserving bin[10] ACPIMemoryNVS range=[0x7EF6E000..0x7EFEDFFF] (128 pages)
    Reserved bin[10] ACPIMemoryNVS: claimed=128 pages, existing=0 pages, conflicting=0 pages (of 128 total)
     PEI seed: RuntimeServicesData +1 pages at 0x7E931000. total=1
     PEI seed: RuntimeServicesData +64 pages at 0x7E8F1000. total=65
     PEI seed: RuntimeServicesData +64 pages at 0x7E8B1000. total=129
    Seeded bin statistics from 3 PEI Memory Allocation HOBs.
    
    Patina DXE Output: Memory Map
    • Note: There are some expected EfiReservedMemoryType allocations of RT types intentionally outside bin ranges.
    DEBUG - GetMemoryMap: processing bin[0] ReservedMemoryType range=[0x7EA33000..0x7EF42FFF]
    DEBUG - GetMemoryMap: processing bin[5] RuntimeServicesCode range=[0x7E933000..0x7EA32FFF]
    DEBUG - GetMemoryMap: processing bin[6] RuntimeServicesData range=[0x7E233000..0x7E932FFF]
    DEBUG - GetMemoryMap: processing bin[9] ACPIReclaimMemory range=[0x7EF43000..0x7EF6DFFF]
    DEBUG - GetMemoryMap: processing bin[10] ACPIMemoryNVS range=[0x7EF6E000..0x7EFEDFFF]
    EfiReservedMemoryType       at 0 for 80 pages
    EfiBootServicesData         at 50000 for 1 pages
    EfiConventionalMemory       at 51000 for 54 pages
    EfiBootServicesData         at 87000 for 1 pages
    EfiConventionalMemory       at 88000 for 24 pages
    EfiConventionalMemory       at 100000 for 1856 pages
    EfiBootServicesData         at 840000 for 3520 pages
    EfiConventionalMemory       at 1600000 for 498110 pages
    EfiBootServicesData         at 7AFBE000 for 32 pages
    EfiConventionalMemory       at 7AFDE000 for 17 pages
    EfiBootServicesData         at 7AFEF000 for 96 pages
    EfiConventionalMemory       at 7B04F000 for 4353 pages
    EfiBootServicesData         at 7C150000 for 1848 pages
    EfiBootServicesCode         at 7C888000 for 27 pages
    EfiBootServicesData         at 7C8A3000 for 538 pages
    EfiBootServicesCode         at 7CABD000 for 1162 pages
    EfiBootServicesData         at 7CF47000 for 256 pages
    EfiBootServicesCode         at 7D047000 for 102 pages
    EfiBootServicesData         at 7D0AD000 for 42 pages
    EfiConventionalMemory       at 7D0D7000 for 1 pages
    EfiBootServicesData         at 7D0D8000 for 4 pages
    EfiBootServicesCode         at 7D0DC000 for 73 pages
    EfiBootServicesData         at 7D125000 for 5 pages
    EfiBootServicesCode         at 7D12A000 for 214 pages
    EfiBootServicesData         at 7D200000 for 2562 pages
    EfiBootServicesCode         at 7DC02000 for 28 pages
    EfiBootServicesData         at 7DC1E000 for 32 pages
    EfiBootServicesCode         at 7DC3E000 for 365 pages
    EfiBootServicesData         at 7DDAB000 for 5 pages
    EfiBootServicesCode         at 7DDB0000 for 19 pages
    EfiBootServicesData         at 7DDC3000 for 1 pages
    EfiBootServicesCode         at 7DDC4000 for 1 pages
    EfiBootServicesData         at 7DDC5000 for 5 pages
    EfiBootServicesCode         at 7DDCA000 for 1 pages
    EfiBootServicesData         at 7DDCB000 for 1 pages
    EfiBootServicesCode         at 7DDCC000 for 1 pages
    EfiBootServicesData         at 7DDCD000 for 41 pages
    EfiBootServicesCode         at 7DDF6000 for 16 pages
    EfiBootServicesData         at 7DE06000 for 33 pages
    EfiBootServicesCode         at 7DE27000 for 12 pages
    EfiBootServicesData         at 7DE33000 for 1024 pages
    EfiRuntimeServicesData      at 7E233000 for 1792 pages
    EfiRuntimeServicesCode      at 7E933000 for 256 pages
    EfiReservedMemoryType       at 7EA33000 for 1296 pages
    EfiACPIReclaimMemory        at 7EF43000 for 43 pages
    EfiACPIMemoryNVS            at 7EF6E000 for 128 pages
    EfiBootServicesCode         at 7EFEE000 for 15 pages
    EfiBootServicesData         at 7EFFD000 for 3 pages
    EfiReservedMemoryType       at 7F000000 for 4096 pages
    PROGRESS CODE: V03051001 I0
    Memory  Previous  Current   Minimum    Next
     Type    Pages     Pages     Pages     Pages
    ======  ========  ========  ========  =======
      0A    00000080  00000080  00000000  00000080
      09    0000002B  0000002B  00000000  0000002B
      00    00000510  00000510  00000000  00000510
      05    00000100  00000100  00000000  00000100
      06    00000700  00000700  00000000  00000700
    

    PEI Bins Inactive Example

    Patina DXE Output

    • memory_bin log target at trace
    Patina DXE Output: Init
    Found Memory Type Information HOB (48 bytes, 6 entries)
      MemTypeInfo: ACPIMemoryNVS pages=128 (GCD alloc will use 128)
      MemTypeInfo: ACPIReclaimMemory pages=43 (GCD alloc will use 43)
      MemTypeInfo: ReservedMemoryType pages=1296 (GCD alloc will use 1296)
      MemTypeInfo: RuntimeServicesCode pages=256 (GCD alloc will use 256)
      MemTypeInfo: RuntimeServicesData pages=1792 (GCD alloc will use 1792)
    Memory Type Information HOB found with 6 entries.
    No MemoryTypeInformation Resource Descriptor HOB found. DXE will allocate bins.
    No PEI bin region found. Allocating bins per-type from GCD.
      Bin[10] ACPIMemoryNVS: base=0x7E8D9000 max=0x7E958FFF pages=128
      Bin[9] ACPIReclaimMemory: base=0x7E8AE000 max=0x7E8D8FFF pages=43
      Bin[0] ReservedMemoryType: base=0x7DFF0000 max=0x7E4FFFFF pages=1296
      Bin[5] RuntimeServicesCode: base=0x7DEF0000 max=0x7DFEFFFF pages=256
      Bin[6] RuntimeServicesData: base=0x7D7F0000 max=0x7DEEFFFF pages=1792
    Seeded bin statistics from 0 PEI Memory Allocation HOBs.
    
    Patina DXE Output: Memory Map
    • Note: There are some expected allocations of RT types intentionally outside bin ranges due to PEI bins being inactive and RT memory allocated in PEI.
    DEBUG - GetMemoryMap: processing bin[0] ReservedMemoryType range=[0x7DFF0000..0x7E4FFFFF]
    DEBUG - GetMemoryMap: processing bin[5] RuntimeServicesCode range=[0x7DEF0000..0x7DFEFFFF]
    DEBUG - GetMemoryMap: processing bin[6] RuntimeServicesData range=[0x7D7F0000..0x7DEEFFFF]
    DEBUG - GetMemoryMap: processing bin[9] ACPIReclaimMemory range=[0x7E8AE000..0x7E8D8FFF]
    DEBUG - GetMemoryMap: processing bin[10] ACPIMemoryNVS range=[0x7E8D9000..0x7E958FFF]
    EfiReservedMemoryType       at 0 for 80 pages
    EfiBootServicesData         at 50000 for 1 pages
    EfiConventionalMemory       at 51000 for 54 pages
    EfiBootServicesData         at 87000 for 1 pages
    EfiConventionalMemory       at 88000 for 24 pages
    EfiConventionalMemory       at 100000 for 1856 pages
    EfiBootServicesData         at 840000 for 3520 pages
    EfiConventionalMemory       at 1600000 for 498110 pages
    EfiBootServicesData         at 7AFBE000 for 32 pages
    EfiConventionalMemory       at 7AFDE000 for 17 pages
    EfiBootServicesData         at 7AFEF000 for 96 pages
    EfiConventionalMemory       at 7B04F000 for 4219 pages
    EfiBootServicesData         at 7C0CA000 for 1848 pages
    EfiBootServicesCode         at 7C802000 for 27 pages
    EfiBootServicesData         at 7C81D000 for 538 pages
    EfiBootServicesCode         at 7CA37000 for 1086 pages
    EfiBootServicesData         at 7CE75000 for 261 pages
    EfiConventionalMemory       at 7CF7A000 for 1 pages
    EfiBootServicesData         at 7CF7B000 for 5 pages
    EfiBootServicesCode         at 7CF80000 for 368 pages
    EfiBootServicesData         at 7D0F0000 for 1792 pages
    EfiRuntimeServicesData      at 7D7F0000 for 1792 pages
    EfiRuntimeServicesCode      at 7DEF0000 for 256 pages
    EfiReservedMemoryType       at 7DFF0000 for 1296 pages
    EfiBootServicesData         at 7E500000 for 769 pages
    EfiBootServicesCode         at 7E801000 for 59 pages
    EfiRuntimeServicesData      at 7E83C000 for 4 pages
    EfiReservedMemoryType       at 7E840000 for 2 pages
    EfiBootServicesData         at 7E842000 for 42 pages
    EfiBootServicesCode         at 7E86C000 for 66 pages
    EfiACPIReclaimMemory        at 7E8AE000 for 43 pages
    EfiACPIMemoryNVS            at 7E8D9000 for 128 pages
    EfiBootServicesData         at 7E959000 for 32 pages
    EfiBootServicesCode         at 7E979000 for 365 pages
    EfiBootServicesData         at 7EAE6000 for 5 pages
    EfiBootServicesCode         at 7EAEB000 for 19 pages
    EfiBootServicesData         at 7EAFE000 for 1 pages
    EfiBootServicesCode         at 7EAFF000 for 1 pages
    EfiBootServicesData         at 7EB00000 for 5 pages
    EfiBootServicesCode         at 7EB05000 for 1 pages
    EfiBootServicesData         at 7EB06000 for 1 pages
    EfiBootServicesCode         at 7EB07000 for 1 pages
    EfiBootServicesData         at 7EB08000 for 41 pages
    EfiBootServicesCode         at 7EB31000 for 16 pages
    EfiBootServicesData         at 7EB41000 for 33 pages
    EfiBootServicesCode         at 7EB62000 for 12 pages
    EfiBootServicesData         at 7EB6E000 for 1024 pages
    EfiRuntimeServicesData      at 7EF6E000 for 129 pages
    EfiBootServicesCode         at 7EFEF000 for 14 pages
    EfiBootServicesData         at 7EFFD000 for 3 pages
    EfiReservedMemoryType       at 7F000000 for 4096 pages
    PROGRESS CODE: V03051001 I0
    Memory  Previous  Current   Minimum    Next
     Type    Pages     Pages     Pages     Pages
    ======  ========  ========  ========  =======
      0A    00000080  00000080  00000000  00000080
      09    0000002B  0000002B  00000000  0000002B
      00    00000510  00000510  00000000  00000510
      05    00000100  00000100  00000000  00000100
      06    00000700  00000700  00000000  00000700
    
      </blockquote>
      <hr>
    </details>
    
  • Update Corosensei to latest upstream release 0.3.4 @joschock (#1541)
    Change Details
      ## Description

    Updates Corosensei dependency to latest upstream release 0.3.4. This includes support for SEH opcodes on aarch64-unknown-uefi that allows for proper stack unwinding through the corosensei co-routine used for start_image.

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

    How This Was Tested

    Confirmed build and boot on hardware and QemuSbsa. Confirmed stack unwinding on SBSA unwinds through start_image properly.

    Integration Instructions

    N/A




  • [REBASE \& FF] Run Clippy/Check on UEFI Target Triples @os-d (#1532)
    Change Details
      ## Description

    Currently the clippy/check configuration is expecting that --all-targets is building for x86_64-unknown-uefi and aarch64-unknown-uefi. However, --all-targets means build lib, docs, test, bin, etc, not target triples. As such, various clippy and check errors are missed in architecture specific code. This adds new steps to cargo make clippy/check to check the architectures. It leaves linting the std code as well because --all-features cannot be used in no-std; it attempts to include std as a feature. Short of manually listing all features, this seemed the best way to get coverage, though it does increase clippy/check times.

    Open to other suggestions on how to implement this or to drop the std checking (nice to keep for tests for use in rust-analyzer). With this PR, times increase (all times in seconds, cargo clean run before each invocation):

    New Original
    Clippy 46 17
    Check 49 39

    Note: The Makefile.toml change will be dropped from this PR and brought to all applicable makefiles in patina-devops. It is here for convenience for anyone who wants to test this change before recommending a different path.

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

    How This Was Tested

    Running cargo make clippy and cargo make check.

    Integration Instructions

    N/A.




📖 Documentation Updates

  • rust-toolchain: Update nightly toolchain (1.95.0) [Rebase \& FF] @makubacki (#1528)
    Change Details
      ## Description

    Closes #1519

    The previous nightly toolchain was from 2026-02-13, which had partial support for some of the changes that ended up in Rust 1.95.0. This updates the toolchain to the same day the 1.95.0 stable tag was created.

    Also fixes clippy issues reported after the update.

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

    How This Was Tested

    • cargo make all with the updated toolchain

    Integration Instructions

    • N/A


Full Changelog: patina-v21.1.0...v21.1.1