]> xenbits.xensource.com Git - xen.git/commitdiff
xen/arm: static memory initialization
authorPenny Zheng <penny.zheng@arm.com>
Fri, 10 Sep 2021 02:52:12 +0000 (02:52 +0000)
committerStefano Stabellini <stefano.stabellini@xilinx.com>
Mon, 13 Sep 2021 21:10:22 +0000 (14:10 -0700)
This patch introduces static memory initialization, during system boot-up.

The new function init_staticmem_pages is responsible for static memory
initialization.

Helper free_staticmem_pages is the equivalent of free_heap_pages, to free
nr_mfns pages of static memory.

This commit also introduces a new CONFIG_STATIC_MEMORY option to wrap all
static-allocation-related code.

Put asynchronously scrubbing pages of static memory in TODO list.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/arch/arm/setup.c
xen/common/Kconfig
xen/common/page_alloc.c
xen/include/xen/mm.h

index 63a908e325eef6aed43b53b84f192a854af6e9e4..5be7f2b0c208e10c2a4763e523d28ccb056ac74b 100644 (file)
@@ -609,6 +609,29 @@ static void __init init_pdx(void)
     }
 }
 
+/* Static memory initialization */
+static void __init init_staticmem_pages(void)
+{
+#ifdef CONFIG_STATIC_MEMORY
+    unsigned int bank;
+
+    for ( bank = 0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ )
+    {
+        if ( bootinfo.reserved_mem.bank[bank].xen_domain )
+        {
+            mfn_t bank_start = _mfn(PFN_UP(bootinfo.reserved_mem.bank[bank].start));
+            unsigned long bank_pages = PFN_DOWN(bootinfo.reserved_mem.bank[bank].size);
+            mfn_t bank_end = mfn_add(bank_start, bank_pages);
+
+            if ( mfn_x(bank_end) <= mfn_x(bank_start) )
+                return;
+
+            free_staticmem_pages(mfn_to_page(bank_start), bank_pages, false);
+        }
+    }
+#endif
+}
+
 #ifdef CONFIG_ARM_32
 static void __init setup_mm(void)
 {
@@ -736,6 +759,8 @@ static void __init setup_mm(void)
     /* Add xenheap memory that was not already added to the boot allocator. */
     init_xenheap_pages(mfn_to_maddr(xenheap_mfn_start),
                        mfn_to_maddr(xenheap_mfn_end));
+
+    init_staticmem_pages();
 }
 #else /* CONFIG_ARM_64 */
 static void __init setup_mm(void)
@@ -789,6 +814,8 @@ static void __init setup_mm(void)
 
     setup_frametable_mappings(ram_start, ram_end);
     max_page = PFN_DOWN(ram_end);
+
+    init_staticmem_pages();
 }
 #endif
 
index ac5491b1cce72c31b72297daa7e007c0937ec131..db687b1785e77ed79c8fcc6e9386595bcb0cafc6 100644 (file)
@@ -70,6 +70,19 @@ config MEM_ACCESS
 config NEEDS_LIBELF
        bool
 
+config STATIC_MEMORY
+       bool "Static Allocation Support (UNSUPPORTED)" if UNSUPPORTED
+       depends on ARM
+       help
+         Static Allocation refers to system or sub-system(domains) for
+         which memory areas are pre-defined by configuration using physical
+         address ranges.
+
+         When enabled, memory can be statically allocated to a domain using
+         the property "xen,static-mem" defined in the domain configuration.
+
+         If unsure, say N.
+
 menu "Speculative hardening"
 
 config SPECULATIVE_HARDEN_ARRAY
index a3ee5eca9ebac41a30c6f8e6ada26e1c91e0e2ac..ba7adc80db01fc5c34131a3ccd08076e35c2aad2 100644 (file)
@@ -2604,6 +2604,27 @@ struct domain *get_pg_owner(domid_t domid)
     return pg_owner;
 }
 
+#ifdef CONFIG_STATIC_MEMORY
+/* Equivalent of free_heap_pages to free nr_mfns pages of static memory. */
+void __init free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
+                                 bool need_scrub)
+{
+    mfn_t mfn = page_to_mfn(pg);
+    unsigned long i;
+
+    for ( i = 0; i < nr_mfns; i++ )
+    {
+        mark_page_free(&pg[i], mfn_add(mfn, i));
+
+        if ( need_scrub )
+        {
+            /* TODO: asynchronous scrubbing for pages of static memory. */
+            scrub_one_page(pg);
+        }
+    }
+}
+#endif
+
 /*
  * Local variables:
  * mode: C
index 667f9dac83a4357ff23886210dd15b2106092e89..8e8fb5a615d56332fd1172f8caa8ac13e99967af 100644 (file)
@@ -85,6 +85,12 @@ bool scrub_free_pages(void);
 } while ( false )
 #define FREE_XENHEAP_PAGE(p) FREE_XENHEAP_PAGES(p, 0)
 
+#ifdef CONFIG_STATIC_MEMORY
+/* These functions are for static memory */
+void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
+                          bool need_scrub);
+#endif
+
 /* Map machine page range in Xen virtual address space. */
 int map_pages_to_xen(
     unsigned long virt,