]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg/ArmVirtPlatformLib: map executable NOR region as normal memory
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 18 Nov 2015 11:50:33 +0000 (11:50 +0000)
committerabiesheuvel <abiesheuvel@Edk2>
Wed, 18 Nov 2015 11:50:33 +0000 (11:50 +0000)
The ARM architecture version 7 and later mandates that device mappings
have the XN (non-executable) bit set, to prevent speculative instruction
fetches from read-sensitive regions. This implies that we should not map
regions as device if we want to execute from them, so the NOR region that
contains our FD image should be mapped as normal memory instead.

The MMU code deals correctly with overlapping ARM_MEMORY_REGION_DESCRIPTOR
entries, and later entries in the array take precedence over earlier ones.
So simply add an entry to the end of the array that overrides the mapping
attributes of the FD image, wherever it resides.

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

ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c

index d5d288fb1b482d47a5978fafcb1bf41640fd6933..530f7d608e0b589fd780728157cd8404a2533247 100644 (file)
@@ -22,7 +22,7 @@
 #include <ArmPlatform.h>\r
 \r
 // Number of Virtual Memory Map Descriptors\r
-#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          4\r
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5\r
 \r
 // DDR attributes\r
 #define DDR_ATTRIBUTES_CACHED    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK\r
@@ -100,8 +100,14 @@ ArmPlatformGetVirtualMemoryMap (
   VirtualMemoryTable[2].Length       = ArmGetPhysAddrTop () - VirtualMemoryTable[2].PhysicalBase;\r
   VirtualMemoryTable[2].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
 \r
+  // Remap the FD region as normal executable memory\r
+  VirtualMemoryTable[3].PhysicalBase = FixedPcdGet64 (PcdFdBaseAddress);\r
+  VirtualMemoryTable[3].VirtualBase  = VirtualMemoryTable[3].PhysicalBase;\r
+  VirtualMemoryTable[3].Length       = FixedPcdGet32 (PcdFdSize);\r
+  VirtualMemoryTable[3].Attributes   = CacheAttributes;\r
+\r
   // End of Table\r
-  ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r
+  ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r
 \r
   *VirtualMemoryMap = VirtualMemoryTable;\r
 }\r