]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
xen/arm: add size parameter to get_xen_paddr
authorLuca Miccio <206497@studenti.unimore.it>
Thu, 22 Aug 2019 08:21:56 +0000 (10:21 +0200)
committerLuca Miccio <206497@studenti.unimore.it>
Mon, 6 Jan 2020 13:59:41 +0000 (14:59 +0100)
In order to efficiently relocate Xen while coloring it, instead of many
memory regions, only a unique can be mapped as the target, as long as it
includes all the pages of the selected colors.  This means that in the
worst case the target region must be greater than xen code size * avail.
colors.  In place this region as high as possible in RAM, we use the
get_xen_paddr function.  However the latter assumes to handle a memory
with size equals only to xen code region.  Add a new "size" parameter to
handle also the coloring case.

Signed-off-by: Luca Miccio <206497@studenti.unimore.it>
Signed-off-by: Marco Solieri <marco.solieri@unimore.it>
Acked-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
xen/arch/arm/setup.c

index dc5d093ded5d334569a3d72f00275764a35b47fa..3e258026065fb999ad88873fcbb536c84a8be61d 100644 (file)
@@ -540,6 +540,58 @@ static paddr_t __init next_module(paddr_t s, paddr_t *end)
     return lowest;
 }
 
+/**
+ * get_xen_paddr - get physical address to relocate Xen to
+ *
+ * Xen is relocated to as near to the top of RAM as possible and
+ * aligned to a XEN_PADDR_ALIGN boundary.
+ */
+static paddr_t __init get_xen_paddr(uint32_t xen_size)
+{
+    struct meminfo *mi = &bootinfo.mem;
+    paddr_t min_size;
+    paddr_t paddr = 0;
+    int i;
+
+    min_size = (xen_size + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
+
+    /* Find the highest bank with enough space. */
+    for ( i = 0; i < mi->nr_banks; i++ )
+    {
+        const struct membank *bank = &mi->bank[i];
+        paddr_t s, e;
+
+        if ( bank->size >= min_size )
+        {
+            e = consider_modules(bank->start, bank->start + bank->size,
+                                 min_size, XEN_PADDR_ALIGN, 0);
+            if ( !e )
+                continue;
+
+#ifdef CONFIG_ARM_32
+            /* Xen must be under 4GB */
+            if ( e > 0x100000000ULL )
+                e = 0x100000000ULL;
+            if ( e < bank->start )
+                continue;
+#endif
+
+            s = e - min_size;
+
+            if ( s > paddr )
+                paddr = s;
+        }
+    }
+
+    if ( !paddr )
+        panic("Not enough memory to relocate Xen");
+
+    printk("Placing Xen at 0x%"PRIpaddr"-0x%"PRIpaddr"\n",
+           paddr, paddr + min_size);
+
+    return paddr;
+}
+
 static void __init init_pdx(void)
 {
     paddr_t bank_start, bank_size, bank_end;
@@ -820,7 +872,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     if ( !coloring_init() )
         panic("Xen Coloring support: setup failed\n");
 
-    xen_paddr = get_xen_paddr();
+    xen_paddr = get_xen_paddr(_end - _start);
     setup_pagetables(boot_phys_offset, xen_paddr);
 
     cmdline = boot_fdt_cmdline(device_tree_flattened);