Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/xen/x86 Start simplifying the Xen locore: rename an...



details:   https://anonhg.NetBSD.org/src/rev/6f1f81b56ffa
branches:  trunk
changeset: 348846:6f1f81b56ffa
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Nov 11 11:12:42 2016 +0000

description:
Start simplifying the Xen locore: rename and reorder several things, remove
awful debug messages, use unsigned counters, fix typos and KNF.

diffstat:

 sys/arch/xen/x86/x86_xpmap.c |  231 +++++++++++++++++-------------------------
 1 files changed, 92 insertions(+), 139 deletions(-)

diffs (truncated from 571 to 300 lines):

diff -r 11cfc2d974c8 -r 6f1f81b56ffa sys/arch/xen/x86/x86_xpmap.c
--- a/sys/arch/xen/x86/x86_xpmap.c      Fri Nov 11 11:00:38 2016 +0000
+++ b/sys/arch/xen/x86/x86_xpmap.c      Fri Nov 11 11:12:42 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_xpmap.c,v 1.63 2016/11/01 12:16:10 maxv Exp $      */
+/*     $NetBSD: x86_xpmap.c,v 1.64 2016/11/11 11:12:42 maxv Exp $      */
 
 /*
  * Copyright (c) 2006 Mathieu Ropert <mro%adviseo.fr@localhost>
@@ -42,7 +42,6 @@
  */
 
 /*
- *
  * Copyright (c) 2004 Christian Limpach.
  * All rights reserved.
  *
@@ -69,7 +68,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.63 2016/11/01 12:16:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.64 2016/11/11 11:12:42 maxv Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -91,13 +90,12 @@
 
 #undef XENDEBUG
 /* #define XENDEBUG_SYNC */
-/* #define     XENDEBUG_LOW */
+/* #define XENDEBUG_LOW */
 
 #ifdef XENDEBUG
 #define        XENPRINTF(x) printf x
 #define        XENPRINTK(x) printk x
 #define        XENPRINTK2(x) /* printk x */
-
 static char XBUF[256];
 #else
 #define        XENPRINTF(x)
@@ -118,6 +116,14 @@
 #define HYPERVISOR_mmu_update_self(req, count, success_count) \
        HYPERVISOR_mmu_update((req), (count), (success_count), DOMID_SELF)
 
+extern volatile struct xencons_interface *xencons_interface; /* XXX */
+extern struct xenstore_domain_interface *xenstore_interface; /* XXX */
+
+static void xen_bt_set_readonly(vaddr_t);
+static void xen_bootstrap_tables(vaddr_t, vaddr_t, size_t, size_t, int);
+
+vaddr_t xen_pmap_bootstrap(void);
+
 /*
  * kcpuset internally uses an array of uint32_t while xen uses an array of
  * u_long. As we're little-endian we can cast one to the other.
@@ -127,8 +133,8 @@
        uint32_t xcpum_km[2];
 #else
        uint32_t xcpum_km[1];
-#endif 
-       u_long   xcpum_xm;
+#endif
+       u_long xcpum_xm;
 } xcpumask_t;
 
 void
@@ -138,7 +144,6 @@
        panic("xen_failsafe_handler called!\n");
 }
 
-
 void
 xen_set_ldt(vaddr_t base, uint32_t entries)
 {
@@ -568,37 +573,16 @@
 #endif
 
 
-extern volatile struct xencons_interface *xencons_interface; /* XXX */
-extern struct xenstore_domain_interface *xenstore_interface; /* XXX */
-
-static void xen_bt_set_readonly(vaddr_t);
-static void xen_bootstrap_tables(vaddr_t, vaddr_t, int, int, int);
-
-/* How many PDEs ? */
 #if L2_SLOT_KERNBASE > 0
 #define TABLE_L2_ENTRIES (2 * (NKL2_KIMG_ENTRIES + 1))
 #else
 #define TABLE_L2_ENTRIES (NKL2_KIMG_ENTRIES + 1)
 #endif
 
