git: 00d78c500783 - main - rwmlock/rwlock/sx: Print the pointer of destroyed locks in panic messages

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 13 Mar 2025 16:57:21 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=00d78c500783fc91512b3c0d231029ac75a131d9

commit 00d78c500783fc91512b3c0d231029ac75a131d9
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-03-13 16:54:40 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-03-13 16:57:06 +0000

    rwmlock/rwlock/sx: Print the pointer of destroyed locks in panic messages
    
    Suggested by:   markj
    Reviewed by:    kib, markj
    Sponsored by:   AFRL, DARPA
    Differential Revision:  https://reviews.freebsd.org/D49332
---
 sys/kern/kern_rmlock.c |  8 ++++----
 sys/kern/kern_rwlock.c | 18 ++++++++++--------
 sys/kern/kern_sx.c     | 17 +++++++++--------
 3 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/sys/kern/kern_rmlock.c b/sys/kern/kern_rmlock.c
index bdee79e2cf1a..0867e9e14fee 100644
--- a/sys/kern/kern_rmlock.c
+++ b/sys/kern/kern_rmlock.c
@@ -601,7 +601,7 @@ _rm_wlock_debug(struct rmlock *rm, const char *file, int line)
 	    ("rm_wlock() by idle thread %p on rmlock %p @ %s:%d",
 	    curthread, rm, file, line));
 	KASSERT(!rm_destroyed(rm),
-	    ("rm_wlock() of destroyed rmlock @ %s:%d", file, line));
+	    ("rm_wlock() of destroyed rmlock %p @ %s:%d", rm, file, line));
 	_rm_assert(rm, RA_UNLOCKED, file, line);
 
 	WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE,
@@ -622,7 +622,7 @@ _rm_wunlock_debug(struct rmlock *rm, const char *file, int line)
 		return;
 
 	KASSERT(!rm_destroyed(rm),
-	    ("rm_wunlock() of destroyed rmlock @ %s:%d", file, line));
+	    ("rm_wunlock() of destroyed rmlock %p @ %s:%d", rm, file, line));
 	_rm_assert(rm, RA_WLOCKED, file, line);
 	WITNESS_UNLOCK(&rm->lock_object, LOP_EXCLUSIVE, file, line);
 	LOCK_LOG_LOCK("RMWUNLOCK", &rm->lock_object, 0, 0, file, line);
@@ -652,7 +652,7 @@ _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
 	    ("rm_rlock() by idle thread %p on rmlock %p @ %s:%d",
 	    curthread, rm, file, line));
 	KASSERT(!rm_destroyed(rm),
-	    ("rm_rlock() of destroyed rmlock @ %s:%d", file, line));
+	    ("rm_rlock() of destroyed rmlock %p @ %s:%d", rm, file, line));
 	if (!trylock) {
 		KASSERT(!rm_wowned(rm),
 		    ("rm_rlock: wlock already held for %s @ %s:%d",
@@ -686,7 +686,7 @@ _rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
 		return;
 
 	KASSERT(!rm_destroyed(rm),
-	    ("rm_runlock() of destroyed rmlock @ %s:%d", file, line));
+	    ("rm_runlock() of destroyed rmlock %p @ %s:%d", rm, file, line));
 	_rm_assert(rm, RA_RLOCKED, file, line);
 	WITNESS_UNLOCK(&rm->lock_object, 0, file, line);
 	LOCK_LOG_LOCK("RMRUNLOCK", &rm->lock_object, 0, 0, file, line);
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index ee04f4f30d2c..ed6ca75bc7a5 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -295,7 +295,7 @@ _rw_wlock_cookie(volatile uintptr_t *c, const char *file, int line)
 	    ("rw_wlock() by idle thread %p on rwlock %p @ %s:%d",
 	    curthread, rw, file, line));
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_wlock() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_wlock() of destroyed rwlock %p @ %s:%d", rw, file, line));
 	WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file,
 	    line, NULL);
 	tid = (uintptr_t)curthread;
@@ -328,7 +328,7 @@ __rw_try_wlock_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF)
 	    ("rw_try_wlock() by idle thread %p on rwlock %p @ %s:%d",
 	    curthread, rw, file, line));
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_try_wlock() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_try_wlock() of destroyed rwlock %p @ %s:%d", rw, file, line));
 
 	rval = 1;
 	recursed = false;
@@ -376,7 +376,7 @@ _rw_wunlock_cookie(volatile uintptr_t *c, const char *file, int line)
 	rw = rwlock2rw(c);
 
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_wunlock() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_wunlock() of destroyed rwlock %p @ %s:%d", rw, file, line));
 	__rw_assert(c, RA_WLOCKED, file, line);
 	WITNESS_UNLOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line);
 	LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file,
@@ -684,7 +684,7 @@ __rw_rlock_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF)
 	    ("rw_rlock() by idle thread %p on rwlock %p @ %s:%d",
 	    td, rw, file, line));
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_rlock() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_rlock() of destroyed rwlock %p @ %s:%d", rw, file, line));
 	KASSERT(rw_wowner(rw) != td,
 	    ("rw_rlock: wlock already held for %p @ %s:%d",
 	    rw, file, line));
