]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmMmuLib: Revert "use a pool allocation for the root table"
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 20 Jan 2017 16:44:35 +0000 (16:44 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 20 Jan 2017 17:50:40 +0000 (17:50 +0000)
This reverts commit d32702d2c2aa23e828363a7f88829b78ce36c3af.

Using a pool allocation for the root translation table seemed like
a good idea at the time, but as it turns out, such allocations are
handled in a way that makes them unsuitable for this purpose: they
are backed by HOBs that don't remain in the same place during the
various PI phase changes, which means the address programmed into
the TTBR register is no longer valid, and may refer to memory that
is reported as available to the OS.

So switch back to using a page based allocation.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c

index c78297084207366b32c135563000c36884f5c04b..540069a59b2e470e255dc20de774ae9d8d5fded4 100644 (file)
@@ -553,12 +553,10 @@ ArmConfigureMmu (
   )\r
 {\r
   VOID*                         TranslationTable;\r
-  VOID*                         TranslationTableBuffer;\r
   UINT32                        TranslationTableAttribute;\r
   UINT64                        MaxAddress;\r
   UINTN                         T0SZ;\r
   UINTN                         RootTableEntryCount;\r
-  UINTN                         RootTableEntrySize;\r
   UINT64                        TCR;\r
   RETURN_STATUS                 Status;\r
 \r
@@ -643,19 +641,8 @@ ArmConfigureMmu (
   // Set TCR\r
   ArmSetTCR (TCR);\r
 \r
-  // Allocate pages for translation table. Pool allocations are 8 byte aligned,\r
-  // but we may require a higher alignment based on the size of the root table.\r
-  RootTableEntrySize = RootTableEntryCount * sizeof(UINT64);\r
-  if (RootTableEntrySize < EFI_PAGE_SIZE / 2) {\r
-    TranslationTableBuffer = AllocatePool (2 * RootTableEntrySize - 8);\r
-    //\r
-    // Naturally align the root table. Preserves possible NULL value\r
-    //\r
-    TranslationTable = (VOID *)((UINTN)(TranslationTableBuffer - 1) | (RootTableEntrySize - 1)) + 1;\r
-  } else {\r
-    TranslationTable = AllocatePages (1);\r
-    TranslationTableBuffer = NULL;\r
-  }\r
+  // Allocate pages for translation table\r
+  TranslationTable = AllocatePages (1);\r
   if (TranslationTable == NULL) {\r
     return RETURN_OUT_OF_RESOURCES;\r
   }\r
@@ -669,10 +656,10 @@ ArmConfigureMmu (
   }\r
 \r
   if (TranslationTableSize != NULL) {\r
-    *TranslationTableSize = RootTableEntrySize;\r
+    *TranslationTableSize = RootTableEntryCount * sizeof(UINT64);\r
   }\r
 \r
-  ZeroMem (TranslationTable, RootTableEntrySize);\r
+  ZeroMem (TranslationTable, RootTableEntryCount * sizeof(UINT64));\r
 \r
   // Disable MMU and caches. ArmDisableMmu() also invalidates the TLBs\r
   ArmDisableMmu ();\r
@@ -689,7 +676,7 @@ ArmConfigureMmu (
     DEBUG_CODE_BEGIN ();\r
       // Find the memory attribute for the Translation Table\r
       if ((UINTN)TranslationTable >= MemoryTable->PhysicalBase &&\r
-          (UINTN)TranslationTable + RootTableEntrySize <= MemoryTable->PhysicalBase +\r
+          (UINTN)TranslationTable + EFI_PAGE_SIZE <= MemoryTable->PhysicalBase +\r
                                                           MemoryTable->Length) {\r
         TranslationTableAttribute = MemoryTable->Attributes;\r
       }\r
@@ -718,11 +705,7 @@ ArmConfigureMmu (
   return RETURN_SUCCESS;\r
 \r
 FREE_TRANSLATION_TABLE:\r
-  if (TranslationTableBuffer != NULL) {\r
-    FreePool (TranslationTableBuffer);\r
-  } else {\r
-    FreePages (TranslationTable, 1);\r
-  }\r
+  FreePages (TranslationTable, 1);\r
   return Status;\r
 }\r
 \r