From 01735bbe4a46a6fb7d5d739d0fc5a14897ad18da Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Wed, 7 Aug 2024 14:44:03 -0700 Subject: [PATCH] MdeModulePkg: Gcd: Only Update gMemoryMap Attributes if Correct GCD Type Currently whenever gDS->SetMemorySpaceCapabilities() is called, it attempts to set the corresponding attributes in the gMemoryMap descriptor. However, gMemoryMap only contains entries from GCD types EfiGcdMemoryTypeSystemMemory and EfiGcdMemoryTypeMoreReliable, so for all other types a failure is reported in the code. This is a failure that is expected, so it does not provide value and can lead to real failures being ignored. This patch updates the gDS->SetMemorySpaceCapabilities() code to only call into updating gMemoryMap if the GCD type is SystemMemory or MoreReliable, to avoid spurious errors being reported. This also avoids the expensive operation of searching through gMemoryMap for entries we know we will fail to find. Signed-off-by: Oliver Smith-Denny --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 99364508cd..6ea89fbc8b 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -989,6 +989,20 @@ CoreConvertSpace ( // case GCD_SET_CAPABILITIES_MEMORY_OPERATION: Entry->Capabilities = Capabilities; + + // Only SystemMemory and MoreReliable memory is in gMemoryMap + // so only attempt to update the attributes there if this is + // a relevant GCD type + if ((Entry->GcdMemoryType == EfiGcdMemoryTypeSystemMemory) || + (Entry->GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) + { + CoreUpdateMemoryAttributes ( + BaseAddress, + RShiftU64 (Length, EFI_PAGE_SHIFT), + Capabilities & (~EFI_MEMORY_RUNTIME) + ); + } + break; } @@ -1700,17 +1714,10 @@ CoreSetMemorySpaceCapabilities ( IN UINT64 Capabilities ) { - EFI_STATUS Status; - DEBUG ((DEBUG_GCD, "GCD:CoreSetMemorySpaceCapabilities(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); DEBUG ((DEBUG_GCD, " Capabilities = %016lx\n", Capabilities)); - Status = CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, Capabilities, 0); - if (!EFI_ERROR (Status)) { - CoreUpdateMemoryAttributes (BaseAddress, RShiftU64 (Length, EFI_PAGE_SHIFT), Capabilities & (~EFI_MEMORY_RUNTIME)); - } - - return Status; + return CoreConvertSpace (GCD_SET_CAPABILITIES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE)0, (EFI_GCD_IO_TYPE)0, BaseAddress, Length, Capabilities, 0); } /**