From nobody Fri Oct 03 05:55:16 2025 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 4cdHv864RRz69c6Y; Fri, 03 Oct 2025 05:55:16 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cdHv85PJpz3glN; Fri, 03 Oct 2025 05:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759470916; 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=5s+0zMuWe5/pW0RreC0MiPjFld2yqKCCe2ZeeGVsY2A=; b=VRoyj9LCmD2WbovBgkurgAMjDmKoihzy6fca0nll+UCWWsoX77srm1fxddAEHxumZEwUU/ Xbh+2HBTwlfm2XHpGH0K4BdYrojruHJylaCy4lvXpe5ag8zAoBOYYKoiDTXQAF3EOl4eJd Hg+QZYCcaIQ8puEmyMw7I563dvHUwW7IzsPomy1OS/algTEeX69ZbYQRyBjg48+UScWMZa Xxo9ZlsS0hA0BqWPwGMj9VI9HUtktTiBbcDVSyBNAnwcitEOuYfAOGPA/R8I45RQo/SdZs 9tizWw9KZsPIJLZB1pU0C2wQu8QnEETo7Sc5nj0DnSggsI10KUCWo9yvpfR82A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759470916; 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=5s+0zMuWe5/pW0RreC0MiPjFld2yqKCCe2ZeeGVsY2A=; b=m3oSaVsIO/SriwK7nNQilC1Vn4DN9aqHa5taDE44w/JDaKiggLHakCKDXKizlrf9glFkHA Yn5TxoOhI7F2PuD2u8/yFOZEsqUz/zoFPEn2E0gG5UkUYXnLVCfeqKRSQFkZiIPNMU6VV4 ElF9VoBVbWRnmU/a9k4zeEBnEMl/SYymhDioiGpHCXOZKyq5CjEccIfl1mzHv1ssG09HF4 kdq7mqMxF65Q816ZhnpObZs7ZQ5rJlXUiMqg5AJew/jfasQ9CUMgeWB0/jfmI+0QYniIEx WfVBCDzNTVI9K4Pf1vf5gIvlG5fTdOoFlY4hxpnCdBxdzquDGJUEpDRZ6WdmVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759470916; a=rsa-sha256; cv=none; b=uMRQaZZ71kBLCO3cWhuOagrghyuCU950pLGs9xJcG2aExzJOwxxqDiv1/vYKQVW3UxBOWr uUxxf677+UkpqGXEMxjNr+Gv2Cof5ow6dAGs+cGwjQ78NR4jc/jEM1IYF6R7nHUMda5SkG 7sHIwdI77Pr4lkuEgJp1/lOoBiziMbmCDd0gY/ks1tLiSm0GZyvlHPqk/LE1gDjLgyByFW qhc7Ls/tdUkLKa4Kk4RaFm2V/0pGOoaaAwxZWXxAJwXFfw72KpmCLntaY6E/Xjw6Z02QUM LLK81nAzcQtZxYRU3fdSxTc5L+2RlyD1GknBJOaDdAinn9Hbx3i8Fl/3HsnaKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cdHv84tKmzjFk; Fri, 03 Oct 2025 05:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5935tGW9018029; Fri, 3 Oct 2025 05:55:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5935tGss018026; Fri, 3 Oct 2025 05:55:16 GMT (envelope-from git) Date: Fri, 3 Oct 2025 05:55:16 GMT Message-Id: <202510030555.5935tGss018026@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ryan Libby Subject: git: e7e958d83d85 - main - ddb show allchains: avoid traps and show pointers for lockmgr and sx List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rlibby X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e7e958d83d8503c3b8714f68418d4509b8288ed9 Auto-Submitted: auto-generated The branch main has been updated by rlibby: URL: https://cgit.FreeBSD.org/src/commit/?id=e7e958d83d8503c3b8714f68418d4509b8288ed9 commit e7e958d83d8503c3b8714f68418d4509b8288ed9 Author: Ryan Libby AuthorDate: 2025-10-03 05:47:47 +0000 Commit: Ryan Libby CommitDate: 2025-10-03 05:47:47 +0000 ddb show allchains: avoid traps and show pointers for lockmgr and sx When trying to walk lock chains, we have to deduce what a thread is blocked on. Checking LOCK_CLASS(td->td_wchan) is not a very reliable method by itself, as it just tests whether a particular 4 bits near where td_wchan points have a particular value. Misinterpreting wait channel pointers of other sleeps as lockmgr locks would frequently cause ddb show allchains (or show lockchain) to trap, or to produce incorrect output. Now, check the sleepq_type. When calling sleepq_add, we use SLEEPQ_LK for lockmgr locks and SLEEPQ_SX for sx locks. This is a more reliable indication that the td_wchan is actually a lock. While here, also make the output of lockmgr and sx locks consistent with the output for other locks (see print_lockchain). Outputting a pointer to the lock allows it to be inspected further with ddb show lock or other methods. Reviewed by: markj Sponsored by: Dell Inc. Differential Revision: https://reviews.freebsd.org/D52794 --- sys/kern/kern_lock.c | 6 ++++-- sys/kern/kern_sx.c | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 31bff6d2c1aa..76f68677e292 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -1780,9 +1780,11 @@ lockmgr_chain(struct thread *td, struct thread **ownerp) lk = td->td_wchan; - if (LOCK_CLASS(&lk->lock_object) != &lock_class_lockmgr) + if (!TD_ON_SLEEPQ(td) || sleepq_type(td->td_wchan) != SLEEPQ_LK || + LOCK_CLASS(&lk->lock_object) != &lock_class_lockmgr) return (0); - db_printf("blocked on lockmgr %s", lk->lock_object.lo_name); + db_printf("blocked on lock %p (%s) \"%s\" ", &lk->lock_object, + lock_class_lockmgr.lc_name, lk->lock_object.lo_name); if (lk->lk_lock & LK_SHARE) db_printf("SHARED (count %ju)\n", (uintmax_t)LK_SHARERS(lk->lk_lock)); diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index c005e112d3b9..249faf5b1ec4 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -1539,16 +1539,19 @@ sx_chain(struct thread *td, struct thread **ownerp) /* * Check to see if this thread is blocked on an sx lock. - * First, we check the lock class. If that is ok, then we - * compare the lock name against the wait message. + * The thread should be on a sleep queue with type SLEEPQ_SX, the + * purported lock should have the lock class index of sx, and the lock + * name should match the wait message. */ sx = td->td_wchan; - if (LOCK_CLASS(&sx->lock_object) != &lock_class_sx || + if (!TD_ON_SLEEPQ(td) || sleepq_type(td->td_wchan) != SLEEPQ_SX || + LOCK_CLASS(&sx->lock_object) != &lock_class_sx || sx->lock_object.lo_name != td->td_wmesg) return (0); /* We think we have an sx lock, so output some details. */ - db_printf("blocked on sx \"%s\" ", td->td_wmesg); + db_printf("blocked on lock %p (%s) \"%s\" ", &sx->lock_object, + lock_class_sx.lc_name, td->td_wmesg); *ownerp = sx_xholder(sx); if (sx->sx_lock & SX_LOCK_SHARED) db_printf("SLOCK (count %ju)\n",