Skip to content

Commit e957a18

Browse files
makubackiFlickdm
authored andcommitted
MemoryInitPei: Remove Non-RT Types from Mem Type Info HOB
MemoryInitPei: Remove Non-RT Types from Mem Type Info HOB Removes the following types from the memory type information HOBs produced in the MemoryInitPei modules in ArmPlatformPkg and ArmVirtPkg. - `EfiBootServicesCode` - `EfiBootServicesData` - `EfiLoaderCode` - `EfiLoaderData` When the memory type information UEFI variable is updated in BDS, it goes through the common variable check code attached to the UEFI variable driver which explicitly checks the size of the variable data to determine if the variable update is valid. MemoryTypeInfoVarCheckHandler () in MdeModulePkg/Library/MemoryTypeInfoSecVarCheckLib/MemoryTypeInfoSecVarCheckLib.c. The size here is `0x50` instead of the expected size of `0x30`. It is not common to place non-runtime memory types in the memory type information HOB so the types are removed from the HOB published here to align with typical code expectations. UEFI variable update error: ``` ERROR: MemoryTypeInfoVarCheckHandler() - DataSize = 0x50 Expected = 0x30 Variable Check handler fail Security Violation - 4C19049F-4137-4DD3-9C10-8B97A83FFDFA:MemoryTypeInformation Memory Type Information settings cannot be saved. OS S4 may fail! ``` Some Arm platforms may use a different UEFI variable driver that does not perform this check. If the types are truly needed, the variable check code should be updated to compensate for them. - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] 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, ... - ArmPlatformPkg build and CI - ArmVirtPkg build and CI - QemuSbsaPkg build and boot to EFI shell with test apps Review code to determine if either of these PEIMs (`MemoryInitPeim`). If so, whether code was dependent on the memory types in the memory type information HOB that were removed to determine if further changes are needed. --------- Signed-off-by: Michael Kubacki <[email protected]>
1 parent 515de56 commit e957a18

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf

+6-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@
4747
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
4848
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
4949
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
50-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode
51-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData
52-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode
53-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData
50+
# MU_CHANGE [BEGIN] - Remove non-RT types from Mem Type Info Settings
51+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode
52+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData
53+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode
54+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData
55+
# MU_CHANGE [END] - Remove non-RT types from Mem Type Info Settings
5456

5557
[Pcd]
5658
gArmTokenSpaceGuid.PcdSystemMemoryBase

ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ BuildMemoryTypeInformationHob (
3737
VOID
3838
)
3939
{
40-
EFI_MEMORY_TYPE_INFORMATION Info[10];
40+
// MU_CHANGE [BEGIN] - Remove non-RT types from Mem Type Info Settings
41+
42+
EFI_MEMORY_TYPE_INFORMATION Info[6];
4143

4244
Info[0].Type = EfiACPIReclaimMemory;
4345
Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
@@ -49,18 +51,11 @@ BuildMemoryTypeInformationHob (
4951
Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
5052
Info[4].Type = EfiRuntimeServicesCode;
5153
Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
52-
Info[5].Type = EfiBootServicesCode;
53-
Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);
54-
Info[6].Type = EfiBootServicesData;
55-
Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);
56-
Info[7].Type = EfiLoaderCode;
57-
Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);
58-
Info[8].Type = EfiLoaderData;
59-
Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);
60-
6154
// Terminator for the list
62-
Info[9].Type = EfiMaxMemoryType;
63-
Info[9].NumberOfPages = 0;
55+
Info[5].Type = EfiMaxMemoryType;
56+
Info[5].NumberOfPages = 0;
57+
58+
// MU_CHANGE [END] - Remove non-RT types from Mem Type Info Settings
6459

6560
BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
6661
}

ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@
5656
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
5757
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
5858
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
59-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode
60-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData
61-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode
62-
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData
59+
# MU_CHANGE [BEGIN] - Remove non-RT types from Mem Type Info Settings
60+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode
61+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData
62+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode
63+
# gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData
64+
# MU_CHANGE [END] - Remove non-RT types from Mem Type Info Settings
6365

6466
[Pcd]
6567
gArmTokenSpaceGuid.PcdSystemMemoryBase

ArmVirtPkg/MemoryInitPei/MemoryInitPeim.c

+12-17
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,25 @@ BuildMemoryTypeInformationHob (
3333
VOID
3434
)
3535
{
36-
EFI_MEMORY_TYPE_INFORMATION Info[10];
36+
// MU_CHANGE [BEGIN] - Remove non-RT types from Mem Type Info Settings
37+
38+
EFI_MEMORY_TYPE_INFORMATION Info[6];
3739

3840
Info[0].Type = EfiACPIReclaimMemory;
39-
Info[0].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
41+
Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
4042
Info[1].Type = EfiACPIMemoryNVS;
41-
Info[1].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);
43+
Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);
4244
Info[2].Type = EfiReservedMemoryType;
43-
Info[2].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType);
45+
Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);
4446
Info[3].Type = EfiRuntimeServicesData;
45-
Info[3].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
47+
Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
4648
Info[4].Type = EfiRuntimeServicesCode;
47-
Info[4].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
48-
Info[5].Type = EfiBootServicesCode;
49-
Info[5].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiBootServicesCode);
50-
Info[6].Type = EfiBootServicesData;
51-
Info[6].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiBootServicesData);
52-
Info[7].Type = EfiLoaderCode;
53-
Info[7].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiLoaderCode);
54-
Info[8].Type = EfiLoaderData;
55-
Info[8].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiLoaderData);
56-
49+
Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
5750
// Terminator for the list
58-
Info[9].Type = EfiMaxMemoryType;
59-
Info[9].NumberOfPages = 0;
51+
Info[5].Type = EfiMaxMemoryType;
52+
Info[5].NumberOfPages = 0;
53+
54+
// MU_CHANGE [END] - Remove non-RT types from Mem Type Info Settings
6055

6156
BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
6257
}

0 commit comments

Comments
 (0)