From nobody Wed Oct 28 01:09:39 2026 X-Original-To: dev-commits-src-main@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 4jDq5b6KS7z6xfwp for ; Wed, 28 Oct 2026 01:09:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jDq5b5mqjz4plZ for ; Wed, 28 Oct 2026 01:09:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793149779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pEvep7FkCJsSDw/rMLpHpFJuT4TkMNIBSFqh0AiEcgg=; b=bR+V+IS9rUgyaLxYE/x7qMMjprwPr1V22wRZNfsS84HqRj+aC0F3rg4cxk+scMUhFpUGU6 cUUbSQ12tWESLJfveCiIFNZmJUV9RsUi+LFY+TFhk0jxu5E5E9mA1qAQ/PTsTlt2mxYxFb DN6Ym3ia4cr7vEINGfXf2lVHOG5gkP9w/lVTxzpUShQ1Yrs1FdzgRZNgamkQ/DAoLESMqi w4CDlrEWELwHkCMVUdKjtpQu9dUXEo62X7pOK6DZTMPtf+lD9GycfhgXJWqT6oCdVsqyLh RQccBtrdlRla27y3QkNi4hYPL79F+MAM3+LCfqW/LA/Mkl91nlKYQlNDGihqUQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793149779; b=P2eV07pkxjB04uCm9RJrXcEgoicePxvCma7rkaafPfsUY1s1nBg0o0RUh4lWIeLOKoF9cc CkVxeI6Y3zuk/vwFFeTBTbt4BCC+nXURY0ohWdg6k9Y5S0TprZXviqU3aY6T5c4/mKFB0Q UPbRrB7ByZaS0oGInKCc9192SMFP5qaQSp+dY492f3LS4YxD+NB0I/5QogCAkGNOewkTE2 yoMg7pxo1Fy6ym47oYPusdXcmC8iawXtBfdtKUH1tO+QmaabRH89YDePjcAFlf97f5Tk8D DllOKA3naDFUIyTuRxIHaK2/ogZAHdSuYOvSogs8PBGBjEkR67IUrlvdmF9Ipg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793149779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pEvep7FkCJsSDw/rMLpHpFJuT4TkMNIBSFqh0AiEcgg=; b=LvgBftOxoVi93+VPS6F//0W2Hx5EPc6Ux+TP9mkc26xOPBrWLDAcuVLBmV/kKw6W4Mq7dY OPgKOkwAH8D9g/PehqzqchdaWbNjd8qiKkTXUoKTEws6a21jHq0cpzwIMxu3A8XekE5OkM vu1wlXKUfKgbwPl35k0WbXc9auhlzXMGiuE5q06H9iNIo5s2Mv7yaVTbefwEnfI83u7smV 1XyJIUsM/dpW+yVCdDnEj0rMQ3WJZWBZyBAShkIYrWLol6Z3c2TCNGa3q5qeSkrOXPw+9c 5YYEy2XGSw8mPJMv53PT6CWKqlIwygHX5+hlxO5bcsCTaXZk+kuw7ycOnrEKDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jDq5b5R3Mzm0L for ; Wed, 28 Oct 2026 01:09:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3f151 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 28 Oct 2026 01:09:39 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4ab9e73994e6 - main - libthr/thr_mutex.c: make mutex asserts more useful List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4ab9e73994e673e518d1b0631f8ce7d1faec6d80 Auto-Submitted: auto-generated Date: Wed, 28 Oct 2026 01:09:39 +0000 Message-Id: <6ae14b53.3f151.6fcf68c4@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4ab9e73994e673e518d1b0631f8ce7d1faec6d80 commit 4ab9e73994e673e518d1b0631f8ce7d1faec6d80 Author: Konstantin Belousov AuthorDate: 2026-10-27 13:05:59 +0000 Commit: Konstantin Belousov CommitDate: 2026-10-28 00:56:06 +0000 libthr/thr_mutex.c: make mutex asserts more useful Print the file and line number of the caller where the assert fired. Use _thread_exitf() directly for this. Sponsored by: The FreeBSD Foundation MFC after: 1 week --- lib/libthr/thread/thr_mutex.c | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 9c0939aa6080..58c79c973a9b 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -131,41 +131,50 @@ mutex_init_link(struct pthread_mutex *m __unused) #endif } +#if defined(_PTHREADS_INVARIANTS) static void -mutex_assert_is_owned(struct pthread_mutex *m __unused) +mutex_assert_is_owned(struct pthread_mutex *m, int line) { - -#if defined(_PTHREADS_INVARIANTS) - if (__predict_false(m->m_qe.tqe_prev == NULL)) - PANIC("mutex %p own %#x is not on list %p %p", + if (__predict_false(m->m_qe.tqe_prev == NULL)) { + _thread_exitf(__FILE__, line, + "mutex %p own %#x is not on list %p %p", m, m->m_lock.m_owner, m->m_qe.tqe_prev, m->m_qe.tqe_next); -#endif + } } static void -mutex_assert_not_owned(struct pthread *curthread __unused, - struct pthread_mutex *m __unused) +mutex_assert_not_owned(struct pthread_mutex *m, int line) { + struct pthread *curthread; -#if defined(_PTHREADS_INVARIANTS) + curthread = _get_curthread(); if (__predict_false(m->m_qe.tqe_prev != NULL || - m->m_qe.tqe_next != NULL)) - PANIC("mutex %p own %#x is on list %p %p", + m->m_qe.tqe_next != NULL)) { + _thread_exitf(__FILE__, line, + "mutex %p own %#x is on list %p %p", m, m->m_lock.m_owner, m->m_qe.tqe_prev, m->m_qe.tqe_next); + } if (__predict_false(is_robust_mutex(m) && (m->m_lock.m_rb_lnk != 0 || m->m_rb_prev != NULL || (is_pshared_mutex(m) && curthread->robust_list == (uintptr_t)&m->m_lock) || (!is_pshared_mutex(m) && curthread->priv_robust_list == - (uintptr_t)&m->m_lock)))) - PANIC( - "mutex %p own %#x is on robust linkage %p %p head %p phead %p", + (uintptr_t)&m->m_lock)))) { + _thread_exitf(__FILE__, line, + "mutex %p own %#x is on robust linkage %p %p head %p phead %p", m, m->m_lock.m_owner, (void *)m->m_lock.m_rb_lnk, m->m_rb_prev, (void *)curthread->robust_list, (void *)curthread->priv_robust_list); -#endif + } } +#define MUTEX_ASSERT_IS_OWNED(m) mutex_assert_is_owned(m, __LINE__) +#define MUTEX_ASSERT_NOT_OWNED(m) mutex_assert_not_owned(m, __LINE__) +#else +#define MUTEX_ASSERT_IS_OWNED(m) do {} while (0) +#define MUTEX_ASSERT_NOT_OWNED(m) do {} while (0) +#endif + static bool is_pshared_mutex(struct pthread_mutex *m) { @@ -477,8 +486,7 @@ _thr_mutex_destroy(pthread_mutex_t *mutex) if (m1 != NULL) { if ((uint32_t)m1->m_lock.m_owner != UMUTEX_RB_OWNERDEAD) { - mutex_assert_not_owned( - _get_curthread(), m1); + MUTEX_ASSERT_NOT_OWNED(m1); } __thr_pshared_destroy(mutex); } @@ -490,7 +498,7 @@ _thr_mutex_destroy(pthread_mutex_t *mutex) ret = EBUSY; } else { *mutex = THR_MUTEX_DESTROYED; - mutex_assert_not_owned(_get_curthread(), m); + MUTEX_ASSERT_NOT_OWNED(m); __thr_free(m); ret = 0; } @@ -530,7 +538,7 @@ enqueue_mutex(struct pthread *curthread, struct pthread_mutex *m, /* Add to the list of owned mutexes: */ if (error != EOWNERDEAD) - mutex_assert_not_owned(curthread, m); + MUTEX_ASSERT_NOT_OWNED(m); qidx = mutex_qidx(m); TAILQ_INSERT_TAIL(&curthread->mq[qidx], m, m_qe); if (!is_pshared_mutex(m)) @@ -558,7 +566,7 @@ dequeue_mutex(struct pthread *curthread, struct pthread_mutex *m) struct pthread_mutex *mp, *mn; int qidx; - mutex_assert_is_owned(m); + MUTEX_ASSERT_IS_OWNED(m); qidx = mutex_qidx(m); if (is_robust_mutex(m)) { mp = m->m_rb_prev; @@ -1054,7 +1062,7 @@ _pthread_mutex_setprioceiling(pthread_mutex_t * __restrict mutex, curthread = _get_curthread(); if (PMUTEX_OWNER_ID(m) == TID(curthread)) { - mutex_assert_is_owned(m); + MUTEX_ASSERT_IS_OWNED(m); m1 = TAILQ_PREV(m, mutex_queue, m_qe); m2 = TAILQ_NEXT(m, m_qe); if ((m1 != NULL && m1->m_lock.m_ceilings[0] > (u_int)ceiling) ||