Module Name: src
Committed By: reinoud
Date: Wed Aug 24 12:54:47 UTC 2011
Modified Files:
src/sys/arch/usermode/include: vmparam.h
src/sys/arch/usermode/usermode: pmap.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/usermode/include/vmparam.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/usermode/usermode/pmap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/usermode/include/vmparam.h
diff -u src/sys/arch/usermode/include/vmparam.h:1.7 src/sys/arch/usermode/include/vmparam.h:1.8
--- src/sys/arch/usermode/include/vmparam.h:1.7 Wed Aug 24 11:26:43 2011
+++ src/sys/arch/usermode/include/vmparam.h Wed Aug 24 12:54:47 2011
@@ -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 <[email protected]>
@@ -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
Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.29 src/sys/arch/usermode/usermode/pmap.c:1.30
--- src/sys/arch/usermode/usermode/pmap.c:1.29 Wed Aug 24 11:50:28 2011
+++ src/sys/arch/usermode/usermode/pmap.c Wed Aug 24 12:54:46 2011
@@ -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 <[email protected]>
@@ -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