]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/UncachedMemoryAllocationLib: restore mapping attributes after free
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 28 Feb 2017 12:13:10 +0000 (12:13 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 8 Mar 2017 08:48:42 +0000 (09:48 +0100)
In order to play nice with platforms that use strict memory permission
policies, restore the original mapping attributes when freeing uncached
allocations.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c

index f6c692f9a4034bdcaf199dc4e1bc5fa3da7c71b7..cd13a7da92e0468f2ec81caf2ba0cd62b7a7b61b 100644 (file)
@@ -42,11 +42,6 @@ UncachedInternalAllocateAlignedPages (
 \r
 \r
 \r
-//\r
-// Assume all of memory has the same cache attributes, unless we do our magic\r
-//\r
-UINT64  gAttributes;\r
-\r
 typedef struct {\r
   EFI_PHYSICAL_ADDRESS  Base;\r
   VOID                  *Allocation;\r
@@ -54,6 +49,7 @@ typedef struct {
   EFI_MEMORY_TYPE       MemoryType;\r
   BOOLEAN               Allocated;\r
   LIST_ENTRY            Link;\r
+  UINT64                Attributes;\r
 } FREE_PAGE_NODE;\r
 \r
 STATIC LIST_ENTRY  mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);\r
@@ -153,10 +149,7 @@ AllocatePagesFromList (
   }\r
 \r
   Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);\r
-  if (!EFI_ERROR (Status)) {\r
-    // We are making an assumption that all of memory has the same default attributes\r
-    gAttributes = Descriptor.Attributes;\r
-  } else {\r
+  if (EFI_ERROR (Status)) {\r
     gBS->FreePages (Memory, Pages);\r
     return Status;\r
   }\r
@@ -181,6 +174,7 @@ AllocatePagesFromList (
   NewNode->Pages      = Pages;\r
   NewNode->Allocated  = TRUE;\r
   NewNode->MemoryType = MemoryType;\r
+  NewNode->Attributes = Descriptor.Attributes;\r
 \r
   InsertTailList (&mPageList, &NewNode->Link);\r
 \r
@@ -266,6 +260,10 @@ UncachedMemoryAllocationLibDestructor (
     // We only free the non-allocated buffer\r
     if (OldNode->Allocated == FALSE) {\r
       gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);\r
+\r
+      gDS->SetMemorySpaceAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base,\r
+             EFI_PAGES_TO_SIZE (OldNode->Pages), OldNode->Attributes);\r
+\r
       RemoveEntryList (&OldNode->Link);\r
       FreePool (OldNode);\r
     }\r