-/* 
- * Construct and switch to new pagetables
- * first_avail is the first vaddr we can use after
- * we get rid of Xen pagetables
- */
-
-vaddr_t xen_pmap_bootstrap(void);
-
-/*
- * Function to get rid of Xen bootstrap tables
- */
-
-/* How many PDP do we need: */
 #ifdef PAE
 /*
- * For PAE, we consider a single contigous L2 "superpage" of 4 pages,
- * all of them mapped by the L3 page. We also need a shadow page
- * for L3[3].
+ * For PAE, we consider a single contigous L2 "superpage" of 4 pages, all of
+ * them mapped by the L3 page. We also need a shadow page for L3[3].
  */
 static const int l2_4_count = 6;
 #elif defined(__x86_64__)
@@ -607,11 +591,14 @@
 static const int l2_4_count = PTP_LEVELS - 1;
 #endif
 
+/*
+ * Xen locore: get rid of the Xen bootstrap tables. Build and switch to new page
+ * tables.
+ */
 vaddr_t
 xen_pmap_bootstrap(void)
 {
-       int count, oldcount;
-       long mapsize;
+       size_t count, oldcount, mapsize;
        vaddr_t bootstrap_tables, init_tables;
 
        xen_init_features();
@@ -620,16 +607,15 @@
 
        xpmap_phys_to_machine_mapping =
            (unsigned long *)xen_start_info.mfn_list;
-       init_tables = xen_start_info.pt_base;
-       __PRINTK(("xen_arch_pmap_bootstrap init_tables=0x%lx\n", init_tables));
 
        /* Space after Xen boostrap tables should be free */
-       bootstrap_tables = xen_start_info.pt_base +
-               (xen_start_info.nr_pt_frames * PAGE_SIZE);
+       init_tables = xen_start_info.pt_base;
+       bootstrap_tables = init_tables +
+           (xen_start_info.nr_pt_frames * PAGE_SIZE);
 
        /*
-        * Calculate how many space we need
-        * first everything mapped before the Xen bootstrap tables
+        * Calculate how much space we need. First, everything mapped before
+        * the Xen bootstrap tables.
         */
        mapsize = init_tables - KERNTEXTOFF;
        /* after the tables we'll have:
@@ -645,30 +631,33 @@
 #endif
        mapsize += PAGE_SIZE;
        mapsize += PAGE_SIZE;
-
 #ifdef DOM0OPS
        if (xendomain_is_dom0()) {
-               /* space for ISA I/O mem */
                mapsize += IOM_SIZE;
        }
 #endif
-       /* at this point mapsize doesn't include the table size */
 
+       /*
+        * At this point, mapsize doesn't include the table size.
+        */
 #ifdef __x86_64__
        count = TABLE_L2_ENTRIES;
 #else
        count = (mapsize + (NBPD_L2 -1)) >> L2_SHIFT;
-#endif /* __x86_64__ */
-       
-       /* now compute how many L2 pages we need exactly */
-       XENPRINTK(("bootstrap_final mapsize 0x%lx count %d\n", mapsize, count));
+#endif
+
+       /*
+        * Now compute how many L2 pages we need exactly. This is useful only
+        * on i386, since the initial count for amd64 is already enough.
+        */
        while (mapsize + (count + l2_4_count) * PAGE_SIZE + KERNTEXTOFF >
-           ((long)count << L2_SHIFT) + KERNBASE) {
+           (count << L2_SHIFT) + KERNBASE) {
                count++;
        }
+
 #ifndef __x86_64__
        /*
-        * one more L2 page: we'll alocate several pages after kva_start
+        * One more L2 page: we'll allocate several pages after kva_start
         * in pmap_bootstrap() before pmap_growkernel(), which have not been
         * counted here. It's not a big issue to allocate one more L2 as
         * pmap_growkernel() will be called anyway.
@@ -678,36 +667,37 @@
 #endif
 
        /*
-        * install bootstrap pages. We may need more L2 pages than will
-        * have the final table here, as it's installed after the final table
+        * Install bootstrap pages. We may need more L2 pages than will
+        * have the final table here, as it's installed after the final table.
         */
        oldcount = count;
 
 bootstrap_again:
