Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys kern: Nix mutex_owner.



details:   https://anonhg.NetBSD.org/src/rev/b2c1727c87e9
branches:  trunk
changeset: 374238:b2c1727c87e9
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Apr 12 06:35:40 2023 +0000

description:
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

diffstat:

 external/cddl/osnet/dist/uts/common/fs/zfs/spa.c |   2 +-
 sys/kern/kern_mutex.c                            |  19 +++++++++++--------
 sys/rump/librump/rumpkern/locks.c                |  13 +++----------
 sys/rump/librump/rumpkern/locks_up.c             |  12 ++----------
 sys/sys/mutex.h                                  |   3 +--
 5 files changed, 18 insertions(+), 31 deletions(-)

diffs (162 lines):

diff -r 21dcc661e042 -r b2c1727c87e9 external/cddl/osnet/dist/uts/common/fs/zfs/spa.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/spa.c  Wed Apr 12 06:35:26 2023 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/spa.c  Wed Apr 12 06:35:40 2023 +0000
@@ -3140,7 +3140,7 @@ spa_open_common(const char *pool, spa_t 
         * 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;
        }
diff -r 21dcc661e042 -r b2c1727c87e9 sys/kern/kern_mutex.c
--- a/sys/kern/kern_mutex.c     Wed Apr 12 06:35:26 2023 +0000
+++ b/sys/kern/kern_mutex.c     Wed Apr 12 06:35:40 2023 +0000
@@ -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 @@ MUTEX_RELEASE(kmutex_t *mtx)
 __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, 
  *     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);
diff -r 21dcc661e042 -r b2c1727c87e9 sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Wed Apr 12 06:35:26 2023 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Wed Apr 12 06:35:40 2023 +0000
@@ -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>
@@ -215,17 +215,10 @@ 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))
diff -r 21dcc661e042 -r b2c1727c87e9 sys/rump/librump/rumpkern/locks_up.c
--- a/sys/rump/librump/rumpkern/locks_up.c      Wed Apr 12 06:35:26 2023 +0000
+++ b/sys/rump/librump/rumpkern/locks_up.c      Wed Apr 12 06:35:40 2023 +0000
@@ -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;
diff -r 21dcc661e042 -r b2c1727c87e9 sys/sys/mutex.h
--- a/sys/sys/mutex.h   Wed Apr 12 06:35:26 2023 +0000
+++ b/sys/sys/mutex.h   Wed Apr 12 06:35:40 2023 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index