Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Feb 2016 23:11:23 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r295419 - head/sys/kern
Message-ID:  <201602082311.u18NBNXr074129@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Mon Feb  8 23:11:23 2016
New Revision: 295419
URL: https://svnweb.freebsd.org/changeset/base/295419

Log:
  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 particular 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
  MFC after:	1 week

Modified:
  head/sys/kern/kern_fork.c

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c	Mon Feb  8 23:06:27 2016	(r295418)
+++ head/sys/kern/kern_fork.c	Mon Feb  8 23:11:23 2016	(r295419)
@@ -1040,7 +1040,7 @@ fork_exit(void (*callout)(void *, struct
 	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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201602082311.u18NBNXr074129>