-       XENPRINTK(("bootstrap_again oldcount %d\n", oldcount));
+
        /* 
         * Xen space we'll reclaim may not be enough for our new page tables,
-        * move bootstrap tables if necessary
+        * move bootstrap tables if necessary.
         */
        if (bootstrap_tables < init_tables + ((count + l2_4_count) * PAGE_SIZE))
                bootstrap_tables = init_tables +
-                                       ((count + l2_4_count) * PAGE_SIZE);
-       /* make sure we have enough to map the bootstrap_tables */
+                   ((count + l2_4_count) * PAGE_SIZE);
+
+       /* Make sure we have enough to map the bootstrap tables. */
        if (bootstrap_tables + ((oldcount + l2_4_count) * PAGE_SIZE) > 
-           ((long)oldcount << L2_SHIFT) + KERNBASE) {
+           (oldcount << L2_SHIFT) + KERNBASE) {
                oldcount++;
                goto bootstrap_again;
        }
 
        /* Create temporary tables */
-       xen_bootstrap_tables(xen_start_info.pt_base, bootstrap_tables,
-               xen_start_info.nr_pt_frames, oldcount, 0);
+       xen_bootstrap_tables(init_tables, bootstrap_tables,
+           xen_start_info.nr_pt_frames, oldcount, 0);
 
        /* Create final tables */
        xen_bootstrap_tables(bootstrap_tables, init_tables,
            oldcount + l2_4_count, count, 1);
 
-       /* zero out free space after tables */
+       /* Zero out free space after tables */
        memset((void *)(init_tables + ((count + l2_4_count) * PAGE_SIZE)), 0,
            (UPAGES + 1) * PAGE_SIZE);
 
@@ -724,8 +714,8 @@
  * We assume the areas don't overlap.
  */
 static void
-xen_bootstrap_tables(vaddr_t old_pgd, vaddr_t new_pgd,
-    int old_count, int new_count, int final)
+xen_bootstrap_tables(vaddr_t old_pgd, vaddr_t new_pgd, size_t old_count,
+    size_t new_count, int final)
 {
        pd_entry_t *pdtpe, *pde, *pte;
        pd_entry_t *bt_pgd;
@@ -739,10 +729,6 @@
        pt_entry_t pg_nx;
        u_int descs[4];
 
-       __PRINTK(("xen_bootstrap_tables(%#" PRIxVADDR ", %#" PRIxVADDR ","
-           " %d, %d)\n",
-           old_pgd, new_pgd, old_count, new_count));
-
        /*
         * Set the NX/XD bit, if available. descs[3] = %edx.
         */
@@ -750,13 +736,13 @@
        pg_nx = (descs[3] & CPUID_NOX) ? PG_NX : 0;
 
        /*
-        * size of R/W area after kernel text:
+        * Size of RW area after the kernel image:
         *     xencons_interface (if present)
         *     xenstore_interface (if present)
         *     table pages (new_count + l2_4_count entries)
-        * extra mappings (only when final is true):
+        * Extra mappings (only when final is true):
         *     UAREA
-        *     dummy user PGD (x86_64 only)/gdt page (i386 only)
+        *     dummy user PGD (x86_64 only) / GDT page (i386 only)
         *     HYPERVISOR_shared_info
         *     early_zerop
         *     ISA I/O mem (if needed)
@@ -771,7 +757,7 @@
        }
 
        /*
-        * we always set atdevbase, as it's used by init386 to find the first
+        * We always set atdevbase, as it's used by init386 to find the first
         * available VA. map_end is updated only if we are dom0, so
         * atdevbase -> atdevbase + IOM_SIZE will be mapped only in
         * this case.
@@ -783,7 +769,7 @@
                /* ISA I/O mem */
                map_end += IOM_SIZE;
        }
-#endif /* DOM0OPS */
+#endif
 



Home | Main Index | Thread Index | Old Index