[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 40/52] xen/mpu: implement remove_early_mappings in MPU system



We implement remove_early_mappings() to remove early mappings of
FDT in MPU system.

When mapping FDT in early_fdt_map(), we mapped the first 2MB firstly,
and check the size and then map with an extra 2MB if needed. So the
unmapping shall follow the same strategy.

In MMU, we could use fixed virtual address to remove the mapping.
As it is not workable for MPU, we pass the FDT physical address
in remove_early_mappings() for MPU to destroy the mapping.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
v3:
- adapt to the change of mapping FDT in two 2MB chunks if needed
---
 xen/arch/arm/include/asm/mm.h |  2 +-
 xen/arch/arm/mmu/mm.c         |  2 +-
 xen/arch/arm/mpu/mm.c         | 15 +++++++++++++++
 xen/arch/arm/setup.c          |  3 +--
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 0352182d99..2b119a87da 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -209,7 +209,7 @@ extern bool flags_has_rwx(unsigned int flags);
 /* Map FDT in boot pagetable */
 extern void *early_fdt_map(paddr_t fdt_paddr);
 /* Remove early mappings */
-extern void remove_early_mappings(void);
+extern void remove_early_mappings(paddr_t dtb_paddr);
 /*
  * Allocate and initialise memory mapping for a secondary CPU.
  * Sets init_mm to the new memory mapping table
diff --git a/xen/arch/arm/mmu/mm.c b/xen/arch/arm/mmu/mm.c
index 4196a55c32..f37912d066 100644
--- a/xen/arch/arm/mmu/mm.c
+++ b/xen/arch/arm/mmu/mm.c
@@ -361,7 +361,7 @@ lpae_t pte_of_xenaddr(vaddr_t va)
     return mfn_to_xen_entry(maddr_to_mfn(ma), MT_NORMAL);
 }
 
-void __init remove_early_mappings(void)
+void __init remove_early_mappings(paddr_t dtb_paddr)
 {
     int rc;
 
diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index 79d1c10d05..27d924e449 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -20,9 +20,11 @@
  */
 
 #include <xen/init.h>
+#include <xen/libfdt/libfdt.h>
 #include <xen/mm.h>
 #include <xen/page-size.h>
 #include <xen/pfn.h>
+#include <xen/sizes.h>
 #include <asm/arm64/mpu.h>
 #include <asm/page.h>
 #include <asm/setup.h>
@@ -857,6 +859,19 @@ bool is_mm_range_mapped_transient(paddr_t pa, paddr_t len)
     return false;
 }
 
+void __init remove_early_mappings(paddr_t dtb_paddr)
+{
+    paddr_t pa = dtb_paddr & PAGE_MASK, offset = dtb_paddr % PAGE_SIZE;
+    uint32_t size = fdt_totalsize(maddr_to_virt(dtb_paddr));
+
+    if ( xen_mpumap_update(pa, pa + SZ_2M, 0) )
+        panic("Unable to destroy early Device-Tree mapping.\n");
+
+    if ( (offset + size) > SZ_2M )
+        if ( xen_mpumap_update(pa + SZ_2M, pa + SZ_2M + SZ_2M, 0) )
+            panic("Unable to destroy early Device-Tree mapping.\n");
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index c21d1db763..200fa6eb53 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -529,8 +529,6 @@ void __init discard_initial_modules(void)
 
         mi->nr_mods = 0;
     }
-
-    remove_early_mappings();
 }
 
 /* Relocate the FDT in Xen heap */
@@ -973,6 +971,7 @@ void __init start_xen(unsigned long boot_phys_offset,
      * will be scrubbed (unless suppressed).
      */
     discard_initial_modules();
+    remove_early_mappings(fdt_paddr);
 
     heap_init_late();
 
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.