From owner-svn-src-all@freebsd.org Mon Mar 21 06:52:36 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D4A41AD7A17; Mon, 21 Mar 2016 06:52:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8FE39A79; Mon, 21 Mar 2016 06:52:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2L6qZn7058781; Mon, 21 Mar 2016 06:52:35 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2L6qZRi058776; Mon, 21 Mar 2016 06:52:35 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201603210652.u2L6qZRi058776@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 21 Mar 2016 06:52:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297141 - head/lib/libthr/thread X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Mar 2016 06:52:36 -0000 Author: kib Date: Mon Mar 21 06:52:35 2016 New Revision: 297141 URL: https://svnweb.freebsd.org/changeset/base/297141 Log: Lock pshared_lock shared around fork, to ensure that the COW snapshot of the pshared hash in child is consistent and can be safely used. Reported and tested by: "Oleg V. Nauman" Sponsored by: The FreeBSD Foundation Modified: head/lib/libthr/thread/thr_fork.c head/lib/libthr/thread/thr_init.c head/lib/libthr/thread/thr_private.h head/lib/libthr/thread/thr_pshared.c Modified: head/lib/libthr/thread/thr_fork.c ============================================================================== --- head/lib/libthr/thread/thr_fork.c Mon Mar 21 06:48:11 2016 (r297140) +++ head/lib/libthr/thread/thr_fork.c Mon Mar 21 06:52:35 2016 (r297141) @@ -168,6 +168,7 @@ __thr_fork(void) if (_thr_isthreaded() != 0) { was_threaded = 1; _malloc_prefork(); + __thr_pshared_atfork_pre(); _rtld_atfork_pre(rtld_locks); } else { was_threaded = 0; @@ -202,8 +203,10 @@ __thr_fork(void) _thr_signal_postfork_child(); - if (was_threaded) + if (was_threaded) { _rtld_atfork_post(rtld_locks); + __thr_pshared_atfork_post(); + } _thr_setthreaded(0); /* reinitalize library. */ @@ -236,6 +239,7 @@ __thr_fork(void) if (was_threaded) { _rtld_atfork_post(rtld_locks); + __thr_pshared_atfork_post(); _malloc_postfork(); } Modified: head/lib/libthr/thread/thr_init.c ============================================================================== --- head/lib/libthr/thread/thr_init.c Mon Mar 21 06:48:11 2016 (r297140) +++ head/lib/libthr/thread/thr_init.c Mon Mar 21 06:52:35 2016 (r297141) @@ -445,7 +445,6 @@ init_private(void) _thr_once_init(); _thr_spinlock_init(); _thr_list_init(); - __thr_pshared_init(); _thr_wake_addr_init(); _sleepq_init(); _single_thread = NULL; @@ -456,6 +455,7 @@ init_private(void) * e.g. after a fork(). */ if (init_once == 0) { + __thr_pshared_init(); /* Find the stack top */ mib[0] = CTL_KERN; mib[1] = KERN_USRSTACK; Modified: head/lib/libthr/thread/thr_private.h ============================================================================== --- head/lib/libthr/thread/thr_private.h Mon Mar 21 06:48:11 2016 (r297140) +++ head/lib/libthr/thread/thr_private.h Mon Mar 21 06:52:35 2016 (r297141) @@ -952,6 +952,8 @@ void _tcb_dtor(struct tcb *); void __thr_pshared_init(void) __hidden; void *__thr_pshared_offpage(void *key, int doalloc) __hidden; void __thr_pshared_destroy(void *key) __hidden; +void __thr_pshared_atfork_pre(void) __hidden; +void __thr_pshared_atfork_post(void) __hidden; __END_DECLS Modified: head/lib/libthr/thread/thr_pshared.c ============================================================================== --- head/lib/libthr/thread/thr_pshared.c Mon Mar 21 06:48:11 2016 (r297140) +++ head/lib/libthr/thread/thr_pshared.c Mon Mar 21 06:52:35 2016 (r297141) @@ -252,3 +252,17 @@ __thr_pshared_destroy(void *key) pshared_clean(key, val); pshared_gc(curthread); } + +void +__thr_pshared_atfork_pre(void) +{ + + _thr_rwl_rdlock(&pshared_lock); +} + +void +__thr_pshared_atfork_post(void) +{ + + _thr_rwl_unlock(&pshared_lock); +}