Skip to content

Commit 3c19214

Browse files
TaylorBeebeos-d
authored andcommitted
Update the ARM MemoryAttributeProtocol to Not Check if Region is System Memory
Description Project Mu allows the use of the memory attribute protocol to update regions which are not of GCD type System Memory. Also, this check can cause a lock issue after the CPU architecture protocol is installed due to the GCD lock being held during GCD synchronization and a call being made to get memory attributes using the memory attribute protocol. - [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, ... How This Was Tested Running QemuSbsaPkg Integration Instructions N/A
1 parent 3ef1e60 commit 3c19214

File tree

1 file changed

+52
-44
lines changed

1 file changed

+52
-44
lines changed

ArmPkg/Drivers/CpuDxe/MemoryAttribute.c

+52-44
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,43 @@
88

99
#include "CpuDxe.h"
1010

11-
/**
12-
Check whether the provided memory range is covered by a single entry of type
13-
EfiGcdSystemMemory in the GCD memory map.
14-
15-
@param BaseAddress The physical address that is the start address of
16-
a memory region.
17-
@param Length The size in bytes of the memory region.
18-
19-
@return Whether the region is system memory or not.
20-
**/
21-
STATIC
22-
BOOLEAN
23-
RegionIsSystemMemory (
24-
IN EFI_PHYSICAL_ADDRESS BaseAddress,
25-
IN UINT64 Length
26-
)
27-
{
28-
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
29-
EFI_PHYSICAL_ADDRESS GcdEndAddress;
30-
EFI_STATUS Status;
31-
32-
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
33-
if (EFI_ERROR (Status) ||
34-
(GcdDescriptor.GcdMemoryType != EfiGcdMemoryTypeSystemMemory))
35-
{
36-
return FALSE;
37-
}
38-
39-
GcdEndAddress = GcdDescriptor.BaseAddress + GcdDescriptor.Length;
40-
41-
//
42-
// Return TRUE if the GCD descriptor covers the range entirely
43-
//
44-
return GcdEndAddress >= (BaseAddress + Length);
45-
}
11+
// MU_CHANGE START: Don't check for GCD system memory when using EFI Attributes Protocol
12+
// /**
13+
// Check whether the provided memory range is covered by a single entry of type
14+
// EfiGcdSystemMemory in the GCD memory map.
15+
16+
// @param BaseAddress The physical address that is the start address of
17+
// a memory region.
18+
// @param Length The size in bytes of the memory region.
19+
20+
// @return Whether the region is system memory or not.
21+
// **/
22+
// STATIC
23+
// BOOLEAN
24+
// RegionIsSystemMemory (
25+
// IN EFI_PHYSICAL_ADDRESS BaseAddress,
26+
// IN UINT64 Length
27+
// )
28+
// {
29+
// EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
30+
// EFI_PHYSICAL_ADDRESS GcdEndAddress;
31+
// EFI_STATUS Status;
32+
33+
// Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
34+
// if (EFI_ERROR (Status) ||
35+
// (GcdDescriptor.GcdMemoryType != EfiGcdMemoryTypeSystemMemory))
36+
// {
37+
// return FALSE;
38+
// }
39+
40+
// GcdEndAddress = GcdDescriptor.BaseAddress + GcdDescriptor.Length;
41+
42+
// //
43+
// // Return TRUE if the GCD descriptor covers the range entirely
44+
// //
45+
// return GcdEndAddress >= (BaseAddress + Length);
46+
// }
47+
// MU_CHANGE END
4648

4749
/**
4850
This function retrieves the attributes of the memory region specified by
@@ -85,9 +87,11 @@ GetMemoryAttributes (
8587
return EFI_INVALID_PARAMETER;
8688
}
8789

88-
if (!RegionIsSystemMemory (BaseAddress, Length)) {
89-
return EFI_UNSUPPORTED;
90-
}
90+
// MU_CHANGE START: Don't check for GCD system memory when using EFI Attributes Protocol
91+
// if (!RegionIsSystemMemory (BaseAddress, Length)) {
92+
// return EFI_UNSUPPORTED;
93+
// }
94+
// MU_CHANGE END
9195

9296
DEBUG ((
9397
DEBUG_VERBOSE,
@@ -198,9 +202,11 @@ SetMemoryAttributes (
198202
return EFI_INVALID_PARAMETER;
199203
}
200204

201-
if (!RegionIsSystemMemory (BaseAddress, Length)) {
202-
return EFI_UNSUPPORTED;
203-
}
205+
// MU_CHANGE START: Don't check for GCD system memory when using EFI Attributes Protocol
206+
// if (!RegionIsSystemMemory (BaseAddress, Length)) {
207+
// return EFI_UNSUPPORTED;
208+
// }
209+
// MU_CHANGE END
204210

205211
return ArmSetMemoryAttributes (BaseAddress, Length, Attributes, Attributes);
206212
}
@@ -259,9 +265,11 @@ ClearMemoryAttributes (
259265
return EFI_INVALID_PARAMETER;
260266
}
261267

262-
if (!RegionIsSystemMemory (BaseAddress, Length)) {
263-
return EFI_UNSUPPORTED;
264-
}
268+
// MU_CHANGE START: Don't check for GCD system memory when using EFI Attributes Protocol
269+
// if (!RegionIsSystemMemory (BaseAddress, Length)) {
270+
// return EFI_UNSUPPORTED;
271+
// }
272+
// MU_CHANGE END
265273

266274
return ArmSetMemoryAttributes (BaseAddress, Length, 0, Attributes);
267275
}

0 commit comments

Comments
 (0)