From nobody@FreeBSD.org  Sun Dec 23 13:39:27 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 9D07B37B416
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 23 Dec 2001 13:38:06 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id fBNLc6m53871;
	Sun, 23 Dec 2001 13:38:06 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200112232138.fBNLc6m53871@freefall.freebsd.org>
Date: Sun, 23 Dec 2001 13:38:06 -0800 (PST)
From: Anders Nor Berle <debolaz@debolaz.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: kthread_create doesnt mark kthreads as kthreads.
X-Send-Pr-Version: www-1.0

>Number:         33124
>Category:       kern
>Synopsis:       kthread_create doesnt mark kthreads as kthreads.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 23 13:40:00 PST 2001
>Closed-Date:    Fri Sep 02 17:52:17 GMT 2005
>Last-Modified:  Fri Sep 02 17:52:17 GMT 2005
>Originator:     Anders Nor Berle
>Release:        RELENG_4_4
>Organization:
Amphibic Online
>Environment:
FreeBSD goliath.amphibic.net 4.4-RELEASE-p2 FreeBSD 4.4-RELEASE-p2 #1: Sun Dec 23 21:46:44 CET 2001     debolaz@goliath.amphibic.net:/usr/src/sys/compile/GOLIATH  i386

>Description:
When kthread_create spawns a kernel thread, it doesnt mark it with the flag P_KTHREADP which at least according to its description, should be used to mark kernel threads.


>How-To-Repeat:
Spawn a kthread and check for P_KTHREADP in p->p_flag.


>Fix:
This is submitted through the web interface and probably wont apply correctly, but it shows how to fix it.

diff --recursive --show-c-function --unified src.old/sys/kern/kern_kthread.c src/sys/kern/kern_kthread.c
--- src.old/sys/kern/kern_kthread.c	Fri Jun 15 11:37:55 2001
+++ src/sys/kern/kern_kthread.c	Sun Dec 23 21:12:51 2001
@@ -83,7 +83,7 @@ kthread_create(void (*func)(void *), voi
 		*newpp = p2;
 
 	/* this is a non-swapped system process */
-	p2->p_flag |= P_INMEM | P_SYSTEM;
+	p2->p_flag |= P_INMEM | P_SYSTEM | P_KTHREADP;
 	p2->p_procsig->ps_flag |= PS_NOCLDWAIT;
 	PHOLD(p2);
 

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Jan 9 06:30:03 PST 2002 
Responsible-Changed-Why:  
John has already made a similar change in HEAD, but the change doesn't 
seem to have been merged onto RELENG_4. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33124 

From: John Baldwin <jhb@FreeBSD.org>
To: sheldonh@FreeBSD.org
Cc: freebsd-bugs@FreeBSD.org, Anders Nor Berle <debolaz@debolaz.com>
Subject: Re: kern/33124: kthread_create doesnt mark kthreads as kthreads.
Date: Wed, 09 Jan 2002 12:19:36 -0800 (PST)

 On 09-Jan-02 sheldonh@FreeBSD.org wrote:
 > Synopsis: kthread_create doesnt mark kthreads as kthreads.
 > 
 > Responsible-Changed-From-To: freebsd-bugs->jhb
 > Responsible-Changed-By: sheldonh
 > Responsible-Changed-When: Wed Jan 9 06:30:03 PST 2002
 > Responsible-Changed-Why: 
 > John has already made a similar change in HEAD, but the change doesn't
 > seem to have been merged onto RELENG_4.
 > 
 > http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33124
 
 This is actually kind of bogus.  Nobody uses this flag except aio, and aio just
 sets the flag, no code actually checks it.  P_KTHREAD is a new flag in -current
 used in a few places.  Unless the submitter has code that actually checks
 P_KTHREADP and needs it set for some reason, I would rather see the flag killed.
 One thing that might be nice to MFC is changing aio to use kthread_create
 rather than using its own home-rolled version.
 
 -- 
 
 John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
 "Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/
State-Changed-From-To: open->closed 
State-Changed-By: jhb 
State-Changed-When: Fri Sep 2 17:51:55 GMT 2005 
State-Changed-Why:  
Fixed in 5.x and later and not going to have time to backport this to 4.x. 

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