From willow@xloling.org  Mon Aug  8 20:30:42 2005
Return-Path: <willow@xloling.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7866616A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  8 Aug 2005 20:30:42 +0000 (GMT)
	(envelope-from willow@xloling.org)
Received: from hellmuth.xloling.org (willow.xloling.org [82.67.83.132])
	by mx1.FreeBSD.org (Postfix) with ESMTP id CDD3B43D45
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  8 Aug 2005 20:30:41 +0000 (GMT)
	(envelope-from willow@xloling.org)
Received: from hellmuth.xloling.org (localhost [127.0.0.1])
	by hellmuth.xloling.org (8.13.4/8.13.4) with ESMTP id j78KUdKS006268
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 8 Aug 2005 22:30:39 +0200 (CEST)
	(envelope-from willow@xloling.org)
Received: (from willow@localhost)
	by hellmuth.xloling.org (8.13.4/8.13.1/Submit) id j78KUcbR006263;
	Mon, 8 Aug 2005 22:30:38 +0200 (CEST)
	(envelope-from willow)
Message-Id: <200508082030.j78KUcbR006263@hellmuth.xloling.org>
Date: Mon, 8 Aug 2005 22:30:38 +0200 (CEST)
From: Antoine Pelisse <apelisse@gmail.com>
Reply-To: Antoine Pelisse <apelisse@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Kernel panic in kern_proc.c
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         84684
>Category:       kern
>Synopsis:       [kernel] [patch] Kernel panic in kern_proc.c
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    truckman
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 08 20:40:13 GMT 2005
>Closed-Date:    Thu Jan 05 19:09:38 GMT 2006
>Last-Modified:  Thu Jan 05 19:09:38 GMT 2006
>Originator:     Antoine Pelisse
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
Xloling	
>Environment:
System: FreeBSD hellmuth.xloling.org 7.0-CURRENT FreeBSD 7.0-CURRENT #21: Mon Aug 8 15:06:49 CEST 2005 i386
>Description:
	Fix for kernel panics:
	http://people.freebsd.org/~pho/stress/log/cons149.html
	http://people.freebsd.org/~pho/stress/log/cons130.html

>How-To-Repeat:
>Fix:

--- sys/kern/kern_proc.c.orig   Mon Apr 18 04:10:36 2005
+++ sys/kern/kern_proc.c        Mon Aug  8 22:00:27 2005
@@ -868,7 +868,7 @@
 {
        struct thread *td;
        struct kinfo_proc kinfo_proc;
-       int error = 0;
+       int error, buffersize = 0;
        struct proc *np;
        pid_t pid = p->p_pid;
 
@@ -883,11 +883,23 @@
        } else {
                _PHOLD(p);
                FOREACH_THREAD_IN_PROC(p, td) {
+                       buffersize += sizeof(struct kinfo_proc);
+               }
+               PROC_UNLOCK(p);
+
+               buffersize += 5 * sizeof(struct kinfo_proc);
+               error = sysctl_wire_old_buffer(req, buffersize);
+               if (error) {
+                       _PRELE(p);
+                       return error;
+               }
+
+               PROC_LOCK(p);
+               FOREACH_THREAD_IN_PROC(p, td) {
                        fill_kinfo_thread(td, &kinfo_proc);
-                       PROC_UNLOCK(p);
                        error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc,
                                           sizeof(kinfo_proc));
-                       PROC_LOCK(p);
+
                        if (error)
                                break;
                }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Fri Sep 30 10:08:40 GMT 2005 
Responsible-Changed-Why:  
Assign to jhb as he is the owner of most process locking related things. 
Thankgs to Antoine for for pointing out that this appear to be related 
to the problem reported on freebsd-hackers and freebsd-amd64 by Jason 
Carroll and Rob Watt in the thread "freebsd-5.4-stable panics". 


http://www.freebsd.org/cgi/query-pr.cgi?pr=84684 
State-Changed-From-To: open->patched 
State-Changed-By: truckman 
State-Changed-When: Sun Oct 2 23:29:01 GMT 2005 
State-Changed-Why:  
Patch committed to HEAD: 

truckman    2005-10-02 23:27:56 UTC 

FreeBSD src repository 

Modified files: 
sys/kern             kern_proc.c  
Log: 
Always wire the sysctl output buffer in sysctl_kern_proc() before 
calling sysctl_out_proc().  -- fix from jhb 

Move the code in fill_kinfo_thread() that gathers data from struct proc 
into the new function fill_kinfo_proc_only(). 

Change all callers of fill_kinfo_thread() to call both 
fill_kinfo_proc_only() and fill_kinfo() thread.  When gathering 
data from a multi-threaded process, fill_kinfo_proc_only() only needs 
to be called once. 

Grab sched_lock before accessing the process thread list or calling 
fill_kinfo_thread(). 

PR:             kern/84684 
MFC after:      3 days 

Revision  Changes    Path 
1.232     +113 -95   src/sys/kern/kern_proc.c 


Responsible-Changed-From-To: jhb->truckman 
Responsible-Changed-By: truckman 
Responsible-Changed-When: Sun Oct 2 23:29:01 GMT 2005 
Responsible-Changed-Why:  
Changed responsible party to patch committer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84684 
State-Changed-From-To: patched->closed 
State-Changed-By: truckman 
State-Changed-When: Thu Jan 5 19:04:45 UTC 2006 
State-Changed-Why:  
Fix merged from HEAD to RELENG_6 with 
kern_proc.c 1.230.2.1	Wed Oct 5 05:30:24 2005 UTC 
and RELENG_5 with 
kern_proc.c 1.215.2.7	Thu Jan 5 18:57:32 2006 UTC 

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