Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Oct 2025 15:54:07 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ccb600906f15 - main - mtx: retire _mtx_release_lock_quick
Message-ID:  <202510051554.595Fs7va076761@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg:

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

commit ccb600906f152df310794f146eac54372e6b2665
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2025-10-05 15:38:06 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2025-10-05 15:39:04 +0000

    mtx: retire _mtx_release_lock_quick
    
    The macro is misleading and of questionable value to begin with.
    
    For starters, it is used for both spinlocks and regular mutexes (the
    latter only the in the slow path), which have fundamentally different
    requirements on unlock -- spinlocks are guaranteed to not have blocked
    waiters and can blindly do a store.
    
    The commentary above the it is also head-scratching:
    > Release mtx_lock quickly, assuming we own it.
    
    You can't *just* release a sleepable mutex "quickly". The only legal use
    right now is when the turnstile lock is held.
    
    Note that unlock of a sleepable mutex without using RMW atomics is very
    much possible and may show up soon (tm).
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/kern/kern_mutex.c | 6 +++---
 sys/sys/mutex.h       | 6 +-----
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 8b5908f5219a..b7316ea5f387 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -869,7 +869,7 @@ _thread_lock(struct thread *td)
 		WITNESS_LOCK(&m->lock_object, LOP_EXCLUSIVE, file, line);
 		return;
 	}
-	_mtx_release_lock_quick(m);
+	atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED);
 slowpath_unlocked:
 	spinlock_exit();
 slowpath_noirq:
@@ -959,7 +959,7 @@ retry:
 		}
 		if (m == td->td_lock)
 			break;
-		_mtx_release_lock_quick(m);
+		atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED);
 	}
 	LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file,
 	    line);
@@ -1071,7 +1071,7 @@ __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v)
 	 * can be removed from the hash list if it is empty.
 	 */
 	turnstile_chain_lock(&m->lock_object);
-	_mtx_release_lock_quick(m);
+	atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED);
 	ts = turnstile_lookup(&m->lock_object);
 	MPASS(ts != NULL);
 	if (LOCK_LOG_TEST(&m->lock_object, opts))
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index b534a74626bc..83300d4eb593 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -221,10 +221,6 @@ void	_thread_lock(struct thread *);
 #define _mtx_release_lock(mp, tid)					\
 	atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED)
 
-/* Release mtx_lock quickly, assuming we own it. */
-#define _mtx_release_lock_quick(mp)					\
-	atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED)
-
 #define	_mtx_release_lock_fetch(mp, vp)					\
 	atomic_fcmpset_rel_ptr(&(mp)->mtx_lock, (vp), MTX_UNOWNED)
 
@@ -332,7 +328,7 @@ void	_thread_lock(struct thread *);
 		(mp)->mtx_recurse--;					\
 	else {								\
 		LOCKSTAT_PROFILE_RELEASE_SPIN_LOCK(spin__release, mp);	\
-		_mtx_release_lock_quick((mp));				\
+		atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED);	\
 	}								\
 	spinlock_exit();						\
 })



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202510051554.595Fs7va076761>