Module Name: src Committed By: martin Date: Wed Nov 20 14:01:59 UTC 2024
Modified Files: src/sys/compat/netbsd32 [netbsd-9]: netbsd32_ioctl.c src/sys/ddb [netbsd-9]: db_xxx.c src/sys/kern [netbsd-9]: kern_descrip.c kern_event.c kern_sig.c subr_exec_fd.c sys_aio.c sys_descrip.c sys_select.c uipc_socket2.c uipc_usrreq.c src/sys/miscfs/fdesc [netbsd-9]: fdesc_vnops.c src/sys/miscfs/procfs [netbsd-9]: procfs_vnops.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #1921): sys/kern/kern_event.c: revision 1.106 sys/kern/sys_select.c: revision 1.51 sys/kern/subr_exec_fd.c: revision 1.10 sys/kern/sys_aio.c: revision 1.46 sys/kern/kern_descrip.c: revision 1.244 sys/kern/kern_descrip.c: revision 1.245 sys/ddb/db_xxx.c: revision 1.72 sys/ddb/db_xxx.c: revision 1.73 sys/miscfs/fdesc/fdesc_vnops.c: revision 1.132 sys/kern/uipc_usrreq.c: revision 1.195 sys/kern/sys_descrip.c: revision 1.36 sys/kern/uipc_usrreq.c: revision 1.196 sys/kern/uipc_socket2.c: revision 1.135 sys/kern/uipc_socket2.c: revision 1.136 sys/kern/kern_sig.c: revision 1.383 sys/kern/kern_sig.c: revision 1.384 sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.107 sys/miscfs/procfs/procfs_vnops.c: revision 1.208 sys/kern/subr_exec_fd.c: revision 1.9 sys/kern/kern_descrip.c: revision 1.252 (all via patch) Load struct filedesc::fd_dt with atomic_load_consume. Exceptions: when fd_refcnt <= 1, or when holding fd_lock. While here: - Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused. => This is used only in fd_close and fd_abort, where it holds. - Move bounds check assertion in fd_putfile to where it matters. - Store fd_dt with atomic_store_release. - Move load of fd_dt under lock in knote_fdclose. - Omit membar_consumer in fdesc_readdir. => atomic_load_consume serves the same purpose now. => Was needed only on alpha anyway. Load struct fdfile::ff_file with atomic_load_consume. Exceptions: when we're only testing whether it's there, not about to dereference it. Note: We do not use atomic_store_release to set it because the preceding mutex_exit should be enough. (That said, it's not clear the mutex_enter/exit is needed unless refcnt > 0 already, in which case maybe it would be a win to switch from the membar implied by mutex_enter to the membar implied by atomic_store_release -- which I would generally expect to be much cheaper. And a little clearer without a long comment.) kern_descrip.c: Fix membars around reference count decrement. In general, the `last one out hit the lights' style of reference counting (as opposed to the `whoever's destroying must wait for pending users to finish' style) requires memory barriers like so: ... usage of resources associated with object ... membar_release(); if (atomic_dec_uint_nv(&obj->refcnt) != 0) return; membar_acquire(); ... freeing of resources associated with object ... This way, all usage happens-before all freeing. This fixes several errors: - fd_close failed to ensure whatever its caller did would happen-before the freeing, in the case where another thread is concurrently trying to close the fd (ff->ff_file == NULL). Fix: Add membar_release before atomic_dec_uint(&ff->ff_refcnt) in that branch. - fd_close failed to ensure all loads its caller had issued will have happened-before the freeing, in the case where the fd is still in use by another thread (fdp->fd_refcnt > 1 and ff->ff_refcnt-- > 0). Fix: Change membar_producer to membar_release before atomic_dec_uint(&ff->ff_refcnt). - fd_close failed to ensure that any usage of fp by other callers would happen-before any freeing it does. Fix: Add membar_acquire after atomic_dec_uint_nv(&ff->ff_refcnt). - fd_free failed to ensure that any usage of fdp by other callers would happen-before any freeing it does. Fix: Add membar_acquire after atomic_dec_uint_nv(&fdp->fd_refcnt). While here, change membar_exit -> membar_release. No semantic change, just updating away from the legacy API. To generate a diff of this commit: cvs rdiff -u -r1.103.2.2 -r1.103.2.3 src/sys/compat/netbsd32/netbsd32_ioctl.c cvs rdiff -u -r1.71 -r1.71.22.1 src/sys/ddb/db_xxx.c cvs rdiff -u -r1.243.4.2 -r1.243.4.3 src/sys/kern/kern_descrip.c cvs rdiff -u -r1.104.4.2 -r1.104.4.3 src/sys/kern/kern_event.c cvs rdiff -u -r1.364.2.9 -r1.364.2.10 src/sys/kern/kern_sig.c cvs rdiff -u -r1.8 -r1.8.4.1 src/sys/kern/subr_exec_fd.c cvs rdiff -u -r1.44 -r1.44.4.1 src/sys/kern/sys_aio.c cvs rdiff -u -r1.33 -r1.33.2.1 src/sys/kern/sys_descrip.c cvs rdiff -u -r1.46 -r1.46.2.1 src/sys/kern/sys_select.c cvs rdiff -u -r1.134.2.2 -r1.134.2.3 src/sys/kern/uipc_socket2.c cvs rdiff -u -r1.194.2.1 -r1.194.2.2 src/sys/kern/uipc_usrreq.c cvs rdiff -u -r1.130.4.1 -r1.130.4.2 src/sys/miscfs/fdesc/fdesc_vnops.c cvs rdiff -u -r1.206.4.2 -r1.206.4.3 src/sys/miscfs/procfs/procfs_vnops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.