From nobody@FreeBSD.ORG Sun Aug 15 13:13:44 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id F045C1538B; Sun, 15 Aug 1999 13:13:43 -0700 (PDT)
Message-Id: <19990815201343.F045C1538B@hub.freebsd.org>
Date: Sun, 15 Aug 1999 13:13:43 -0700 (PDT)
From: anderson@cs.duke.edu
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: kthread_exit stops, but doesn't release process context
X-Send-Pr-Version: www-1.0

>Number:         13164
>Category:       kern
>Synopsis:       kthread_exit stops, but doesn't release process context
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 15 13:20:01 PDT 1999
>Closed-Date:    Sat Mar 10 17:50:01 PST 2001
>Last-Modified:  Sat Mar 10 17:52:24 PST 2001
>Originator:     Darrell Anderson
>Release:        FreeBSD 4.0-CURRENT (TPZX) #1: Thu Aug 12 18:43:35 EDT 1999
>Organization:
Duke University Dept. of Computer Science
>Environment:
FreeBSD flapjack.cs.duke.edu 4.0-CURRENT FreeBSD 4.0-CURRENT #1: Thu Aug 12 18:43:35 EDT 1999     anderson@treefrog.cs.duke.edu:/usr/project/ari1/users/anderson/projects/freebsd/sys/compile/TPZX  i386

>Description:
calling kthread_exit leaves the kthread_create'd processes in zombie state.

If those dead threads were created by a kernel module and the module is
unloaded, "w" (more specifically kern_proc.c line 452) can crash the system
when it tries to examine the dead thread's wait channel that points off
into unloaded module vacuum.


>How-To-Repeat:
create a kernel thread with "kthread_create" and have it "kthread_exit."
the process context lingers.
>Fix:
I've added "RFNOWAIT" to the kthread_create fork1 flags.  This
causes the threads to adopt init as their parent and go away cleanly after
a kthread_exit.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: jasone 
Responsible-Changed-When: Mon Oct 23 14:37:23 PDT 2000 
Responsible-Changed-Why:  
jhb has recently done some work in -current that should fix this. 
State-Changed-From-To: open->closed 
State-Changed-By: jhb 
State-Changed-When: Sat Mar 10 17:50:01 PST 2001 
State-Changed-Why:  
This was fixed a few months ago in current and MFC'd a few weeks ago. 
Rather than creating kthreads with RFNOWAIT, which reparents the 
process to init during fork, I did an explicit reparent in kthread_exit. 
This way, kernel threads had a parent process of proc0 while they were 
executing since it would just be weird to have kernel threads children 
of a userland process. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13164 
>Unformatted:
 
