CVS commit: src/sys/kern

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:52:05 UTC 2022

Modified Files:
src/sys/kern: sys_select.c

Log Message:
select(9): Use membar_acquire/release and atomic_store_release.

No store-before-load ordering here -- this was obviously always
intended to be load-before-load/store all along.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/kern/sys_select.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_select.c
diff -u src/sys/kern/sys_select.c:1.58 src/sys/kern/sys_select.c:1.59
--- src/sys/kern/sys_select.c:1.58	Sat Feb 12 15:51:29 2022
+++ src/sys/kern/sys_select.c	Sat Apr  9 23:52:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_select.c,v 1.58 2022/02/12 15:51:29 thorpej Exp $	*/
+/*	$NetBSD: sys_select.c,v 1.59 2022/04/09 23:52:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2019, 2020 The NetBSD Foundation, Inc.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.58 2022/02/12 15:51:29 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.59 2022/04/09 23:52:05 riastradh Exp $");
 
 #include 
 #include 
@@ -282,7 +282,7 @@ sel_do_scan(const char *opname, void *fd
 			l->l_selflag = SEL_SCANNING;
 		}
 		ncoll = sc->sc_ncoll;
-		membar_exit();
+		membar_release();
 
 		if (opname == selop_select) {
 			error = selscan((char *)fds, nf, ni, retval);
@@ -653,7 +653,7 @@ selrecord(lwp_t *selector, struct selinf
 		 * barrier to ensure that we access sel_lwp (above) before
 		 * other fields - this guards against a call to selclear().
 		 */
-		membar_enter();
+		membar_acquire();
 		sip->sel_lwp = selector;
 		SLIST_INSERT_HEAD(>l_selwait, sip, sel_chain);
 		/* Copy the argument, which is for selnotify(). */
@@ -872,9 +872,8 @@ selclear(void)
 		 * globally visible.
 		 */
 		next = SLIST_NEXT(sip, sel_chain);
-		membar_exit();
 		/* Release the record for another named waiter to use. */
-		sip->sel_lwp = NULL;
+		atomic_store_release(>sel_lwp, NULL);
 	}
 	mutex_spin_exit(lock);
 }



CVS commit: src/sys

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:52:23 UTC 2022

Modified Files:
src/sys/kern: uipc_socket.c uipc_socket2.c uipc_usrreq.c
src/sys/sys: socketvar.h

Log Message:
unix(4): Convert membar_exit to membar_release.

Use atomic_load_consume or atomic_load_relaxed where necessary.

Comment on why unlocked nonatomic access is valid where it is done.


To generate a diff of this commit:
cvs rdiff -u -r1.301 -r1.302 src/sys/kern/uipc_socket.c
cvs rdiff -u -r1.140 -r1.141 src/sys/kern/uipc_socket2.c
cvs rdiff -u -r1.201 -r1.202 src/sys/kern/uipc_usrreq.c
cvs rdiff -u -r1.164 -r1.165 src/sys/sys/socketvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:32:53 UTC 2022

Modified Files:
src/common/lib/libc/arch/aarch64/atomic: membar_ops.S
src/common/lib/libc/arch/alpha/atomic: membar_ops.S
src/common/lib/libc/arch/arm/atomic: membar_ops.S
src/common/lib/libc/arch/hppa/atomic: membar_ops.S
src/common/lib/libc/arch/i386/atomic: atomic.S
src/common/lib/libc/arch/ia64/atomic: atomic.S
src/common/lib/libc/arch/mips/atomic: membar_ops.S
src/common/lib/libc/arch/or1k/atomic: membar_ops.S
src/common/lib/libc/arch/powerpc/atomic: membar_ops.S
src/common/lib/libc/arch/riscv/atomic: membar_ops.S
src/common/lib/libc/arch/sparc/atomic: membar_ops.S
src/common/lib/libc/arch/sparc64/atomic: membar_ops.S
src/common/lib/libc/arch/x86_64/atomic: atomic.S
src/common/lib/libc/atomic: membar_ops_nop.c
src/distrib/sets/lists/comp: mi
src/lib/libc/atomic: Makefile.inc membar_ops.3
src/share/man/man9: atomic_loadstore.9
src/sys/sys: atomic.h
src/tests/lib/libc/membar: t_dekker.c t_spinlock.c

Log Message:
Introduce membar_acquire/release.  Deprecate membar_enter/exit.

The names membar_enter/exit were unclear, and the documentation of
membar_enter has disagreed with the implementations on sparc,
powerpc, and even x86(!) for the entire time it has been in NetBSD.

The terms `acquire' and `release' are ubiquitous in the literature
today, and have been adopted in the C and C++ standards to mean
load-before-load/store and load/store-before-store, respectively,
which are exactly the orderings required by acquiring and releasing a
mutex, as well as other useful applications like decrementing a
reference count and then freeing the underlying object if it went to
zero.

