From owner-freebsd-current@freebsd.org Sat Jun 25 09:20:47 2016 Return-Path: Delivered-To: freebsd-current@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 9CDDCB73FE6 for ; Sat, 25 Jun 2016 09:20:47 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4856C2D73 for ; Sat, 25 Jun 2016 09:20:47 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u5P9KeR9049434 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 25 Jun 2016 12:20:41 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u5P9KeR9049434 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u5P9Kejq049433; Sat, 25 Jun 2016 12:20:40 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 25 Jun 2016 12:20:40 +0300 From: Konstantin Belousov To: Guy Yur Cc: Daniel Engberg , freebsd-current Subject: Re: Samba 4.3 and 4.4 crashes on FreeBSD 11-ALPHA4 Message-ID: <20160625092040.GL38613@kib.kiev.ua> References: <20160625084939.GI38613@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160625084939.GI38613@kib.kiev.ua> User-Agent: Mutt/1.6.1 (2016-04-27) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2016 09:20:47 -0000 On Sat, Jun 25, 2016 at 11:49:39AM +0300, Konstantin Belousov wrote: > On Sat, Jun 25, 2016 at 01:03:13AM +0300, Guy Yur wrote: > > libtdb.so.1`tdb_runtime_check_for_robust_mutexes + 1475 at mutex.c:957 > > ... > > The pointer to tdb_runtime_check_for_robust_mutexes() appeared to be > most useful, thanks. > > The two patches below should fix samba use of robustness. First, > kernel erronously reset robust lists locations on fork. Second, the > pthread_mutex_trylock() for owned errorcheck mutex must return EDEADLK > and not EBUSY. Try that. Correction, there was a reason why I initially put the rb list pointers into zeroed region. It still needs to be zeroed on new thread creation. Updated patch. diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 5a99605..da71c70 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -850,9 +871,12 @@ mutex_self_trylock(struct pthread_mutex *m) switch (PMUTEX_TYPE(m->m_flags)) { case PTHREAD_MUTEX_ERRORCHECK: - case PTHREAD_MUTEX_NORMAL: case PTHREAD_MUTEX_ADAPTIVE_NP: - ret = EBUSY; + ret = EDEADLK; + break; + + case PTHREAD_MUTEX_NORMAL: + ret = EBUSY; break; case PTHREAD_MUTEX_RECURSIVE: diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index 10ccdab..293574c 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -234,6 +234,7 @@ thread_create(struct thread *td, struct rtprio *rtp, bcopy(&td->td_startcopy, &newtd->td_startcopy, __rangeof(struct thread, td_startcopy, td_endcopy)); newtd->td_proc = td->td_proc; + newtd->td_rb_list = newtd->td_rbp_list = newtd->td_rb_inact = 0; thread_cow_get(newtd, td); error = initialize_thread(newtd, thunk); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 6d03062..6162a16 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -282,9 +282,6 @@ struct thread { int td_no_sleeping; /* (k) Sleeping disabled count. */ int td_dom_rr_idx; /* (k) RR Numa domain selection. */ void *td_su; /* (k) FFS SU private */ - uintptr_t td_rb_list; /* (k) Robust list head. */ - uintptr_t td_rbp_list; /* (k) Robust priv list head. */ - uintptr_t td_rb_inact; /* (k) Current in-action mutex loc. */ #define td_endzero td_sigmask /* Copied during fork1() or create_thread(). */ @@ -298,6 +295,9 @@ struct thread { u_char td_base_user_pri; /* (t) Base user pri */ u_int td_dbg_sc_code; /* (c) Syscall code to debugger. */ u_int td_dbg_sc_narg; /* (c) Syscall arg count to debugger.*/ + uintptr_t td_rb_list; /* (k) Robust list head. */ + uintptr_t td_rbp_list; /* (k) Robust priv list head. */ + uintptr_t td_rb_inact; /* (k) Current in-action mutex loc. */ #define td_endcopy td_pcb /*