svn commit: r295684 - in stable: 8/sys/kern 9/sys/kern
John Baldwin
jhb at FreeBSD.org
Wed Feb 17 01:45:36 UTC 2016
Author: jhb
Date: Wed Feb 17 01:45:34 2016
New Revision: 295684
URL: https://svnweb.freebsd.org/changeset/base/295684
Log:
MFC 295418,295419:
Fix hangs or panics when misbehaved kernel threads return from their
main function.
295418:
Mark proc0 as a kernel process via the P_KTHREAD flag.
All other kernel processes have this flag set and all threads in proc0
(including thread0) have the similar TDP_KTHREAD flag set.
295419:
Call kthread_exit() rather than kproc_exit() for a premature kthread exit.
Kernel threads (and processes) are supposed to call kthread_exit() (or
kproc_exit()) to terminate. However, the kernel includes a fallback in
fork_exit() to force a kthread exit if a kernel thread's "main" routine
returns. This fallback was added back when the kernel only had processes
and was not updated to call kthread_exit() instead of kproc_exit() when
threads were added to the kernel.
This mistake was particularly exciting when the errant thread belonged to
proc0. Due to the missing P_KTHREAD flag the fallback did not kick in
and instead tried to return to userland via whatever garbage was in the
trapframe. With P_KTHREAD set it tried to terminate proc0 resulting in
other amusements.
PR: 204999
Modified:
stable/8/sys/kern/init_main.c
stable/8/sys/kern/kern_fork.c
Directory Properties:
stable/8/sys/ (props changed)
stable/8/sys/kern/ (props changed)
Changes in other areas also in this revision:
Modified:
stable/9/sys/kern/init_main.c
stable/9/sys/kern/kern_fork.c
Directory Properties:
stable/9/sys/ (props changed)
Modified: stable/8/sys/kern/init_main.c
==============================================================================
--- stable/8/sys/kern/init_main.c Wed Feb 17 00:30:28 2016 (r295683)
+++ stable/8/sys/kern/init_main.c Wed Feb 17 01:45:34 2016 (r295684)
@@ -451,7 +451,7 @@ proc0_init(void *dummy __unused)
session0.s_leader = p;
p->p_sysent = &null_sysvec;
- p->p_flag = P_SYSTEM | P_INMEM;
+ p->p_flag = P_SYSTEM | P_INMEM | P_KTHREAD;
p->p_state = PRS_NORMAL;
knlist_init_mtx(&p->p_klist, &p->p_mtx);
STAILQ_INIT(&p->p_ktr);
Modified: stable/8/sys/kern/kern_fork.c
==============================================================================
--- stable/8/sys/kern/kern_fork.c Wed Feb 17 00:30:28 2016 (r295683)
+++ stable/8/sys/kern/kern_fork.c Wed Feb 17 01:45:34 2016 (r295684)
@@ -878,7 +878,7 @@ fork_exit(callout, arg, frame)
if (p->p_flag & P_KTHREAD) {
printf("Kernel thread \"%s\" (pid %d) exited prematurely.\n",
td->td_name, p->p_pid);
- kproc_exit(0);
+ kthread_exit();
}
mtx_assert(&Giant, MA_NOTOWNED);
More information about the svn-src-stable-8
mailing list