From nobody Tue Jan 14 22:28:27 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 4YXkL85LKzz5kWVQ; Tue, 14 Jan 2025 22:28:32 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXkL82P4Bz3L5W; Tue, 14 Jan 2025 22:28:32 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6d8fd060e27so48823886d6.1; Tue, 14 Jan 2025 14:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736893711; x=1737498511; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=f4LxTL2KfiCyptCccNppROFKAhwK4vqnHgK9mBIC5vs=; b=ALpnpRf3LQGZPuQfK5HX6qJig16dKFU+AIQ3DAq05KQqHu4wU5sPlsFPRmObQuF9IO Z+zxnnqtWOaRwHNJ5C2wpDdijx3tC09MwSdakkvsNXvXP0d50G3I7T4bN/esvE/htfRg nJB1aVybAzSE4k57FvwNYC3RmcYfkt4CfYOWwXhrweSBakNmmSDpXiZV8m6Ed224srMd 9Mpp+DLBL8Su+ZshDfju6Iih1fvM7wR/Ol/T6JRI4vkL3ZAiIcq+VBvsnKhHw7Ybsgt0 pJrqjiXGRsBnyy22SSMb8Qd8Ofp7/Uf473uXOLbgLu2z04apF5p3U5ZU428EXo6PJW6B vuGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736893711; x=1737498511; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f4LxTL2KfiCyptCccNppROFKAhwK4vqnHgK9mBIC5vs=; b=sbMjEGBtZ5v7PdmiG3oxbQTxvioeCGdeGFdqn7b1kniTeLzWkRAiEbBfFUeOdvOhLu FsV7i1TgRcZJqEjjW0LO5g4pZIS+F+2M6JnZYtG9LLWIsgRsE3CEGZrFvwcWHmxOZm7P JQ14SGpD7Zs3g8/PYobiz80TKSlotVweOfLWf3IJKBIwtFbckBA/bVfVykhZRrIXagVs cdnm+QXsCLmla7i252x2THUfv801BzZe3+Kks683Z3Re/ElB/CtkCIij+IJaa+XWdDhC L5sb6Q9kFqYw6id700s+c292pKd1qlx7LhuNQ4dLM4qVMZbSo4gBfYJyS39NM1Vyvsqk YOKw== X-Forwarded-Encrypted: i=1; AJvYcCUCLzCtflwc3aMahXXCSGyfEcoRmW3mfqaV7I35TG/kHTHIpryl5Y/aLqKxKiuB9GpR0RYvaisHc4Hq9VWI5Wpi1jpN@freebsd.org, AJvYcCVcREw9UAreDYO/qJj4r+Nl0BBUUpX0ab3NKANvbQH61eTspj1mWmeBCxIPsYaHrwKavPlTE41YXQrPyGN+8auEm260w9A=@freebsd.org X-Gm-Message-State: AOJu0YyHm88IB03AoIYNtEM2dTC4KNBsTs1BPnWmsnxNKyargs7jdo3+ IJwYk/C2a3ycccHS8yNvwtwX7pbGeJ5mEfxZI8LwwTDHjh0lUagi X-Gm-Gg: ASbGncs7eHFr6pCudRGCTkNz7qG58D8+OSqB/Sb622zpq69JS53l0GDMbc79mIxstJC 1vhWuR9jaValOCwpdHV56dpePFgwDqKJRIAM4VHBg7V5FrPWnoSSiKZ9n/l5jx97UlNB6jiLaRn YJeAJKH/0jvNgzNd4mkNabSvg7IGMYgjhitu9WLtkjolGTulPEEWyHuPdyiUXcPNM8V4JB2aTs+ elCCktaf3KBq4aOHIxBWDF6q/kmcDsf9vITqOjeYevmQTAGH/6jXcLg0R8aKpS19fH8VfM= X-Google-Smtp-Source: AGHT+IEE4Wr7NSNoUczKtHxBvy255GMe1y7YIEE2ulwPPz8RWwzFVQGP5Qu5eEeKn81qJq0eyeUnDw== X-Received: by 2002:a05:6214:501a:b0:6df:9740:68a3 with SMTP id 6a1803df08f44-6df9b2b3231mr487072996d6.38.1736893711055; Tue, 14 Jan 2025 14:28:31 -0800 (PST) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7bce3516004sm651336585a.101.2025.01.14.14.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 14:28:29 -0800 (PST) Date: Tue, 14 Jan 2025 17:28:27 -0500 From: Mark Johnston To: Konstantin Belousov 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-Rspamd-Queue-Id: 4YXkL82P4Bz3L5W 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:15169, ipnet:2607:f8b0::/32, country:US] On Wed, Jan 15, 2025 at 12:19:08AM +0200, Konstantin Belousov wrote: > 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. It seems to fix the hang for me as well, thanks. > 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)