Originally I proposed changing one word in the documentation for
membar_enter to make it load-before-load/store instead of
store-before-load/store, i.e., to make it an acquire barrier.  I
proposed this on the grounds that

(a) all implementations guarantee load-before-load/store,
(b) some implementations fail to guarantee store-before-load/store,
and
(c) all uses in-tree assume load-before-load/store.

I verified parts (a) and (b) (except, for (a), powerpc didn't even
guarantee load-before-load/store -- isync isn't necessarily enough;
need lwsync in general -- but it _almost_ did, and it certainly didn't
guarantee store-before-load/store).

Part (c) might not be correct, however: under the mistaken assumption
that atomic-r/m/w then membar-w/rw is equivalent to atomic-r/m/w then
membar-r/rw, I only audited the cases of membar_enter that _aren't_
immediately after an atomic-r/m/w.  All of those cases assume
load-before-load/store.  But my assumption was wrong -- there are
cases of atomic-r/m/w then membar-w/rw that would be broken by
changing to atomic-r/m/w then membar-r/rw:

https://mail-index.netbsd.org/tech-kern/2022/03/29/msg028044.html

Furthermore, the name membar_enter has been adopted in other places
like OpenBSD where it actually does follow the documentation and
guarantee store-before-load/store, even if that order is not useful.
So the name membar_enter currently lives in a bad place where it
means either of two things -- r/rw or w/rw.

With this change, we deprecate membar_enter/exit, introduce
membar_acquire/release as better names for the useful pair (r/rw and
rw/w), and make sure the implementation of membar_enter guarantees
both what was documented _and_ what was implemented, making it an
alias for membar_sync.

While here, rework all of the membar_* definitions and aliases.  The
new logic follows a rule to make it easier to audit:

membar_X is defined as an alias for membar_Y iff membar_X is
guaranteed by membar_Y.

The `no stronger than' relation is (the transitive closure of):

- membar_consumer (r/r) is guaranteed by membar_acquire (r/rw)
- membar_producer (w/w) is guaranteed by membar_release (rw/w)
- membar_acquire (r/rw) is guaranteed by membar_sync (rw/rw)
- membar_release (rw/w) is guaranteed by membar_sync (rw/rw)

And, for the deprecated membars:

- membar_enter (whether r/rw, w/rw, or rw/rw) is guaranteed by
  membar_sync (rw/rw)
- membar_exit (rw/w) is guaranteed by membar_release (rw/w)

(membar_exit is identical to membar_release, but the name is
deprecated.)

Finally, while here, annotate some of the instructions with their
semantics.  For powerpc, leave an essay with citations on the
unfortunate but -- as far as I can tell -- necessary decision to use
lwsync, not isync, for membar_acquire and membar_consumer.

Also add membar(3) and atomic(3) man page links.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/arch/aarch64/atomic/membar_ops.S
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/arch/alpha/atomic/membar_ops.S
cvs rdiff -u -r1.9 -r1.10 src/common/lib/libc/arch/arm/atomic/membar_ops.S
cvs rdiff -u -r1.2 -r1.3 

CVS commit: src

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:32:53 UTC 2022

Modified Files:
src/common/lib/libc/arch/aarch64/atomic: membar_ops.S
src/common/lib/libc/arch/alpha/atomic: membar_ops.S
src/common/lib/libc/arch/arm/atomic: membar_ops.S
src/common/lib/libc/arch/hppa/atomic: membar_ops.S
src/common/lib/libc/arch/i386/atomic: atomic.S
src/common/lib/libc/arch/ia64/atomic: atomic.S
src/common/lib/libc/arch/mips/atomic: membar_ops.S
src/common/lib/libc/arch/or1k/atomic: membar_ops.S
src/common/lib/libc/arch/powerpc/atomic: membar_ops.S
src/common/lib/libc/arch/riscv/atomic: membar_ops.S
src/common/lib/libc/arch/sparc/atomic: membar_ops.S
src/common/lib/libc/arch/sparc64/atomic: membar_ops.S
src/common/lib/libc/arch/x86_64/atomic: atomic.S
src/common/lib/libc/atomic: membar_ops_nop.c
src/distrib/sets/lists/comp: mi
src/lib/libc/atomic: Makefile.inc membar_ops.3
src/share/man/man9: atomic_loadstore.9
src/sys/sys: atomic.h
src/tests/lib/libc/membar: t_dekker.c t_spinlock.c

Log Message:
Introduce membar_acquire/release.  Deprecate membar_enter/exit.

The names membar_enter/exit were unclear, and the documentation of
membar_enter has disagreed with the implementations on sparc,
powerpc, and even x86(!) for the entire time it has been in NetBSD.

The terms `acquire' and `release' are ubiquitous in the literature
today, and have been adopted in the C and C++ standards to mean
load-before-load/store and load/store-before-store, respectively,
which are exactly the orderings required by acquiring and releasing a
mutex, as well as other useful applications like decrementing a
reference count and then freeing the underlying object if it went to
zero.

