Subject: vmspace0 initialization in proc0_init()
To: None <tech-kern@netbsd.org>
From: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
List: tech-kern
Date: 03/10/2007 00:45:59
--nFreZHaLTZJo0R7j
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Would it be possible to change proc0_init() to initialize vmspace0 and
proc0->p_vmspace before anything else?
I recently stumbled upon a MUTEX_ACQUIRE() bug on VAX, which caused a
page fault in proc0_init() before this initialization took place. This
caused the page fault handler to dereference a NULL pointer and fault
again, which recursed until a "kernel stack invalid" panic happened.
Doing this initialization early in proc0_init() makes this page fault
cause a "Segv in kernel mode" panic which shows the real problem and
which I would have expected in first place.
--
%SYSTEM-F-ANARCHISM, The operating system has been overthrown
--nFreZHaLTZJo0R7j
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kern_proc.c.diff"
Index: sys/kern/kern_proc.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_proc.c,v
retrieving revision 1.106
diff -u -r1.106 kern_proc.c
--- sys/kern/kern_proc.c 4 Mar 2007 06:03:05 -0000 1.106
+++ sys/kern/kern_proc.c 9 Mar 2007 23:42:47 -0000
@@ -301,6 +301,15 @@
sess = &session0;
l = &lwp0;
+ /*
+ * Initialize proc0's vmspace, which uses the kernel pmap.
+ * All kernel processes (which never have user space mappings)
+ * share proc0's vmspace, and thus, the kernel pmap.
+ */
+ uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
+ trunc_page(VM_MAX_ADDRESS));
+ p->p_vmspace = &vmspace0;
+
/* XXX p_smutex can be IPL_VM except for audio drivers */
mutex_init(&p->p_smutex, MUTEX_SPIN, IPL_SCHED);
mutex_init(&p->p_stmutex, MUTEX_SPIN, IPL_STATCLOCK);
@@ -401,15 +410,6 @@
/* Initialize file descriptor table for proc0. */
p->p_fd = &filedesc0.fd_fd;
fdinit1(&filedesc0);
-
- /*
- * Initialize proc0's vmspace, which uses the kernel pmap.
- * All kernel processes (which never have user space mappings)
- * share proc0's vmspace, and thus, the kernel pmap.
- */
- uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
- trunc_page(VM_MAX_ADDRESS));
- p->p_vmspace = &vmspace0;
l->l_addr = proc0paddr; /* XXX */
--nFreZHaLTZJo0R7j--