From owner-freebsd-threads@FreeBSD.ORG Mon Jan 28 11:07:12 2008 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 290A116A4D7 for ; Mon, 28 Jan 2008 11:07:12 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 170A813C4EC for ; Mon, 28 Jan 2008 11:07:12 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0SB7B89016486 for ; Mon, 28 Jan 2008 11:07:11 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0SB7Bg2016482 for freebsd-threads@FreeBSD.org; Mon, 28 Jan 2008 11:07:11 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 28 Jan 2008 11:07:11 GMT Message-Id: <200801281107.m0SB7Bg2016482@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-threads@FreeBSD.org Cc: Subject: Current problem reports assigned to freebsd-threads@FreeBSD.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2008 11:07:12 -0000 Current FreeBSD problem reports Critical problems S Tracker Resp. Description -------------------------------------------------------------------------------- s threa/76690 threads fork hang in child for -lc_r 1 problem total. Serious problems S Tracker Resp. Description -------------------------------------------------------------------------------- s threa/24472 threads libc_r does not honor SO_SNDTIMEO/SO_RCVTIMEO socket o s threa/24632 threads libc_r delicate deviation from libc in handling SIGCHL s bin/32295 threads pthread dont dequeue signals s threa/34536 threads accept() blocks other threads f kern/38549 threads the procces compiled whith pthread stopped in pthread_ s threa/39922 threads [threads] [patch] Threaded applications executed with s threa/48856 threads Setting SIGCHLD to SIG_IGN still leaves zombies under s threa/49087 threads Signals lost in programs linked with libc_r o threa/70975 threads unexpected and unreliable behaviour when using SYSV se o threa/72953 threads fork() unblocks blocked signals w/o PTHREAD_SCOPE_SYST o threa/75273 threads FBSD 5.3 libpthread (KSE) bug o threa/75374 threads pthread_kill() ignores SA_SIGINFO flag s threa/76694 threads fork cause hang in dup()/close() function in child (-l o threa/79683 threads svctcp_create() fails if multiple threads call at the o threa/80435 threads panic on high loads o threa/83914 threads [libc] popen() doesn't work in static threaded program s threa/84483 threads problems with devel/nspr and -lc_r on 4.x s threa/94467 threads send(), sendto() and sendmsg() are not correct in libc s threa/100815 threads FBSD 5.5 broke nanosleep in libc_r o threa/101323 threads fork(2) in threaded programs broken. o threa/103975 threads Implicit loading/unloading of libpthread.so may crash o threa/110636 threads [request] gdb(1): using gdb with multi thread applicat o threa/118715 threads kse problem o threa/119920 threads [patch] fork broken in libpthread 24 problems total. Non-critical problems S Tracker Resp. Description -------------------------------------------------------------------------------- s threa/30464 threads pthread mutex attributes -- pshared s threa/37676 threads libc_r: msgsnd(), msgrcv(), pread(), pwrite() need wra s threa/40671 threads pthread_cancel doesn't remove thread from condition qu s threa/69020 threads pthreads library leaks _gc_mutex o threa/79887 threads [patch] freopen() isn't thread-safe o threa/80992 threads abort() sometimes not caught by gdb depending on threa o threa/110306 threads apache 2.0 segmentation violation when calling gethost o threa/115211 threads pthread_atfork misbehaves in initial thread o threa/116181 threads /dev/io-related io access permissions are not propagat o threa/116668 threads can no longer use jdk15 with libthr on -stable SMP 10 problems total. From owner-freebsd-threads@FreeBSD.ORG Mon Jan 28 19:19:18 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E5F8C16A417; Mon, 28 Jan 2008 19:19:18 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id BCC6B13C4EF; Mon, 28 Jan 2008 19:19:18 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id BD23C497A4; Mon, 28 Jan 2008 13:59:27 -0500 (EST) Date: Mon, 28 Jan 2008 18:59:27 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Daniel Eischen In-Reply-To: Message-ID: <20080128185830.B56811@fledge.watson.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Gary Stanley , Julian Elischer , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2008 19:19:19 -0000 On Thu, 24 Jan 2008, Daniel Eischen wrote: >> dan what IS the fix for this? I assume you must have fixed it in >> -current/7 > > You want cvs diff -u -r1.126 -r1.128 src/lib/libkse/thread/thr_kern.c. The > WARNS'ify diffs are not necessary, so it should look something like shown > below. Probably an MFC of all of libkse (minus jasone's malloc changes) > should be done to -7 and -6. Should the patch be considered for an errata notice for 6.x? Should we be trying to MFC this to 7.x for inclusion with 7.0 or does it need more time to shake out and should potentially be a 7.0 errata notice or just appear in 7.1? Robert N M Watson Computer Laboratory University of Cambridge From owner-freebsd-threads@FreeBSD.ORG Mon Jan 28 19:43:55 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5613316A469 for ; Mon, 28 Jan 2008 19:43:55 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outO.internet-mail-service.net (outO.internet-mail-service.net [216.240.47.238]) by mx1.freebsd.org (Postfix) with ESMTP id 39E1113C4D9 for ; Mon, 28 Jan 2008 19:43:55 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Mon, 28 Jan 2008 11:43:54 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id B2126127029; Mon, 28 Jan 2008 11:43:53 -0800 (PST) Message-ID: <479E3079.3000803@elischer.org> Date: Mon, 28 Jan 2008 11:43:53 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Robert Watson References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> In-Reply-To: <20080128185830.B56811@fledge.watson.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , Gary Stanley , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2008 19:43:55 -0000 Robert Watson wrote: > > On Thu, 24 Jan 2008, Daniel Eischen wrote: > >>> dan what IS the fix for this? I assume you must have fixed it in >>> -current/7 >> >> You want cvs diff -u -r1.126 -r1.128 src/lib/libkse/thread/thr_kern.c. >> The WARNS'ify diffs are not necessary, so it should look something >> like shown below. Probably an MFC of all of libkse (minus jasone's >> malloc changes) should be done to -7 and -6. > > Should the patch be considered for an errata notice for 6.x? Should we > be trying to MFC this to 7.x for inclusion with 7.0 or does it need more > time to shake out and should potentially be a 7.0 errata notice or just > appear in 7.1? > > Robert N M Watson > Computer Laboratory > University of Cambridge yes and yes and no From owner-freebsd-threads@FreeBSD.ORG Tue Jan 29 20:59:02 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E203616A41A; Tue, 29 Jan 2008 20:59:01 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id C000F13C4E1; Tue, 29 Jan 2008 20:59:01 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 631F21707F; Tue, 29 Jan 2008 12:33:05 -0800 (PST) In-Reply-To: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-6--6718150" Message-Id: <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> From: Landon Fuller Date: Tue, 29 Jan 2008 12:33:01 -0800 To: Daniel Eischen Content-Transfer-Encoding: 7bit X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jan 2008 20:59:02 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-6--6718150 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 24, 2008, at 07:08, Daniel Eischen wrote: > On Thu, 24 Jan 2008, Julian Elischer wrote: > >> Gary Stanley wrote: >>> The following reply was made to PR threads/119920; it has been >>> noted by >>> GNATS. >>> >>> From: Gary Stanley >>> To: bug-followup@FreeBSD.org >>> Cc: Subject: Re: threads/119920: fork broken in libpthread >>> Date: Thu, 24 Jan 2008 03:24:47 -0500 >>> >>> I also have this problem, see threads/118715 >>> I was able to grab some ktrace info, but most of the time the >>> process is >>> stuck, and ktrace doesn't display any data. >>> _______________________________________________ >>> freebsd-threads@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/freebsd-threads >>> To unsubscribe, send any mail to "freebsd-threads- >>> unsubscribe@freebsd.org" >> >> dan what IS the fix for this? I assume you must have fixed it in - >> current/7 > > You want cvs diff -u -r1.126 -r1.128 src/lib/libkse/thread/thr_kern.c. > The WARNS'ify diffs are not necessary, so it should look something > like shown below. Probably an MFC of all of libkse (minus jasone's > malloc changes) should be done to -7 and -6. There appears to be a remaining issue I'm still seeing locally, with the above patch; I wasn't able to reproduce this on 6.2: #0 0x0000000800648b13 in mutex_lock_common (curthread=0x0, m=0x8007616e8, abstime=0x0) at /usr/src/lib/libpthread/thread/ thr_mutex.c:503 #1 0x000000080064ac25 in _pthread_mutex_lock (m=0x8007616e8) at /usr/ src/lib/libpthread/thread/thr_mutex.c:868 #2 0x000000080063e9ce in _spinlock (lck=0x8009ac200) at /usr/src/lib/ libpthread/thread/thr_spinlock.c:97 #3 0x00000008007eafc3 in pubrealloc (ptr=0x0, size=24, func=0x8008802b7 " in malloc():") at /usr/src/lib/libc/stdlib/ malloc.c:1090 #4 0x00000008007eb1e1 in malloc (size=24) at /usr/src/lib/libc/ stdlib/malloc.c:1150 #5 0x000000080065ab8c in _lockuser_init (lu=0x52e068, priv=0x52e000) at /usr/src/lib/libpthread/sys/lock.c:99 #6 0x000000080065ac69 in _lockuser_reinit (lu=0x52e068, priv=0x52e000) at /usr/src/lib/libpthread/sys/lock.c:128 #7 0x000000080064d6d0 in _kse_single_thread (curthread=0x50cc00) at / usr/src/lib/libpthread/thread/thr_kern.c:343 #8 0x000000080063b627 in _fork () at /usr/src/lib/libpthread/thread/ thr_fork.c:101 #9 0x00000000004008f1 in forker () #10 0x000000080064516e in thread_start (curthread=0x50cc00, start_routine=0x4008e0 , arg=0x0) at /usr/src/lib/libpthread/ thread/thr_create.c:341 #11 0x00000008007b3cd9 in makectx_wrapper (ucp=0x800530860, func=0x800645150 , args=0x7fffff7fcfd0) at /usr/src/lib/ libc/amd64/gen/makecontext.c:100 #12 0x0000000000000000 in ?? () #13 0x000000000050cc00 in ?? () #14 0x00000000004008e0 in frame_dummy () via this reproduction case: #include #include #include void *forker (void *arg) { while (1) { pid_t pid = fork(); if (pid == 0) { exit(0); } else if (pid > 0) { int status; waitpid(pid, &status, 0); } else { printf("Fork failed\n"); abort(); } } } int main(void) { int i = 0; for (i = 0; i < 4; i++) { pthread_t thr; pthread_create(&thr, NULL, forker, NULL); pthread_detach(thr); } while(1) sleep(1000); } --Apple-Mail-6--6718150 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHn419lplZCE/15mMRApnPAJ46HOR3yxe63AKFJRzw9F6bK5vbhwCfbVzK 5Dvl/hOzdh37iQtcJkGaf+E= =POmG -----END PGP SIGNATURE----- --Apple-Mail-6--6718150-- From owner-freebsd-threads@FreeBSD.ORG Tue Jan 29 21:30:14 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12A4A16A417 for ; Tue, 29 Jan 2008 21:30:14 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id ABA1E13C442 for ; Tue, 29 Jan 2008 21:30:13 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.2/8.14.2/NETPLEX) with ESMTP id m0TLD2uO021434; Tue, 29 Jan 2008 16:13:02 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Tue, 29 Jan 2008 16:13:02 -0500 (EST) Date: Tue, 29 Jan 2008 16:13:02 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Landon Fuller In-Reply-To: <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> Message-ID: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jan 2008 21:30:14 -0000 On Tue, 29 Jan 2008, Landon Fuller wrote: > > On Jan 24, 2008, at 07:08, Daniel Eischen wrote: > >> On Thu, 24 Jan 2008, Julian Elischer wrote: >> >>> Gary Stanley wrote: >>>> The following reply was made to PR threads/119920; it has been noted by >>>> GNATS. >>>> >>>> From: Gary Stanley >>>> To: bug-followup@FreeBSD.org >>>> Cc: Subject: Re: threads/119920: fork broken in libpthread >>>> Date: Thu, 24 Jan 2008 03:24:47 -0500 >>>> >>>> I also have this problem, see threads/118715 >>>> I was able to grab some ktrace info, but most of the time the process >>>> is >>>> stuck, and ktrace doesn't display any data. >>>> _______________________________________________ >>>> freebsd-threads@freebsd.org mailing list >>>> http://lists.freebsd.org/mailman/listinfo/freebsd-threads >>>> To unsubscribe, send any mail to >>>> "freebsd-threads-unsubscribe@freebsd.org" >>> >>> dan what IS the fix for this? I assume you must have fixed it in >>> -current/7 >> >> You want cvs diff -u -r1.126 -r1.128 src/lib/libkse/thread/thr_kern.c. >> The WARNS'ify diffs are not necessary, so it should look something >> like shown below. Probably an MFC of all of libkse (minus jasone's >> malloc changes) should be done to -7 and -6. > > There appears to be a remaining issue I'm still seeing locally, with the > above patch; I wasn't able to reproduce this on 6.2: > > #0 0x0000000800648b13 in mutex_lock_common (curthread=0x0, m=0x8007616e8, > abstime=0x0) at /usr/src/lib/libpthread/thread/thr_mutex.c:503 > #1 0x000000080064ac25 in _pthread_mutex_lock (m=0x8007616e8) at > /usr/src/lib/libpthread/thread/thr_mutex.c:868 > #2 0x000000080063e9ce in _spinlock (lck=0x8009ac200) at > /usr/src/lib/libpthread/thread/thr_spinlock.c:97 > #3 0x00000008007eafc3 in pubrealloc (ptr=0x0, size=24, func=0x8008802b7 " in > malloc():") at /usr/src/lib/libc/stdlib/malloc.c:1090 > #4 0x00000008007eb1e1 in malloc (size=24) at > /usr/src/lib/libc/stdlib/malloc.c:1150 > #5 0x000000080065ab8c in _lockuser_init (lu=0x52e068, priv=0x52e000) at > /usr/src/lib/libpthread/sys/lock.c:99 There is a bug somewhere else or something is stomping on the thread's lockuser. It is allocated once when the thread is created and should never be null thereafter. Hence, it should never be malloc'd and the reinit should be sufficient. -- DE From owner-freebsd-threads@FreeBSD.ORG Tue Jan 29 22:27:48 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1623716A468; Tue, 29 Jan 2008 22:27:48 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id DE42713C468; Tue, 29 Jan 2008 22:27:47 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 5425D4AC78; Tue, 29 Jan 2008 17:27:47 -0500 (EST) Date: Tue, 29 Jan 2008 22:27:47 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Julian Elischer In-Reply-To: <479E3079.3000803@elischer.org> Message-ID: <20080129222455.T53151@fledge.watson.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Daniel Eischen , Gary Stanley , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jan 2008 22:27:48 -0000 On Mon, 28 Jan 2008, Julian Elischer wrote: >>>> dan what IS the fix for this? I assume you must have fixed it in >>>> -current/7 >>> >>> You want cvs diff -u -r1.126 -r1.128 src/lib/libkse/thread/thr_kern.c. The >>> WARNS'ify diffs are not necessary, so it should look something like shown >>> below. Probably an MFC of all of libkse (minus jasone's malloc changes) >>> should be done to -7 and -6. >> >> Should the patch be considered for an errata notice for 6.x? Should we be >> trying to MFC this to 7.x for inclusion with 7.0 or does it need more time >> to shake out and should potentially be a 7.0 errata notice or just appear >> in 7.1? > > yes and yes and no If the fix is going to ship in 7.0 and hasn't yet been MFC'd, that needs to happen ASAP. Could someone forward the patch/etc over to re@ for approval? The procedure for doing an errata patch is basically that whoever is proposing the errata patch needs to e-mail a patch, or multiple patches if it's different for different branches, a proposed branch list, and as much of a completed errata notice template as possible (impact, etc) to re@ for review. Once re@ is OK that it's ready to go, it will get sent over to secteam@ to be put into production, binary updates generated, etc. If in doubt about which branches, drop e-mail to secteam@ to ask which are supported, etc. At this point we would probably not advise doing the errata patch before 7.0 is released, so priority should go to preparing any patches that need to go out with 7.0. Thanks, Robert N M Watson Computer Laboratory University of Cambridge From owner-freebsd-threads@FreeBSD.ORG Tue Jan 29 23:15:05 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 04ABA16A417 for ; Tue, 29 Jan 2008 23:15:05 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id CE47B13C447 for ; Tue, 29 Jan 2008 23:15:04 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 3B05217070; Tue, 29 Jan 2008 15:15:04 -0800 (PST) In-Reply-To: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-9-2999179" Message-Id: <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> From: Landon Fuller Date: Tue, 29 Jan 2008 15:14:58 -0800 To: Daniel Eischen Content-Transfer-Encoding: 7bit X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jan 2008 23:15:05 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-9-2999179 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 29, 2008, at 13:13, Daniel Eischen wrote: >> > > There is a bug somewhere else or something is stomping > on the thread's lockuser. It is allocated once when the > thread is created and should never be null thereafter. > Hence, it should never be malloc'd and the reinit should > be sufficient. I'm totally unfamiliar with KSE, so perhaps this a stupid question -- it seems to solve the issue locally, so I'll ask it -- Why not place the fork() code inside of _kse_critical_enter / _kse_critical_leave, to ensure upcalls are blocked while re- initializing in the child process post-fork? Unless I'm off base, this should be an adequate replacement for this code? http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_fork.c.diff? r1=1.285;r2=1.286 -landonf --Apple-Mail-9-2999179 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHn7NylplZCE/15mMRAjbZAKCKGhKp5wht4wXSo+14HWSkpIOIQACfaFh5 10JHx+QAWHep3PcHPPwgDZ8= =+pQ/ -----END PGP SIGNATURE----- --Apple-Mail-9-2999179-- From owner-freebsd-threads@FreeBSD.ORG Tue Jan 29 23:27:27 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B57B816A419 for ; Tue, 29 Jan 2008 23:27:27 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id 912CB13C45A for ; Tue, 29 Jan 2008 23:27:27 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 7D76617070; Tue, 29 Jan 2008 15:27:27 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v753) In-Reply-To: <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-11-3749467" Message-Id: From: Landon Fuller Date: Tue, 29 Jan 2008 15:27:28 -0800 To: Daniel Eischen , freebsd-threads@freebsd.org Content-Transfer-Encoding: 7bit X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jan 2008 23:27:27 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-11-3749467 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 29, 2008, at 15:14, Landon Fuller wrote: > http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/ > kern_fork.c.diff?r1=1.285;r2=1.286 Sorry, here's the correct 6.3 MFC: http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_fork.c.diff? r1=1.252.2.6;r2=1.252.2.7 --Apple-Mail-11-3749467 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHn7ZglplZCE/15mMRAsMoAKCBfSJG4ms+TYsLlclHipK4L0lrqgCfR+jT dqs2OXHkgExmKdWAnIibNEw= =1jYm -----END PGP SIGNATURE----- --Apple-Mail-11-3749467-- From owner-freebsd-threads@FreeBSD.ORG Wed Jan 30 04:23:34 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 416A616A417 for ; Wed, 30 Jan 2008 04:23:34 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id EE7D713C457 for ; Wed, 30 Jan 2008 04:23:33 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.2/8.14.2/NETPLEX) with ESMTP id m0U4NUTs005631; Tue, 29 Jan 2008 23:23:30 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Tue, 29 Jan 2008 23:23:30 -0500 (EST) Date: Tue, 29 Jan 2008 23:23:30 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Landon Fuller In-Reply-To: <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> Message-ID: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jan 2008 04:23:34 -0000 On Tue, 29 Jan 2008, Landon Fuller wrote: > > On Jan 29, 2008, at 13:13, Daniel Eischen wrote: >>> >> >> There is a bug somewhere else or something is stomping >> on the thread's lockuser. It is allocated once when the >> thread is created and should never be null thereafter. >> Hence, it should never be malloc'd and the reinit should >> be sufficient. > > I'm totally unfamiliar with KSE, so perhaps this a stupid question -- it > seems to solve the issue locally, so I'll ask it -- > Why not place the fork() code inside of _kse_critical_enter / > _kse_critical_leave, to ensure upcalls are blocked while re-initializing in > the child process post-fork? That just prevents an upcall from happening (which my patch solves), but doesn't prevent the corruption of the lockuser or lock. My patch does solve this in -current, but -stable probably lacks a few other patches. It (-stable) really needs all of -current's code, not just this patch. -- DE From owner-freebsd-threads@FreeBSD.ORG Wed Jan 30 10:30:05 2008 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8058D16A46C for ; Wed, 30 Jan 2008 10:30:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5414A13C448 for ; Wed, 30 Jan 2008 10:30:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0UAU5ef048610 for ; Wed, 30 Jan 2008 10:30:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0UAU5Ul048607; Wed, 30 Jan 2008 10:30:05 GMT (envelope-from gnats) Date: Wed, 30 Jan 2008 10:30:05 GMT Message-Id: <200801301030.m0UAU5Ul048607@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Bernard Buri Cc: Subject: Re: threads/119920: [patch] fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bernard Buri List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jan 2008 10:30:05 -0000 The following reply was made to PR threads/119920; it has been noted by GNATS. From: Bernard Buri To: bug-followup@FreeBSD.org, bsd@ask-us.at Cc: Subject: Re: threads/119920: [patch] fork broken in libpthread Date: Wed, 30 Jan 2008 11:14:13 +0100 I tried the patch, and first, it seemed to fix the problem. But it looks like there are more similar problems. I did not have time to analyze it. I use libthr in the meanwhile: Everything's fine here. I think we could use some good regression tests here. From owner-freebsd-threads@FreeBSD.ORG Wed Jan 30 19:22:56 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0370816A418 for ; Wed, 30 Jan 2008 19:22:56 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id DCCC613C459 for ; Wed, 30 Jan 2008 19:22:55 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id B724517043; Wed, 30 Jan 2008 11:22:55 -0800 (PST) In-Reply-To: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-14-75471841" Message-Id: Content-Transfer-Encoding: 7bit From: Landon Fuller Date: Wed, 30 Jan 2008 11:22:51 -0800 To: Daniel Eischen X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jan 2008 19:22:56 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-14-75471841 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 29, 2008, at 20:23, Daniel Eischen wrote: > On Tue, 29 Jan 2008, Landon Fuller wrote: > >> >> On Jan 29, 2008, at 13:13, Daniel Eischen wrote: >>> There is a bug somewhere else or something is stomping >>> on the thread's lockuser. It is allocated once when the >>> thread is created and should never be null thereafter. >>> Hence, it should never be malloc'd and the reinit should >>> be sufficient. >> >> I'm totally unfamiliar with KSE, so perhaps this a stupid question >> -- it seems to solve the issue locally, so I'll ask it -- >> Why not place the fork() code inside of _kse_critical_enter / >> _kse_critical_leave, to ensure upcalls are blocked while re- >> initializing in the child process post-fork? > > That just prevents an upcall from happening (which my patch solves), > but doesn't prevent the corruption of the lockuser or lock. My assumption was that lockuser was being corrupted in a post-fork upcall; after wrapping fork in kse_critical_enter(), and can not reproduce the lockuser-reallocation I was seeing before. Is my assumption that kse_critical_enter() prevents any other code from being run during the critical section incorrect? --- thread/thr_fork.c.orig 2008-01-30 11:08:45.000000000 -0800 +++ thread/thr_fork.c 2008-01-30 11:09:36.000000000 -0800 @@ -93,12 +93,16 @@ if (_kse_isthreaded() != 0) { _spinlock(__malloc_lock); } + + kse_critical_t crit = _kse_critical_enter(); + if ((ret = __sys_fork()) == 0) { /* Child process */ errsave = errno; /* Kernel signal mask is restored in _kse_single_thread */ _kse_single_thread(curthread); + _kse_critical_leave(crit); /* Run down atfork child handlers. */ TAILQ_FOREACH(af, &_thr_atfork_list, qe) { @@ -107,6 +111,7 @@ } _thr_mutex_reinit(&_thr_atfork_mutex); } else { + _kse_critical_leave(crit); if ((_kse_isthreaded() != 0) && (__malloc_lock != NULL)) { _spinunlock(__malloc_lock); } > My patch does solve this in -current, but -stable probably lacks > a few other patches. It (-stable) really needs all of -current's > code, not just this patch. Is this change viable for an errata fix for 6.3? -landonf --Apple-Mail-14-75471841 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHoM6NlplZCE/15mMRAiL0AJ44TC7y1TPRcETD6w5aXo+/bSlPtACffYQ0 hwOy02U/Y5KBmHcX4UuYMB4= =6kkq -----END PGP SIGNATURE----- --Apple-Mail-14-75471841-- From owner-freebsd-threads@FreeBSD.ORG Wed Jan 30 19:41:18 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E1B516A420 for ; Wed, 30 Jan 2008 19:41:18 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outD.internet-mail-service.net (outD.internet-mail-service.net [216.240.47.227]) by mx1.freebsd.org (Postfix) with ESMTP id 6114613C46B for ; Wed, 30 Jan 2008 19:41:18 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Wed, 30 Jan 2008 11:41:17 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id 33814127059; Wed, 30 Jan 2008 11:41:17 -0800 (PST) Message-ID: <47A0D2DE.9060005@elischer.org> Date: Wed, 30 Jan 2008 11:41:18 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jan 2008 19:41:18 -0000 Landon Fuller wrote: > > On Jan 29, 2008, at 20:23, Daniel Eischen wrote: > >> On Tue, 29 Jan 2008, Landon Fuller wrote: >> >>> >>> On Jan 29, 2008, at 13:13, Daniel Eischen wrote: >>>> There is a bug somewhere else or something is stomping >>>> on the thread's lockuser. It is allocated once when the >>>> thread is created and should never be null thereafter. >>>> Hence, it should never be malloc'd and the reinit should >>>> be sufficient. >>> >>> I'm totally unfamiliar with KSE, so perhaps this a stupid question -- >>> it seems to solve the issue locally, so I'll ask it -- >>> Why not place the fork() code inside of _kse_critical_enter / >>> _kse_critical_leave, to ensure upcalls are blocked while >>> re-initializing in the child process post-fork? >> >> That just prevents an upcall from happening (which my patch solves), >> but doesn't prevent the corruption of the lockuser or lock. > > My assumption was that lockuser was being corrupted in a post-fork > upcall; after wrapping fork in kse_critical_enter(), and can not > reproduce the lockuser-reallocation I was seeing before. > > Is my assumption that kse_critical_enter() prevents any other code from > being run during the critical section incorrect? My understanding (not being a userland expert) is that critical-enter sets a flag in the thread's mailbox telling the kernel that no matter what happens, it must not allow another thread to pre-empt this one. This means that any system call (or page fault or whatever) will be handled synchronously. if it blocks, that schedulable entity will block and no upcall will be made to schedule another thread. It does not in any way however ensure that any other thread changes its behaviour. Dan, is my understanding correct? > > --- thread/thr_fork.c.orig 2008-01-30 11:08:45.000000000 -0800 > +++ thread/thr_fork.c 2008-01-30 11:09:36.000000000 -0800 > @@ -93,12 +93,16 @@ > if (_kse_isthreaded() != 0) { > _spinlock(__malloc_lock); > } > + > + kse_critical_t crit = _kse_critical_enter(); > + > if ((ret = __sys_fork()) == 0) { > /* Child process */ > errsave = errno; > > /* Kernel signal mask is restored in _kse_single_thread */ > _kse_single_thread(curthread); > + _kse_critical_leave(crit); > > /* Run down atfork child handlers. */ > TAILQ_FOREACH(af, &_thr_atfork_list, qe) { > @@ -107,6 +111,7 @@ > } > _thr_mutex_reinit(&_thr_atfork_mutex); > } else { > + _kse_critical_leave(crit); > if ((_kse_isthreaded() != 0) && (__malloc_lock != NULL)) { > _spinunlock(__malloc_lock); > } > >> My patch does solve this in -current, but -stable probably lacks >> a few other patches. It (-stable) really needs all of -current's >> code, not just this patch. > > > Is this change viable for an errata fix for 6.3? > > -landonf From owner-freebsd-threads@FreeBSD.ORG Wed Jan 30 22:09:22 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B5ED416A41A for ; Wed, 30 Jan 2008 22:09:22 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id 796F913C4D9 for ; Wed, 30 Jan 2008 22:09:22 +0000 (UTC) (envelope-from eischen@vigrid.com) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.2/8.14.2/NETPLEX) with ESMTP id m0UM9G75028701; Wed, 30 Jan 2008 17:09:17 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Wed, 30 Jan 2008 17:09:17 -0500 (EST) Date: Wed, 30 Jan 2008 17:09:17 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Julian Elischer In-Reply-To: <47A0D2DE.9060005@elischer.org> Message-ID: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> <47A0D2DE.9060005@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jan 2008 22:09:22 -0000 On Wed, 30 Jan 2008, Julian Elischer wrote: > Landon Fuller wrote: >> >> Is my assumption that kse_critical_enter() prevents any other code from >> being run during the critical section incorrect? > > My understanding (not being a userland expert) is that > critical-enter sets a flag in the thread's mailbox telling the > kernel that no matter what happens, it must not allow another > thread to pre-empt this one. This means that any system call > (or page fault or whatever) will be handled synchronously. if > it blocks, that schedulable entity will block and no upcall > will be made to schedule another thread. > > It does not in any way however ensure that any other thread changes its > behaviour. > Dan, is my understanding correct? Right, it doesn't prevent another KSE from getting an upcall and doing things to threads. The problem seems to be in src/libpthread/sys/lock.c. See the patch here: http://people.freebsd.org/~deischen/kse/libpthread.6.diffs It is an attempt to merge in all of HEAD to 6.x. I can't test it, but it compiles. You at least want the part of the patchset that patches sys/lock.c (along with the previous patch I posted which is also included in the patchset). -- DE From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 01:02:03 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E14D016A46E for ; Thu, 31 Jan 2008 01:02:03 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id BE48E13C442 for ; Thu, 31 Jan 2008 01:02:03 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 17AA51703C; Wed, 30 Jan 2008 17:02:02 -0800 (PST) In-Reply-To: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> <47A0D2DE.9060005@elischer.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-18-95820135" Message-Id: <35535E7A-0804-4DAD-B0A0-CCF9EE7060B0@bikemonkey.org> Content-Transfer-Encoding: 7bit From: Landon Fuller Date: Wed, 30 Jan 2008 17:01:59 -0800 To: Daniel Eischen X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) Cc: Julian Elischer , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 01:02:04 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-18-95820135 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 30, 2008, at 14:09, Daniel Eischen wrote: > On Wed, 30 Jan 2008, Julian Elischer wrote: > >> Landon Fuller wrote: >>> Is my assumption that kse_critical_enter() prevents any other >>> code from being run during the critical section incorrect? >> >> My understanding (not being a userland expert) is that >> critical-enter sets a flag in the thread's mailbox telling the >> kernel that no matter what happens, it must not allow another >> thread to pre-empt this one. This means that any system call >> (or page fault or whatever) will be handled synchronously. if >> it blocks, that schedulable entity will block and no upcall >> will be made to schedule another thread. >> >> It does not in any way however ensure that any other thread >> changes its behaviour. >> Dan, is my understanding correct? > > Right, it doesn't prevent another KSE from getting an upcall > and doing things to threads. > > The problem seems to be in src/libpthread/sys/lock.c. > See the patch here: > > http://people.freebsd.org/~deischen/kse/libpthread.6.diffs > > It is an attempt to merge in all of HEAD to 6.x. I can't > test it, but it compiles. You at least want the part of > the patchset that patches sys/lock.c (along with the previous > patch I posted which is also included in the patchset). Thanks -- pulling in relevant change from sys/lock.c -- plus your previous patch -- solves my reproduction case: http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63- fork -landonf --Apple-Mail-18-95820135 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHoR4HlplZCE/15mMRAsNkAJsFHS3R4Ez3hjoIHe1XVjw3Cnv4FgCfV5uc wOp5FtITWAh/UVK/EED2zFg= =6xni -----END PGP SIGNATURE----- --Apple-Mail-18-95820135-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 08:58:55 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 57A5616A41B for ; Thu, 31 Jan 2008 08:58:55 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outU.internet-mail-service.net (outU.internet-mail-service.net [216.240.47.244]) by mx1.freebsd.org (Postfix) with ESMTP id F3D3713C4D9 for ; Thu, 31 Jan 2008 08:58:54 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 00:58:53 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id 963E2127072; Thu, 31 Jan 2008 00:58:52 -0800 (PST) Message-ID: <47A18DCD.2070101@elischer.org> Date: Thu, 31 Jan 2008 00:58:53 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> <47A0D2DE.9060005@elischer.org> <35535E7A-0804-4DAD-B0A0-CCF9EE7060B0@bikemonkey.org> In-Reply-To: <35535E7A-0804-4DAD-B0A0-CCF9EE7060B0@bikemonkey.org> Content-Type: multipart/mixed; boundary="------------020701010806090604090704" Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 08:58:55 -0000 This is a multi-part message in MIME format. --------------020701010806090604090704 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Landon Fuller wrote: > Thanks -- pulling in relevant change from sys/lock.c -- plus your > previous patch -- solves my reproduction case: > http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63-fork is this the patch you used? It's huge.. I cut it down to a smaller size by removing most of the cosmetic stuff (included) but if your change is smaller can you post it back? (sounds like you cherry picked smaller psrts) > > > -landonf > --------------020701010806090604090704 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="libpthread.6.diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="libpthread.6.diffs" Index: sys/lock.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/sys/Attic/lock.c,v retrieving revision 1.9.2.1 diff -u -r1.9.2.1 lock.c --- sys/lock.c 5 Aug 2005 19:43:56 -0000 1.9.2.1 +++ sys/lock.c 30 Jan 2008 21:56:05 -0000 @@ -54,11 +54,12 @@ int _lock_init(struct lock *lck, enum lock_type ltype, - lock_handler_t *waitfunc, lock_handler_t *wakeupfunc) + lock_handler_t *waitfunc, lock_handler_t *wakeupfunc, + void *(calloc_cb)(size_t, size_t)) { if (lck == NULL) return (-1); - else if ((lck->l_head = malloc(sizeof(struct lockreq))) == NULL) + else if ((lck->l_head = calloc_cb(1, sizeof(struct lockreq))) == NULL) return (-1); else { lck->l_type = ltype; @@ -80,7 +81,7 @@ if (lck == NULL) return (-1); else if (lck->l_head == NULL) - return (_lock_init(lck, ltype, waitfunc, wakeupfunc)); + return (_lock_init(lck, ltype, waitfunc, wakeupfunc, calloc)); else { lck->l_head->lr_locked = 0; lck->l_head->lr_watcher = NULL; @@ -117,14 +118,22 @@ { if (lu == NULL) return (-1); - /* - * All lockusers keep their watch request and drop their - * own (lu_myreq) request. Their own request is either - * some other lockuser's watch request or is the head of - * the lock. - */ - lu->lu_myreq = lu->lu_watchreq; + if (lu->lu_watchreq != NULL) { + /* + * In this case the lock is active. All lockusers + * keep their watch request and drop their own + * (lu_myreq) request. Their own request is either + * some other lockuser's watch request or is the + * head of the lock. + */ + lu->lu_myreq = lu->lu_watchreq; + lu->lu_watchreq = NULL; + } if (lu->lu_myreq == NULL) + /* + * Oops, something isn't quite right. Try to + * allocate one. + */ return (_lockuser_init(lu, priv)); else { lu->lu_myreq->lr_locked = 1; Index: sys/lock.h =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/sys/Attic/lock.h,v retrieving revision 1.7 diff -u -r1.7 lock.h --- sys/lock.h 4 Nov 2003 20:01:38 -0000 1.7 +++ sys/lock.h 30 Jan 2008 21:14:31 -0000 @@ -83,7 +83,7 @@ void _lock_destroy(struct lock *); void _lock_grant(struct lock *, struct lockuser *); int _lock_init(struct lock *, enum lock_type, - lock_handler_t *, lock_handler_t *); + lock_handler_t *, lock_handler_t *, void *(size_t, size_t)); int _lock_reinit(struct lock *, enum lock_type, lock_handler_t *, lock_handler_t *); void _lock_release(struct lock *, struct lockuser *); Index: thread/thr_exit.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_exit.c,v retrieving revision 1.39 diff -u -r1.39 thr_exit.c --- thread/thr_exit.c 23 Oct 2004 23:37:54 -0000 1.39 +++ thread/thr_exit.c 30 Jan 2008 21:14:31 -0000 @@ -10,10 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Birrell. - * 4. Neither the name of the author nor the names of any co-contributors + * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,6 +28,8 @@ * * $FreeBSD: src/lib/libpthread/thread/thr_exit.c,v 1.39 2004/10/23 23:37:54 davidxu Exp $ */ + +#include "namespace.h" #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include "un-namespace.h" #include "thr_private.h" void _pthread_exit(void *status); @@ -45,7 +45,7 @@ __weak_reference(_pthread_exit, pthread_exit); void -_thr_exit(char *fname, int lineno, char *msg) +_thr_exit(const char *fname, int lineno, const char *msg) { /* Write an error message to the standard error file descriptor: */ @@ -122,7 +122,7 @@ /* Save the return value: */ curthread->ret = status; while (curthread->cleanup != NULL) { - pthread_cleanup_pop(1); + _pthread_cleanup_pop(1); } if (curthread->attr.cleanup_attr != NULL) { curthread->attr.cleanup_attr(curthread->attr.arg_attr); Index: thread/thr_init.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_init.c,v retrieving revision 1.70.2.1 diff -u -r1.70.2.1 thr_init.c --- thread/thr_init.c 16 Mar 2006 23:29:07 -0000 1.70.2.1 +++ thread/thr_init.c 30 Jan 2008 21:14:31 -0000 @@ -462,16 +460,16 @@ * process signal mask and pending signal sets. */ if (_lock_init(&_thread_signal_lock, LCK_ADAPTIVE, - _kse_lock_wait, _kse_lock_wakeup) != 0) + _kse_lock_wait, _kse_lock_wakeup, calloc) != 0) PANIC("Cannot initialize _thread_signal_lock"); if (_lock_init(&_mutex_static_lock, LCK_ADAPTIVE, - _thr_lock_wait, _thr_lock_wakeup) != 0) + _thr_lock_wait, _thr_lock_wakeup, calloc) != 0) PANIC("Cannot initialize mutex static init lock"); if (_lock_init(&_rwlock_static_lock, LCK_ADAPTIVE, - _thr_lock_wait, _thr_lock_wakeup) != 0) + _thr_lock_wait, _thr_lock_wakeup, calloc) != 0) PANIC("Cannot initialize rwlock static init lock"); if (_lock_init(&_keytable_lock, LCK_ADAPTIVE, - _thr_lock_wait, _thr_lock_wakeup) != 0) + _thr_lock_wait, _thr_lock_wakeup, calloc) != 0) PANIC("Cannot initialize thread specific keytable lock"); _thr_spinlock_init(); Index: thread/thr_kern.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_kern.c,v retrieving revision 1.116.2.1 diff -u -r1.116.2.1 thr_kern.c --- thread/thr_kern.c 16 Mar 2006 23:29:07 -0000 1.116.2.1 +++ thread/thr_kern.c 30 Jan 2008 21:14:31 -0000 @@ -176,7 +176,7 @@ static void kse_gc(struct pthread *thread); static void kseg_gc(struct pthread *thread); -static void __inline +static __inline void thr_accounting(struct pthread *thread) { if ((thread->slice_usec != -1) && @@ -228,6 +228,10 @@ __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); _thread_active_threads = 1; + curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL; + curthread->attr.flags &= ~PTHREAD_SCOPE_PROCESS; + curthread->attr.flags |= PTHREAD_SCOPE_SYSTEM; + /* * Enter a loop to remove and free all threads other than * the running thread from the active thread list: @@ -310,13 +314,6 @@ inited = 0; } - /* - * After a fork(), the leftover thread goes back to being - * scope process. - */ - curthread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM; - curthread->attr.flags |= PTHREAD_SCOPE_PROCESS; - /* We're no longer part of any lists */ curthread->tlflags = 0; @@ -345,6 +342,16 @@ _LCK_SET_PRIVATE2(&curthread->kse->k_lockusers[i], NULL); } curthread->kse->k_locklevel = 0; + + /* + * Reinitialize the thread and signal locks so that + * sigaction() will work after a fork(). + */ + _lock_reinit(&curthread->lock, LCK_ADAPTIVE, _thr_lock_wait, + _thr_lock_wakeup); + _lock_reinit(&_thread_signal_lock, LCK_ADAPTIVE, _kse_lock_wait, + _kse_lock_wakeup); + _thr_spinlock_init(); if (__isthreaded) { _thr_rtld_fini(); @@ -354,6 +361,19 @@ curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL; curthread->attr.flags |= PTHREAD_SCOPE_SYSTEM; + /* + * After a fork, it is possible that an upcall occurs in + * the parent KSE that fork()'d before the child process + * is fully created and before its vm space is copied. + * During the upcall, the tcb is set to null or to another + * thread, and this is what gets copied in the child process + * when the vm space is cloned sometime after the upcall + * occurs. Note that we shouldn't have to set the kcb, but + * we do it for completeness. + */ + _kcb_set(curthread->kse->k_kcb); + _tcb_set(curthread->kse->k_kcb, curthread->tcb); + /* After a fork(), there child should have no pending signals. */ sigemptyset(&curthread->sigpend); @@ -381,13 +401,13 @@ TAILQ_INIT(&free_threadq); TAILQ_INIT(&gc_ksegq); if (_lock_init(&kse_lock, LCK_ADAPTIVE, - _kse_lock_wait, _kse_lock_wakeup) != 0) + _kse_lock_wait, _kse_lock_wakeup, calloc) != 0) PANIC("Unable to initialize free KSE queue lock"); if (_lock_init(&thread_lock, LCK_ADAPTIVE, - _kse_lock_wait, _kse_lock_wakeup) != 0) + _kse_lock_wait, _kse_lock_wakeup, calloc) != 0) PANIC("Unable to initialize free thread queue lock"); if (_lock_init(&_thread_list_lock, LCK_ADAPTIVE, - _kse_lock_wait, _kse_lock_wakeup) != 0) + _kse_lock_wait, _kse_lock_wakeup, calloc) != 0) PANIC("Unable to initialize thread list lock"); _pthread_mutex_init(&_tcb_mutex, NULL); active_kse_count = 0; @@ -764,7 +784,6 @@ break; case PS_DEAD: - curthread->check_pending = 0; /* Unlock the scheduling queue and exit the KSE and thread. */ thr_cleanup(curkse, curthread); KSE_SCHED_UNLOCK(curkse, curkse->k_kseg); @@ -1150,6 +1170,11 @@ struct kse_mailbox *kmbx = NULL; int sys_scope; + thread->active = 0; + thread->need_switchout = 0; + thread->lock_switch = 0; + thread->check_pending = 0; + if ((joiner = thread->joiner) != NULL) { /* Joinee scheduler lock held; joiner won't leave. */ if (joiner->kseg == curkse->k_kseg) { @@ -1717,9 +1742,6 @@ * stack. It is safe to do garbage collecting * here. */ - thread->active = 0; - thread->need_switchout = 0; - thread->lock_switch = 0; thr_cleanup(kse, thread); return; break; @@ -2122,7 +2144,7 @@ { kseg_reinit(kseg); _lock_init(&kseg->kg_lock, LCK_ADAPTIVE, _kse_lock_wait, - _kse_lock_wakeup); + _kse_lock_wakeup, calloc); } static void @@ -2392,7 +2414,7 @@ * enter critical region before doing this! */ if (_lock_init(&thread->lock, LCK_ADAPTIVE, - _thr_lock_wait, _thr_lock_wakeup) != 0) + _thr_lock_wait, _thr_lock_wakeup, calloc) != 0) PANIC("Cannot initialize thread lock"); for (i = 0; i < MAX_THR_LOCKLEVEL; i++) { _lockuser_init(&thread->lockusers[i], (void *)thread); Index: thread/thr_mutex.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_mutex.c,v retrieving revision 1.47.2.1 diff -u -r1.47.2.1 thr_mutex.c --- thread/thr_mutex.c 16 Mar 2006 23:29:07 -0000 1.47.2.1 +++ thread/thr_mutex.c 30 Jan 2008 21:28:13 -0000 @@ -76,7 +76,7 @@ */ static struct kse_mailbox *mutex_handoff(struct pthread *, struct pthread_mutex *); -static inline int mutex_self_trylock(struct pthread *, pthread_mutex_t); +static inline int mutex_self_trylock(pthread_mutex_t); static inline int mutex_self_lock(struct pthread *, pthread_mutex_t); static int mutex_unlock_common(pthread_mutex_t *, int); static void mutex_priority_adjust(struct pthread *, pthread_mutex_t); @@ -87,6 +87,16 @@ static inline void mutex_queue_enq(pthread_mutex_t, pthread_t); static void mutex_lock_backout(void *arg); +int __pthread_mutex_init(pthread_mutex_t *mutex, + const pthread_mutexattr_t *mutex_attr); +int __pthread_mutex_trylock(pthread_mutex_t *mutex); +int __pthread_mutex_lock(pthread_mutex_t *m); +int __pthread_mutex_timedlock(pthread_mutex_t *m, + const struct timespec *abs_timeout); +int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, + void *(calloc_cb)(size_t, size_t)); + + static struct pthread_mutex_attr static_mutex_attr = PTHREAD_MUTEXATTR_STATIC_INITIALIZER; static pthread_mutexattr_t static_mattr = &static_mutex_attr; @@ -101,11 +111,9 @@ __weak_reference(_pthread_mutex_destroy, pthread_mutex_destroy); __weak_reference(_pthread_mutex_unlock, pthread_mutex_unlock); - - -int -__pthread_mutex_init(pthread_mutex_t *mutex, - const pthread_mutexattr_t *mutex_attr) +static int +thr_mutex_init(pthread_mutex_t *mutex, + const pthread_mutexattr_t *mutex_attr, void *(calloc_cb)(size_t, size_t)) { struct pthread_mutex *pmutex; enum pthread_mutextype type; @@ -149,10 +157,10 @@ /* Check no errors so far: */ if (ret == 0) { if ((pmutex = (pthread_mutex_t) - malloc(sizeof(struct pthread_mutex))) == NULL) + calloc_cb(1, sizeof(struct pthread_mutex))) == NULL) ret = ENOMEM; else if (_lock_init(&pmutex->m_lock, LCK_ADAPTIVE, - _thr_lock_wait, _thr_lock_wakeup) != 0) { + _thr_lock_wait, _thr_lock_wakeup, calloc_cb) != 0) { free(pmutex); *mutex = NULL; ret = ENOMEM; @@ -207,6 +215,14 @@ } int +__pthread_mutex_init(pthread_mutex_t *mutex, + const pthread_mutexattr_t *mutex_attr) +{ + + return (thr_mutex_init(mutex, mutex_attr, calloc)); +} + +int _pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_attr) { @@ -222,6 +238,23 @@ } } +/* This function is used internally by malloc. */ +int +_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, + void *(calloc_cb)(size_t, size_t)) +{ + static const struct pthread_mutex_attr attr = { + .m_type = PTHREAD_MUTEX_NORMAL, + .m_protocol = PTHREAD_PRIO_NONE, + .m_ceiling = 0, + .m_flags = 0 + }; + static const struct pthread_mutex_attr *pattr = &attr; + + return (thr_mutex_init(mutex, (pthread_mutexattr_t *)&pattr, + calloc_cb)); +} + void _thr_mutex_reinit(pthread_mutex_t *mutex) { @@ -252,7 +285,7 @@ * Check to see if this mutex is in use: */ if (((*mutex)->m_owner != NULL) || - (TAILQ_FIRST(&(*mutex)->m_queue) != NULL) || + (!TAILQ_EMPTY(&(*mutex)->m_queue)) || ((*mutex)->m_refcount != 0)) { ret = EBUSY; @@ -290,7 +323,7 @@ THR_LOCK_ACQUIRE(thread, &_mutex_static_lock); if (*mutex == NULL) - ret = pthread_mutex_init(mutex, NULL); + ret = _pthread_mutex_init(mutex, NULL); else ret = 0; @@ -307,7 +340,7 @@ THR_LOCK_ACQUIRE(thread, &_mutex_static_lock); if (*mutex == NULL) - ret = pthread_mutex_init(mutex, &static_mattr); + ret = _pthread_mutex_init(mutex, &static_mattr); else ret = 0; @@ -353,7 +386,7 @@ TAILQ_INSERT_TAIL(&curthread->mutexq, (*mutex), m_qe); } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(curthread, *mutex); + ret = mutex_self_trylock(*mutex); else /* Return a busy error: */ ret = EBUSY; @@ -385,7 +418,7 @@ TAILQ_INSERT_TAIL(&curthread->mutexq, (*mutex), m_qe); } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(curthread, *mutex); + ret = mutex_self_trylock(*mutex); else /* Return a busy error: */ ret = EBUSY; @@ -422,7 +455,7 @@ TAILQ_INSERT_TAIL(&curthread->mutexq, (*mutex), m_qe); } else if ((*mutex)->m_owner == curthread) - ret = mutex_self_trylock(curthread, *mutex); + ret = mutex_self_trylock(*mutex); else /* Return a busy error: */ ret = EBUSY; @@ -949,7 +982,7 @@ } static inline int -mutex_self_trylock(struct pthread *curthread, pthread_mutex_t m) +mutex_self_trylock(pthread_mutex_t m) { int ret = 0; @@ -1561,7 +1594,7 @@ for (m = TAILQ_FIRST(&pthread->mutexq); m != NULL; m = m_next) { m_next = TAILQ_NEXT(m, m_qe); if ((m->m_flags & MUTEX_FLAGS_PRIVATE) != 0) - pthread_mutex_unlock(&m); + _pthread_mutex_unlock(&m); } } Index: thread/thr_mutex_prioceiling.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_mutex_prioceiling.c,v retrieving revision 1.8 diff -u -r1.8 thr_mutex_prioceiling.c --- thread/thr_mutex_prioceiling.c 7 Jul 2003 04:28:23 -0000 1.8 +++ thread/thr_mutex_prioceiling.c 30 Jan 2008 21:14:31 -0000 @@ -31,10 +31,13 @@ * * $FreeBSD: src/lib/libpthread/thread/thr_mutex_prioceiling.c,v 1.8 2003/07/07 04:28:23 davidxu Exp $ */ + +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" #include "thr_private.h" __weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling); @@ -82,10 +85,11 @@ ret = EINVAL; else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) ret = EINVAL; - else - ret = (*mutex)->m_prio; - - return(ret); + else { + *prioceiling = (*mutex)->m_prio; + ret = 0; + } + return (ret); } int @@ -100,13 +104,13 @@ else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) ret = EINVAL; /* Lock the mutex: */ - else if ((ret = pthread_mutex_lock(mutex)) == 0) { + else if ((ret = _pthread_mutex_lock(mutex)) == 0) { tmp = (*mutex)->m_prio; /* Set the new ceiling: */ (*mutex)->m_prio = prioceiling; /* Unlock the mutex: */ - ret = pthread_mutex_unlock(mutex); + ret = _pthread_mutex_unlock(mutex); /* Return the old ceiling: */ Index: thread/thr_rtld.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_rtld.c,v retrieving revision 1.5.10.1 diff -u -r1.5.10.1 thr_rtld.c --- thread/thr_rtld.c 16 Mar 2006 23:29:08 -0000 1.5.10.1 +++ thread/thr_rtld.c 30 Jan 2008 21:14:31 -0000 @@ -162,7 +162,7 @@ if ((l = malloc(sizeof(struct rtld_kse_lock))) != NULL) { _lock_init(&l->lck, LCK_ADAPTIVE, _kse_lock_wait, - _kse_lock_wakeup); + _kse_lock_wakeup, calloc); l->owner = NULL; l->count = 0; l->write = 0; Index: thread/thr_sig.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_sig.c,v retrieving revision 1.83.2.2 diff -u -r1.83.2.2 thr_sig.c --- thread/thr_sig.c 23 Jun 2006 10:51:35 -0000 1.83.2.2 +++ thread/thr_sig.c 30 Jan 2008 21:14:31 -0000 @@ -299,16 +299,18 @@ struct sigcontext *scp, char *addr, __sighandler_t *catcher); void -_thr_sig_handler(int sig, siginfo_t *info, ucontext_t *ucp) +_thr_sig_handler(int sig, siginfo_t *info, void *ucp_arg) { struct pthread_sigframe psf; __siginfohandler_t *sigfunc; struct pthread *curthread; struct kse *curkse; + ucontext_t *ucp; struct sigaction act; int sa_flags, err_save; err_save = errno; + ucp = (ucontext_t *)ucp_arg; DBG_MSG(">>> _thr_sig_handler(%d)\n", sig); Index: thread/thr_sigaction.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_sigaction.c,v retrieving revision 1.22.10.1 diff -u -r1.22.10.1 thr_sigaction.c --- thread/thr_sigaction.c 23 Jun 2006 10:51:36 -0000 1.22.10.1 +++ thread/thr_sigaction.c 30 Jan 2008 21:14:31 -0000 @@ -86,7 +86,7 @@ * Specify the thread kernel signal * handler: */ - newact.sa_handler = (void (*) ())_thr_sig_handler; + newact.sa_sigaction = _thr_sig_handler; } /* * Install libpthread signal handler wrapper @@ -95,8 +95,7 @@ * SIG_DFL or SIG_IGN. */ if (sig == SIGINFO && _thr_dump_enabled()) { - newact.sa_handler = - (void (*) ())_thr_sig_handler; + newact.sa_sigaction = _thr_sig_handler; } /* Change the signal action in the kernel: */ if (__sys_sigaction(sig, &newact, NULL) != 0) { Index: thread/thr_spinlock.c =================================================================== RCS file: /opt/FreeBSD/cvs/src/lib/libpthread/thread/Attic/thr_spinlock.c,v retrieving revision 1.22 diff -u -r1.22 thr_spinlock.c --- thread/thr_spinlock.c 18 Dec 2004 18:07:37 -0000 1.22 +++ thread/thr_spinlock.c 30 Jan 2008 21:14:31 -0000 @@ -33,20 +30,30 @@ * */ +#include "namespace.h" #include #include - +#include #include +#include "un-namespace.h" #include "spinlock.h" #include "thr_private.h" -#define MAX_SPINLOCKS 5 +#define MAX_SPINLOCKS 72 struct spinlock_extra { spinlock_t *owner; pthread_mutex_t lock; }; +struct nv_spinlock { + long access_lock; + long lock_owner; + struct spinlock_extra *extra; /* overlays fname in spinlock_t */ + int lineno; +}; +typedef struct nv_spinlock nv_spinlock_t; + static void init_spinlock(spinlock_t *lck); static struct pthread_mutex_attr static_mutex_attr = @@ -66,10 +73,10 @@ void _spinunlock(spinlock_t *lck) { - struct spinlock_extra *extra; + struct spinlock_extra *sl_extra; - extra = (struct spinlock_extra *)lck->fname; - _pthread_mutex_unlock(&extra->lock); + sl_extra = ((nv_spinlock_t *)lck)->extra; + _pthread_mutex_unlock(&sl_extra->lock); } /* @@ -81,7 +88,7 @@ void _spinlock(spinlock_t *lck) { - struct spinlock_extra *extra; + struct spinlock_extra *sl_extra; if (!__isthreaded) PANIC("Spinlock called when not threaded."); @@ -93,8 +100,8 @@ */ if (lck->fname == NULL) init_spinlock(lck); - extra = (struct spinlock_extra *)lck->fname; - _pthread_mutex_lock(&extra->lock); + sl_extra = ((nv_spinlock_t *)lck)->extra; + _pthread_mutex_lock(&sl_extra->lock); } /* @@ -108,7 +115,7 @@ * returning. */ void -_spinlock_debug(spinlock_t *lck, char *fname, int lineno) +_spinlock_debug(spinlock_t *lck, char *fname __unused, int lineno __unused) { _spinlock(lck); } --------------020701010806090604090704-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 09:20:09 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9AFBA16A418 for ; Thu, 31 Jan 2008 09:20:09 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id 6D22013C465 for ; Thu, 31 Jan 2008 09:20:09 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [172.16.99.14] (unknown [172.16.99.14]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 12B531703A; Thu, 31 Jan 2008 01:20:09 -0800 (PST) Message-Id: <01819294-7795-493D-A054-D4ACEC8706D6@bikemonkey.org> From: Landon Fuller To: Julian Elischer In-Reply-To: <47A18DCD.2070101@elischer.org> Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-1-125705283" Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v915) Date: Thu, 31 Jan 2008 01:20:04 -0800 References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> <47A0D2DE.9060005@elischer.org> <35535E7A-0804-4DAD-B0A0-CCF9EE7060B0@bikemonkey.org> <47A18DCD.2070101@elischer.org> X-Pgp-Agent: GPGMail d51 (Leopard) X-Mailer: Apple Mail (2.915) Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 09:20:09 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-1-125705283 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Jan 31, 2008, at 12:58 AM, Julian Elischer wrote: > Landon Fuller wrote: > >> Thanks -- pulling in relevant change from sys/lock.c -- plus your >> previous patch -- solves my reproduction case: >> http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63-fork > > > is this the patch you used? It's huge.. Are you sure you fetched the patch-libpthread63-fork file? I cherry picked just the changes to _lockuser_reinit() and _kse_single_thread(). Posted patch here, inlined below: http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63-fork Cheers, Landon diff -ru lib/libpthread.orig/sys/lock.c lib/libpthread/sys/lock.c --- lib/libpthread.orig/sys/lock.c 2008-01-30 16:30:07.000000000 -0800 +++ lib/libpthread/sys/lock.c 2008-01-30 16:58:59.000000000 -0800 @@ -117,14 +117,23 @@ { if (lu == NULL) return (-1); - /* - * All lockusers keep their watch request and drop their - * own (lu_myreq) request. Their own request is either - * some other lockuser's watch request or is the head of - * the lock. - */ - lu->lu_myreq = lu->lu_watchreq; - if (lu->lu_myreq == NULL) + + if (lu->lu_watchreq != NULL) { + /* + * In this case the lock is active. All lockusers + * keep their watch request and drop their own + * (lu_myreq) request. Their own request is either + * some other lockuser's watch request or is the + * head of the lock. + */ + lu->lu_myreq = lu->lu_watchreq; + lu->lu_watchreq = NULL; + } + if (lu->lu_myreq == NULL) + /* + * Oops, something isn't quite right. Try to + * allocate one. + */ return (_lockuser_init(lu, priv)); else { lu->lu_myreq->lr_locked = 1; diff -ru lib/libpthread.orig/thread/thr_kern.c lib/libpthread/thread/ thr_kern.c --- lib/libpthread.orig/thread/thr_kern.c 2008-01-30 16:30:07.000000000 -0800 +++ lib/libpthread/thread/thr_kern.c 2008-01-30 16:55:19.000000000 -0800 @@ -345,6 +345,17 @@ _LCK_SET_PRIVATE2(&curthread->kse->k_lockusers[i], NULL); } curthread->kse->k_locklevel = 0; + + /* + * Reinitialize the thread and signal locks so that + * sigaction() will work after a fork(). + */ + _lock_reinit(&curthread->lock, LCK_ADAPTIVE, _thr_lock_wait, + _thr_lock_wakeup); + _lock_reinit(&_thread_signal_lock, LCK_ADAPTIVE, _kse_lock_wait, + _kse_lock_wakeup); + + _thr_spinlock_init(); if (__isthreaded) { _thr_rtld_fini(); @@ -354,6 +365,20 @@ curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL; curthread->attr.flags |= PTHREAD_SCOPE_SYSTEM; + /* + * After a fork, it is possible that an upcall occurs in + * the parent KSE that fork()'d before the child process + * is fully created and before its vm space is copied. + * During the upcall, the tcb is set to null or to another + * thread, and this is what gets copied in the child process + * when the vm space is cloned sometime after the upcall + * occurs. Note that we shouldn't have to set the kcb, but + * we do it for completeness. + */ + _kcb_set(curthread->kse->k_kcb); + _tcb_set(curthread->kse->k_kcb, curthread->tcb); + + /* After a fork(), there child should have no pending signals. */ sigemptyset(&curthread->sigpend); --Apple-Mail-1-125705283 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHoZLElplZCE/15mMRAv73AJ0eMwfbrarcHAWeg5D026EYtYu08ACeJb1z FD9UQa43xswZF9ugzWCr9Kw= =ACc/ -----END PGP SIGNATURE----- --Apple-Mail-1-125705283-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 09:36:13 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D75C716A475; Thu, 31 Jan 2008 09:36:13 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id A285813C4EF; Thu, 31 Jan 2008 09:36:13 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 4E41647D36; Thu, 31 Jan 2008 04:36:13 -0500 (EST) Date: Thu, 31 Jan 2008 09:36:13 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Julian Elischer In-Reply-To: <20080129222455.T53151@fledge.watson.org> Message-ID: <20080131093321.K35034@fledge.watson.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Daniel Eischen , Gary Stanley , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 09:36:13 -0000 On Tue, 29 Jan 2008, Robert Watson wrote: >>> Should the patch be considered for an errata notice for 6.x? Should we be >>> trying to MFC this to 7.x for inclusion with 7.0 or does it need more time >>> to shake out and should potentially be a 7.0 errata notice or just appear >>> in 7.1? >> >> yes and yes and no > > If the fix is going to ship in 7.0 and hasn't yet been MFC'd, that needs to > happen ASAP. Could someone forward the patch/etc over to re@ for approval? > > The procedure for doing an errata patch is basically that whoever is > proposing the errata patch needs to e-mail a patch, or multiple patches if > it's different for different branches, a proposed branch list, and as much > of a completed errata notice template as possible (impact, etc) to re@ for > review. Once re@ is OK that it's ready to go, it will get sent over to > secteam@ to be put into production, binary updates generated, etc. If in > doubt about which branches, drop e-mail to secteam@ to ask which are > supported, etc. > > At this point we would probably not advise doing the errata patch before 7.0 > is released, so priority should go to preparing any patches that need to go > out with 7.0. Hello? Right now this is on re@'s list of "waiting for this to do RC2", which means that the release is holding on the fix. Please let me know what the plan is so we can either move on with the release without waiting, or have some sort of timeline in mind. Is this patch believed mature enough to be merged as-is? Thanks, Robert N M Watson Computer Laboratory University of Cambridge From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 18:00:20 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 50C2816A46C for ; Thu, 31 Jan 2008 18:00:20 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outI.internet-mail-service.net (outI.internet-mail-service.net [216.240.47.232]) by mx1.freebsd.org (Postfix) with ESMTP id 2A56613C45A for ; Thu, 31 Jan 2008 18:00:20 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 10:00:19 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id AC5E0127081; Thu, 31 Jan 2008 10:00:18 -0800 (PST) Message-ID: <47A20CB2.1010508@elischer.org> Date: Thu, 31 Jan 2008 10:00:18 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> <47A0D2DE.9060005@elischer.org> <35535E7A-0804-4DAD-B0A0-CCF9EE7060B0@bikemonkey.org> <47A18DCD.2070101@elischer.org> <01819294-7795-493D-A054-D4ACEC8706D6@bikemonkey.org> In-Reply-To: <01819294-7795-493D-A054-D4ACEC8706D6@bikemonkey.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 18:00:20 -0000 Landon Fuller wrote: > > On Jan 31, 2008, at 12:58 AM, Julian Elischer wrote: > >> Landon Fuller wrote: >> >>> Thanks -- pulling in relevant change from sys/lock.c -- plus your >>> previous patch -- solves my reproduction case: >>> >>> http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63-fork >>> >> >> >> is this the patch you used? It's huge.. > > Are you sure you fetched the patch-libpthread63-fork file? I cherry > picked just the changes to _lockuser_reinit() and _kse_single_thread(). hmm maybe I clicked on the wrong file somewhere. > > Posted patch here, inlined below: > http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63-fork ok that's more what I was expecting.. lets's see if we can get this in RELENG_6 (and errata for 6.3) and ensure it is in 7.0kjfnb8_k > > > Cheers, > Landon > > diff -ru lib/libpthread.orig/sys/lock.c lib/libpthread/sys/lock.c > --- lib/libpthread.orig/sys/lock.c 2008-01-30 16:30:07.000000000 -0800 > +++ lib/libpthread/sys/lock.c 2008-01-30 16:58:59.000000000 -0800 > @@ -117,14 +117,23 @@ > { > if (lu == NULL) > return (-1); > - /* > - * All lockusers keep their watch request and drop their > - * own (lu_myreq) request. Their own request is either > - * some other lockuser's watch request or is the head of > - * the lock. > - */ > - lu->lu_myreq = lu->lu_watchreq; > - if (lu->lu_myreq == NULL) > + > + if (lu->lu_watchreq != NULL) { > + /* > + * In this case the lock is active. All lockusers > + * keep their watch request and drop their own > + * (lu_myreq) request. Their own request is either > + * some other lockuser's watch request or is the > + * head of the lock. > + */ > + lu->lu_myreq = lu->lu_watchreq; > + lu->lu_watchreq = NULL; > + } > + if (lu->lu_myreq == NULL) > + /* > + * Oops, something isn't quite right. Try to > + * allocate one. > + */ > return (_lockuser_init(lu, priv)); > else { > lu->lu_myreq->lr_locked = 1; > diff -ru lib/libpthread.orig/thread/thr_kern.c > lib/libpthread/thread/thr_kern.c > --- lib/libpthread.orig/thread/thr_kern.c 2008-01-30 > 16:30:07.000000000 -0800 > +++ lib/libpthread/thread/thr_kern.c 2008-01-30 16:55:19.000000000 -0800 > @@ -345,6 +345,17 @@ > _LCK_SET_PRIVATE2(&curthread->kse->k_lockusers[i], NULL); > } > curthread->kse->k_locklevel = 0; > + > + /* > + * Reinitialize the thread and signal locks so that > + * sigaction() will work after a fork(). > + */ > + _lock_reinit(&curthread->lock, LCK_ADAPTIVE, _thr_lock_wait, > + _thr_lock_wakeup); > + _lock_reinit(&_thread_signal_lock, LCK_ADAPTIVE, _kse_lock_wait, > + _kse_lock_wakeup); > + > + > _thr_spinlock_init(); > if (__isthreaded) { > _thr_rtld_fini(); > @@ -354,6 +365,20 @@ > curthread->kse->k_kcb->kcb_kmbx.km_curthread = NULL; > curthread->attr.flags |= PTHREAD_SCOPE_SYSTEM; > > + /* > + * After a fork, it is possible that an upcall occurs in > + * the parent KSE that fork()'d before the child process > + * is fully created and before its vm space is copied. > + * During the upcall, the tcb is set to null or to another > + * thread, and this is what gets copied in the child process > + * when the vm space is cloned sometime after the upcall > + * occurs. Note that we shouldn't have to set the kcb, but > + * we do it for completeness. > + */ > + _kcb_set(curthread->kse->k_kcb); > + _tcb_set(curthread->kse->k_kcb, curthread->tcb); > + > + > /* After a fork(), there child should have no pending signals. */ > sigemptyset(&curthread->sigpend); > > From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 18:44:31 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BF4EC16A417 for ; Thu, 31 Jan 2008 18:44:31 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outA.internet-mail-service.net (outA.internet-mail-service.net [216.240.47.224]) by mx1.freebsd.org (Postfix) with ESMTP id 63C8A13C4DB for ; Thu, 31 Jan 2008 18:44:31 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 10:44:30 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id BEADE127095; Thu, 31 Jan 2008 10:44:29 -0800 (PST) Message-ID: <47A2170D.6020308@elischer.org> Date: Thu, 31 Jan 2008 10:44:29 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Robert Watson References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> In-Reply-To: <20080131093321.K35034@fledge.watson.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , Gary Stanley , Landon Fuller , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 18:44:31 -0000 Robert Watson wrote: > > On Tue, 29 Jan 2008, Robert Watson wrote: > >>>> Should the patch be considered for an errata notice for 6.x? Should >>>> we be trying to MFC this to 7.x for inclusion with 7.0 or does it >>>> need more time to shake out and should potentially be a 7.0 errata >>>> notice or just appear in 7.1? >>> >>> yes and yes and no >> >> If the fix is going to ship in 7.0 and hasn't yet been MFC'd, that >> needs to happen ASAP. Could someone forward the patch/etc over to re@ >> for approval? >> >> The procedure for doing an errata patch is basically that whoever is >> proposing the errata patch needs to e-mail a patch, or multiple >> patches if it's different for different branches, a proposed branch >> list, and as much of a completed errata notice template as possible >> (impact, etc) to re@ for review. Once re@ is OK that it's ready to go, >> it will get sent over to secteam@ to be put into production, binary >> updates generated, etc. If in doubt about which branches, drop e-mail >> to secteam@ to ask which are supported, etc. >> >> At this point we would probably not advise doing the errata patch >> before 7.0 is released, so priority should go to preparing any patches >> that need to go out with 7.0. > > Hello? > > Right now this is on re@'s list of "waiting for this to do RC2", which > means that the release is holding on the fix. Please let me know what > the plan is so we can either move on with the release without waiting, > or have some sort of timeline in mind. Is this patch believed mature > enough to be merged as-is? the releng 6 and releng 7 versions of this patch are at: http://www.freebsd.org/~julian/kse-6.diff and http://www.freebsd.org/~julian/kse-7.diff but the one for 7 is just speculative. I don't have a 7.x system to test. Landon, what is your test case? > > Thanks, > > Robert N M Watson > Computer Laboratory > University of Cambridge > _______________________________________________ > freebsd-threads@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 18:52:11 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F2C616A417; Thu, 31 Jan 2008 18:52:11 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id DDB8913C45B; Thu, 31 Jan 2008 18:52:10 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.2/8.14.2/NETPLEX) with ESMTP id m0VIq7cA002314; Thu, 31 Jan 2008 13:52:07 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Thu, 31 Jan 2008 13:52:07 -0500 (EST) Date: Thu, 31 Jan 2008 13:52:07 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Julian Elischer In-Reply-To: <47A2170D.6020308@elischer.org> Message-ID: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Gary Stanley , Landon Fuller , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 18:52:11 -0000 On Thu, 31 Jan 2008, Julian Elischer wrote: > Robert Watson wrote: >> Right now this is on re@'s list of "waiting for this to do RC2", which >> means that the release is holding on the fix. Please let me know what the >> plan is so we can either move on with the release without waiting, or have >> some sort of timeline in mind. Is this patch believed mature enough to be >> merged as-is? > > the releng 6 and releng 7 versions of this patch are at: > http://www.freebsd.org/~julian/kse-6.diff > and > http://www.freebsd.org/~julian/kse-7.diff > > but the one for 7 is just speculative. > I don't have a 7.x system to test. It looks good to me, but I don't have a fast multi-cpu system to test with either (running 6 or 7). -- DE From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:03:09 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6057716A46B; Thu, 31 Jan 2008 19:03:09 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id 34F9713C46A; Thu, 31 Jan 2008 19:03:09 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id EDFE517032; Thu, 31 Jan 2008 11:03:08 -0800 (PST) In-Reply-To: <47A2170D.6020308@elischer.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-29-160686945" Message-Id: <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> From: Landon Fuller Date: Thu, 31 Jan 2008 11:03:06 -0800 To: Julian Elischer Content-Transfer-Encoding: 7bit X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:03:09 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-29-160686945 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 31, 2008, at 10:44, Julian Elischer wrote: > the releng 6 and releng 7 versions of this patch are at: > http://www.freebsd.org/~julian/kse-6.diff > and > http://www.freebsd.org/~julian/kse-7.diff > > but the one for 7 is just speculative. > I don't have a 7.x system to test. > > Landon, what is your test case? Inlined below. On our 8-core 6.3 system without this patch, the fork () threads wedge and spin in <2 minutes. With the patch, works as expected. #include #include #include void *forker (void *arg) { while (1) { pid_t pid = fork(); if (pid == 0) { exit(0); } else if (pid > 0) { int status; waitpid(pid, &status, 0); } else { printf("Fork failed\n"); abort(); } } } int main(void) { int i = 0; for (i = 0; i < 4; i++) { pthread_t thr; pthread_create(&thr, NULL, forker, NULL); pthread_detach(thr); } while(1) sleep(1000); } --Apple-Mail-29-160686945 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHohtqlplZCE/15mMRArX+AJ4l9gd9JiEkf8lUh+YfVKydeF//AACePCBf oOVWV6RDLo9WpMnfFYlwsmY= =5b3p -----END PGP SIGNATURE----- --Apple-Mail-29-160686945-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:10:00 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3AB2016A418 for ; Thu, 31 Jan 2008 19:10:00 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outH.internet-mail-service.net (outH.internet-mail-service.net [216.240.47.231]) by mx1.freebsd.org (Postfix) with ESMTP id 1FD8513C448 for ; Thu, 31 Jan 2008 19:10:00 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 11:09:59 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id EE428127077; Thu, 31 Jan 2008 11:09:58 -0800 (PST) Message-ID: <47A21D06.50608@elischer.org> Date: Thu, 31 Jan 2008 11:09:58 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <488DBC6A-CF33-4E50-B1BB-C396C8957F92@bikemonkey.org> <892A73B3-0114-4718-ABC0-CADD45D9D0FA@bikemonkey.org> <47A0D2DE.9060005@elischer.org> <35535E7A-0804-4DAD-B0A0-CCF9EE7060B0@bikemonkey.org> <47A18DCD.2070101@elischer.org> <01819294-7795-493D-A054-D4ACEC8706D6@bikemonkey.org> <47A20CB2.1010508@elischer.org> In-Reply-To: <47A20CB2.1010508@elischer.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:10:00 -0000 Julian Elischer wrote: >> >> Posted patch here, inlined below: >> >> http://landonf.bikemonkey.org/static/code/freebsd/patch-libpthread63-fork > > ok that's more what I was expecting.. > lets's see if we can get this in RELENG_6 (and errata for 6.3) > and ensure it is in 7.0kjfnb8_k ^^^^^^^^ 4 year old gets to my keyboard as I hit 'send" > > > From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:13:13 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1A58616A417 for ; Thu, 31 Jan 2008 19:13:13 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outC.internet-mail-service.net (outC.internet-mail-service.net [216.240.47.226]) by mx1.freebsd.org (Postfix) with ESMTP id 034A913C44B for ; Thu, 31 Jan 2008 19:13:12 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 11:13:12 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id E4973127099; Thu, 31 Jan 2008 11:13:11 -0800 (PST) Message-ID: <47A21DC7.3050402@elischer.org> Date: Thu, 31 Jan 2008 11:13:11 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> In-Reply-To: <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:13:13 -0000 Landon Fuller wrote: > > On Jan 31, 2008, at 10:44, Julian Elischer wrote: > >> the releng 6 and releng 7 versions of this patch are at: >> >> http://www.freebsd.org/~julian/kse-6.diff >> >> and >> >> http://www.freebsd.org/~julian/kse-7.diff >> >> >> but the one for 7 is just speculative. >> >> I don't have a 7.x system to test. >> >> >> Landon, what is your test case? >> > > Inlined below. On our 8-core 6.3 system without this patch, the fork() > threads wedge and spin in <2 minutes. With the patch, works as expected. > > #include > #include > #include > > void *forker (void *arg) { > while (1) { > pid_t pid = fork(); > if (pid == 0) { > exit(0); > } else if (pid > 0) { > int status; > waitpid(pid, &status, 0); > } else { > printf("Fork failed\n"); > abort(); > } > } > } > > int main(void) { > int i = 0; > for (i = 0; i < 4; i++) { > pthread_t thr; > pthread_create(&thr, NULL, forker, NULL); > pthread_detach(thr); > } > > while(1) > sleep(1000); > } great.. is there anyone with a 7.0 MP system, that can confirm that this happens in 7 and that the patch (above) fixes it? From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:25:13 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2038C16A418 for ; Thu, 31 Jan 2008 19:25:13 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outI.internet-mail-service.net (outI.internet-mail-service.net [216.240.47.232]) by mx1.freebsd.org (Postfix) with ESMTP id 0971A13C4CC for ; Thu, 31 Jan 2008 19:25:12 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 11:25:12 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id E8DCC12708F; Thu, 31 Jan 2008 11:25:11 -0800 (PST) Message-ID: <47A22097.2040303@elischer.org> Date: Thu, 31 Jan 2008 11:25:11 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> In-Reply-To: <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:25:13 -0000 Landon Fuller wrote: > > On Jan 31, 2008, at 10:44, Julian Elischer wrote: > >> the releng 6 and releng 7 versions of this patch are at: >> >> http://www.freebsd.org/~julian/kse-6.diff >> >> and >> >> http://www.freebsd.org/~julian/kse-7.diff >> >> >> but the one for 7 is just speculative. >> >> I don't have a 7.x system to test. >> >> >> Landon, what is your test case? >> > > Inlined below. On our 8-core 6.3 system without this patch, the fork() > threads wedge and spin in <2 minutes. With the patch, works as expected. when you say "wedge and spin" what do you see in top? which is it , wedge, or spin? > > #include > #include > #include > > void *forker (void *arg) { > while (1) { > pid_t pid = fork(); > if (pid == 0) { > exit(0); > } else if (pid > 0) { > int status; > waitpid(pid, &status, 0); > } else { > printf("Fork failed\n"); > abort(); > } > } > } > > int main(void) { > int i = 0; > for (i = 0; i < 4; i++) { > pthread_t thr; > pthread_create(&thr, NULL, forker, NULL); > pthread_detach(thr); > } > > while(1) > sleep(1000); > } From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:28:19 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E35C116A418; Thu, 31 Jan 2008 19:28:19 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id C95CF13C46A; Thu, 31 Jan 2008 19:28:19 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id BDB3717032; Thu, 31 Jan 2008 11:28:19 -0800 (PST) In-Reply-To: <47A22097.2040303@elischer.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> <47A22097.2040303@elischer.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-34-162199877" Message-Id: <79EBC63D-72A1-4CB9-962C-C4649544FF7A@bikemonkey.org> Content-Transfer-Encoding: 7bit From: Landon Fuller Date: Thu, 31 Jan 2008 11:28:19 -0800 To: Julian Elischer X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:28:20 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-34-162199877 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 31, 2008, at 11:25, Julian Elischer wrote: > Landon Fuller wrote: >> On Jan 31, 2008, at 10:44, Julian Elischer wrote: >>> the releng 6 and releng 7 versions of this patch are at: >>> >>> http://www.freebsd.org/~julian/kse-6.diff >>> >>> and >>> >>> http://www.freebsd.org/~julian/kse-7.diff >>> >>> >>> but the one for 7 is just speculative. >>> >>> I don't have a 7.x system to test. >>> >>> >>> Landon, what is your test case? >>> >> Inlined below. On our 8-core 6.3 system without this patch, the >> fork() threads wedge and spin in <2 minutes. With the patch, works >> as expected. > > when you say "wedge and spin" what do you see in top? > > which is it , wedge, or spin? The children processes spin (in either sigprocmask() or _lockuser_reinit()), and the parent process thread wedges on waitpid(). --Apple-Mail-34-162199877 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHoiFTlplZCE/15mMRAt3UAJ9YpEkDmvP+4oSeIklNdIA/NaW8gQCdEnRY V1Ze/PZnZaPhGUPWXWpUtFg= =A3bn -----END PGP SIGNATURE----- --Apple-Mail-34-162199877-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:29:41 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BA60816A53E; Thu, 31 Jan 2008 19:29:41 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id 9DFF713C447; Thu, 31 Jan 2008 19:29:41 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 9AC3417032; Thu, 31 Jan 2008 11:29:41 -0800 (PST) In-Reply-To: <79EBC63D-72A1-4CB9-962C-C4649544FF7A@bikemonkey.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> <47A22097.2040303@elischer.org> <79EBC63D-72A1-4CB9-962C-C4649544FF7A@bikemonkey.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-35-162281784" Message-Id: <235AB648-B822-4306-881F-CF202B17AEED@bikemonkey.org> Content-Transfer-Encoding: 7bit From: Landon Fuller Date: Thu, 31 Jan 2008 11:29:40 -0800 To: Julian Elischer X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:29:41 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-35-162281784 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 31, 2008, at 11:28, Landon Fuller wrote: > > On Jan 31, 2008, at 11:25, Julian Elischer wrote: > >> when you say "wedge and spin" what do you see in top? >> >> which is it , wedge, or spin? > > The children processes spin (in either sigprocmask() or > _lockuser_reinit()), and the parent process thread wedges on waitpid > (). ... and blocking on waitpid() is clearly expected behavior =) -landonf --Apple-Mail-35-162281784 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHoiGllplZCE/15mMRAst1AJ4xDRcKi4hW24e7JJ2mUJ7xpDRLfwCdHNLO LtTik8uTKsgQUDKCXjnj+9A= =FX4u -----END PGP SIGNATURE----- --Apple-Mail-35-162281784-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:31:47 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 938F416A46B for ; Thu, 31 Jan 2008 19:31:47 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outT.internet-mail-service.net (outT.internet-mail-service.net [216.240.47.243]) by mx1.freebsd.org (Postfix) with ESMTP id 707A113C47E for ; Thu, 31 Jan 2008 19:31:47 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.40) with ESMTP; Thu, 31 Jan 2008 11:31:46 -0800 Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id 892B6127086; Thu, 31 Jan 2008 11:31:45 -0800 (PST) Message-ID: <47A22220.70006@elischer.org> Date: Thu, 31 Jan 2008 11:31:44 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Landon Fuller References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> <47A22097.2040303@elischer.org> <79EBC63D-72A1-4CB9-962C-C4649544FF7A@bikemonkey.org> In-Reply-To: <79EBC63D-72A1-4CB9-962C-C4649544FF7A@bikemonkey.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:31:47 -0000 Landon Fuller wrote: > > On Jan 31, 2008, at 11:25, Julian Elischer wrote: > >> Landon Fuller wrote: >>> On Jan 31, 2008, at 10:44, Julian Elischer wrote: >>>> the releng 6 and releng 7 versions of this patch are at: >>>> >>>> http://www.freebsd.org/~julian/kse-6.diff >>>> >>>> and >>>> >>>> http://www.freebsd.org/~julian/kse-7.diff >>>> >>>> >>>> but the one for 7 is just speculative. >>>> >>>> I don't have a 7.x system to test. >>>> >>>> >>>> Landon, what is your test case? >>>> >>> Inlined below. On our 8-core 6.3 system without this patch, the >>> fork() threads wedge and spin in <2 minutes. With the patch, works as >>> expected. >> >> when you say "wedge and spin" what do you see in top? >> >> which is it , wedge, or spin? > > The children processes spin (in either sigprocmask() or > _lockuser_reinit()), and the parent process thread wedges on waitpid(). so if the children show up in top at all (usually they are already exited by the time top looks) then the problem has been hit. right? From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:36:49 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 874EB16A46C; Thu, 31 Jan 2008 19:36:49 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from secure.bikemonkey.org (bluefish.bikemonkey.org [69.80.211.101]) by mx1.freebsd.org (Postfix) with ESMTP id 6CD7213C4CE; Thu, 31 Jan 2008 19:36:49 +0000 (UTC) (envelope-from landonf@bikemonkey.org) Received: from [192.168.54.11] (unknown [192.168.54.11]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by secure.bikemonkey.org (Postfix) with ESMTP id 1DDD717038; Thu, 31 Jan 2008 11:36:49 -0800 (PST) In-Reply-To: <47A22220.70006@elischer.org> References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> <42D09215-18FD-43A1-97E8-D4CC9E97AFDD@bikemonkey.org> <47A22097.2040303@elischer.org> <79EBC63D-72A1-4CB9-962C-C4649544FF7A@bikemonkey.org> <47A22220.70006@elischer.org> Mime-Version: 1.0 (Apple Message framework v753) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-36-162709505" Message-Id: <6DCF8C56-DFF9-41CB-8AC9-E7EB9F9A1CCC@bikemonkey.org> Content-Transfer-Encoding: 7bit From: Landon Fuller Date: Thu, 31 Jan 2008 11:36:48 -0800 To: Julian Elischer X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.753) Cc: Daniel Eischen , Gary Stanley , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:36:49 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-36-162709505 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 31, 2008, at 11:31, Julian Elischer wrote: > Landon Fuller wrote: >> The children processes spin (in either sigprocmask() or >> _lockuser_reinit()), and the parent process thread wedges on >> waitpid(). > > so if the children show up in top at all (usually they are already > exited by the time top looks) then the problem has been hit. right? Exactly. With the test case's default number of threads, one should see up to four children appear in top, eating CPU. --Apple-Mail-36-162709505 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHoiNQlplZCE/15mMRAojqAJ9q5PAVEmuVlHzWbxcB1RNK5MMCGwCfVenx bYRpn5bUNyS2BMkISDpEOfc= =ttJe -----END PGP SIGNATURE----- --Apple-Mail-36-162709505-- From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:40:03 2008 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0DEE16A418 for ; Thu, 31 Jan 2008 19:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B7CA213C44B for ; Thu, 31 Jan 2008 19:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0VJe3E2005818 for ; Thu, 31 Jan 2008 19:40:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0VJe3hi005817; Thu, 31 Jan 2008 19:40:03 GMT (envelope-from gnats) Date: Thu, 31 Jan 2008 19:40:03 GMT Message-Id: <200801311940.m0VJe3hi005817@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: dfilter@FreeBSD.org (dfilter service) Cc: Subject: Re: threads/119920: commit references a PR X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dfilter service List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:40:03 -0000 The following reply was made to PR threads/119920; it has been noted by GNATS. From: dfilter@FreeBSD.ORG (dfilter service) To: bug-followup@FreeBSD.org Cc: Subject: Re: threads/119920: commit references a PR Date: Thu, 31 Jan 2008 19:38:37 +0000 (UTC) deischen 2008-01-31 19:38:26 UTC FreeBSD src repository Modified files: lib/libkse/sys lock.c Log: When reinitializing a lockuser, don't assume that the lock is in use. If it is in use, use the watched request, otherwise use the lockuser's own request. Only allocate a lockuser request if both requests are null. PR: 119920 Tested by (6.x): Landon Fuller Revision Changes Path 1.14 +15 -7 src/lib/libkse/sys/lock.c _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org" From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 19:41:46 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1DA5C16A41A; Thu, 31 Jan 2008 19:41:46 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id CB9D613C465; Thu, 31 Jan 2008 19:41:45 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.2/8.14.2/NETPLEX) with ESMTP id m0VJfh3C007229; Thu, 31 Jan 2008 14:41:43 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Thu, 31 Jan 2008 14:41:43 -0500 (EST) Date: Thu, 31 Jan 2008 14:41:43 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Julian Elischer In-Reply-To: Message-ID: References: <200801240850.m0O8o2JQ023500@freefall.freebsd.org> <4798564B.7070500@elischer.org> <20080128185830.B56811@fledge.watson.org> <479E3079.3000803@elischer.org> <20080129222455.T53151@fledge.watson.org> <20080131093321.K35034@fledge.watson.org> <47A2170D.6020308@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Gary Stanley , Landon Fuller , Robert Watson , freebsd-threads@freebsd.org Subject: Re: threads/119920: fork broken in libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 19:41:46 -0000 On Thu, 31 Jan 2008, Daniel Eischen wrote: > On Thu, 31 Jan 2008, Julian Elischer wrote: > >> Robert Watson wrote: >>> Right now this is on re@'s list of "waiting for this to do RC2", which >>> means that the release is holding on the fix. Please let me know what the >>> plan is so we can either move on with the release without waiting, or have >>> some sort of timeline in mind. Is this patch believed mature enough to be >>> merged as-is? >> >> the releng 6 and releng 7 versions of this patch are at: >> http://www.freebsd.org/~julian/kse-6.diff >> and >> http://www.freebsd.org/~julian/kse-7.diff >> >> but the one for 7 is just speculative. >> I don't have a 7.x system to test. > > It looks good to me, but I don't have a fast multi-cpu system > to test with either (running 6 or 7). I just committed an appropriate fix to -current (sys/lock.c). The other part of the fix is already in -current. -- DE From owner-freebsd-threads@FreeBSD.ORG Thu Jan 31 20:19:21 2008 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5E79216A417 for ; Thu, 31 Jan 2008 20:19:21 +0000 (UTC) (envelope-from jin@george.lbl.gov) Received: from smtp119.sbc.mail.sp1.yahoo.com (smtp119.sbc.mail.sp1.yahoo.com [69.147.64.92]) by mx1.freebsd.org (Postfix) with SMTP id 3FD3213C44B for ; Thu, 31 Jan 2008 20:19:21 +0000 (UTC) (envelope-from jin@george.lbl.gov) Received: (qmail 77155 invoked from network); 31 Jan 2008 19:52:41 -0000 Received: from unknown (HELO ?192.168.1.238?) (jinmtb@sbcglobal.net@67.111.218.125 with plain) by smtp119.sbc.mail.sp1.yahoo.com with SMTP; 31 Jan 2008 19:52:41 -0000 X-YMail-OSG: iRYsG4kVM1nawf7BByiMThIZ0dkkt7TWKzGwz7XKdx2eiRPh.lwUwEPd07rcL.QA6DgOGKqmyg-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <47A22703.7030903@george.lbl.gov> Date: Thu, 31 Jan 2008 11:52:35 -0800 From: Jin Guojun User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20061027 X-Accept-Language: zh, zh-CN, en MIME-Version: 1.0 To: threads@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: improper order to check NULL pointer in libthr X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 20:19:21 -0000 Most pthread_mutex functions and some pthread_ functions in linbthr do not check NULL pointer at the function entry, but they dereference the pointer to see if its content is NULL. The NULL pointer is ASSERTed at last stage (in xxxxx_common routines) somehow, which is meaningless. So, what is the correct design pattern? -- (should be like libpthread, which looks correct) Return EFAULT / EINVAL at the entry point as +++ below if the pointer is NULL? or ASSERT at the entry point if pointer or its content is NULL? Please CC me since I am not on thread list. Thanks, -Jin int _pthread_mutex_trylock(pthread_mutex_t *mutex) { + if (!mutex) + return EFAULT; + struct pthread *curthread = _get_curthread(); int ret = 0; /* * If the mutex is statically initialized, perform the dynamic * initialization marking the mutex private (delete safe): */ if ((*mutex != NULL) || ((ret = init_static_private(curthread, mutex)) == 0)) ret = mutex_trylock_common(curthread, mutex); return (ret); } static int mutex_lock_common(struct pthread *curthread, pthread_mutex_t *m, const struct timespec * abstime) { struct timespec ts, ts2; long cycle; int ret = 0; THR_ASSERT((m != NULL) && (*m != NULL), "Uninitialized mutex in mutex_lock_common");