Originally I proposed changing one word in the documentation for
membar_enter to make it load-before-load/store instead of
store-before-load/store, i.e., to make it an acquire barrier.  I
proposed this on the grounds that

(a) all implementations guarantee load-before-load/store,
(b) some implementations fail to guarantee store-before-load/store,
and
(c) all uses in-tree assume load-before-load/store.

I verified parts (a) and (b) (except, for (a), powerpc didn't even
guarantee load-before-load/store -- isync isn't necessarily enough;
need lwsync in general -- but it _almost_ did, and it certainly didn't
guarantee store-before-load/store).

Part (c) might not be correct, however: under the mistaken assumption
that atomic-r/m/w then membar-w/rw is equivalent to atomic-r/m/w then
membar-r/rw, I only audited the cases of membar_enter that _aren't_
immediately after an atomic-r/m/w.  All of those cases assume
load-before-load/store.  But my assumption was wrong -- there are
cases of atomic-r/m/w then membar-w/rw that would be broken by
changing to atomic-r/m/w then membar-r/rw:

https://mail-index.netbsd.org/tech-kern/2022/03/29/msg028044.html

Furthermore, the name membar_enter has been adopted in other places
like OpenBSD where it actually does follow the documentation and
guarantee store-before-load/store, even if that order is not useful.
So the name membar_enter currently lives in a bad place where it
means either of two things -- r/rw or w/rw.

With this change, we deprecate membar_enter/exit, introduce
membar_acquire/release as better names for the useful pair (r/rw and
rw/w), and make sure the implementation of membar_enter guarantees
both what was documented _and_ what was implemented, making it an
alias for membar_sync.

While here, rework all of the membar_* definitions and aliases.  The
new logic follows a rule to make it easier to audit:

membar_X is defined as an alias for membar_Y iff membar_X is
guaranteed by membar_Y.

