diff mbox series

[v2,35/40] xen/mpu: destroy boot modules and early FDT mapping in MPU system

Message ID 20230113052914.3845596-36-Penny.Zheng@arm.com (mailing list archive)
State New, archived
Headers show
Series xen/arm: Add Armv8-R64 MPU support to Xen - Part#1 | expand

Commit Message

Penny Zheng Jan. 13, 2023, 5:29 a.m. UTC
In MMU system, we will free all memory as boot modules, like kernel
initramfs module, into heap, and it is not applicable in MPU system.
Heap must be statically configured in Device tree, so it should not
change.
In MPU system, we destory MPU memory regions of boot modules.

In MPU version of remove_early_mappings, we destroy MPU memory
region of early FDT mapping.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Wei Chen <wei.chen@arm.com>
---
 xen/arch/arm/mm_mpu.c    |  4 ++++
 xen/arch/arm/setup.c     | 25 -------------------------
 xen/arch/arm/setup_mmu.c | 25 +++++++++++++++++++++++++
 xen/arch/arm/setup_mpu.c | 26 ++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/xen/arch/arm/mm_mpu.c b/xen/arch/arm/mm_mpu.c
index de0c7d919a..118bb11d1a 100644
--- a/xen/arch/arm/mm_mpu.c
+++ b/xen/arch/arm/mm_mpu.c
@@ -854,6 +854,10 @@  void dump_hyp_walk(vaddr_t addr)
 
 void __init remove_early_mappings(void)
 {
+    /* Earlier, early FDT is mapped with MAX_FDT_SIZE in early_fdt_map */
+    if ( destroy_xen_mappings(round_pgdown(dtb_paddr),
+                              round_pgup(dtb_paddr + MAX_FDT_SIZE)) )
+        panic("Unable to destroy early Device-Tree mapping.\n");
 }
 
 int init_secondary_pagetables(int cpu)
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 0eac33e68c..49ba998f68 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -412,31 +412,6 @@  const char * __init boot_module_kind_as_string(bootmodule_kind kind)
     }
 }
 
-void __init discard_initial_modules(void)
-{
-    struct bootmodules *mi = &bootinfo.modules;
-    int i;
-
-    for ( i = 0; i < mi->nr_mods; i++ )
-    {
-        paddr_t s = mi->module[i].start;
-        paddr_t e = s + PAGE_ALIGN(mi->module[i].size);
-
-        if ( mi->module[i].kind == BOOTMOD_XEN )
-            continue;
-
-        if ( !mfn_valid(maddr_to_mfn(s)) ||
-             !mfn_valid(maddr_to_mfn(e)) )
-            continue;
-
-        fw_unreserved_regions(s, e, init_domheap_pages, 0);
-    }
-
-    mi->nr_mods = 0;
-
-    remove_early_mappings();
-}
-
 /* Relocate the FDT in Xen heap */
 static void * __init relocate_fdt(paddr_t dtb_paddr, size_t dtb_size)
 {
diff --git a/xen/arch/arm/setup_mmu.c b/xen/arch/arm/setup_mmu.c
index 7e5d87f8bd..611a60633e 100644
--- a/xen/arch/arm/setup_mmu.c
+++ b/xen/arch/arm/setup_mmu.c
@@ -340,6 +340,31 @@  void __init setup_mm(void)
 }
 #endif
 
+void __init discard_initial_modules(void)
+{
+    struct bootmodules *mi = &bootinfo.modules;
+    int i;
+
+    for ( i = 0; i < mi->nr_mods; i++ )
+    {
+        paddr_t s = mi->module[i].start;
+        paddr_t e = s + PAGE_ALIGN(mi->module[i].size);
+
+        if ( mi->module[i].kind == BOOTMOD_XEN )
+            continue;
+
+        if ( !mfn_valid(maddr_to_mfn(s)) ||
+             !mfn_valid(maddr_to_mfn(e)) )
+            continue;
+
+        fw_unreserved_regions(s, e, init_domheap_pages, 0);
+    }
+
+    mi->nr_mods = 0;
+
+    remove_early_mappings();
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/arm/setup_mpu.c b/xen/arch/arm/setup_mpu.c
index f7d74ea604..f47f1f39ee 100644
--- a/xen/arch/arm/setup_mpu.c
+++ b/xen/arch/arm/setup_mpu.c
@@ -152,6 +152,32 @@  bool __init mpu_memory_section_contains(paddr_t s, paddr_t e,
     return false;
 }
 
+void __init discard_initial_modules(void)
+{
+    unsigned int i = 0;
+
+    /*
+     * Xenheap in MPU system must be statically configured in FDT in MPU
+     * system, so its base address and size couldn't change and it could not
+     * accept freed memory from boot modules.
+     * Disable MPU memory region of boot module section, since it will be in
+     * no use after boot.
+     */
+    for ( ; i < mpuinfo.sections[MSINFO_BOOTMODULE].nr_banks; i++ )
+    {
+        paddr_t start = mpuinfo.sections[MSINFO_BOOTMODULE].bank[i].start;
+        paddr_t size = mpuinfo.sections[MSINFO_BOOTMODULE].bank[i].size;
+        int rc;
+
+        rc = destroy_xen_mappings(start, start + size);
+        if ( rc )
+            panic("mpu: Unable to destroy boot module section 0x%"PRIpaddr"- 0x%"PRIpaddr"\n",
+                  start, start + size);
+    }
+
+    remove_early_mappings();
+}
+
 /*
  * Local variables:
  * mode: C