From 313658963621f1e5353ad4a61ae7c928a1736ce4 Mon Sep 17 00:00:00 2001 From: reinoud Date: Wed, 24 Aug 2011 12:54:46 +0000 Subject: [PATCH] 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. --- sys/arch/usermode/include/vmparam.h | 6 +++--- sys/arch/usermode/usermode/pmap.c | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sys/arch/usermode/include/vmparam.h b/sys/arch/usermode/include/vmparam.h index f0794ddbb4f2..88dbe5a8ec1e 100644 --- a/sys/arch/usermode/include/vmparam.h +++ b/sys/arch/usermode/include/vmparam.h @@ -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 @@ -38,9 +38,9 @@ extern paddr_t kmem_user_start, kmem_user_end; #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 --git a/sys/arch/usermode/usermode/pmap.c b/sys/arch/usermode/usermode/pmap.c index 41d2ca7342fd..37fd89bd832f 100644 --- a/sys/arch/usermode/usermode/pmap.c +++ b/sys/arch/usermode/usermode/pmap.c @@ -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 @@ -27,7 +27,7 @@ */ #include -__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 @@ pmap_bootstrap(void) /* 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 @@ pmap_bootstrap(void) /* 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 @@ pmap_bootstrap(void) 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 @@ pmap_bootstrap(void) 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 @@ pmap_bootstrap(void) 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 @@ pmap_do_enter(pmap_t pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, uint flags, i 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