Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode Swap userland code and kvm spaces so that ...



details:   https://anonhg.NetBSD.org/src/rev/16f59e410201
branches:  trunk
changeset: 768672:16f59e410201
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Wed Aug 24 12:54:46 2011 +0000

description:
Swap userland code and kvm spaces so that userland lives from VM_MIN_ADDRESS
to VM_MAXUSER_ADDRESS and KVM is above that.

Note that the userspace is surrounded by a configurable amount of
non-accessible barrier space to prevent accidental out-of-boundaries access
even when reading.

diffstat:

 sys/arch/usermode/include/vmparam.h |   6 +++---
 sys/arch/usermode/usermode/pmap.c   |  21 +++++++++++----------
 2 files changed, 14 insertions(+), 13 deletions(-)

diffs (98 lines):

diff -r 8465fcf1d967 -r 16f59e410201 sys/arch/usermode/include/vmparam.h
--- a/sys/arch/usermode/include/vmparam.h       Wed Aug 24 12:15:44 2011 +0000
+++ b/sys/arch/usermode/include/vmparam.h       Wed Aug 24 12:54:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.7 2011/08/24 11:26:43 reinoud Exp $ */
+/* $NetBSD: vmparam.h,v 1.8 2011/08/24 12:54:47 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -38,9 +38,9 @@
 
 #define VM_MIN_KERNEL_ADDRESS  kmem_k_start
 #define VM_MAX_KERNEL_ADDRESS  kmem_k_end
-#define VM_MIN_ADDRESS         kmem_ext_start
-#define VM_MAX_ADDRESS         kmem_user_end
+#define VM_MIN_ADDRESS         kmem_user_start
 #define VM_MAXUSER_ADDRESS     kmem_user_end
+#define VM_MAX_ADDRESS         kmem_ext_end
 
 #define VM_PHYSSEG_STRAT       VM_PSTRAT_BIGFIRST
 #define VM_PHYSSEG_MAX         1
diff -r 8465fcf1d967 -r 16f59e410201 sys/arch/usermode/usermode/pmap.c
--- a/sys/arch/usermode/usermode/pmap.c Wed Aug 24 12:15:44 2011 +0000
+++ b/sys/arch/usermode/usermode/pmap.c Wed Aug 24 12:54:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.29 2011/08/24 11:50:28 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.30 2011/08/24 12:54:46 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%NetBSD.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.29 2011/08/24 11:50:28 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.30 2011/08/24 12:54:46 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -143,11 +143,6 @@
        /* make page aligned */
        mpos = round_page((vaddr_t) mem_uvm) + PAGE_SIZE;
 
-       /* calculate KVM section (RW-) */
-       kmem_ext_start = mpos;
-       mpos += kmem_len;
-       kmem_ext_end   = mpos;
-
        /* low barrier (---) */
        mpos += barrier_len;
 
@@ -160,6 +155,11 @@
        /* upper barrier (---) */
        mpos += barrier_len;
 
+       /* calculate KVM section (RW-) */
+       kmem_ext_start = mpos;
+       mpos += kmem_len;
+       kmem_ext_end   = mpos;
+
 #if 0
        /* protect complete UVM area (---) */
        addr = thunk_mmap((void*) mem_uvm,
@@ -197,7 +197,7 @@
        if (wlen != 1)
                panic("pmap_bootstrap: can't grow file\n");
 
-       /* (un)protect the current kernel and data sections */
+       /* protect the current kernel section */
        /* XXX kernel stack? */
        err = thunk_mprotect((void *) kmem_k_start, kmem_k_end - kmem_k_start,
                PROT_READ | PROT_EXEC);
@@ -210,6 +210,7 @@
 
        phys_npages = (free_end - free_start) / PAGE_SIZE;
        pv_table_size = round_page(phys_npages * sizeof(struct pv_entry));
+
        aprint_debug("claiming %"PRIu64" KB of pv_table for "
                "%"PRIdPTR" pages of physical memory\n",
                (uint64_t) pv_table_size/1024, (uintptr_t) phys_npages);
@@ -233,7 +234,7 @@
        fpos += pv_table_size;
 
        /* set up kernel pmap */
-       pm_nentries = (kmem_user_end - kmem_ext_start) / PAGE_SIZE;
+       pm_nentries = (VM_MAX_ADDRESS - VM_MIN_ADDRESS) / PAGE_SIZE;
        pm_entries_size = round_page(pm_nentries * sizeof(struct pv_entry *));
        aprint_debug("pmap va->pa lookup table is %"PRIu64" KB for %d logical pages\n",
                pm_entries_size/1024, pm_nentries);
@@ -473,7 +474,7 @@
        ppn = atop(pa);
        lpn = atop(va - VM_MIN_ADDRESS);        /* V->A */
 #ifdef DIAGNOSTIC
-       if ((va < kmem_k_start) || (va > kmem_user_end))
+       if ((va < VM_MIN_ADDRESS) || (va > VM_MAX_ADDRESS))
                panic("pmap_do_enter: invalid va isued\n");
 #endif
 



Home | Main Index | Thread Index | Old Index