From nobody Tue Jan 14 22:19:08 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YXk7c2tlFz5kVv2; Tue, 14 Jan 2025 22:19:24 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXk7b4HfQz3HbF; Tue, 14 Jan 2025 22:19:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 50EMJ8lJ019196; Wed, 15 Jan 2025 00:19:11 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 50EMJ8lJ019196 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 50EMJ8QW019195; Wed, 15 Jan 2025 00:19:08 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 15 Jan 2025 00:19:08 +0200 From: Konstantin Belousov To: Mark Johnston Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 9a2ae72421cd - main - libthr: switch thread and sleepq memory allocator to crt from libc malloc Message-ID: References: <202501141755.50EHtFwt072647@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Rspamd-Queue-Id: 4YXk7b4HfQz3HbF X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] On Tue, Jan 14, 2025 at 03:42:52PM -0500, Mark Johnston wrote: > On Tue, Jan 14, 2025 at 05:55:15PM +0000, Konstantin Belousov wrote: > > The branch main has been updated by kib: > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=9a2ae72421cd75c741984f63b8c9ee89346a188d > > > > commit 9a2ae72421cd75c741984f63b8c9ee89346a188d > > Author: Konstantin Belousov > > AuthorDate: 2025-01-14 09:06:58 +0000 > > Commit: Konstantin Belousov > > CommitDate: 2025-01-14 17:55:08 +0000 > > > > libthr: switch thread and sleepq memory allocator to crt from libc malloc > > > > There are more complex interactions between malloc and libthr > > initialization that can happen if libthr functions are called from ELF > > object' constructors, before libthr is initialized. Break the > > dependencies loop by using the private allocator with controlled init. > > > > Reported by: yuri > > Reviewed by: markj, olce > > Sponsored by: The FreeBSD Foundation > > MFC after: 1 week > > Differential revision: https://reviews.freebsd.org/D48454 > > I see some startup deadlock when running the googletest regression tests > (/usr/tests/lib/googletest/gmock_main) after this commit. gdb (which > itself also hangs due to this bug) shows: > > (gdb) bt > #0 _umtx_op_err () at /home/markj/sb/main/src/lib/libsys/amd64/_umtx_op_err.S:38 > #1 0x000015e1ba96fd2c in __thr_umutex_lock (mtx=0x15e1ba974468, id=100113) at /usr/src/lib/libthr/thread/thr_umtx.c:69 > #2 0x000015e1ba966a41 in __thr_calloc (num=1, size=17) at /usr/src/lib/libthr/thread/thr_malloc.c:92 > #3 0x000015e1ba969213 in mutex_init (mutex=warning: (Internal error: pc 0x15e1bd5c0240 in read in CU, but not in symtab.) > warning: (Error: pc 0x15e1bd5c0240 in address map, but not in symtab.) The following fixed the issue for me. I am somewhat surprised that the problem did not manifested itself before. commit 783d95d0d6e6e508705cf16cfd9e4a5e2f8db8e4 Author: Konstantin Belousov Date: Wed Jan 15 00:11:48 2025 +0200 libpthread_init(): ensure curthread == NULL until set explicitly Otherwise libthr::_get_curthread() returns a garbage kept there from allocate_initial_tls(), until libthr initialization proceeds enough to set initial pcb->pcb_thread. The garbage pcb_thread was dereferenced as struct pthread and some memory read as TID. Since it was not consistent between reads, thr_malloc_umtx unlock returned EPERM instead of clearing the lock word. Reported by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 708c425d69c1..e5e438897dee 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -334,6 +334,7 @@ _libpthread_init(struct pthread *curthread) /* Set the initial thread. */ if (curthread == NULL) { first = 1; + _tcb_get()->tcb_thread = NULL; /* Create and initialize the initial thread. */ curthread = _thr_alloc(NULL); if (curthread == NULL)