@@ -727,7 +727,8 @@ __rw_try_rlock_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF)
 	x = rw->rw_lock;
 	for (;;) {
 		KASSERT(rw->rw_lock != RW_DESTROYED,
-		    ("rw_try_rlock() of destroyed rwlock @ %s:%d", file, line));
+		    ("rw_try_rlock() of destroyed rwlock %p @ %s:%d", rw, file,
+		    line));
 		if (!(x & RW_LOCK_READ))
 			break;
 		if (atomic_fcmpset_acq_ptr(&rw->rw_lock, &x, x + RW_ONE_READER)) {
@@ -862,7 +863,7 @@ _rw_runlock_cookie_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF)
 	uintptr_t v;
 
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_runlock() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_runlock() of destroyed rwlock %p @ %s:%d", rw, file, line));
 	__rw_assert(&rw->rw_lock, RA_RLOCKED, file, line);
 	WITNESS_UNLOCK(&rw->lock_object, 0, file, line);
 	LOCK_LOG_LOCK("RUNLOCK", &rw->lock_object, 0, 0, file, line);
@@ -1310,7 +1311,8 @@ __rw_try_upgrade_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF)
 		return (1);
 
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_try_upgrade() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_try_upgrade() of destroyed rwlock %p @ %s:%d", rw, file,
+	    line));
 	__rw_assert(&rw->rw_lock, RA_RLOCKED, file, line);
 
 	/*
@@ -1393,7 +1395,7 @@ __rw_downgrade_int(struct rwlock *rw LOCK_FILE_LINE_ARG_DEF)
 		return;
 
 	KASSERT(rw->rw_lock != RW_DESTROYED,
-	    ("rw_downgrade() of destroyed rwlock @ %s:%d", file, line));
+	    ("rw_downgrade() of destroyed rwlock %p @ %s:%d", rw, file, line));
 	__rw_assert(&rw->rw_lock, RA_WLOCKED | RA_NOTRECURSED, file, line);
 #ifndef INVARIANTS
 	if (rw_recursed(rw))
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index e9aad6c6be58..accea5d288eb 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -284,7 +284,8 @@ sx_try_slock_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF)
 	x = sx->sx_lock;
 	for (;;) {
 		KASSERT(x != SX_LOCK_DESTROYED,
-		    ("sx_try_slock() of destroyed sx @ %s:%d", file, line));
+		    ("sx_try_slock() of destroyed sx %p @ %s:%d", sx, file,
+		    line));
 		if (!(x & SX_LOCK_SHARED))
 			break;
 		if (atomic_fcmpset_acq_ptr(&sx->sx_lock, &x, x + SX_ONE_SHARER)) {
@@ -320,7 +321,7 @@ _sx_xlock(struct sx *sx, int opts, const char *file, int line)
 	    ("sx_xlock() by idle thread %p on sx %p @ %s:%d",
 	    curthread, sx, file, line));
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_xlock() of destroyed sx @ %s:%d", file, line));
+	    ("sx_xlock() of destroyed sx %p @ %s:%d", sx, file, line));
 	WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file,
 	    line, NULL);
 	tid = (uintptr_t)curthread;
@@ -357,7 +358,7 @@ sx_try_xlock_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF)
 	    ("sx_try_xlock() by idle thread %p on sx %p @ %s:%d",
 	    curthread, sx, file, line));
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_try_xlock() of destroyed sx @ %s:%d", file, line));
+	    ("sx_try_xlock() of destroyed sx %p @ %s:%d", sx, file, line));
 
 	rval = 1;
 	recursed = false;
@@ -401,7 +402,7 @@ _sx_xunlock(struct sx *sx, const char *file, int line)
 {
 
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_xunlock() of destroyed sx @ %s:%d", file, line));
+	    ("sx_xunlock() of destroyed sx %p @ %s:%d", sx, file, line));
 	_sx_assert(sx, SA_XLOCKED, file, line);
 	WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line);
 	LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file,
@@ -430,7 +431,7 @@ sx_try_upgrade_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF)
 		return (1);
 
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_try_upgrade() of destroyed sx @ %s:%d", file, line));
+	    ("sx_try_upgrade() of destroyed sx %p @ %s:%d", sx, file, line));
 	_sx_assert(sx, SA_SLOCKED, file, line);
 
 	/*
@@ -479,7 +480,7 @@ sx_downgrade_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF)
 		return;
 
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_downgrade() of destroyed sx @ %s:%d", file, line));
+	    ("sx_downgrade() of destroyed sx %p @ %s:%d", sx, file, line));
 	_sx_assert(sx, SA_XLOCKED | SA_NOTRECURSED, file, line);
 #ifndef INVARIANTS
 	if (sx_recursed(sx))
@@ -1267,7 +1268,7 @@ _sx_slock_int(struct sx *sx, int opts LOCK_FILE_LINE_ARG_DEF)
 	    ("sx_slock() by idle thread %p on sx %p @ %s:%d",
 	    curthread, sx, file, line));
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_slock() of destroyed sx @ %s:%d", file, line));
+	    ("sx_slock() of destroyed sx %p @ %s:%d", sx, file, line));
 	WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER, file, line, NULL);
 
 	error = 0;
@@ -1369,7 +1370,7 @@ _sx_sunlock_int(struct sx *sx LOCK_FILE_LINE_ARG_DEF)
 	uintptr_t x;
 
 	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
-	    ("sx_sunlock() of destroyed sx @ %s:%d", file, line));
+	    ("sx_sunlock() of destroyed sx %p  @ %s:%d", sx, file, line));
 	_sx_assert(sx, SA_SLOCKED, file, line);
 	WITNESS_UNLOCK(&sx->lock_object, 0, file, line);
 	LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line);