Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Use only one function to pin pages with Xen, and pr...



details:   https://anonhg.NetBSD.org/src/rev/112c49249c7a
branches:  trunk
changeset: 761870:112c49249c7a
user:      jym <jym%NetBSD.org@localhost>
date:      Thu Feb 10 00:23:14 2011 +0000

description:
Use only one function to pin pages with Xen, and provide macros to
call it for different levels (L1 => L4).

Replace all calls to xpq_queue_pin_table(...) in MD code with these new
functions, with proper #ifdef'ing depending on $MACHINE.

Rationale:
- only one function to modify for logging
- pushes responsibility to caller for chosing the proper pin level, rather
than Xen internal functions; this makes the pin level explicit rather than
implicit.

Boot tested for dom0 i386/amd64, PAE included. No functional change intended.

diffstat:

 sys/arch/x86/x86/pmap.c        |  15 ++++++++----
 sys/arch/xen/include/xenpmap.h |  13 +++++++++-
 sys/arch/xen/x86/x86_xpmap.c   |  51 +++++++++++++----------------------------
 3 files changed, 37 insertions(+), 42 deletions(-)

diffs (189 lines):

diff -r 0ab7c93df358 -r 112c49249c7a sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Thu Feb 10 00:05:52 2011 +0000
+++ b/sys/arch/x86/x86/pmap.c   Thu Feb 10 00:23:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.116 2011/02/05 13:50:08 yamt Exp $  */
+/*     $NetBSD: pmap.c,v 1.117 2011/02/10 00:23:14 jym Exp $   */
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -142,7 +142,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.116 2011/02/05 13:50:08 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.117 2011/02/10 00:23:14 jym Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1497,7 +1497,7 @@
        HYPERVISOR_update_va_mapping(xen_dummy_user_pgd + KERNBASE,
            pmap_pa2pte(xen_dummy_user_pgd) | PG_u | PG_V, UVMF_INVLPG);
        /* Pin as L4 */
-       xpq_queue_pin_table(xpmap_ptom_masked(xen_dummy_user_pgd));
+       xpq_queue_pin_l4_table(xpmap_ptom_masked(xen_dummy_user_pgd));
 #endif /* __x86_64__ */
        idt_vaddr = virtual_avail;                      /* don't need pte */
        idt_paddr = avail_start;                        /* steal a page */
@@ -2182,12 +2182,17 @@
                if (i == l2tol3(PDIR_SLOT_PTE))
                        continue;
 #endif
-               xpq_queue_pin_table(xpmap_ptom_masked(pdirpa));
+
+#ifdef __x86_64__
+               xpq_queue_pin_l4_table(xpmap_ptom_masked(pdirpa));
+#else
+               xpq_queue_pin_l2_table(xpmap_ptom_masked(pdirpa));
+#endif
        }
 #ifdef PAE
        object = ((vaddr_t)pdir) + PAGE_SIZE  * l2tol3(PDIR_SLOT_PTE);
        (void)pmap_extract(pmap_kernel(), object, &pdirpa);
-       xpq_queue_pin_table(xpmap_ptom_masked(pdirpa));
+       xpq_queue_pin_l2_table(xpmap_ptom_masked(pdirpa));
 #endif
        splx(s);
 #endif /* XEN */
