Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHERRY-PICK][REBASE & FF] Revert Mu Commits In Favor of edk2 Commits #327

Merged
merged 7 commits into from
Aug 29, 2024
38 changes: 33 additions & 5 deletions EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,12 @@ DmaAllocateAlignedBuffer (
{
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
VOID *Allocation;
UINT64 MemType;
UINT64 Attributes;
UNCACHED_ALLOCATION *Alloc;
EFI_STATUS Status;

Attributes = EFI_MEMORY_XP;

if (Alignment == 0) {
Alignment = EFI_PAGE_SIZE;
}
Expand Down Expand Up @@ -534,9 +536,9 @@ DmaAllocateAlignedBuffer (

// Choose a suitable uncached memory type that is supported by the region
if (GcdDescriptor.Capabilities & EFI_MEMORY_WC) {
MemType = EFI_MEMORY_WC;
Attributes |= EFI_MEMORY_WC;
} else if (GcdDescriptor.Capabilities & EFI_MEMORY_UC) {
MemType = EFI_MEMORY_UC;
Attributes |= EFI_MEMORY_UC;
} else {
Status = EFI_UNSUPPORTED;
goto FreeBuffer;
Expand All @@ -553,11 +555,37 @@ DmaAllocateAlignedBuffer (

InsertHeadList (&UncachedAllocationList, &Alloc->Link);

// Remap the region with the new attributes
// Ensure that EFI_MEMORY_XP is in the capability set
if ((GcdDescriptor.Capabilities & EFI_MEMORY_XP) != EFI_MEMORY_XP) {
Status = gDS->SetMemorySpaceCapabilities (
(PHYSICAL_ADDRESS)(UINTN)Allocation,
EFI_PAGES_TO_SIZE (Pages),
GcdDescriptor.Capabilities | EFI_MEMORY_XP
);

// if we were to fail setting the capability, this would indicate an internal failure of the GCD code. We should
// assert here to let a platform know something went crazy, but for a release build we can let the allocation occur
// without the EFI_MEMORY_XP bit set, as that was the existing behavior
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
"%a failed to set EFI_MEMORY_XP capability on 0x%llx for length 0x%llx. Attempting to allocate without XP set.\n",
__func__,
Allocation,
EFI_PAGES_TO_SIZE (Pages)
));

ASSERT_EFI_ERROR (Status);

Attributes &= ~EFI_MEMORY_XP;
}
}

// Remap the region with the new attributes and mark it non-executable
Status = gDS->SetMemorySpaceAttributes (
(PHYSICAL_ADDRESS)(UINTN)Allocation,
EFI_PAGES_TO_SIZE (Pages),
MemType | EFI_MEMORY_XP // MU_CHANGE: Allocate DMA memory XP by default
Attributes
);
if (EFI_ERROR (Status)) {
goto FreeAlloc;
Expand Down
8 changes: 5 additions & 3 deletions FmpDevicePkg/FmpDxe/FmpDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ GetImageTypeIdGuid (
if (ImageTypeIdGuidSize == sizeof (EFI_GUID)) {
FmpDeviceLibGuid = (EFI_GUID *)PcdGetPtr (PcdFmpDeviceImageTypeIdGuid);
} else {
// MU_CHANGE start - this is a misconfiguration error, we should assert
DEBUG ((DEBUG_ERROR, "FmpDxe(%s): Fall back to ImageTypeIdGuid of gEfiCallerIdGuid. FmpDxe error: misconfiguration\n", mImageIdName));
DEBUG ((
DEBUG_ERROR,
"FmpDxe(%s): Fall back to ImageTypeIdGuid of gEfiCallerIdGuid. FmpDxe error: misconfiguration\n",
mImageIdName
));
ASSERT (FALSE);
// MU_CHANGE end
FmpDeviceLibGuid = &gEfiCallerIdGuid;
}
}
Expand Down
12 changes: 5 additions & 7 deletions PrmPkg/PrmConfigDxe/PrmConfigDxe.c
os-d marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,15 @@ SetRuntimeMemoryRangeAttributes (
continue;
}

// The memory space descriptor access attributes are not accurate. Don't pass
// in access attributes so SetMemorySpaceAttributes() doesn't update them.
// EFI_MEMORY_RUNTIME is not a CPU arch attribute, so calling
// SetMemorySpaceAttributes() with only it set will not clear existing page table
// attributes for this region, such as EFI_MEMORY_XP
Status = gDS->SetMemorySpaceAttributes (
RuntimeMmioRanges->Range[Index].PhysicalBaseAddress,
(UINT64)RuntimeMmioRanges->Range[Index].Length,
// MU_CHANGE START: The memory space descriptor access attributes are not accurate. Don't pass
// in access attributes so SetMemorySpaceAttributes() doesn't update them.
// EFI_MEMORY_RUNTIME is not a CPU arch attribute, so calling
// SetMemorySpaceAttributes() with only it set will not clear existing page table
// attributes for this region, such as EFI_MEMORY_XP
// Descriptor.Attributes | EFI_MEMORY_RUNTIME
EFI_MEMORY_RUNTIME
// MU_CHANGE END
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
Expand Down
Loading