The `no stronger than' relation is (the transitive closure of):

- membar_consumer (r/r) is guaranteed by membar_acquire (r/rw)
- membar_producer (w/w) is guaranteed by membar_release (rw/w)
- membar_acquire (r/rw) is guaranteed by membar_sync (rw/rw)
- membar_release (rw/w) is guaranteed by membar_sync (rw/rw)

And, for the deprecated membars:

- membar_enter (whether r/rw, w/rw, or rw/rw) is guaranteed by
  membar_sync (rw/rw)
- membar_exit (rw/w) is guaranteed by membar_release (rw/w)

(membar_exit is identical to membar_release, but the name is
deprecated.)

Finally, while here, annotate some of the instructions with their
semantics.  For powerpc, leave an essay with citations on the
unfortunate but -- as far as I can tell -- necessary decision to use
lwsync, not isync, for membar_acquire and membar_consumer.

Also add membar(3) and atomic(3) man page links.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/arch/aarch64/atomic/membar_ops.S
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/arch/alpha/atomic/membar_ops.S
cvs rdiff -u -r1.9 -r1.10 src/common/lib/libc/arch/arm/atomic/membar_ops.S
cvs rdiff -u -r1.2 -r1.3 

CVS commit: src/sys

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:38:33 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/arm/arm32: pmap.c
src/sys/arch/hppa/hppa: pmap.c
src/sys/arch/ia64/ia64: pmap.c
src/sys/arch/powerpc/oea: pmap.c
src/sys/arch/sparc/sparc: pmap.c
src/sys/arch/sparc64/sparc64: pmap.c
src/sys/dev/hyperv: vmbus.c
src/sys/dev/marvell: mvxpsec.c
src/sys/dev/scsipi: atapiconf.c scsiconf.c scsipi_base.c
src/sys/external/bsd/drm2/linux: linux_stop_machine.c
src/sys/kern: kern_auth.c kern_exec.c kern_mutex_obj.c kern_resource.c
kern_rwlock_obj.c kern_sig.c subr_kcpuset.c sys_futex.c uipc_mbuf.c
vfs_cwd.c vfs_mount.c vfs_vnode.c vfs_wapbl.c
src/sys/net: if.c
src/sys/net/npf: npf_nat.c npf_rproc.c npf_tableset.c
src/sys/uvm: uvm_aobj.c uvm_map.c
src/sys/uvm/pmap: pmap.c

Log Message:
sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.306 -r1.307 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.435 -r1.436 src/sys/arch/arm/arm32/pmap.c
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/hppa/hppa/pmap.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/ia64/ia64/pmap.c
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/powerpc/oea/pmap.c
cvs rdiff -u -r1.376 -r1.377 src/sys/arch/sparc/sparc/pmap.c
cvs rdiff -u -r1.315 -r1.316 src/sys/arch/sparc64/sparc64/pmap.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/hyperv/vmbus.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/marvell/mvxpsec.c
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/scsipi/atapiconf.c
cvs rdiff -u -r1.300 -r1.301 src/sys/dev/scsipi/scsiconf.c
cvs rdiff -u -r1.188 -r1.189 src/sys/dev/scsipi/scsipi_base.c
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/linux/linux_stop_machine.c
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_auth.c
cvs rdiff -u -r1.516 -r1.517 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.8 -r1.9 src/sys/kern/kern_mutex_obj.c
cvs rdiff -u -r1.188 -r1.189 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.6 -r1.7 src/sys/kern/kern_rwlock_obj.c
cvs rdiff -u -r1.403 -r1.404 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_kcpuset.c
cvs rdiff -u -r1.16 -r1.17 src/sys/kern/sys_futex.c
cvs rdiff -u -r1.245 -r1.246 src/sys/kern/uipc_mbuf.c
cvs rdiff -u -r1.7 -r1.8 src/sys/kern/vfs_cwd.c
cvs rdiff -u -r1.92 -r1.93 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/vfs_wapbl.c
cvs rdiff -u -r1.502 -r1.503 src/sys/net/if.c
cvs rdiff -u -r1.51 -r1.52 src/sys/net/npf/npf_nat.c
cvs rdiff -u -r1.21 -r1.22 src/sys/net/npf/npf_rproc.c
cvs rdiff -u -r1.37 -r1.38 src/sys/net/npf/npf_tableset.c
cvs rdiff -u -r1.154 -r1.155 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.392 -r1.393 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.63 -r1.64 src/sys/uvm/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:38:33 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c
src/sys/arch/alpha/alpha: pmap.c
src/sys/arch/arm/arm32: pmap.c
src/sys/arch/hppa/hppa: pmap.c
src/sys/arch/ia64/ia64: pmap.c
src/sys/arch/powerpc/oea: pmap.c
src/sys/arch/sparc/sparc: pmap.c
src/sys/arch/sparc64/sparc64: pmap.c
src/sys/dev/hyperv: vmbus.c
src/sys/dev/marvell: mvxpsec.c
src/sys/dev/scsipi: atapiconf.c scsiconf.c scsipi_base.c
src/sys/external/bsd/drm2/linux: linux_stop_machine.c
src/sys/kern: kern_auth.c kern_exec.c kern_mutex_obj.c kern_resource.c
kern_rwlock_obj.c kern_sig.c subr_kcpuset.c sys_futex.c uipc_mbuf.c
vfs_cwd.c vfs_mount.c vfs_vnode.c vfs_wapbl.c
src/sys/net: if.c
src/sys/net/npf: npf_nat.c npf_rproc.c npf_tableset.c
src/sys/uvm: uvm_aobj.c uvm_map.c
src/sys/uvm/pmap: pmap.c

Log Message:
sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.306 -r1.307 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.435 -r1.436 src/sys/arch/arm/arm32/pmap.c
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/hppa/hppa/pmap.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/ia64/ia64/pmap.c
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/powerpc/oea/pmap.c
cvs rdiff -u -r1.376 -r1.377 src/sys/arch/sparc/sparc/pmap.c
cvs rdiff -u -r1.315 -r1.316 src/sys/arch/sparc64/sparc64/pmap.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/hyperv/vmbus.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/marvell/mvxpsec.c
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/scsipi/atapiconf.c
cvs rdiff -u -r1.300 -r1.301 src/sys/dev/scsipi/scsiconf.c
cvs rdiff -u -r1.188 -r1.189 src/sys/dev/scsipi/scsipi_base.c
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/linux/linux_stop_machine.c
cvs rdiff -u -r1.80 -r1.81 src/sys/kern/kern_auth.c
cvs rdiff -u -r1.516 -r1.517 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.8 -r1.9 src/sys/kern/kern_mutex_obj.c
cvs rdiff -u -r1.188 -r1.189 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.6 -r1.7 src/sys/kern/kern_rwlock_obj.c
cvs rdiff -u -r1.403 -r1.404 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_kcpuset.c
cvs rdiff -u -r1.16 -r1.17 src/sys/kern/sys_futex.c
cvs rdiff -u -r1.245 -r1.246 src/sys/kern/uipc_mbuf.c
cvs rdiff -u -r1.7 -r1.8 src/sys/kern/vfs_cwd.c
cvs rdiff -u -r1.92 -r1.93 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.111 -r1.112 src/sys/kern/vfs_wapbl.c
cvs rdiff -u -r1.502 -r1.503 src/sys/net/if.c
cvs rdiff -u -r1.51 -r1.52 src/sys/net/npf/npf_nat.c
cvs rdiff -u -r1.21 -r1.22 src/sys/net/npf/npf_rproc.c
cvs rdiff -u -r1.37 -r1.38 src/sys/net/npf/npf_tableset.c
cvs rdiff -u -r1.154 -r1.155 src/sys/uvm/uvm_aobj.c
cvs rdiff -u -r1.392 -r1.393 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.63 -r1.64 src/sys/uvm/pmap/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.132 src/sys/arch/aarch64/aarch64/pmap.c:1.133
--- src/sys/arch/aarch64/aarch64/pmap.c:1.132	Sat Apr  2 11:16:06 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sat Apr  9 23:38:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.132 2022/04/02 11:16:06 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.133 2022/04/09 23:38:31 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.132 2022/04/02 11:16:06 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.133 2022/04/09 23:38:31 riastradh Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1651,11 +1651,11 @@ pmap_destroy(struct pmap *pm)
 	if (pm == pmap_kernel())
 		panic("cannot destroy kernel pmap");
 
-	membar_exit();
+	membar_release();
 	refcnt = atomic_dec_uint_nv(>pm_refcnt);
 	if (refcnt > 0)
 		return;
-	membar_enter();
+	membar_acquire();
 
 	KASSERT(LIST_EMPTY(>pm_pvlist));
 	pmap_tlb_asid_release_all(pm);

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.306 src/sys/arch/alpha/alpha/pmap.c:1.307
--- src/sys/arch/alpha/alpha/pmap.c:1.306	Sat Apr  9 23:36:22 2022
+++ src/sys/arch/alpha/alpha/pmap.c	Sat Apr  9 23:38:31 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.306 2022/04/09 23:36:22 riastradh Exp $ */
+/* $NetBSD: pmap.c,v 1.307 2022/04/09 23:38:31 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 

CVS commit: src/common/lib/libc/atomic

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:38:57 UTC 2022

Modified Files:
src/common/lib/libc/atomic: atomic_load.c atomic_store.c

Log Message:
libc/atomic: Fix membars in __atomic_load/store_* stubs.

- membar_enter/exit ordering was backwards.
- membar_enter doesn't make any sense for load anyway.
- Switch to membar_release for store and membar_acquire for load.

The only sensible orderings for a simple load or store are acquire or
release, respectively, or sequential consistency.  This never
provided correct sequential consistency before -- we should really
make it conditional on memmodel but I don't know offhand what the
values of memmodel might be and this is at least better than before.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/atomic/atomic_load.c \
src/common/lib/libc/atomic/atomic_store.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/common/lib/libc/atomic

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:38:57 UTC 2022

Modified Files:
src/common/lib/libc/atomic: atomic_load.c atomic_store.c

Log Message:
libc/atomic: Fix membars in __atomic_load/store_* stubs.

- membar_enter/exit ordering was backwards.
- membar_enter doesn't make any sense for load anyway.
- Switch to membar_release for store and membar_acquire for load.

The only sensible orderings for a simple load or store are acquire or
release, respectively, or sequential consistency.  This never
provided correct sequential consistency before -- we should really
make it conditional on memmodel but I don't know offhand what the
values of memmodel might be and this is at least better than before.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/atomic/atomic_load.c \
src/common/lib/libc/atomic/atomic_store.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/atomic/atomic_load.c
diff -u src/common/lib/libc/atomic/atomic_load.c:1.3 src/common/lib/libc/atomic/atomic_load.c:1.4
--- src/common/lib/libc/atomic/atomic_load.c:1.3	Mon Sep  7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_load.c	Sat Apr  9 23:38:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atomic_load.c,v 1.3 2020/09/07 00:52:19 mrg Exp $	*/
+/*	$NetBSD: atomic_load.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: atomic_load.c,v 1.3 2020/09/07 00:52:19 mrg Exp $");
+__RCSID("$NetBSD: atomic_load.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $");
 
 #include "atomic_op_namespace.h"
 
@@ -40,9 +40,8 @@ uint ## b ## _t \
 __atomic_load_ ## n(const volatile void *ptr, int memmodel) \
 { \
 	uint## b ##_t val; \
-	membar_enter(); \
 	val = *(const volatile uint ## b ## _t *)ptr; \
-	membar_exit(); \
+	membar_acquire(); \
 	return val; \
 }
 
Index: src/common/lib/libc/atomic/atomic_store.c
diff -u src/common/lib/libc/atomic/atomic_store.c:1.3 src/common/lib/libc/atomic/atomic_store.c:1.4
--- src/common/lib/libc/atomic/atomic_store.c:1.3	Mon Sep  7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_store.c	Sat Apr  9 23:38:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atomic_store.c,v 1.3 2020/09/07 00:52:19 mrg Exp $	*/
+/*	$NetBSD: atomic_store.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: atomic_store.c,v 1.3 2020/09/07 00:52:19 mrg Exp $");
+__RCSID("$NetBSD: atomic_store.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $");
 
 #include "atomic_op_namespace.h"
 
@@ -40,9 +40,8 @@ void \
 __atomic_store_ ## n(volatile void *ptr, uint ## b ## _t val, \
  int memmodel) \
 { \
-	membar_enter(); \
+	membar_release(); \
 	*(volatile uint ## b ## _t *)ptr = val; \
-	membar_exit(); \
 }
 
 atomic_store_n(1, 8)



CVS commit: src/libexec/ld.elf_so

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:39:07 UTC 2022

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
rtld: Convert membar_exit/enter to membar_release/acquire.

These are basic CAS-based locking primitives needing release and
acquire semantics, nothing fancy here -- except the membar_sync parts
which are questionable but not relevant to the present audit.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.210 src/libexec/ld.elf_so/rtld.c:1.211
--- src/libexec/ld.elf_so/rtld.c:1.210	Sat Dec  4 14:39:08 2021
+++ src/libexec/ld.elf_so/rtld.c	Sat Apr  9 23:39:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.211 2022/04/09 23:39:07 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.211 2022/04/09 23:39:07 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -1682,7 +1682,7 @@ _rtld_shared_enter(void)
 			/* Yes, so increment use counter */
 			if (atomic_cas_uint(&_rtld_mutex, cur, cur + 1) != cur)
 continue;
-			membar_enter();
+			membar_acquire();
 			return;
 		}
 		/*
@@ -1728,7 +1728,7 @@ _rtld_shared_exit(void)
 	 * Wakeup LWPs waiting for an exclusive lock if this is the last
 	 * LWP on the shared lock.
 	 */
-	membar_exit();
+	membar_release();
 	if (atomic_dec_uint_nv(&_rtld_mutex))
 		return;
 	membar_sync();
@@ -1750,7 +1750,7 @@ _rtld_exclusive_enter(sigset_t *mask)
 
 	for (;;) {
 		if (atomic_cas_uint(&_rtld_mutex, 0, locked_value) == 0) {
-			membar_enter();
+			membar_acquire();
 			break;
 		}
 		waiter = atomic_swap_uint(&_rtld_waiter_exclusive, self);
@@ -1774,7 +1774,7 @@ _rtld_exclusive_exit(sigset_t *mask)
 {
 	lwpid_t waiter;
 
-	membar_exit();
+	membar_release();
 	_rtld_mutex = 0;
 	membar_sync();
 	if ((waiter = _rtld_waiter_exclusive) != 0)



CVS commit: src/sys/arch/alpha/alpha

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:39:18 UTC 2022

Modified Files:
src/sys/arch/alpha/alpha: cpu.c

Log Message:
alpha: Convert cpu_iccb_send from membar_exit to membar_release.

XXX Maybe this should really use alpha_mb, since it's not writing to
normal MI-type memory so technically the membr_* semantics doesn't
apply?


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/alpha/alpha/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/alpha/alpha

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:39:18 UTC 2022

Modified Files:
src/sys/arch/alpha/alpha: cpu.c

Log Message:
alpha: Convert cpu_iccb_send from membar_exit to membar_release.

XXX Maybe this should really use alpha_mb, since it's not writing to
normal MI-type memory so technically the membr_* semantics doesn't
apply?


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/alpha/alpha/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/cpu.c
diff -u src/sys/arch/alpha/alpha/cpu.c:1.105 src/sys/arch/alpha/alpha/cpu.c:1.106
--- src/sys/arch/alpha/alpha/cpu.c:1.105	Sun Feb 27 14:17:10 2022
+++ src/sys/arch/alpha/alpha/cpu.c	Sat Apr  9 23:39:18 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.105 2022/02/27 14:17:10 riastradh Exp $ */
+/* $NetBSD: cpu.c,v 1.106 2022/04/09 23:39:18 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2020 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.105 2022/02/27 14:17:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.106 2022/04/09 23:39:18 riastradh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -887,7 +887,7 @@ cpu_iccb_send(long cpu_id, const char *m
 	 */
 	strcpy(pcsp->pcs_iccb.iccb_rxbuf, msg);
 	pcsp->pcs_iccb.iccb_rxlen = strlen(msg);
-	membar_exit();
+	membar_release();
 	atomic_or_ulong(>rpb_rxrdy, cpumask);
 
 	/* Wait for the message to be received. */



CVS commit: src/libexec/ld.elf_so

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:39:07 UTC 2022

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
rtld: Convert membar_exit/enter to membar_release/acquire.

These are basic CAS-based locking primitives needing release and
acquire semantics, nothing fancy here -- except the membar_sync parts
which are questionable but not relevant to the present audit.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/audio

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:35:58 UTC 2022

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
audio(4): Use membar_acquire, not membar_enter.

Cheaper and adequate to make an atomic_swap into a load-acquire.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/audio/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.122 src/sys/dev/audio/audio.c:1.123
--- src/sys/dev/audio/audio.c:1.122	Thu Mar 31 19:30:15 2022
+++ src/sys/dev/audio/audio.c	Sat Apr  9 23:35:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.122 2022/03/31 19:30:15 pgoyette Exp $	*/
+/*	$NetBSD: audio.c,v 1.123 2022/04/09 23:35:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.122 2022/03/31 19:30:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.123 2022/04/09 23:35:58 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -316,7 +316,7 @@ audio_mlog_flush(void)
 	/* Nothing to do if already in use ? */
 	if (atomic_swap_32(_inuse, 1) == 1)
 		return;
-	membar_enter();
+	membar_acquire();
 
 	int rpage = mlog_wpage;
 	mlog_wpage ^= 1;
@@ -353,7 +353,7 @@ audio_mlog_printf(const char *fmt, ...)
 		mlog_drop++;
 		return;
 	}
-	membar_enter();
+	membar_acquire();
 
 	va_start(ap, fmt);
 	len = vsnprintf(
@@ -1684,7 +1684,7 @@ audio_track_lock_tryenter(audio_track_t 
 
 	if (atomic_swap_uint(>lock, 1) != 0)
 		return false;
-	membar_enter();
+	membar_acquire();
 	return true;
 }
 



CVS commit: src/sys/dev/audio

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:35:58 UTC 2022

Modified Files:
src/sys/dev/audio: audio.c

Log Message:
audio(4): Use membar_acquire, not membar_enter.

Cheaper and adequate to make an atomic_swap into a load-acquire.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/audio/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/alpha/alpha

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:36:22 UTC 2022

Modified Files:
src/sys/arch/alpha/alpha: pmap.c

Log Message:
alpha: Omit needless membar in pmap_reference.

If the pmap is published enough for us to obtain a reference to it
then there's no membar needed.  If it's not then something else is
wrong and we can't use pmap_reference here anyway.  Membars are
needed only on the destruction side to make sure all use, by any
thread, happens-before all freeing in the last user thread.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/arch/alpha/alpha/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/alpha/alpha

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:36:22 UTC 2022

Modified Files:
src/sys/arch/alpha/alpha: pmap.c

Log Message:
alpha: Omit needless membar in pmap_reference.

If the pmap is published enough for us to obtain a reference to it
then there's no membar needed.  If it's not then something else is
wrong and we can't use pmap_reference here anyway.  Membars are
needed only on the destruction side to make sure all use, by any
thread, happens-before all freeing in the last user thread.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/arch/alpha/alpha/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.305 src/sys/arch/alpha/alpha/pmap.c:1.306
--- src/sys/arch/alpha/alpha/pmap.c:1.305	Sat Mar 12 15:32:31 2022
+++ src/sys/arch/alpha/alpha/pmap.c	Sat Apr  9 23:36:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.305 2022/03/12 15:32:31 riastradh Exp $ */
+/* $NetBSD: pmap.c,v 1.306 2022/04/09 23:36:22 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.305 2022/03/12 15:32:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.306 2022/04/09 23:36:22 riastradh Exp $");
 
 #include 
 #include 
@@ -1706,7 +1706,6 @@ pmap_reference(pmap_t pmap)
 
 	newcount = atomic_inc_uint_nv(>pm_count);
 	KASSERT(newcount != 0);
-	PMAP_MP(membar_enter());
 }
 
 /*



CVS commit: src/sys/external/bsd/drm2/linux

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:44:45 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/linux: linux_dma_buf.c linux_dma_fence.c
linux_dma_fence_chain.c

Log Message:
drm: Convert membar_enter/exit stragglers to membar_acquire/release.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/linux/linux_dma_buf.c
cvs rdiff -u -r1.39 -r1.40 src/sys/external/bsd/drm2/linux/linux_dma_fence.c
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/external/bsd/drm2/linux

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:44:45 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/linux: linux_dma_buf.c linux_dma_fence.c
linux_dma_fence_chain.c

Log Message:
drm: Convert membar_enter/exit stragglers to membar_acquire/release.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/external/bsd/drm2/linux/linux_dma_buf.c
cvs rdiff -u -r1.39 -r1.40 src/sys/external/bsd/drm2/linux/linux_dma_fence.c
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/linux/linux_dma_buf.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.14 src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.15
--- src/sys/external/bsd/drm2/linux/linux_dma_buf.c:1.14	Thu Feb 17 01:38:38 2022
+++ src/sys/external/bsd/drm2/linux/linux_dma_buf.c	Sat Apr  9 23:44:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_buf.c,v 1.14 2022/02/17 01:38:38 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_buf.c,v 1.15 2022/04/09 23:44:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.14 2022/02/17 01:38:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_buf.c,v 1.15 2022/04/09 23:44:44 riastradh Exp $");
 
 #include 
 #include 
@@ -160,10 +160,10 @@ void
 dma_buf_put(struct dma_buf *dmabuf)
 {
 
-	membar_exit();
+	membar_release();
 	if (atomic_dec_uint_nv(>db_refcnt) != 0)
 		return;
-	membar_enter();
+	membar_acquire();
 
 	dma_resv_poll_fini(>db_resv_poll);
 	mutex_destroy(>db_lock);

Index: src/sys/external/bsd/drm2/linux/linux_dma_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.39 src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.40
--- src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.39	Sun Dec 19 12:39:40 2021
+++ src/sys/external/bsd/drm2/linux/linux_dma_fence.c	Sat Apr  9 23:44:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_fence.c,v 1.39 2021/12/19 12:39:40 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_fence.c,v 1.40 2022/04/09 23:44:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.39 2021/12/19 12:39:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.40 2022/04/09 23:44:44 riastradh Exp $");
 
 #include 
 #include 
@@ -245,9 +245,9 @@ dma_fence_context_alloc(unsigned n)
 	} S;
 	uint64_t c;
 
-	while (__predict_false(atomic_cas_uint(, 0, 1) != 0))
+	while (__predict_false(atomic_swap_uint(, 1)))
 		SPINLOCK_BACKOFF_HOOK;
-	membar_enter();
+	membar_acquire();
 	c = S.context;
 	S.context += n;
 	atomic_store_release(, 0);

Index: src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c:1.3 src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c:1.4
--- src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c:1.3	Sun Dec 19 12:39:32 2021
+++ src/sys/external/bsd/drm2/linux/linux_dma_fence_chain.c	Sat Apr  9 23:44:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_fence_chain.c,v 1.3 2021/12/19 12:39:32 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_fence_chain.c,v 1.4 2022/04/09 23:44:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence_chain.c,v 1.3 2021/12/19 12:39:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence_chain.c,v 1.4 2022/04/09 23:44:44 riastradh Exp $");
 
 #include 
 
@@ -262,7 +262,7 @@ dma_fence_chain_walk(struct dma_fence *f
 break;
 			splice = NULL;
 		}
-		membar_exit();	/* pairs with dma_fence_get_rcu_safe */
+		membar_release();	/* pairs with dma_fence_get_rcu_safe */
 		if (atomic_cas_ptr(>dfc_prev, prev, splice) == prev)
 			dma_fence_put(prev); /* transferred to splice */
 		else



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:44:25 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: ratelimit.h

Log Message:
linux/ratelimit: Convert to membar_acquire and atomic_store_release.

Simplify while here: atomic_swap is enough, no need for atomic_cas.
(Maybe drm'll run faster on sparcv8 this way...!)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/include/linux/ratelimit.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/external/bsd/drm2/include/linux

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:44:25 UTC 2022

Modified Files:
src/sys/external/bsd/drm2/include/linux: ratelimit.h

Log Message:
linux/ratelimit: Convert to membar_acquire and atomic_store_release.

Simplify while here: atomic_swap is enough, no need for atomic_cas.
(Maybe drm'll run faster on sparcv8 this way...!)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/include/linux/ratelimit.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/ratelimit.h
diff -u src/sys/external/bsd/drm2/include/linux/ratelimit.h:1.5 src/sys/external/bsd/drm2/include/linux/ratelimit.h:1.6
--- src/sys/external/bsd/drm2/include/linux/ratelimit.h:1.5	Sun Dec 19 11:36:57 2021
+++ src/sys/external/bsd/drm2/include/linux/ratelimit.h	Sat Apr  9 23:44:25 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ratelimit.h,v 1.5 2021/12/19 11:36:57 riastradh Exp $	*/
+/*	$NetBSD: ratelimit.h,v 1.6 2022/04/09 23:44:25 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -86,14 +86,13 @@ __ratelimit(struct ratelimit_state *r)
 {
 	int ok;
 
-	if (atomic_cas_uint(>rl_lock, 0, 1)) {
+	if (atomic_swap_uint(>rl_lock, 1)) {
 		ok = false;
 		goto out;
 	}
-	membar_enter();
+	membar_acquire();
 	ok = ppsratecheck(>rl_lasttime, >rl_curpps, r->rl_maxpps);
-	membar_exit();
-	r->rl_lock = 0;
+	atomic_store_release(>rl_lock, 0);
 
 out:	if (!ok)
 		atomic_store_relaxed(>missed, 1);



<    1   2