git: 2e376cca379b - main - rangelock: Reimplement _rangelock_cookie_assert()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 27 Aug 2026 23:29:54 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=2e376cca379b744ce24c849aced684bf770c0f75
commit 2e376cca379b744ce24c849aced684bf770c0f75
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-08-27 19:47:44 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-08-27 23:29:40 +0000
rangelock: Reimplement _rangelock_cookie_assert()
After rangelocks were reimplemented, _rangelock_cookie_assert() became a
stub. Re-provide an implementation.
Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D59222
---
sys/kern/kern_rangelock.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++
sys/kern/uipc_shm.c | 6 +++---
2 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/sys/kern/kern_rangelock.c b/sys/kern/kern_rangelock.c
index cd66bff62608..a2b6829c0107 100644
--- a/sys/kern/kern_rangelock.c
+++ b/sys/kern/kern_rangelock.c
@@ -813,6 +813,58 @@ rangelock_may_recurse(struct rangelock *lock)
void
_rangelock_cookie_assert(void *cookie, int what, const char *file, int line)
{
+ struct rl_q_entry *entry;
+ struct thread *td;
+ uintptr_t c;
+
+ c = (uintptr_t)cookie;
+ switch (what) {
+ case RCA_LOCKED:
+ if (c == RL_RET_CHEAT_RLOCKED || c == RL_RET_CHEAT_WLOCKED)
+ break;
+ entry = cookie;
+ if ((entry->rl_q_flags & RL_LOCK_TYPE_MASK) == 0)
+ panic("rangelock not held (%#x) @ %s:%d\n",
+ entry->rl_q_flags, file, line);
+ td = entry->rl_q_owner;
+ if (td != curthread)
+ panic("rangelock held by thread %d @ %s:%d\n",
+ td != NULL ? td->td_tid : -1, file, line);
+ break;
+ case RCA_RLOCKED:
+ if (c == RL_RET_CHEAT_RLOCKED)
+ break;
+ if (c == RL_RET_CHEAT_WLOCKED)
+ panic("rangelock not rlocked (%#lx) @ %s:%d\n",
+ c, file, line);
+ entry = cookie;
+ if ((entry->rl_q_flags & RL_LOCK_TYPE_MASK) != RL_LOCK_READ)
+ panic("rangelock not rlocked (%#x) @ %s:%d\n",
+ entry->rl_q_flags, file, line);
+ td = entry->rl_q_owner;
+ if (td != curthread)
+ panic("rangelock held by thread %d @ %s:%d\n",
+ td != NULL ? td->td_tid : -1, file, line);
+ break;
+ case RCA_WLOCKED:
+ if (c == RL_RET_CHEAT_WLOCKED)
+ break;
+ if (c == RL_RET_CHEAT_RLOCKED)
+ panic("rangelock not wlocked (%#lx) @ %s:%d\n",
+ c, file, line);
+ entry = cookie;
+ if ((entry->rl_q_flags & RL_LOCK_TYPE_MASK) != RL_LOCK_WRITE)
+ panic("rangelock not wlocked (%#x) @ %s:%d\n",
+ entry->rl_q_flags, file, line);
+ td = entry->rl_q_owner;
+ if (td != curthread)
+ panic("rangelock held by thread %d @ %s:%d\n",
+ td != NULL ? td->td_tid : -1, file, line);
+ break;
+ default:
+ panic("rangelock cookie assert type %d @ %s:%d\n",
+ what, file, line);
+ }
}
#endif /* INVARIANT_SUPPORT */
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index 067a628fdab0..b77731f8188b 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -742,7 +742,7 @@ shm_dotruncate_locked(struct shmfd *shmfd, off_t length, void *rl_cookie)
KASSERT(length >= 0, ("shm_dotruncate: length < 0"));
object = shmfd->shm_object;
VM_OBJECT_ASSERT_WLOCKED(object);
- rangelock_cookie_assert(rl_cookie, RA_WLOCKED);
+ rangelock_cookie_assert(rl_cookie, RCA_WLOCKED);
if (length == shmfd->shm_size)
return (0);
nobjsize = OFF_TO_IDX(length + PAGE_MASK);
@@ -807,7 +807,7 @@ shm_dotruncate_largepage(struct shmfd *shmfd, off_t length, void *rl_cookie)
KASSERT(length >= 0, ("shm_dotruncate_largepage: length < 0"));
object = shmfd->shm_object;
VM_OBJECT_ASSERT_WLOCKED(object);
- rangelock_cookie_assert(rl_cookie, RA_WLOCKED);
+ rangelock_cookie_assert(rl_cookie, RCA_WLOCKED);
oldobjsz = object->size;
newobjsz = OFF_TO_IDX(length);
@@ -1584,7 +1584,7 @@ shm_mmap_large(struct shmfd *shmfd, vm_map_t map, vm_offset_t *addr,
int docow, error, rv, try;
bool curmap;
- rangelock_cookie_assert(rl_cookie, RA_LOCKED);
+ rangelock_cookie_assert(rl_cookie, RCA_LOCKED);
if (shmfd->shm_lp_psind == 0)
return (EINVAL);