]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtualizationPkg: Xen: shuffle init order to deal with incoherency
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 14 Apr 2015 11:56:56 +0000 (11:56 +0000)
committeroliviermartin <oliviermartin@Edk2>
Tue, 14 Apr 2015 11:56:56 +0000 (11:56 +0000)
In order to prevent memory corruption issues caused by the fact that,
under virtualization, the guest is incoherent with the hypervisor's view
of memory until it enables its caches and MMU, this patch reshuffles the
init sequence so that the Xen shared memory regions are not touched
before the caches and MMU are enabled.

In addition, the loaded image itself is invalidated by virtual address,
to ensure that any runtime changes (such as the applied relocations) will
not suddenly become invisible once we turn the caches on.

Contributed-under: TianoCore Contribution Agreement 1.0
Reviewed-by: Olivier Martin <Olivier.Martin@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17178 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c

index 86cf870b79acd2debeb520c7f12662bb87543b09..16023382a6799bcaf0ddf87441815c99c396bdc0 100755 (executable)
@@ -55,6 +55,7 @@
   PrePiHobListPointerLib\r
   PlatformPeiLib\r
   MemoryInitPeiLib\r
+  CacheMaintenanceLib\r
 \r
 [Ppis]\r
   gArmMpCoreInfoPpiGuid\r
index 0772805890f2045d7c98643e9410ea729fd30034..f9ad37427217830140f88950f20f9b92d99ce75b 100755 (executable)
@@ -20,6 +20,7 @@
 #include <Library/PrePiHobListPointerLib.h>\r
 #include <Library/TimerLib.h>\r
 #include <Library/PerformanceLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
 \r
 #include <Ppi/GuidedSectionExtraction.h>\r
 #include <Ppi/ArmMpCoreInfo.h>\r
@@ -102,12 +103,6 @@ PrePiMain (
   // Initialize the architecture specific bits\r
   ArchInitialize ();\r
 \r
-  // Initialize the Serial Port\r
-  SerialPortInitialize ();\r
-  CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
-    (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
-  SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
-\r
   // Declare the PI/UEFI memory region\r
   HobList = HobConstructor (\r
     (VOID*)UefiMemoryBase,\r
@@ -117,10 +112,23 @@ PrePiMain (
     );\r
   PrePeiSetHobList (HobList);\r
 \r
+  //\r
+  // Ensure that the loaded image is invalidated in the caches, so that any\r
+  // modifications we made with the caches and MMU off (such as the applied\r
+  // relocations) don't become invisible once we turn them on.\r
+  //\r
+  InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
+\r
   // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
   Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  // Initialize the Serial Port\r
+  SerialPortInitialize ();\r
+  CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
+    (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
+  SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
+\r
   // Create the Stacks HOB (reserve the memory for all stacks)\r
   StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
   BuildStackHob (StacksBase, StacksSize);\r