diff mbox

[edk2,3/3] ArmVirtualizationPkg: wipe caches by VA before enabling the MMU

Message ID 1427224544-29955-3-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel March 24, 2015, 7:15 p.m. UTC
As a guest under virtualization, it is not sufficient to enable
the caches using the architecturally mandated procedure of
invalidating by set/way. We also have to explicitly invalidate
the stack and heap regions by virtual address, to prevent dirty
cachelines in system caches or on other CPUs to shadow the data
that we have written straight to main memory while executing
with the MMU off.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 .../ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf   | 1 +
 ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c                   | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
index 86cf870b79ac..16023382a679 100755
--- a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
+++ b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
@@ -55,6 +55,7 @@ 
   PrePiHobListPointerLib
   PlatformPeiLib
   MemoryInitPeiLib
+  CacheMaintenanceLib
 
 [Ppis]
   gArmMpCoreInfoPpiGuid
diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c
index 0772805890f2..99f23a665f46 100755
--- a/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c
+++ b/ArmPlatformPkg/ArmVirtualizationPkg/PrePi/PrePi.c
@@ -20,6 +20,7 @@ 
 #include <Library/PrePiHobListPointerLib.h>
 #include <Library/TimerLib.h>
 #include <Library/PerformanceLib.h>
+#include <Library/CacheMaintenanceLib.h>
 
 #include <Ppi/GuidedSectionExtraction.h>
 #include <Ppi/ArmMpCoreInfo.h>
@@ -117,12 +118,15 @@  PrePiMain (
     );
   PrePeiSetHobList (HobList);
 
+  StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
+  InvalidateDataCacheRange ((VOID *) StacksBase, StacksSize);
+  InvalidateDataCacheRange ((VOID *) UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
+
   // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
   Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
   ASSERT_EFI_ERROR (Status);
 
   // Create the Stacks HOB (reserve the memory for all stacks)
-  StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
   BuildStackHob (StacksBase, StacksSize);
 
   // Declare the Global Variable HOB