From owner-svn-src-releng@freebsd.org Thu Sep 21 20:13:05 2017 Return-Path: Delivered-To: svn-src-releng@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EDD0BE1F233; Thu, 21 Sep 2017 20:13:05 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C951A68617; Thu, 21 Sep 2017 20:13:05 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8LKD5dP024258; Thu, 21 Sep 2017 20:13:05 GMT (envelope-from marius@FreeBSD.org) Received: (from marius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8LKD3Of024243; Thu, 21 Sep 2017 20:13:03 GMT (envelope-from marius@FreeBSD.org) Message-Id: <201709212013.v8LKD3Of024243@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marius set sender to marius@FreeBSD.org using -f From: Marius Strobl Date: Thu, 21 Sep 2017 20:13:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-releng@freebsd.org Subject: svn commit: r323872 - in releng/10.4: share/man/man9 sys/kern sys/sys X-SVN-Group: releng X-SVN-Commit-Author: marius X-SVN-Commit-Paths: in releng/10.4: share/man/man9 sys/kern sys/sys X-SVN-Commit-Revision: 323872 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-releng@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the release engineering / security commits to the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Sep 2017 20:13:06 -0000 Author: marius Date: Thu Sep 21 20:13:03 2017 New Revision: 323872 URL: https://svnweb.freebsd.org/changeset/base/323872 Log: MF10: r323870, MFC: r275751 Add _NEW flag to mtx(9), sx(9), rmlock(9) and rwlock(9). A _NEW flag passed to _init_flags() to avoid check for double-init. Approved by: re (gjb) Modified: releng/10.4/share/man/man9/mutex.9 releng/10.4/share/man/man9/rmlock.9 releng/10.4/share/man/man9/rwlock.9 releng/10.4/share/man/man9/sx.9 releng/10.4/sys/kern/kern_mutex.c releng/10.4/sys/kern/kern_rmlock.c releng/10.4/sys/kern/kern_rwlock.c releng/10.4/sys/kern/kern_sx.c releng/10.4/sys/kern/subr_lock.c releng/10.4/sys/sys/lock.h releng/10.4/sys/sys/mutex.h releng/10.4/sys/sys/rmlock.h releng/10.4/sys/sys/rwlock.h releng/10.4/sys/sys/sx.h Directory Properties: releng/10.4/ (props changed) Modified: releng/10.4/share/man/man9/mutex.9 ============================================================================== --- releng/10.4/share/man/man9/mutex.9 Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/share/man/man9/mutex.9 Thu Sep 21 20:13:03 2017 (r323872) @@ -183,13 +183,17 @@ It may contain either or .Dv MTX_SPIN but not both. -See below for additional initialization options. -It is not permissible to pass the same -.Fa mutex -to +If the kernel has been compiled with +.Cd "option INVARIANTS" , .Fn mtx_init -multiple times without intervening calls to -.Fn mtx_destroy . +will assert that the +.Fa mutex +has not been initialized multiple times without intervening calls to +.Fn mtx_destroy +unless the +.Dv MTX_NEW +option is specified. +See below for additional initialization options. .Pp The .Fn mtx_lock @@ -473,6 +477,8 @@ to ignore this lock. Witness should not log messages about duplicate locks being acquired. .It Dv MTX_NOPROFILE Do not profile this lock. +.It Dv MTX_NEW +Do not check for double-init. .El .Ss Lock and Unlock Flags The flags passed to the Modified: releng/10.4/share/man/man9/rmlock.9 ============================================================================== --- releng/10.4/share/man/man9/rmlock.9 Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/share/man/man9/rmlock.9 Thu Sep 21 20:13:03 2017 (r323872) @@ -26,7 +26,7 @@ .\" $FreeBSD$ .\" .\" Based on rwlock.9 man page -.Dd June 25, 2013 +.Dd December 13, 2014 .Dt RMLOCK 9 .Os .Sh NAME @@ -156,6 +156,15 @@ Allow threads to recursively acquire shared locks for .Fa rm . .It Dv RM_SLEEPABLE Create a sleepable read-mostly lock. +.It Dv RM_NEW +If the kernel has been compiled with +.Cd "option INVARIANTS" , +.Fn rm_init_flags +will assert that the +.Fa rm +has not been initialized multiple times without intervening calls to +.Fn rm_destroy +unless this option is specified. .El .It Fn rm_rlock "struct rmlock *rm" "struct rm_priotracker* tracker" Lock Modified: releng/10.4/share/man/man9/rwlock.9 ============================================================================== --- releng/10.4/share/man/man9/rwlock.9 Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/share/man/man9/rwlock.9 Thu Sep 21 20:13:03 2017 (r323872) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 20, 2013 +.Dd December 13, 2014 .Dt RWLOCK 9 .Os .Sh NAME @@ -154,6 +154,15 @@ Do not log any operations for this lock via .It Dv RW_RECURSE Allow threads to recursively acquire exclusive locks for .Fa rw . +.It Dv RW_NEW +If the kernel has been compiled with +.Cd "option INVARIANTS" , +.Fn rw_init_flags +will assert that the +.Fa rw +has not been initialized multiple times without intervening calls to +.Fn rw_destroy +unless this option is specified. .El .It Fn rw_rlock "struct rwlock *rw" Lock Modified: releng/10.4/share/man/man9/sx.9 ============================================================================== --- releng/10.4/share/man/man9/sx.9 Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/share/man/man9/sx.9 Thu Sep 21 20:13:03 2017 (r323872) @@ -142,6 +142,15 @@ Allow threads to recursively acquire exclusive locks f .It Dv SX_QUIET Do not log any operations for this lock via .Xr ktr 4 . +.It Dv SX_NEW +If the kernel has been compiled with +.Cd "options INVARIANTS" , +.Fn sx_init +will assert that the +.Fa sx +has not been initialized multiple times without intervening calls to +.Fn sx_destroy +unless this option is specified. .El .Pp Shared/exclusive locks are destroyed with Modified: releng/10.4/sys/kern/kern_mutex.c ============================================================================== --- releng/10.4/sys/kern/kern_mutex.c Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/kern/kern_mutex.c Thu Sep 21 20:13:03 2017 (r323872) @@ -979,7 +979,7 @@ _mtx_init(volatile uintptr_t *c, const char *name, con m = mtxlock2mtx(c); MPASS((opts & ~(MTX_SPIN | MTX_QUIET | MTX_RECURSE | - MTX_NOWITNESS | MTX_DUPOK | MTX_NOPROFILE)) == 0); + MTX_NOWITNESS | MTX_DUPOK | MTX_NOPROFILE | MTX_NEW)) == 0); ASSERT_ATOMIC_LOAD_PTR(m->mtx_lock, ("%s: mtx_lock not aligned for %s: %p", __func__, name, &m->mtx_lock)); @@ -1005,6 +1005,8 @@ _mtx_init(volatile uintptr_t *c, const char *name, con flags |= LO_DUPOK; if (opts & MTX_NOPROFILE) flags |= LO_NOPROFILE; + if (opts & MTX_NEW) + flags |= LO_NEW; /* Initialize mutex. */ lock_init(&m->lock_object, class, name, type, flags); Modified: releng/10.4/sys/kern/kern_rmlock.c ============================================================================== --- releng/10.4/sys/kern/kern_rmlock.c Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/kern/kern_rmlock.c Thu Sep 21 20:13:03 2017 (r323872) @@ -278,22 +278,28 @@ void rm_init_flags(struct rmlock *rm, const char *name, int opts) { struct lock_class *lc; - int liflags; + int liflags, xflags; liflags = 0; if (!(opts & RM_NOWITNESS)) liflags |= LO_WITNESS; if (opts & RM_RECURSE) liflags |= LO_RECURSABLE; + if (opts & RM_NEW) + liflags |= LO_NEW; rm->rm_writecpus = all_cpus; LIST_INIT(&rm->rm_activeReaders); if (opts & RM_SLEEPABLE) { liflags |= LO_SLEEPABLE; lc = &lock_class_rm_sleepable; - sx_init_flags(&rm->rm_lock_sx, "rmlock_sx", SX_NOWITNESS); + xflags = (opts & RM_NEW ? SX_NEW : 0); + sx_init_flags(&rm->rm_lock_sx, "rmlock_sx", + xflags | SX_NOWITNESS); } else { lc = &lock_class_rm; - mtx_init(&rm->rm_lock_mtx, name, "rmlock_mtx", MTX_NOWITNESS); + xflags = (opts & RM_NEW ? MTX_NEW : 0); + mtx_init(&rm->rm_lock_mtx, name, "rmlock_mtx", + xflags | MTX_NOWITNESS); } lock_init(&rm->lock_object, lc, name, NULL, liflags); } Modified: releng/10.4/sys/kern/kern_rwlock.c ============================================================================== --- releng/10.4/sys/kern/kern_rwlock.c Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/kern/kern_rwlock.c Thu Sep 21 20:13:03 2017 (r323872) @@ -216,7 +216,7 @@ _rw_init_flags(volatile uintptr_t *c, const char *name rw = rwlock2rw(c); MPASS((opts & ~(RW_DUPOK | RW_NOPROFILE | RW_NOWITNESS | RW_QUIET | - RW_RECURSE)) == 0); + RW_RECURSE | RW_NEW)) == 0); ASSERT_ATOMIC_LOAD_PTR(rw->rw_lock, ("%s: rw_lock not aligned for %s: %p", __func__, name, &rw->rw_lock)); @@ -232,6 +232,8 @@ _rw_init_flags(volatile uintptr_t *c, const char *name flags |= LO_RECURSABLE; if (opts & RW_QUIET) flags |= LO_QUIET; + if (opts & RW_NEW) + flags |= LO_NEW; lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags); rw->rw_lock = RW_UNLOCKED; Modified: releng/10.4/sys/kern/kern_sx.c ============================================================================== --- releng/10.4/sys/kern/kern_sx.c Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/kern/kern_sx.c Thu Sep 21 20:13:03 2017 (r323872) @@ -240,7 +240,7 @@ sx_init_flags(struct sx *sx, const char *description, int flags; MPASS((opts & ~(SX_QUIET | SX_RECURSE | SX_NOWITNESS | SX_DUPOK | - SX_NOPROFILE | SX_NOADAPTIVE)) == 0); + SX_NOPROFILE | SX_NOADAPTIVE | SX_NEW)) == 0); ASSERT_ATOMIC_LOAD_PTR(sx->sx_lock, ("%s: sx_lock not aligned for %s: %p", __func__, description, &sx->sx_lock)); @@ -256,6 +256,8 @@ sx_init_flags(struct sx *sx, const char *description, flags |= LO_RECURSABLE; if (opts & SX_QUIET) flags |= LO_QUIET; + if (opts & SX_NEW) + flags |= LO_NEW; flags |= opts & SX_NOADAPTIVE; lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags); Modified: releng/10.4/sys/kern/subr_lock.c ============================================================================== --- releng/10.4/sys/kern/subr_lock.c Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/kern/subr_lock.c Thu Sep 21 20:13:03 2017 (r323872) @@ -76,8 +76,8 @@ lock_init(struct lock_object *lock, struct lock_class int i; /* Check for double-init and zero object. */ - KASSERT(!lock_initalized(lock), ("lock \"%s\" %p already initialized", - name, lock)); + KASSERT(flags & LO_NEW || !lock_initalized(lock), + ("lock \"%s\" %p already initialized", name, lock)); /* Look up lock class to find its index. */ for (i = 0; i < LOCK_CLASS_MAX; i++) Modified: releng/10.4/sys/sys/lock.h ============================================================================== --- releng/10.4/sys/sys/lock.h Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/sys/lock.h Thu Sep 21 20:13:03 2017 (r323872) @@ -83,6 +83,7 @@ struct lock_class { #define LO_IS_VNODE 0x00800000 /* Tell WITNESS about a VNODE lock */ #define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */ #define LO_NOPROFILE 0x10000000 /* Don't profile this lock */ +#define LO_NEW 0x20000000 /* Don't check for double-init */ /* * Lock classes are statically assigned an index into the gobal lock_classes Modified: releng/10.4/sys/sys/mutex.h ============================================================================== --- releng/10.4/sys/sys/mutex.h Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/sys/mutex.h Thu Sep 21 20:13:03 2017 (r323872) @@ -52,6 +52,7 @@ #define MTX_RECURSE 0x00000004 /* Option: lock allowed to recurse */ #define MTX_NOWITNESS 0x00000008 /* Don't do any witness checking. */ #define MTX_NOPROFILE 0x00000020 /* Don't profile this lock */ +#define MTX_NEW 0x00000040 /* Don't check for double-init */ /* * Option flags passed to certain lock/unlock routines, through the use Modified: releng/10.4/sys/sys/rmlock.h ============================================================================== --- releng/10.4/sys/sys/rmlock.h Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/sys/rmlock.h Thu Sep 21 20:13:03 2017 (r323872) @@ -45,6 +45,7 @@ #define RM_NOWITNESS 0x00000001 #define RM_RECURSE 0x00000002 #define RM_SLEEPABLE 0x00000004 +#define RM_NEW 0x00000008 void rm_init(struct rmlock *rm, const char *name); void rm_init_flags(struct rmlock *rm, const char *name, int opts); Modified: releng/10.4/sys/sys/rwlock.h ============================================================================== --- releng/10.4/sys/sys/rwlock.h Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/sys/rwlock.h Thu Sep 21 20:13:03 2017 (r323872) @@ -254,6 +254,7 @@ struct rw_args_flags { #define RW_NOWITNESS 0x04 #define RW_QUIET 0x08 #define RW_RECURSE 0x10 +#define RW_NEW 0x20 /* * The INVARIANTS-enabled rw_assert() functionality. Modified: releng/10.4/sys/sys/sx.h ============================================================================== --- releng/10.4/sys/sys/sx.h Thu Sep 21 19:30:32 2017 (r323871) +++ releng/10.4/sys/sys/sx.h Thu Sep 21 20:13:03 2017 (r323872) @@ -289,6 +289,7 @@ __sx_sunlock(struct sx *sx, const char *file, int line #define SX_QUIET 0x08 #define SX_NOADAPTIVE 0x10 #define SX_RECURSE 0x20 +#define SX_NEW 0x40 /* * Options passed to sx_*lock_hard().