kern: Nix mutex_owner.

There is no valid reason to use this except in assertions of the form

	KASSERT(mutex_owner(lock) == curlwp),

which is more obviously spelled as

	KASSERT(mutex_owned(lock)).

Exception: There's one horrible kludge in zfs that abuses this, which
should be eliminated.

XXX kernel revbump -- deleting symbol

PR kern/47114
This commit is contained in:
riastradh 2023-04-12 06:35:40 +00:00
parent a87a5383a9
commit 617315ebb6
5 changed files with 18 additions and 31 deletions

View File

@ -3140,7 +3140,7 @@ spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t *nvpolicy,
* up calling spa_open() again. The real fix is to figure out how to
* avoid dsl_dir_open() calling this in the first place.
*/
if (mutex_owner(&spa_namespace_lock) != curthread) {
if (!mutex_owned(&spa_namespace_lock)) {
mutex_enter(&spa_namespace_lock);
locked = B_TRUE;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_mutex.c,v 1.104 2023/02/24 11:21:28 riastradh Exp $ */
/* $NetBSD: kern_mutex.c,v 1.105 2023/04/12 06:35:40 riastradh Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@ -40,7 +40,7 @@
#define __MUTEX_PRIVATE
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.104 2023/02/24 11:21:28 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.105 2023/04/12 06:35:40 riastradh Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -277,9 +277,10 @@ __strong_alias(mutex_spin_enter,mutex_vector_enter);
__strong_alias(mutex_spin_exit,mutex_vector_exit);
#endif
static void mutex_abort(const char *, size_t, const kmutex_t *,
const char *);
static void mutex_abort(const char *, size_t, volatile const kmutex_t *,
const char *);
static void mutex_dump(const volatile void *, lockop_printer_t);
static lwp_t *mutex_owner(wchan_t);
lockops_t mutex_spin_lockops = {
.lo_name = "Mutex",
@ -298,7 +299,7 @@ syncobj_t mutex_syncobj = {
.sobj_unsleep = turnstile_unsleep,
.sobj_changepri = turnstile_changepri,
.sobj_lendpri = sleepq_lendpri,
.sobj_owner = (void *)mutex_owner,
.sobj_owner = mutex_owner,
};
/*
@ -325,7 +326,8 @@ mutex_dump(const volatile void *cookie, lockop_printer_t pr)
* we ask the compiler to not inline it.
*/
static void __noinline
mutex_abort(const char *func, size_t line, const kmutex_t *mtx, const char *msg)
mutex_abort(const char *func, size_t line, volatile const kmutex_t *mtx,
const char *msg)
{
LOCKDEBUG_ABORT(func, line, mtx, (MUTEX_SPIN_P(mtx->mtx_owner) ?
@ -835,9 +837,10 @@ mutex_owned(const kmutex_t *mtx)
* Return the current owner of an adaptive mutex. Used for
* priority inheritance.
*/
lwp_t *
mutex_owner(const kmutex_t *mtx)
static lwp_t *
mutex_owner(wchan_t wchan)
{
volatile const kmutex_t *mtx = wchan;
MUTEX_ASSERT(mtx, MUTEX_ADAPTIVE_P(mtx->mtx_owner));
return (struct lwp *)MUTEX_OWNER(mtx->mtx_owner);

View File

@ -1,4 +1,4 @@
/* $NetBSD: locks.c,v 1.83 2022/10/26 23:22:22 riastradh Exp $ */
/* $NetBSD: locks.c,v 1.84 2023/04/12 06:35:40 riastradh Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.83 2022/10/26 23:22:22 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.84 2023/04/12 06:35:40 riastradh Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@ -214,18 +214,11 @@ mutex_ownable(const kmutex_t *mtx)
int
mutex_owned(const kmutex_t *mtx)
{
return mutex_owner(mtx) == curlwp;
}
lwp_t *
mutex_owner(const kmutex_t *mtx)
{
struct lwp *l;
rumpuser_mutex_owner(RUMPMTX(mtx), &l);
return l;
return l == curlwp;
}
#define RUMPRW(rw) (*(struct rumpuser_rw **)(rw))

View File

@ -1,4 +1,4 @@
/* $NetBSD: locks_up.c,v 1.11 2020/02/22 21:44:51 ad Exp $ */
/* $NetBSD: locks_up.c,v 1.12 2023/04/12 06:35:40 riastradh Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.11 2020/02/22 21:44:51 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.12 2023/04/12 06:35:40 riastradh Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -164,14 +164,6 @@ mutex_owned(kmutex_t *mtx)
return upm->upm_owner == curlwp;
}
struct lwp *
mutex_owner(kmutex_t *mtx)
{
UPMTX(mtx);
return upm->upm_owner;
}
struct uprw {
struct lwp *uprw_owner;
int uprw_readers;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mutex.h,v 1.26 2022/10/26 23:21:20 riastradh Exp $ */
/* $NetBSD: mutex.h,v 1.27 2023/04/12 06:35:40 riastradh Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@ -199,7 +199,6 @@ int mutex_tryenter(kmutex_t *);
int mutex_owned(const kmutex_t *);
int mutex_ownable(const kmutex_t *);
lwp_t *mutex_owner(const kmutex_t *);
bool mutex_owner_running(const kmutex_t *);
void mutex_obj_init(void);