]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
xen/common vmap: fix alternative with coloring support
authorLuca Miccio <206497@studenti.unimore.it>
Thu, 22 Aug 2019 09:56:25 +0000 (11:56 +0200)
committerLuca Miccio <206497@studenti.unimore.it>
Mon, 6 Jan 2020 14:07:34 +0000 (15:07 +0100)
Alternative module remaps Xen code (.text) with a physical contiguous
mapping. If Xen code is colored, the current remap will break
alternative system. Fix this problem by remapping Xen code using its
color selection.

Notes:
A more desiderable way to solve this issues is to create a common function
that can be used both with and without coloring support. This avoid to
have code inside #ifdefs. A first implementation is in WIP but early
testings show that in same cases Linux has booting issues.
Keep this working code as it is now until we have a more stable solution.

Signed-off-by: Luca Miccio <206497@studenti.unimore.it>
Signed-off-by: Marco Solieri <marco.solieri@unimore.it>
xen/common/vmap.c

index faebc1ddf1145210d95144606107a0a16c9c561e..be442ff288c80bb432d5283ad32a80ae7912d973 100644 (file)
@@ -8,6 +8,7 @@
 #include <xen/types.h>
 #include <xen/vmap.h>
 #include <asm/page.h>
+#include <asm/coloring.h>
 
 static DEFINE_SPINLOCK(vm_lock);
 static void *__read_mostly vm_base[VMAP_REGION_NR];
@@ -205,7 +206,35 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
 {
     void *va = vm_alloc(nr * granularity, align, type);
     unsigned long cur = (unsigned long)va;
-
+#ifdef CONFIG_COLORING
+    /*
+     * Since the alternative module re-maps the Xen text, we need to handle
+     * the coloring scenario.
+     * In that case we need to re-map Xen using the same coloring logic used
+     * before during setup_pagetables.
+     */
+    if ((unsigned long)mfn_to_maddr(*mfn) == __pa(_start))
+    {
+        mfn_t mfn_col;
+        paddr_t xen_paddr = mfn_to_maddr(*mfn);
+        int iter = granularity * nr;
+        int i;
+
+        C_DEBUG("VM Alloc: %p\n", va);
+        C_DEBUG("Starting to mapping colored from physical 0x%lx\n", xen_paddr);
+        for ( i = 0; i < iter; i++, cur += PAGE_SIZE )
+        {
+            xen_paddr = next_xen_colored(xen_paddr);
+            mfn_col = maddr_to_mfn(xen_paddr);
+            if ( map_pages_to_xen(cur, mfn_col, 1, flags) )
+            {
+                vunmap(va);
+                va = NULL;
+            }
+            xen_paddr += PAGE_SIZE;
+        }
+    } else
+#endif
     for ( ; va && nr--; ++mfn, cur += PAGE_SIZE * granularity )
     {
         if ( map_pages_to_xen(cur, *mfn, granularity, flags) )