diff -r 0ab7c93df358 -r 112c49249c7a sys/arch/xen/include/xenpmap.h
--- a/sys/arch/xen/include/xenpmap.h    Thu Feb 10 00:05:52 2011 +0000
+++ b/sys/arch/xen/include/xenpmap.h    Thu Feb 10 00:23:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xenpmap.h,v 1.24 2009/10/23 02:32:33 snj Exp $ */
+/*     $NetBSD: xenpmap.h,v 1.25 2011/02/10 00:23:14 jym Exp $ */
 
 /*
  *
@@ -40,10 +40,19 @@
 void xpq_flush_queue(void);
 void xpq_queue_set_ldt(vaddr_t, uint32_t);
 void xpq_queue_tlb_flush(void);
-void xpq_queue_pin_table(paddr_t);
+void xpq_queue_pin_table(paddr_t, int);
 void xpq_queue_unpin_table(paddr_t);
 int  xpq_update_foreign(paddr_t, pt_entry_t, int);
 
+#define xpq_queue_pin_l1_table(pa)     \
+       xpq_queue_pin_table(pa, MMUEXT_PIN_L1_TABLE)
+#define xpq_queue_pin_l2_table(pa)     \
+       xpq_queue_pin_table(pa, MMUEXT_PIN_L2_TABLE)
+#define xpq_queue_pin_l3_table(pa)     \
+       xpq_queue_pin_table(pa, MMUEXT_PIN_L3_TABLE)
+#define xpq_queue_pin_l4_table(pa)     \
+       xpq_queue_pin_table(pa, MMUEXT_PIN_L4_TABLE)
+
 extern unsigned long *xpmap_phys_to_machine_mapping;
 
 /*   
diff -r 0ab7c93df358 -r 112c49249c7a sys/arch/xen/x86/x86_xpmap.c
--- a/sys/arch/xen/x86/x86_xpmap.c      Thu Feb 10 00:05:52 2011 +0000
+++ b/sys/arch/xen/x86/x86_xpmap.c      Thu Feb 10 00:23:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_xpmap.c,v 1.23 2010/12/20 21:18:45 jym Exp $       */
+/*     $NetBSD: x86_xpmap.c,v 1.24 2011/02/10 00:23:14 jym Exp $       */
 
 /*
  * Copyright (c) 2006 Mathieu Ropert <mro%adviseo.fr@localhost>
@@ -69,7 +69,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.23 2010/12/20 21:18:45 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.24 2011/02/10 00:23:14 jym Exp $");
 
 #include "opt_xen.h"
 #include "opt_ddb.h"
@@ -237,49 +237,28 @@
 }
 
 void
-xpq_queue_pin_table(paddr_t pa)
+xpq_queue_pin_table(paddr_t pa, int lvl)
 {
        struct mmuext_op op;
        xpq_flush_queue();
 
-       XENPRINTK2(("xpq_queue_pin_table: 0x%" PRIx64 " 0x%" PRIx64 "\n",
-           (int64_t)pa, (int64_t)pa));
-       op.arg1.mfn = pa >> PAGE_SHIFT;
+       XENPRINTK2(("xpq_queue_pin_l%d_table: %#" PRIxPADDR "\n",
+           lvl + 1, pa));
 
-#if defined(__x86_64__)
-       op.cmd = MMUEXT_PIN_L4_TABLE;
-#else
-       op.cmd = MMUEXT_PIN_L2_TABLE;
-#endif
+       op.arg1.mfn = pa >> PAGE_SHIFT;
+       op.cmd = lvl;
+
        if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0)
                panic("xpq_queue_pin_table");
 }
 
-#ifdef PAE
-static void
-xpq_queue_pin_l3_table(paddr_t pa)
-{
-       struct mmuext_op op;
-       xpq_flush_queue();
-
-       XENPRINTK2(("xpq_queue_pin_l2_table: 0x%" PRIx64 " 0x%" PRIx64 "\n",
-           (int64_t)pa, (int64_t)pa));
-       op.arg1.mfn = pa >> PAGE_SHIFT;
-
-       op.cmd = MMUEXT_PIN_L3_TABLE;
-       if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0)
-               panic("xpq_queue_pin_table");
-}
-#endif
-
 void
 xpq_queue_unpin_table(paddr_t pa)
 {
        struct mmuext_op op;
        xpq_flush_queue();
 
-       XENPRINTK2(("xpq_queue_unpin_table: 0x%" PRIx64 " 0x%" PRIx64 "\n",
-           (int64_t)pa, (int64_t)pa));
+       XENPRINTK2(("xpq_queue_unpin_table: %#" PRIxPADDR "\n", pa));
        op.arg1.mfn = pa >> PAGE_SHIFT;
        op.cmd = MMUEXT_UNPIN_TABLE;
        if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0)
@@ -781,18 +760,18 @@
                        continue;
 #if 0
                __PRINTK(("pin L2 %d addr 0x%" PRIx64 "\n", i, (int64_t)addr));
-               xpq_queue_pin_table(xpmap_ptom_masked(addr));
+               xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 #endif
        }
        if (final) {
                addr = (u_long)pde - KERNBASE + 3 * PAGE_SIZE;
                __PRINTK(("pin L2 %d addr %#" PRIxPADDR "\n", 2, addr));
-               xpq_queue_pin_table(xpmap_ptom_masked(addr));
+               xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
        }
 #if 0
        addr = (u_long)pde - KERNBASE + 2 * PAGE_SIZE;
        __PRINTK(("pin L2 %d addr 0x%" PRIx64 "\n", 2, (int64_t)addr));
-       xpq_queue_pin_table(xpmap_ptom_masked(addr));
+       xpq_queue_pin_l2_table(xpmap_ptom_masked(addr));
 #endif
 #else /* PAE */
        /* recursive entry in higher-level PD */
@@ -812,10 +791,12 @@
 #endif
        /* Pin the PGD */
        __PRINTK(("pin PGD\n"));
-#ifdef PAE
+#ifdef __x86_64__
+       xpq_queue_pin_l4_table(xpmap_ptom_masked(new_pgd - KERNBASE));
+#elif PAE
        xpq_queue_pin_l3_table(xpmap_ptom_masked(new_pgd - KERNBASE));
 #else
-       xpq_queue_pin_table(xpmap_ptom_masked(new_pgd - KERNBASE));
+       xpq_queue_pin_l2_table(xpmap_ptom_masked(new_pgd - KERNBASE));
 #endif
 
        /* Save phys. addr of PDP, for libkvm. */



Home | Main Index | Thread Index | Old Index